Module engine

Classes

class Record (chart: Optional[pandas.core.frame.DataFrame], ticker: str, time_res: int, marginable: bool, shortable: bool, div_freq: DividendFrequency, short_rate: float, next_tick: Optional[pandas.core.series.Series] = None)

This class contains information about a stock and is pass to the strategy.

Args:

chart: The prepared chart of the stock
ticker: The ticker of the stock
time_res: The idx in the list of resolution of the backtest object of the time resolution of the record.
marginable: Whether the stock is marginable
shortable: Whether the stock is shortable
div_freq: The dividend frequency of the stock
short_rate: The short rate of the stock
next_tick: The next tick of the stock

Instance variables

var next_tick

This method is used to get the next tick of the stock.

Returns:

The next tick of the stock
class Records (records: Union[List[Record], Dict[str, Record]], time_res: datetime.timedelta, time_res_idx: int, window: int)

Class containing multiple records for a given time resolution. You can access the record like a list with the index of the record being the index of the ticker in the list of tickers. You can also access the record by the string of the ticker like a dictionary. You can iterate over the records like a dictionary (ticker, record). Finally, you can check if a ticker is in the records like a dictionary.

Attributes

records
The records. The keys are the tickers of the securities.
tickers
The tickers of the securities in the same order as the records attribute.
features
The features of the records. It is the columns of the charts.
time_res
The time resolution
time_res_idx
The index of the time resolution in the available_time_res attribute of the backtest object
window
The window size (lookback period) of the records. Used when exporting to numpy.

Implements

getitem, setitem, iter, contains

Args:

records: The records. If a list, it will be converted to a dictionary internally. If a dictionary, the keys will be the tickers of the securities.
time_res: The time resolution
time_res_idx: The index of the time resolution in the available_time_res attribute of the backtest object
window: The window size (lookback period) of the records. Used when exporting to numpy.

Methods

def numpy(self) ‑> numpy.ndarray[typing.Any, numpy.dtype[numpy.float64]]

This method will return the charts as a numpy array. The array might contain nan values if the chart is not long enough to fill the window.

Returns:

A numpy array of the shape (n, w, p) where n is the number of securities, w is the window size and p is the number of features.
def to_list(self) ‑> List[Record]

Convert the Records object to a list of Record

Returns:

A list of Record
def update_features(self)

This method will update the features attribute to the new features set based on the columns of the charts. Assuming all the charts have the same features.

Returns:

None
class RecordsBucket (records: Union[List[Records], List[Iterable[Record]]], available_time_res: List[datetime.timedelta], main_timestep: int, window: Optional[int] = None)

Class containing multiple Records objects for all time resolutions. You can access each Records object by their corresponding time resolution or their index in the available_time_res attribute of the backtest object. You can also iterate over the Records objects like a dictionary (time resolution, Records object). To simplify the access of the Records object associated with the main time resolution, you can use the main attribute.

Attributes

records
The Records objects. The keys are the time resolutions.
available_time_res
The available time resolutions
main_timestep
The index of the main time resolution in the available_time_res attribute of the backtest object

Args:

records: The records
available_time_res: The available time resolutions

Instance variables

var main : Records

Get the main timestep set of records

Returns:

The main timestep set of records