Skip to content

BaseStrategy


class backtide.strategies.base.BaseStrategy()[source]

Abstract base class for all strategies.

Subclass it to create a custom strategy.


Example

from backtide.strategies import BaseStrategy

class MyStrategy(BaseStrategy):
    def __init__(self, threshold=0.02):
        self.threshold = threshold

    def evaluate(self, data, portfolio, state, indicators):
        orders = []
        # Your logic here ...
        return orders


Methods

evaluate Evaluate the strategy and return orders.
log Write a message to the experiment log.


method backtide.strategies.baseevaluate(data, portfolio, state, indicators)[source]

Evaluate the strategy and return orders.

Parameters

data : dict[str, np.array | pd.DataFrame | pl.DataFrame]

Keys are the experiment's symbols and values are the historical OHLCV data available up to the current bar.

portfolio : Portfolio
Current portfolio holdings (cash, positions and open orders).

state : State
Current simulation state.

indicators : dict[str, dict[str, np.array | pd.DataFrame | pl.DataFrame]] | None
The first keys are the indicator names. The second keys are the experiment's symbols. The values are the pre-computed indicator values. None if no indicators were selected.

Returns

list[Order]

Orders to place this tick.



method backtide.strategies.baselog(message, level="info")[source]

Write a message to the experiment log.

Messages appear in the live log viewer while the experiment runs and are persisted to the experiment's logs.txt file.

Example

def evaluate(self, data, portfolio, state, indicators):
    self.log(f"Bar {state.bar_index}: evaluating...")
    ...
Parameters

message : str

The message to log.

level : str | LogLevel, default="info"
Tracing log level. Choose from: "error", "warn", "info", "debug".