### Setup Virtual Environment Source: https://systematica.mintlify.app/getting-started/quickstart Steps to create and activate a Python virtual environment using uv. This isolates project dependencies. ```shell uv venv ``` ```shell # On Unix or macOS: source .venv/bin/activate # On Windows: .venv\Scripts\activate ``` -------------------------------- ### Systematica ArbitrageClipIndex Model Usage Source: https://systematica.mintlify.app/getting-started/quickstart Demonstrates importing the Systematica library, loading data, initializing the ArbitrageClipIndex model, and obtaining model outputs and signals. ```python import systematica as sma data = sma.load_clean_data('1d') s1, s2 = data.symbols model = sma.ArbitrageClipIndex(training_window=365, testing_window=60) model_output = model(data, s1, s2) vbt.pprint(model_output) signals = model.get_signals(model_output, signal_model='twin_spread', long_entries=0.9, long_exits= 0.0, short_entries=-0.9, short_exits=0.0) vbt.pprint(signals) ``` -------------------------------- ### Systematica ArbitrageClipIndex Analyzer and Reporter Source: https://systematica.mintlify.app/getting-started/quickstart Illustrates how to run the analyzer and reporter functionalities for the ArbitrageClipIndex model, which process data and generate insights or reports. ```python # Run analyzer sma.ArbitrageClipIndex.run_analyzer(data, s1, s2, ...) # Run report sma.ArbitrageClipIndex.run_report(data, s1, s2, ...) ``` -------------------------------- ### Systematica ArbitrageClipIndex Pipeline Execution Source: https://systematica.mintlify.app/getting-started/quickstart Shows how to run the ArbitrageClipIndex model pipeline to generate a Portfolio instance, calculate metrics like Sharpe Ratio, and compute rolling metrics. ```python # Run pipeline to get Portfolio instance sma.ArbitrageClipIndex.run_pipeline(data, s1, s2, ...) # Get specific metrics sma.ArbitrageClipIndex.run_pipeline( data, s1, s2, ..., metrics='sharpe_ratio' ) # Get rolling metrics sma.ArbitrageClipIndex.run_pipeline( data, s1, s2, ..., metrics='sharpe_ratio', use_rolling=True ) ``` -------------------------------- ### Clone the Repository Source: https://systematica.mintlify.app/getting-started/installation Clones the project repository using the provided Git URL. This is the first step to get the project files onto your local machine. ```shell git clone https://github.com/bfcdev/quant-research.git ``` -------------------------------- ### Systematica ArbitrageClipIndex Optuna Study Source: https://systematica.mintlify.app/getting-started/quickstart Demonstrates using Optuna to run an optimization study for the ArbitrageClipIndex model, specifying metrics, direction, trials, and hyperparameter ranges. ```python sma.ArbitrageClipIndex.run_optuna_study( data, s1, s2, ..., metrics='sharpe_ratio', direction='maximize', n_trials=10, training_window=sma.Int('training_window', low=20, high=500, step=10) ) ``` -------------------------------- ### Install uv on Windows Source: https://systematica.mintlify.app/getting-started/installation Installs the 'uv' package manager on Windows using PowerShell to download and execute the installation script. ```shell powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex" ``` -------------------------------- ### Install vectorbtpro from GitHub Source: https://systematica.mintlify.app/getting-started/installation Installs the 'vectorbtpro' package directly from a GitHub repository using 'uv add'. Requires specifying GitHub username, token, and organization. The '[base]' extra installs core functionalities. ```shell uv add -U "vectorbtpro[base] @ git+https://GH_USER:GH_TOKEN@github.com/ORGANIZATION/vectorbt.pro.git" ``` -------------------------------- ### Install dependencies from requirements.txt with uv Source: https://systematica.mintlify.app/getting-started/installation Installs project dependencies listed in a requirements.txt file into the activated virtual environment using 'uv pip install'. ```shell uv pip install -r requirements.txt ``` -------------------------------- ### Initialize a new project with uv Source: https://systematica.mintlify.app/getting-started/installation Initializes a new Python project using 'uv', creating a pyproject.toml file for project metadata and dependencies. ```shell uv init ``` -------------------------------- ### Install uv using pip Source: https://systematica.mintlify.app/getting-started/installation Installs the 'uv' package manager using pip, a common Python package installer. ```python pip install uv ``` -------------------------------- ### Create a virtual environment with uv Source: https://systematica.mintlify.app/getting-started/installation Creates a virtual environment for the project, typically in a .venv directory, using the 'uv venv' command. ```shell uv venv ``` -------------------------------- ### Setup Virtual Environment Source: https://systematica.mintlify.app/getting-started/contributing Instructions for setting up a Python virtual environment using the 'uv' tool and activating it. This ensures project dependencies are isolated. ```shell uv venv ``` ```shell # On Unix or macOS: source .venv/bin/activate # On Windows: .venv\Scripts\activate ``` -------------------------------- ### Install uv using curl Source: https://systematica.mintlify.app/getting-started/installation Installs the 'uv' package manager on Linux or macOS using a curl command to download and execute the installation script. ```shell curl -LsSf https://astral.sh/uv/install.sh | sh ``` -------------------------------- ### Run project with uv Source: https://systematica.mintlify.app/getting-started/installation Executes a project script (e.g., main.py) within the isolated virtual environment managed by 'uv', ensuring correct dependencies are used. ```shell uv run main.py ``` -------------------------------- ### Workflow Configuration TOML Example Source: https://systematica.mintlify.app/workspaces/workflow An example of a workflow configuration file written in TOML format. This file defines a specific strategy, including meta-information, data loading parameters, model settings, signal generation parameters, and portfolio configurations. ```toml [meta] study_name = "dale" tags = ["arbitrage", "copula", "clip-index", "1h"] [loader] name = "BFCData" [loader_params] symbols = ["CB-BTC-USD", "CB-ETH-USD"] timeframe = "60m" table = "candle" index_col = "close_datetime" engine_name = "research" start = "2018-01-01 UTC" [model] name = "ArbitrageClipIndex" [model_params] training_window = 3244 testing_window = 992 splitter = "from_custom_rolling" copula = "auto" method = "aic" lower = -1.57 upper = 1.11 sequential = false use_close = true [signal] signal_model = "twin_spread" long_entries = 0.78 long_exits = 0.0 short_entries = -1.33 short_exits = 0.0 [portfolio] size = 50 size_type = "valuepercent100" cash_sharing = true call_seq = "auto" ``` -------------------------------- ### Activate virtual environment (Unix/macOS) Source: https://systematica.mintlify.app/getting-started/installation Activates the project's virtual environment on Unix-like systems (Linux, macOS) using the 'source' command. ```shell source .venv/bin/activate ``` -------------------------------- ### Activate virtual environment (Windows) Source: https://systematica.mintlify.app/getting-started/installation Activates the project's virtual environment on Windows using the 'activate' script within the .venv directory. ```shell .venv\Scripts\activate ``` -------------------------------- ### Install package in development mode Source: https://systematica.mintlify.app/getting-started/installation Installs the current project in editable mode using pip, allowing changes to be reflected immediately without reinstallation. ```python pip install -e . ``` -------------------------------- ### Add dependencies with uv Source: https://systematica.mintlify.app/getting-started/installation Adds a specified package dependency to your project using the 'uv add' command, updating the pyproject.toml and lockfile. ```shell uv add PACKAGE_NAME ``` -------------------------------- ### Visualize API Reference Locally Source: https://systematica.mintlify.app/getting-started/development_tips This command sequence navigates into the `docs` directory and starts a local development server using `mint dev`. This allows you to preview the API reference in your browser. ```bash cd docs ``` ```bash mint dev ``` -------------------------------- ### Run Project Tests with Pytest Source: https://systematica.mintlify.app/getting-started/tests Instructions on how to execute the project's tests using the pytest framework. Ensure you are in the project's root directory before running the command. ```bash uv run pytest tests ``` -------------------------------- ### Get Portfolio Statistics Source: https://systematica.mintlify.app/api-reference/systematica/portfolio/analyzers/base Retrieves all statistics for a given portfolio, allowing specification of start and end dates, and additional arguments for stats and drawdowns. Returns a pandas Series containing comprehensive portfolio metrics. ```python all_stats( self, start: str | pandas._libs.tslibs.timestamps.Timestamp = None, end: str | pandas._libs.tslibs.timestamps.Timestamp = None, portfolio: Dict[str, Any] = None, drawdowns: Dict[str, Any] = None, ) -> pandas.core.series.Series Get all statistics of the portfolio. Parameters: start: The start date. Defaults to None. end: The end date. Defaults to None. portfolio: Addtional arguments for vbt.stats. Defaults to None. drawdowns: Addtional arguments for vbt.drawdowns.stats. Defaults to None. Returns: pd.Series: All portfolio, returns, orders, trades and drawdowns statistics. ``` -------------------------------- ### Systematica Mintlify App API Reference Source: https://systematica.mintlify.app/api-reference/systematica/portfolio/analyzers/base Comprehensive API documentation for the Systematica Mintlify App, including class variables, instance variables, and method signatures with parameter and return value details. ```APIDOC Class Variables: data: vectorbtpro.data.base.Data Data object. s1: str First symbol. s2: str Second symbol. vbt: vectorbtpro.portfolio.base.Portfolio VectorBT PRO Portfolio object. model_output: pandas.core.frame.DataFrame | numpy.ndarray Model output used in the strategy. Defaults to None. window: int Rolling window used in the model. Defaults to None. minp: int Minimum number of observations required in the model. Defaults to None. Instance Variables: freq: pandas._libs.tslibs.timedeltas.Timedelta Get the frequency of the data. column_wrapper: List[str] Get the column wrapper for the portfolio. If MultiIndex (where group_by is False), Get the first level only. categories: pandas.core.frame.DataFrame | None Retrieve asset categories. drawdowns_readable Get the drawdowns of the portfolio. pfo: vectorbtpro.portfolio.pfopt.base.PortfolioOptimizer Pick allocations from an already filled array. pfo_allocations: pandas.core.frame.DataFrame Get the portfolio allocations. latest_allocation: pandas.core.frame.DataFrame Get the latest allocation of the portfolio. current_holdings Get the current holdings of the portfolio. pfo_describe: pandas.core.frame.DataFrame Get descriptive statistics of portfolio allocations. average_allocation Get the average allocation of the portfolio. allocation_records_readable Get readable allocation records. latest_allocation_records Get the latest allocation records. Methods: get_signals(sim_start: ArrayLike = None, sim_end: ArrayLike = None, group_by: bool = False) -> systematica.signals.base.Signals Return signals for long and short entries and exits. Compute boolean signals indicating the occurrence of long entry orders, long exit orders, short entry orders, and short exit orders. Signals are computed per group if grouping is enabled. Pass group_by=False to disable grouping. Parameters: sim_start: Start index of the simulation range. sim_end: End index of the simulation range. group_by: Grouping specification. Returns: Signals: systematica Signals namedtuple class. get_market_returns() -> pandas.core.frame.DataFrame Calculate market returns without NaNs. Returns: pd.DataFrame: DataFrame of market returns. get_rolling_metrics(metrics: str | List[str], window: int = None, minp: int = None, to_numpy: bool = False, validate_metrics: bool = True, **kwargs) -> pandas.core.frame.DataFrame | numpy.ndarray Get rolling metrics. Parameters: metrics: Metric to compute window: Rolling window length. The default is None. minp: Minimum periods. The default is None. to_numpy: Output numpy array if True. The default is False. validate_metrics: Validate metrics if True. The default is True. kwargs: Additional key-word arguments passed to MetricRegistry.run_rolling_metric. Raises: ValueError: if parameter window is to be specified. Returns: pd.DataFrame | tp.Array: Rolling metrics. ``` -------------------------------- ### Pie Class Example - systematica Source: https://systematica.mintlify.app/api-reference/systematica/utils/custom_plots Example demonstrating how to create and display a pie chart using the systematica.Pie class with sample data. ```python import numpy as np import systematica as sma pie = sma.Pie( data=np.array([0.06, 0.02, 0.05, 0.09]), trace_names=['SPY', 'TLT', 'XLF', 'XLE'], ) pie.fig.show() ``` -------------------------------- ### Activate conda environment Source: https://systematica.mintlify.app/getting-started/installation Activates an existing conda environment, making its packages and Python interpreter available. ```shell conda activate your_environment_name ``` -------------------------------- ### Get Annualized Return Method Source: https://systematica.mintlify.app/api-reference/systematica/api/base Computes and returns the annualized returns specifically for the test set of the dataset. ```apidoc get_annualized_return() -> pandas.core.series.Series Description: Computes the annualized returns for the test set. Returns: - pd.Series: Series containing the annualized returns for the test set. ``` -------------------------------- ### Systematica API Models Source: https://systematica.mintlify.app/api-reference/systematica/api/models/volume_profile References to various models available within the Systematica API, including their specific documentation paths. ```APIDOC API Reference - Models: - Arbitrage Index: /api-reference/systematica/api/models/arbitrage_index - Meta Model: /api-reference/systematica/api/models/meta_model - Momentum: /api-reference/systematica/api/models/momentum - Ou Process: /api-reference/systematica/api/models/ou_process - Range Breakout: /api-reference/systematica/api/models/range_breakout - Volatility: /api-reference/systematica/api/models/volatility - Volume Profile: /api-reference/systematica/api/models/volume_profile ``` -------------------------------- ### Systematica API Signals Source: https://systematica.mintlify.app/api-reference/systematica/api/models/volume_profile References to various signals available within the Systematica API, including their specific documentation paths. ```APIDOC API Reference - Signals: - Cross Spread: /api-reference/systematica/api/signals/cross_spread - Crossover: /api-reference/systematica/api/signals/crossover - Spread: /api-reference/systematica/api/signals/spread - Twin Spread: /api-reference/systematica/api/signals/twin_spread ``` -------------------------------- ### Systematica API Reports Source: https://systematica.mintlify.app/api-reference/systematica/api/models/volume_profile References to various reports available within the Systematica API, including their specific documentation paths. ```APIDOC API Reference - Reports: - Arbitrage Index: /api-reference/systematica/api/reports/arbitrage_index - Meta Model: /api-reference/systematica/api/reports/meta_model - Momentum: /api-reference/systematica/api/reports/momentum - Ou Process: /api-reference/systematica/api/reports/ou_process - Range Breakout: /api-reference/systematica/api/reports/range_breakout - Volatility: /api-reference/systematica/api/reports/volatility - Volume Profile: /api-reference/systematica/api/reports/volume_profile ``` -------------------------------- ### Data Loading and Pipeline Initialization Source: https://systematica.mintlify.app/workspaces/sandbox Describes the initial data fetching and preparation steps using vectorbtpro's Data objects and the load_clean_data function. This sets up the foundation for strategy execution and optimization. ```python from vectorbtpro import Data # Load and clean historical market data data = Data.load_clean_data(symbols=["BTC-USD", "ETH-USD"], timeframe="1D") ``` -------------------------------- ### run method for data pipeline execution Source: https://systematica.mintlify.app/api-reference/systematica/portfolio/composers/models Executes a data pipeline with specified input data and symbols. It is designed to process financial data for portfolio analysis. ```APIDOC run(self, data: vectorbtpro.data.base.Data, s1: str, s2: str, use_close: bool = True) -> systematica.portfolio.analyzers.base.PortfolioAnalyzer Executes the pipeline with the given data and symbols. Parameters: data (vbt.Data): Input data for the pipeline. s1 (str): First symbol. s2 (str): Second symbol. use_close (bool, optional): Whether to use ‘Close’ prices. Defaults to True. Returns: PortfolioAnalyzer: Portfolio analyzer object with the pipeline results. ``` -------------------------------- ### Sandbox Configuration and Execution Source: https://systematica.mintlify.app/workspaces/sandbox Covers configuration options for the Sandbox, which manages the OptunaTuner. Key parameters include n_trials, n_jobs, gc_after_trial, and cross_validate. It also mentions the use of Samplers and Pruners. ```python from vectorbtpro.sandbox import Sandbox from optuna.samplers import TPESampler from optuna.pruners import SuccessiveHalvingPruner # Sandbox configuration sandbox_config = { "n_trials": 50, "n_jobs": -1, # Use all available cores "gc_after_trial": True, "cross_validate": True, "sampler": TPESampler(), "pruner": SuccessiveHalvingPruner() } # The Sandbox passes these options to OptunaTuner ``` -------------------------------- ### BaseTransformer Instantiation Source: https://systematica.mintlify.app/api-reference/systematica/portfolio/transformers/base Example of how to instantiate the BaseTransformer class. This is typically used as a base for creating specific transformer implementations. ```Python from systematica.portfolio.transformers.base import BaseTransformer # Instantiate the base transformer (or a subclass) transformer = BaseTransformer() ``` -------------------------------- ### Get Plants API Endpoint Source: https://systematica.mintlify.app/api-reference/post-plants Retrieves a list of plants from the store. This endpoint is part of the plant management API. ```APIDOC GET /plants Retrieves a list of plants from the store. This is a placeholder for the GET /plants endpoint documentation. Specific parameters, request/response formats, and authorization details would be detailed here. ``` -------------------------------- ### OptunaTuner Constructor Source: https://systematica.mintlify.app/api-reference/systematica/portfolio/tuners/optuna_tuner Initializes the OptunaTuner with various parameters for hyperparameter optimization. It allows configuration of samplers, pruners, optimization direction, trial counts, parallel jobs, and tracking mechanisms. ```python OptunaTuner( pruner: optuna.pruners._base.BasePruner = , sampler: optuna.samplers._base.BaseSampler = , direction: str | List[str] = 'maximize', create_study_kwargs: Dict[str, Any] = _Nothing.NOTHING, n_trials: int = 100, n_completed_trials: int = None, n_jobs: int = -1, gc_after_trial: bool = False, optimize_kwargs: Dict[str, Any] = _Nothing.NOTHING, verbose: bool = True, tracker: systematica.portfolio.trackers.base.BaseTracker = None, metrics: str | List[str] = 'sharpe_ratio', metric_registry_kwargs: Dict[str, Any] = _Nothing.NOTHING, cross_validate: bool = False, reduce_func: Callable = CPUDispatcher(), use_rolling: bool = False, ) ``` -------------------------------- ### Cross-Validation Loop Example Source: https://systematica.mintlify.app/api-reference/systematica/models/meta_model/clf_model Demonstrates a cross-validation loop, fitting a pipeline on training data and predicting on test data for each split. ```python X_slices, y_slices = splitter.take(X), splitter.take(y) y_tests = [] y_preds = [] for split in X_slices.index.unique(level="split"): X_train_slice = X_slices[(split, "train")] y_train_slice = y_slices[(split, "train")] X_test_slice = X_slices[(split, "test")] y_test_slice = y_slices[(split, "test")] try: fitted_pipe = pipeline.fit(X_train_slice, y_train_slice) test_pred = fitted_pipe.predict(X_test_slice) test_pred_ser = pd.Series(test_pred, index=y_test_slice.index) ``` -------------------------------- ### Get Kurtosis Python Source: https://systematica.mintlify.app/api-reference/systematica/preprocessing/stats Estimates the kurtosis of time series data. Takes a 2D NumPy array of time series. Returns the kurtosis. ```python get_kurtosis( rets: numpy.ndarray, ) ‑> numpy.ndarray Estimate kurtosis. **Parameters**: | Name | Type | Default | Description | | --- | --- | --- | --- | | `rets` | `tp.Array2d` | `--` | A 2D NumPy array where each column represents a time series. | **Returns**: | Type | Description | | --- | --- | | `tp.Array2d` | The kurtosis. | ``` -------------------------------- ### Get Skewness Python Source: https://systematica.mintlify.app/api-reference/systematica/preprocessing/stats Estimates the skewness of time series data. Takes a 2D NumPy array of time series. Returns the skewness. ```python get_skewness( rets: numpy.ndarray, ) ‑> numpy.ndarray Estimate skewness. **Parameters**: | Name | Type | Default | Description | | --- | --- | --- | --- | | `rets` | `tp.Array2d` | `--` | A 2D NumPy array where each column represents a time series. | **Returns**: | Type | Description | | --- | --- | | `tp.Array2d` | The skewness. | ```