Skip to main content

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

Metadata

Release files for sf-backtester 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sf-backtester 0.2.0
File Size Uploaded Provenance Actions
sf_backtester-0.2.0.tar.gz 9.3 kB Without provenance Details for sf_backtester-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for sf-backtester 0.2.0
File Interpreter ABI Platform Actions
sf_backtester-0.2.0-py3-none-any.whl Python 3 none any Details for sf_backtester-0.2.0-py3-none-any.whl

Total release size: 20.8 kB

Release files / sf_backtester-0.2.0.tar.gz

Download URL sf_backtester-0.2.0.tar.gz
Size 9.3 kB
Tags Source
SHA-256 checksum
How to use checksums
395814c41b28a5c5ce954bfc22f6ab551d10af5325c45635b5188c57c7a5a742
BLAKE2b-256 checksum
How to use checksums
ef4fee378d0c892690f0316fcb2621c1f76666a8fb2c49deec43a4d503000d4a
Upload date
Uploaded using Trusted Publishing?
What is 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}

Release files / sf_backtester-0.2.0-py3-none-any.whl

Download URL sf_backtester-0.2.0-py3-none-any.whl
Size 11.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bd4ddfe907dc7f8d920f0d63701547c9e38494f3c0dd3905fa52b84eca9e31a6
BLAKE2b-256 checksum
How to use checksums
edaaa8d46ecb9cf3322fac575490fa64deda450177fa6935d6b0bd50865429d2
Upload date
Uploaded using Trusted Publishing?
What is 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}

Security for sf-backtester 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page