Engine Reference¶
Backtrader-style advanced event-driven API.
Backtrader-compatible facade backed by tradelearn's backtest engine.
Analyzer ¶
Base analyzer class attached through Cerebro.addanalyzer.
Cerebro ¶
Main orchestrator for backtesting (Backtrader facade).
setcommission ¶
setcommission(commission: float = 0.0, margin: float = 0.0, mult: float = 1.0, comminfo: Any = None, name: str | None = None) -> None
Set commission parameters or a custom CommInfo object.
plot ¶
plot(*args: Any, **kwargs: Any) -> list[Any]
Return market replay charts for the most recent run.
report ¶
report(path: str = 'report.html', benchmark: Any | None = None, sections: Any | None = None) -> Any
Write a Tradelearn report for the most recent run.
OptReturn ¶
Lightweight optimization result returned by Cerebro.run(optreturn=True).
GridSearchResult
dataclass
¶
One grid-search run result.
Indicator ¶
Base class for Engine custom indicators.
Built-in indicators are intentionally not exposed from tradelearn.engine.
Use bt.pta / bt.talib / bt.tdx / bt.tv for built-in vector indicators, or
subclass this class for strategy-specific custom indicators.
Observer ¶
Minimal Backtrader observer base class.
Signal ¶
Wraps any single-line indicator as a signal source.
SignalStrategy ¶
Strategy subclass that auto-trades based on registered signals.
Signals are indicator lines whose current value (> 0 or < 0)
drives entry/exit decisions. Users can still define next() for
custom logic executed after signal processing.
Usage via cerebro.add_signal::
cerebro.add_signal(SIGNAL_LONG, MySignalIndicator, period=20)
Or directly inside __init__::
class MySigStrategy(SignalStrategy):
def __init__(self):
sma = bt.talib.SMA(self.data.close, period=20)
sig = Signal(sma - self.data.close)
self.signal_add(SIGNAL_LONGSHORT, sig)
Sizer ¶
Backtrader-style Sizer with params support.
CommInfoBase ¶
Base class for commission schemes.
DataFeed ¶
Backtrader-style DataFeed with LineSeries magic.
LineSeries ¶
get ¶
get(ago: int = 0, size: int = 1) -> np.ndarray
Return a Backtrader-style trailing window ending at ago.
line.get(size=n) follows Backtrader's strategy helper semantics and
returns a trailing window ending at the addressed cursor.
Missing leading values are omitted.
wrap_indicator ¶
wrap_indicator(values: Any, name: str | None = None) -> Any
Wrap vector indicator output back into Engine line objects.
Order
dataclass
¶
from_request
classmethod
¶
from_request(ref: int, request: OrderRequest, *, data: Any = None) -> Order
Create a backtest runtime order from a broker-neutral request.
to_fill ¶
to_fill(*, qty: float, price: float, commission: float, ts: Timestamp | None = None, broker_oid: str | None = None) -> Fill
Emit a broker-neutral fill event for this backtest order.
Params ¶
Backtrader-style parameter storage object.
Position
dataclass
¶
__call__ ¶
__call__(*args: Any, **kwargs: Any) -> Position
Return self so facade position objects can be used as position().
Strategy ¶
grid_search ¶
grid_search(strategy: type[Strategy], data: DataFrame, param_grid: dict[str, list[Any]], *, mlflow: dict[str, Any] | None = None) -> list[GridSearchResult]
Run a simple strategy parameter grid with nested MLflow runs.