Skip to main content

BaseStatArb

BaseStatArb()
Base Statistical Arbitrage class. Method generated by attrs for class BaseStatArb.

Ancestors

  • abc.ABC

Descendants

  • systematica.api.models.arbitrage_index.ArbitrageBaseIndex
  • systematica.api.models.arbitrage_index.ArbitrageClipIndex
  • systematica.api.models.arbitrage_index.ArbitrageCumulativeIndex
  • systematica.api.models.arbitrage_index.ArbitrageProbabilityIndex
  • systematica.api.models.arbitrage_index.ArbitrageResetIndex
  • systematica.api.models.arbitrage_index.ArbitrageRollingZscoreIndex
  • systematica.api.models.meta_model.MetaModel
  • systematica.api.models.momentum.AverageMomentumFactorCV
  • systematica.api.models.momentum.RollingAverageMomentumFactor
  • systematica.api.models.ou_process.RollingOUProcess
  • systematica.api.models.range_breakout.RangeBreakout
  • systematica.api.models.spread.RollingSpreadModel
  • systematica.api.models.spread.RollingZscoreModel
  • systematica.api.models.volatility.RollingVolatilityFactor
  • systematica.api.models.volatility.VolatilityFactorCV
  • systematica.api.models.volume_profile.RollingVolumeProfileFactor
  • systematica.api.models.volume_profile.VolumeProfileFactorCV

Static methods

is_valid

is_valid(
    model_params: Dict[str, Any],
    signal_params: Dict[str, Any],
)
Validate model parameters. This method checks if the model parameters are valid for the statistical arbitrage model. It should be implemented in subclasses and decorated with staticmethod to allow calling it without an instance. If the model does not require validation, it can be implemented as a no-op method with the @staticmethod decorator. Examples: To implement this method, define it in the subclass and use the @staticmethod decorator like so:
>>> @staticmethod
>>> def is_valid(model_params: tp.Kwargs, signal_params: tp.Kwargs):
...     # Implement validation logic here
...     pass
Parameters:
NameTypeDefaultDescription
model_paramstp.Kwargs--Model parameters.
signal_paramstp.Kwargs--Signal parameters.

run_walk_forward

run_walk_forward(
    cls,
    **feature,
) ‑> systematica.walk_forward.base.BaseWalkForward
Analyzes model using rolling or cross-validation techniques. Determine the appropriate wf selection class based on model attributes and use_rolling flag. Parameters:
NameTypeDefaultDescription
featuretp.Kwargs--Configuration for a feature calculation.
Returns:
TypeDescription
BaseReportAn instance of BaseWalkForwardRolling or BaseWalkForwardCV depending on the model and parameters.

run_analyzer

run_analyzer(
    cls,
    validate_model: bool = True,
    **feature,
) ‑> systematica.portfolio.analyzer.PortfolioAnalyzer
Executes the portfolio analyzer.
Combines scoring, signal generation, and portfolio simulation into a single pipeline for streamlined backtesting.
Parameters:
NameTypeDefaultDescription
validate_modelboolTrueValidate model parameters. Defaults to True.
featuretp.Kwargs--Configuration for a feature calculation.
Returns:
TypeDescription
PortfolioAnalyzerAn instance of PortfolioAnalyzer containing the results of the backtest.

run_model

run_model(
    cls,
    **feature,
) ‑> pandas.core.frame.DataFrame
Run parameterized scores generation.
The method utilizes parameterization to run scores over various parameter combinations. The results can be merged and accessed as a single output object.
Parameters:
NameTypeDefaultDescription
featuretp.Kwargs--Configuration for a feature calculation.
Returns:
TypeDescription
pd.DataFrameScores for each parameter combination.

run_signals

run_signals(
    cls,
    validate_model: bool = True,
    **feature,
) ‑> pandas.core.frame.DataFrame
Run parametrized signals generation.
The method utilizes parameterization to run signal generation over various parameter combinations. The results can be merged and accessed as a single output object.
Parameters:
NameTypeDefaultDescription
validate_modelboolTrueValidate model parameters. Defaults to True.
featuretp.Kwargs--Configuration for a feature calculation.
Returns:
TypeDescription
pd.DataFrameSignals for each parameter combination.

run_pipeline

run_pipeline(
    cls,
    validate_model: bool = True,
    to_numpy: bool = False,
    **feature,
) ‑> vectorbtpro.portfolio.base.Portfolio | collections.OrderedDict | pandas.core.frame.DataFrame | numpy.ndarray
Executes the portfolio pipeline. Method is parametrizable.
Combines scoring, signal generation, and portfolio simulation into a single pipeline for streamlined backtesting.
Parameters:
NameTypeDefaultDescription
validate_modelboolTrueValidate model parameters. Defaults to True.
to_numpyboolFalseIf True, returns a np.ndarray. Default is False, returning a pd.DataFrame.
featuretp.Kwargs--Configuration for a feature calculation.
Returns:
TypeDescription
vbt.PF | OrderedDict | pd.DataFrame | tp.ArrayBacktested portfolio or requested metrics.

run_expression

run_expression(
    cls,
    feature_expression: systematica.generic.base.FeatureExpression = None,
    runner_kwargs: Dict[str, Any] = None,
    validate_model: bool = True,
    to_numpy: bool = False,
    **feature,
) ‑> vectorbtpro.portfolio.base.Portfolio | collections.OrderedDict | pandas.core.frame.DataFrame | numpy.ndarray
Build an indicator class from an indicator expression. Builds a new indicator class based on a Python expression string. See vbt.IF.from_expr for more information. Parameters:
NameTypeDefaultDescription
feature_expressionFeatureExpressiontoNone Instance of FeatureExpression. If None, take cls.get_expression method as reference. Defaults to None.
runner_kwargstp.Kwargs--Additional key-word arguments used in vbt.Data.run. Defaults to None.
validate_modelboolTrueCheck if model parameters are valid. Defaults to True.
to_numpyboolFalseIf True, returns a np.ndarray. Default is False, returning a pd.DataFrame.
featuretp.Kwargs--Configuration for a feature calculation.
Returns:
TypeDescription
vbt.PF | OrderedDict | pd.DataFrame | tp.ArrayBacktested portfolio or requested metrics.
Raises:
TypeDescription
ValueErrorIf both feature_expression and cls.get_feature_expression are None.

run_optuna_study

run_optuna_study(
    objective: systematica.tuners.base.BaseOptunaObjective,
    feature: systematica.generic.base.Feature,
    search_space: Dict[str, Any],
    callbacks: Iterable = None,
) ‑> optuna.study.study.Study
Run hyperparameter optimization using optuna for a signal-based trading strategy.
  • Optuna is used for hyperparameter tuning and efficiently finds the best parameters.
  • The study prunes trials with poor results to accelerate the search process.
References: Parameters:
NameTypeDefaultDescription
ObjectiveBaseOptunaObjective--Optuna custom objective object.
featureFeature--The feature configuration.
search_spacedict--The hyperparameter search space.
callbackstp.IterableNoneList 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.
Returns:
TypeDescription
optuna.StudyThe Optuna study object containing optimization results.

Methods

get_signals

get_signals(
    self,
    validate_model: bool = True,
    **feature,
) ‑> systematica.signals.base.Signals
Generate trading signals based on scores. Parameters:
NameTypeDefaultDescription
validate_modelboolTrueValidate model parameters. Defaults to True.
featuretp.Kwargs--Configuration for a feature calculation.
Returns:
TypeDescription
SignalsGenerated signals.