Skip to main content

BaseStatArb

Base Statistical Arbitrage class.

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.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.range_breakout.RangeMeanReversion
  • 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

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:
Parameters:

run_report

Analyzes model using rolling or cross-validation techniques. Parameters: Returns:

get_report_metrics

Run report: Analyzes model using rolling or cross-validation techniques. Parameters: Returns:

run_analyzer

Executes the portfolio analyzer.
Combines scoring, signal generation, and portfolio simulation into a single pipeline for streamlined backtesting.
Parameters: Returns:

run_model

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: Returns:

run_signals

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: Returns:

run_pipeline

Executes the portfolio pipeline. Method is parametrizable.
Combines scoring, signal generation, and portfolio simulation into a single pipeline for streamlined backtesting.
Parameters: Returns:

run_optuna_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: Returns:

Methods

get_signals

Generate trading signals based on scores. Parameters: Returns:

BaseReportMixin

Report mixin used in both rolling and cross-validated versions.

Ancestors

  • abc.ABC

Descendants

  • systematica.api.base.BaseReportCV
  • systematica.api.base.BaseRollingReport

Instance variables

  • all_metrics: List[str]: Get all available metrics
  • price_data: Retrieves price data for the specified symbols.
  • non_tunable_metrics: List[str]: Retrieves all non-tunable metrics from registry

Methods

get_annualized_return

Computes the rolling (annualized) returns. Returns:

get_portfolio_metric

Computes portfolio performance metrics for different test sets. Parameters: Returns:

get_model_output

Computes the model output. Parameters: Returns:

set_labels

Generate column labels for the output DataFrame. Parameters: Returns:

plot_annualized_return

Plots total returns over time. Parameters: Returns:

plot_model_output

Plots model output over time. Parameters: Returns:

plot_portfolio_metric

Plot portfolio performance metrics over time. Parameters: Returns:

BaseReportCV

Analyzes a statistical arbitrage model using cross-validation. Method generated by attrs for class BaseReportCV.

Ancestors

  • systematica.api.base.BaseReportMixin
  • abc.ABC

Descendants

  • systematica.api.reports.arbitrage_index.ArbitrageIndexReport
  • systematica.api.reports.meta_model.MetaModelCVReport
  • systematica.api.reports.momentum.AverageMomentumFactorCVReport
  • systematica.api.reports.momentum.MomentumFactorCVReport
  • systematica.api.reports.ou_process.OUProcessCVReport
  • systematica.api.reports.range_breakout.RangeBreakoutReport
  • systematica.api.reports.volatility.VolatilityFactorCVReport
  • systematica.api.reports.volume_profile.VolumeProfileFactorCVReport

Instance variables

  • splitter: systematica.utils.custom_splitter.CustomSplitter: Split arrays or matrices into specified train and test subsets.
  • splits: pandas.core.frame.DataFrame: Retrieves data splits based on the cross-validation splitter.
  • index_test: pandas.core.indexes.base.Index: Computes and returns the test set index of the dataset. The test set index is derived from the end bounds values returned by the splitter.
  • all_metrics: List[str]: Get available cross-validation metrics.
  • data: vectorbtpro.data.base.Data: Input data containing time series data.
  • freq: str: Set frequency. Default is auto, which infers frequency from the data index.
  • model: ~BaseStatArb: Model to analyse.
  • s1: str: Symbol.
  • s2: str: Symbol.
  • use_close: bool: Price close or open. Default is True, using close prices.

Methods

check

Validates CV model. Parameters: Raises:

price_reset_stacked_by_set

Resets the price data stacked by set and attaches bounds to the index. This method uses the splitter to reset the price data, stacking it by set and attaching bounds to the index. Returns:

model_reset_stacked_by_set

Resets the model output stacked by set and attaches bounds to the index. This method uses the splitter to reset the model output, stacking it by set and attaching bounds to the index. Returns:

get_annualized_return

Computes the annualized returns for the test set. Returns:

get_portfolio_metric

Computes portfolio performance metrics for different test sets. Parameters: Returns:

BaseRollingReport

Analyzes a statistical arbitrage model using rolling metrics. Method generated by attrs for class BaseRollingReport.

Ancestors

  • systematica.api.base.BaseReportMixin
  • abc.ABC

Descendants

  • systematica.api.reports.meta_model.RollingMetaModelReport
  • systematica.api.reports.momentum.RollingAverageMomentumFactorReport
  • systematica.api.reports.momentum.RollingMomentumFactorReport
  • systematica.api.reports.ou_process.RollingOUProcessReport
  • systematica.api.reports.volatility.RollingVolatilityFactorReport
  • systematica.api.reports.volume_profile.RollingVolumeProfileFactorReport

Instance variables

  • window: int: Window size.
  • minp: None | int: Minimum number of observations required.
  • all_metrics: List[str]: Get available rolling metrics.
  • data: vectorbtpro.data.base.Data: Input data containing time series data.
  • freq: str: Set frequency.
  • model: ~BaseStatArb: Model to analyse.
  • s1: str: Symbol.
  • s2: str: Symbol.
  • use_close: bool: Price close or open.

Methods

check

Validates that the model has the necessary parameters for the strategy. Specifically, the model must have either:
  • Both window and minp attributes, or
  • Both train_window and splitter (set to *_rolling).
Parameters: Raises:

get_portfolio_metric

Computes portfolio performance metrics on a rolling basis. Parameters: Returns:

BaseSignal

Abstract base class for signal generation.

Ancestors

  • abc.ABC

Descendants

  • systematica.api.signals.cross_spread.CrossSpread
  • systematica.api.signals.crossover.Crossover
  • systematica.api.signals.crossover.Crossover1d
  • systematica.api.signals.spread.Spread
  • systematica.api.signals.twin_spread.TwinSpread

Static methods

run

Run the signal generation process. Parameters: