Skip to main content

Feature

Feature(
    idstr = None,
    loader_or_data: Callable = <function load_clean_data>,
    timeframe: str = '1d',
    start: str = None,
    end: str = None,
    s1: str = 'BTCUSDT',
    s2: str = 'ETHUSDT',
    suffix: str = 'h5',
    use_close: bool = True,
    freq: str = None,
    signal_model: str = None,
    long_entries: float = nan,
    long_exits: float = nan,
    short_entries: float = nan,
    short_exits: float = nan,
    clean: bool = True,
    select_symbols: str | int | List[str | int= None,
    portfolio_config: Dict[str, Any] = _Nothing.NOTHING,
    model_params: Dict[str, Any] = _Nothing.NOTHING,
    metrics: str | List[str= None,
    metrics_kwargs: Dict[str, Any] = _Nothing.NOTHING,
    use_rolling: bool = False,
    storage: str | optuna.storages._base.BaseStorage = None,
    pruner: optuna.pruners._base.BasePruner = <optuna.pruners._successive_halving.SuccessiveHalvingPruner object>,
    sampler: optuna.samplers._base.BaseSampler = <optuna.samplers._tpe.sampler.TPESampler object>,
    study_name: str = None,
    direction: str | List[str= 'maximize',
    load_if_exists: bool = False,
    n_trials: int = 100,
    n_completed_trials: int = None,
    timeout: float = None,
    n_jobs: int = 1,
    catch: Iterable[Type[Exception]] | Type[Exception= _Nothing.NOTHING,
    callbacks: Iterable[Callable[[optuna.study.study.Study, optuna.trial._frozen.FrozenTrial], None]] | None = None,
    gc_after_trial: bool = False,
    show_progress_bar: bool = False,
    verbose: bool = True,
    tracker: Type = None,
)
Configuration for a feature calculation. This class encapsulates the necessary configuration for computing a feature. It includes the feature’s name, a callable to compute the feature, a list of required data keys, and optional parameters for the computation. Method generated by attrs for class Feature.

Descendants

  • systematica.generic.base.Model

Instance variables

  • symbols: List[str]: Symbols.
  • loader_name: str: Loader name.
  • frequency: str: Frequency.
  • optuna_metadata: Dict: Metadata for Optuna study tracking. Returns dictionary containing key configuration parameters excluding runtime objects (tracker, sampler, pruner, etc.).
  • callbacks: Iterable[Callable[[optuna.study.study.Study, optuna.trial._frozen.FrozenTrial], None]] | None: List of callback functions that are invoked at the end of each trial. Each function must accept two parameters with the following types in this order: Study and FrozenTrial.
  • catch: Iterable[Type[Exception]] | Type[Exception]: A study continues to run even when a trial raises one of the exceptions specified in this argument. Default is an empty tuple, i.e. the study will stop for any exception except for TrialPruned.
  • clean: bool: Clean signals. Defaults to True.
  • close: vectorbtpro.data.base.Data:
  • data: vectorbtpro.data.base.Data:
  • data_symbols: vectorbtpro.data.base.Data:
  • direction: str | List[str]: Optimization objective, either minimize or maximize, default is maximize.
  • end: str: The end date for the data in string format (e.g., YYYY-MM UTC). If None, use datetie.utcnow() to fetch the latest data possible. Default to None.
  • end_date: str:
  • freq: str: Frequency of the data. Used when cross_validate is True. Defaults to None.
  • gc_after_trial: bool: Flag to determine whether to automatically run garbage collection after each trial. Set to True to run the garbage collection, False otherwise. It runs a full collection by internally calling gc.collect. If you see an increase in memory consumption over several trials, try setting this flag to True. Defaults to False.
  • high: vectorbtpro.data.base.Data:
  • id: str: Custom searchable id.
  • load_if_exists: bool: Flag to control the behavior to handle a conflict of study names. In the case where a study named study_name already exists in the storage, a DuplicatedStudyError is raised if load_if_exists is set to False. Otherwise, the creation of the study is skipped, and the existing one is returned.
  • loader_or_data: Callable: Default loader or data. If loader, it must accept timeframe as retriever. More information in data/loader. Defaults to load_clean_data.
  • long_entries: float: Long entry signals.
  • long_exits: float: Long exit signals.
  • low: vectorbtpro.data.base.Data:
  • metrics: str | List[str]: Performance metrics to compute. Defaults to None.
  • metrics_kwargs: Dict[str, Any]: Parameters for metric config. If None, uses default parameters based on the model type. This is used to specify parameters such as window or minp for rolling metrics. If using cross-validation, this should be set to None as it is not applicable. If using rolling metrics, this should be set to a dictionary with parameters for the metric config. For example, {"window": 20}. Defaults to None.
  • model_params: Dict[str, Any]: A dictionary of optional keyword arguments needed to compute the model.
  • n_completed_trials: int: The number of successfully completed trials before stopping the optimization. If None, it will run for n_trials trials. TO be effective, the number of trials should be higher than the number of completed trials. default is None.
  • n_jobs: int: Number of parallel jobs for optimization (-1 for using all available CPUs cores), default is -1.
  • n_trials: int: The number of trials for the optimization. This is the maximum number of trials that will be run. If n_completed_trials is set, the optimization will stop when the number of completed trials reaches this value. If n_completed_trials is not set, the optimization will run for n_trials trials. If n_trials is set to None, it will run indefinitely until n_completed_trials is reached. If n_trials is set to 0, it will not run any trials. If n_trials is set to a negative value, it will run indefinitely until n_completed_trials is reached. Defaults to 100.
  • open: vectorbtpro.data.base.Data:
  • portfolio_config: Dict[str, Any]: Default VectorBT portfolio parameters used in the systematica package. These parameters are used to define the portfolio simulation and its behavior. The default values are set to None or specific values as per the requirements of the systematica package.
  • price: vectorbtpro.data.base.Data:
  • pruner: optuna.pruners._base.BasePruner: Optuna Pruner. If None, defaults to Asynchronous Successive Halving Algorithm. Defaults to None.
  • s1: str: First symbol.
  • s2: str: Second symbol.
  • sampler: optuna.samplers._base.BaseSampler: Optuna Sampler. If None, defaults to TPE (Tree-structured Parzen Estimator) algorithm. Defaults to None.
  • select_symbols: str | int | List[str | int]: Symbol name (e.g., BTCUSDT or ETHUSDT) or column index (e.g., 0 or 1) to keep. If None, no filtering.
  • short_entries: float: Short entry signals.
  • short_exits: float: Short exit signals.
  • show_progress_bar: bool: Flag to show progress bars or not. To show progress bar, set this True. Note that it is disabled when n_trials is None, timeout is not None, and n_jobs.
  • signal_model: str: Signal model used for generating signals.
  • start: str: The start date for the data in string format (e.g., YYYY-MM UTC). Default to None.
  • start_date: Dict[str, Any]:
  • storage: str | optuna.storages._base.BaseStorage: Database URL. If this argument is set to None, InMemoryStorage is used, and the Study will not be persistent.
  • study_name: str: The name of the (optuna and tracker) study.
  • suffix: str: Extension (suffix) of the file to load. Defaults to None.
  • timeframe: str: Timeframe of the file to be loaded. Defaults to None.
  • timeout: float: Stop study after the given number of second(s). None represents no limit in terms of elapsed time. The study continues to create trials until the number of trials reaches n_trials, timeout period elapses, stop() is called or, a termination signal such as SIGTERM or Ctrl+C is received.
  • tracker: Type: Tracker instance for logging and monitoring the optimization process. If None, no tracking is performed. If you want to use a tracker, you can pass an instance of a tracker class that inherits from BaseTracker. For example, you can use NeptuneTracker. This tracker will log the optimization process and metrics to the tracker service. Default to None.
  • use_close: bool: Use close price if set to True. Otherwise, use open price.
  • use_rolling: bool: Flag to use rolling method via BaseWalkForwardRolling. Note that both rolling and cv models can be passed. Fallbacks to BaseWalkForwardCV if model is not using from_rolling splitter without error message. Defaults to False.
  • verbose: bool: Whether to print Optuna logs during the optimization process. If True, prints logs to the console. Default is True.

Methods

check_direction

check_direction(
    self,
    attribute: str,
    value: str | list[str],
)
Validate optimization directions. Parameters:
NameTypeDefaultDescription
attributeattrs.Attribute--The attribute being validated.
valueBaseStatArb--The model instance.
Raises:
TypeDescription
ValueErrorIf direction is not “maximize” or “minimize”.
TypeErrorIf direction is not a string or a list

check_metrics

check_metrics(
    self,
    attribute: str,
    value: str | list[str],
)
Validate metrics. Parameters:
NameTypeDefaultDescription
attributeattrs.Attribute--The attribute being validated.
valueBaseStatArb--The model instance.
Raises:
TypeDescription
TypeErrorIf metrics is not a string or list.
ValueErrorIf metric has not been configured and is not tunable.

asdict

asdict(
    self,
) ‑> Dict[str, Any]
Convert instance to a shallow dict. Returns:
TypeDescription
Ttp.KwargsFeature dict.

FeatureExpression

FeatureExpression(
    expr: str,
    include_pckg: Dict[str, Any] = None,
    kwargs: Dict[str, Any] = None,
)
StatArb expression model. Method generated by attrs for class FeatureExpression.

Instance variables

  • expr: str: Expression string. Must contain valid Python code and can be single-line or multi-line.
  • include_pckg: Dict[str, Any]: External packages used in expr.
  • kwargs: Dict[str, Any]: Additional key-word arguments used in vbt.IF.from_expr

Model

Model(
    idstr = None,
    loader_or_data: Callable = <function load_clean_data>,
    timeframe: str = '1d',
    start: str = None,
    end: str = None,
    s1: str = 'BTCUSDT',
    s2: str = 'ETHUSDT',
    suffix: str = 'h5',
    use_close: bool = True,
    freq: str = None,
    signal_model: str = None,
    long_entries: float = nan,
    long_exits: float = nan,
    short_entries: float = nan,
    short_exits: float = nan,
    clean: bool = True,
    select_symbols: str | int | List[str | int= None,
    portfolio_config: Dict[str, Any] = _Nothing.NOTHING,
    model_params: Dict[str, Any] = _Nothing.NOTHING,
    metrics: str | List[str= None,
    metrics_kwargs: Dict[str, Any] = _Nothing.NOTHING,
    use_rolling: bool = False,
    storage: str | optuna.storages._base.BaseStorage = None,
    pruner: optuna.pruners._base.BasePruner = <optuna.pruners._successive_halving.SuccessiveHalvingPruner object>,
    sampler: optuna.samplers._base.BaseSampler = <optuna.samplers._tpe.sampler.TPESampler object>,
    study_name: str = None,
    direction: str | List[str= 'maximize',
    load_if_exists: bool = False,
    n_trials: int = 100,
    n_completed_trials: int = None,
    timeout: float = None,
    n_jobs: int = 1,
    catch: Iterable[Type[Exception]] | Type[Exception= _Nothing.NOTHING,
    callbacks: Iterable[Callable[[optuna.study.study.Study, optuna.trial._frozen.FrozenTrial], None]] | None = None,
    gc_after_trial: bool = False,
    show_progress_bar: bool = False,
    verbose: bool = True,
    tracker: Type = None,
    model: Any = None,
    preprocess_func: Callable = None,
)
Configuration for a feature calculation. This class encapsulates the necessary configuration for computing a feature. It includes the feature’s name, a callable to compute the feature, a list of required data keys, and optional parameters for the computation. Method generated by attrs for class Model.

Ancestors

  • systematica.generic.base.Feature

Descendants

  • systematica.walk_forward.base.BaseWalkForward

Instance variables

  • model_name: str: Model name.
  • model: Any: Compute model, which defines the method to compute the feature.
  • model_cls: Type:
  • model_output: numpy.ndarray | pandas.core.frame.DataFrame | systematica.signals.base.Signals:
  • preprocess_data: pandas.core.frame.DataFrame:
  • preprocess_func: Callable: Preprocessing function applied to price data. If None, the model uses price data by default. Defaults to None.

Methods

updated_metrics_kwargs

updated_metrics_kwargs(
    self,
    use_rolling: bool = None,
)
Set metrics kwargs. Parameters:
NameTypeDefaultDescription
attributeattrs.Attribute--The attribute being validated.
valueBaseStatArb--The model instance.
Raises:
TypeDescription
TypeErrorIf metrics is not a string or list.
ValueErrorIf metric has not been configured and is not tunable.

get_model_output

get_model_output(
    self,
    to_numpy: bool = True,
    **kwargs,
) ‑> numpy.ndarray | pandas.core.series.Series | pandas.core.frame.DataFrame
Computes the model output. Parameters:
NameTypeDefaultDescription
to_numpyboolFalseIf True, converts output to a np.array. Default is False, returning a pd.DataFrame.
Returns:
TypeDescription
np.ndarray or pd.DataFrameModel output data.

get_signals

get_signals(
    self,
    validate_model: bool = True,
) ‑> systematica.signals.base.Signals
Generated trading signals. Parameters:
NameTypeDefaultDescription
validate_modelboolTrueCheck if model parameters are valid. Defaults to True.
Returns:
TypeDescription
SignalsGenerated trading signals.