Module engine

Classes

class Metadata (strategy_name: Optional[str] = None, description: Optional[str] = None, author: Optional[str] = None, version: Optional[str] = None, time_res: Optional[datetime.timedelta] = None, save_code: bool = True, hash_only: bool = True, file_blacklist: Optional[Iterable[str]] = (), code_path: Optional[str] = None)

This class is meant to contain all the information needed to reproduce the results of the backtest of a startegy Usually, the dataset must be big, so it is recomended to write in the description how to acquire the dataset,or make a script that download it and save the script.

This class contains the metadata of the strategy.

Args:

strategy_name: The name of the strategy. If None, the name of the class will be used.
description: The description of the strategy. It is strongly recommended to write steps on how to reproduce the results here. If description is None, the docstring of the strategy will be used.
author: The author of the strategy. If None, the git author will be used.
version: The version of the strategy. If None, the git commit hash will be used. If no git repository, it will be "Unknown"
time_res: The time resolution. If None, the automatically found time resolution will be saved. It is the task of the broker to provide the time resolution. (Not handled in this class)
save_code: Whether to save the code of the strategy. If True, the code will be saved.
hash_only: Only used if save_code is True. If True, only the hash of the code will be saved. (It can spare storage space)
file_blacklist: Files to not include in the code saved. It is a list of strings with the file paths relative to the current working directory.
code_path: The path to the root folder where to search for the code. Default is the current working directory (If None). If no '*' is present in the path, it will be added at the end to search for py files.

Static methods

def get_git_author() ‑> str

This method return the git author name.

Returns:

git author name
def load(data: dict)

This method load the metadata from a dictionary.

Note

The file_blacklist parameter is not loaded (and not saved) for privacy purposes.

Args:

data: The dictionary to load the metadata from.

Returns:

The metadata object

Methods

def export(self) ‑> dict

This method export the metadata to a JSONable dictionary.

Note

The file_blacklist parameter is not saved (and not loaded) for privacy purposes.

Returns:

The state of the object as a dictionary
def get_git_commit(self) ‑> str

This method return the git commit hash.

Returns:

git commit hash
def init(self, strategy: Strategy, backtest_parameters: Optional[dict] = None, tickers: Optional[List[str]] = None, features: Optional[List[str]] = None, run_duration: Optional[float] = None)

This method is used to initialize the metadata object from the Backtest object (When the simulation has started)

Args:

strategy: The strategy object. (Used to get its name
backtest_parameters: The parameters of the backtest object (Init paraeters)
tickers: The tickers used in the backtest
features: The features used in the backtest (Columns)
run_duration: The duration of the backtest (in seconds)

Returns:

None
def load_code(self, checksum: bool = True, ignore: Iterable[str] = (), path: str = './**/*.py') ‑> Dict[str, Dict[str, Optional[str]]]

This method load the code of the strategy.

Args:

path: The path to search for the code. Default is the current working directory. (And ignore venv)
checksum: Whether to return only the checksum of each file.
ignore: Files to ignore when loading the code.

Returns:

The code of the strategy