Skip to main content

Multi-node parallelized backtesting tool for BYU Silver Fund Quant Team.

Project description

sf-backtester

SLURM-based parallel backtesting for quantitative finance. Distributes MVO optimization across compute nodes, processing one year per task.

Installation

pip install sf-backtester

Usage

CLI

# Run backtest
sf_backtester run config.yml

# Run dynamic backtest
sf_backtester run-dynamic config.yml

# Preview sbatch script without submitting
sf_backtester run config.yml --dry-run

Python API

from sf_backtester import BacktestRunner, BacktestConfig, SlurmConfig

slurm_config = SlurmConfig(
    n_cpus=8,
    mem="32G",
    time="03:00:00",
    mail_type="BEGIN,END,FAIL",
    max_concurrent_jobs=30,
)

config = BacktestConfig(
    signal_name="momentum",
    gamma=50,
    data_path="/path/to/alphas.parquet",
    project_root="/path/to/project",
    byu_email="you@byu.edu",
    constraints=["ZeroBeta", "ZeroInvestment"],
    slurm=slurm_config,
)

runner = BacktestRunner(config)

# Submit to SLURM
runner.submit()

Or load from YAML:

from sf_backtester import BacktestRunner

runner = BacktestRunner.from_yaml("config.yml")

runner.submit()

You can also pass a DataFrame directly:

from sf_backtester import BacktestRunner
import polars as pl

runner = BacktestRunner.from_yaml("config.yml")

data = pl.read_parquet("alphas.parquet")

runner.submit(data=data)

Configuration

Standard backtest (YAML)

signal_name: momentum
gamma: 500
data_path: /path/to/alphas.parquet
project_root: /path/to/project
byu_email: you@byu.edu

constraints:
  - ZeroBeta
  - ZeroInvestment

slurm:
  n_cpus: 8
  mem: 32G
  time: "03:00:00"
  mail_type: BEGIN,END,FAIL
  max_concurrent_jobs: 31

Dynamic backtest (YAML)

Uses initial_gamma as a starting point and adjusts it each period to target a specific active risk level.

Important! If you use the ZeroBeta and ZeroInvestment constraints set active_weights as true. This will allow for the dynamic gamma computation. If you use UnitBeta, FullInvestment, and LongOnly set active_weights as false.

signal_name: momentum
initial_gamma: 50
target_active_risk: 0.05
active_weights: true
data_path: /path/to/alphas.parquet
project_root: /path/to/project
byu_email: you@byu.edu

constraints:
  - ZeroBeta
  - ZeroInvestment

slurm:
  n_cpus: 8
  mem: 32G
  time: "06:00:00"
  mail_type: BEGIN,END,FAIL
  max_concurrent_jobs: 31

Available constraints

  • ZeroBeta
  • ZeroInvestment
  • UnitBeta
  • FullInvestment
  • LongOnly
  • NoBuyingOnMargin

Data format

Input parquet must have columns:

  • date: Date column
  • barrid: Asset identifier
  • alpha: Alpha signal values
  • predicted_beta: Predicted beta values
  • benchmark_weight: Benchmark weight (if doing total portfolio)

Output is one parquet per year in output_dir/{year}.parquet containing portfolio weights.

Publishing

  1. Bump the version
uv version v*.*.*
  1. Add changes (it can be just the version change)
git add .
git commit -m "Bumped version."
  1. Tag the branch
git tag v*.*.*
  1. Push to origin
git push --tags

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sf_backtester-0.2.0.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sf_backtester-0.2.0-py3-none-any.whl (11.6 kB view details)

Uploaded Python 3

File details

Details for the file sf_backtester-0.2.0.tar.gz.

File metadata

  • Download URL: sf_backtester-0.2.0.tar.gz
  • Upload date:
  • Size: 9.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.3 {"installer":{"name":"uv","version":"0.11.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for sf_backtester-0.2.0.tar.gz
Algorithm Hash digest
SHA256 395814c41b28a5c5ce954bfc22f6ab551d10af5325c45635b5188c57c7a5a742
MD5 c8a25e57ceba43cee42cb4a5d4e6d3cb
BLAKE2b-256 ef4fee378d0c892690f0316fcb2621c1f76666a8fb2c49deec43a4d503000d4a

See more details on using hashes here.

File details

Details for the file sf_backtester-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: sf_backtester-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 11.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.3 {"installer":{"name":"uv","version":"0.11.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for sf_backtester-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bd4ddfe907dc7f8d920f0d63701547c9e38494f3c0dd3905fa52b84eca9e31a6
MD5 7bb379fe5e90e8951d152b29cda3ea75
BLAKE2b-256 edaaa8d46ecb9cf3322fac575490fa64deda450177fa6935d6b0bd50865429d2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page