Skip to main content

No project description provided

Project description

Hawk Backtester

A high-performance portfolio backtesting system implemented in Rust with Python bindings.

Features

  • Fast backtesting engine written in Rust
  • Python bindings using PyO3
  • Compatible with Polars DataFrames
  • Support for date-based rebalancing events
  • Percent of volume slippage trading costs (in bps)

Installation

From PyPI

pip install hawk_backtester

From source

# Clone the repository
git clone https://github.com/Hawk-Center/hawk-backtester.git
cd hawk-backtester

# Install maturin if you don't have it
pip install maturin

# Build and install the package
maturin develop

Usage

Here's a simple example of how to use the backtester:

import polars as pl
from hawk_backtester import HawkBacktester

# Load your price data with a timestamp column (YYYY-MM-DD format)
# and columns for each asset's price
prices_df = pl.read_csv("data/prices.csv")

# Load your weight data with a timestamp column (YYYY-MM-DD format)
# and columns for each asset's weight
weights_df = pl.read_csv("data/weights.csv")

# Recommended data cleaning process
### For Prices, forward fill first to avoid look-ahead, then backfill missing data
prices_df = prices_df.fill_null(strategy="forward")
prices_df = prices_df.fill_null(strategy="backward")
### For weights, drop null values or fill with 0.0, depending on the desired behavior.
weights_df = weights_df.drop_nulls()
#  weights_df = weights_df.fill_null(0.0)

# Initalize backtester with optional slippage costs (in basis points)
backtester = HawkBacktester(initial_value=1_000_000, slippage_bps=1.0)
results = backtester.run(prices_df, weights_df)

# Parse the result dictionary
results_df = results["backtest_results"]
metrics_df = results["backtest_metrics"]
cash_positions_df = results["backtest_positions"]
position_weights_df = results["backtest_weights"]

Input Data Format

Price Data

The price DataFrame should have the following structure:

  • A date column with dates in YYYY-MM-DD format (e.g., "2023-01-01")
  • One column per asset with the price at that timestamp

Example:

date,AAPL,MSFT,GOOG,AMZN
2023-01-01,150.00,250.00,2000.00,100.00
2023-01-02,152.50,255.00,2020.00,102.00
...

Weight Data

The weight DataFrame should have the following structure:

  • A date column with dates in YYYY-MM-DD format (e.g., "2023-01-01")
  • One column per asset with the target weight at that timestamp (0.0 to 1.0)
  • Use negative weights for short positions (e.g., -0.3 for a 30% short position)

Example:

date,AAPL,MSFT,GOOG,AMZN
2023-01-04,0.30,0.30,0.20,0.10
2023-01-05,0.25,0.35,0.20,0.15
...

Note: Both DataFrames must use the same date format (YYYY-MM-DD) and column name (date) for consistency.

To Publish the project (Developer)

PYPI_API_TOKEN="your-token-here"
maturin publish --username __token__ --password $PYPI_API_TOKEN

License

This project is licensed under the Apache 2.0 License - see the LICENSE file for details.

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

hawk_backtester-0.3.5.tar.gz (162.3 kB view details)

Uploaded Source

Built Distribution

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

hawk_backtester-0.3.5-cp310-cp310-macosx_11_0_arm64.whl (3.8 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

Details for the file hawk_backtester-0.3.5.tar.gz.

File metadata

  • Download URL: hawk_backtester-0.3.5.tar.gz
  • Upload date:
  • Size: 162.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.7.4

File hashes

Hashes for hawk_backtester-0.3.5.tar.gz
Algorithm Hash digest
SHA256 6a0661feca98cff980915e071ab28a31711343418453b352d802bbb949f9723b
MD5 21494c01d4574057f46324d1f8ce2ad4
BLAKE2b-256 e64169fbe94fff6e83a3f1d436a7490f2082b438637262217f0d795abef62bb1

See more details on using hashes here.

File details

Details for the file hawk_backtester-0.3.5-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for hawk_backtester-0.3.5-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b0adc08a570e9f333e904aab1c083e0ec897bfe56e101fa02479e715ba7f1890
MD5 c765bfa6bde1586a98399590452a7af5
BLAKE2b-256 f537a1a46250c73e87b7bca634d99db2020b37921b86bf6c528654e9e46848e1

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