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

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, and run backtest
backtester = HawkBacktester(initial_value=1)
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)

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.4.tar.gz (335.6 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.4-cp310-cp310-macosx_14_0_arm64.whl (3.8 MB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

File details

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

File metadata

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

File hashes

Hashes for hawk_backtester-0.3.4.tar.gz
Algorithm Hash digest
SHA256 e4b2bfc21e066017840076499cd27858c1efcc9b8ba0f0675bb9b2ec44213e8f
MD5 3d58fb136696bc2d331ed5ea45165023
BLAKE2b-256 e71f4776acfeab935b35599eedb34b64a0cc371ae12d923e5d5f61769d71e9ff

See more details on using hashes here.

File details

Details for the file hawk_backtester-0.3.4-cp310-cp310-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for hawk_backtester-0.3.4-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 19c46d2ccbe6054dfa7fdc2e3063d51d6910281231683e4e036ea53db62df12d
MD5 2fd6cf72b77aa991e6e1d87fe3561daa
BLAKE2b-256 6bdc13c5da44b667dce4bc4ee3de43bda2d45bccbd0487d96f6382fdfa19db5a

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