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"]
Input Data Format
Price Data
The price DataFrame should have the following structure:
- A
datecolumn 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
datecolumn 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 MIT License - see the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file hawk_backtester-0.3.3.tar.gz.
File metadata
- Download URL: hawk_backtester-0.3.3.tar.gz
- Upload date:
- Size: 309.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.7.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7eb41a95dd22ce46777527b399ae689715a11403cf1c333ad20b14e6382cee77
|
|
| MD5 |
9d6ef4eff35a31bc51754022da19f5c0
|
|
| BLAKE2b-256 |
048c8e232808705ed812d27b518a68344eb01bb05bc2549395da17e22c5858c3
|
File details
Details for the file hawk_backtester-0.3.3-cp312-cp312-macosx_14_0_arm64.whl.
File metadata
- Download URL: hawk_backtester-0.3.3-cp312-cp312-macosx_14_0_arm64.whl
- Upload date:
- Size: 3.8 MB
- Tags: CPython 3.12, macOS 14.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.7.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
439020fa37c2e454dc137b8d5de136ed1edb172049facd361f997c27038b59f7
|
|
| MD5 |
86cdac58e5fb782db4642d89beab0497
|
|
| BLAKE2b-256 |
d45aea4e5a6d78fafe827129100dcebb7e752446541bdfa501630209054e1504
|