Ultra-fast backtesting and trading framework. Built with Polars for speed, designed for simplicity.
Project description
wrtrade
Ultra-fast backtesting and trading framework. Built with Polars for speed, designed for simplicity.
Install
pip install wrtrade
Quick Start
import wrtrade as wrt
import polars as pl
# Define your signal
def trend(prices):
fast = prices.rolling_mean(10)
slow = prices.rolling_mean(30)
return (fast > slow).cast(int) - (fast < slow).cast(int)
# One-line backtest
result = wrt.backtest(trend, prices)
print(f"Sortino: {result.sortino:.2f}")
That's it. No builders, no managers, no factories.
The API
Portfolio
Portfolio is the core data type. It holds trading signals.
# Single signal
portfolio = wrt.Portfolio(trend)
# Multiple signals with weights
portfolio = wrt.Portfolio([
(trend, 0.6),
(momentum, 0.4),
])
# Named signals
portfolio = wrt.Portfolio({
'trend': (trend, 0.6),
'momentum': (momentum, 0.4),
})
Backtest
# From a signal function
result = wrt.backtest(trend, prices)
# From a portfolio
result = portfolio.backtest(prices)
# Access metrics
result.sortino # Sortino ratio
result.sharpe # Sharpe ratio
result.max_drawdown # Maximum drawdown
result.total_return # Total return
result.volatility # Annualized volatility
result.returns # Returns series
# Print formatted report
result.tear_sheet()
Validate
Statistical validation using permutation testing:
# One-line validation
p_value = wrt.validate(trend, prices)
if p_value < 0.05:
print("Strategy is statistically significant!")
# With more control
p_value = portfolio.validate(prices, n_permutations=1000, parallel=True)
Optimize
Kelly criterion optimization for position sizing:
# Optimize weights
portfolio.optimize(prices)
# With parameters
portfolio.optimize(prices, method='kelly', max_leverage=1.0)
Complete Example
import wrtrade as wrt
import polars as pl
import numpy as np
# 1. Define signals
def trend(prices):
fast = prices.rolling_mean(10)
slow = prices.rolling_mean(30)
return (fast > slow).cast(int) - (fast < slow).cast(int)
def momentum(prices):
returns = prices.pct_change(20).fill_null(0)
return (returns > 0.05).cast(int) - (returns < -0.05).cast(int)
# 2. Create portfolio
portfolio = wrt.Portfolio([
(trend, 0.6),
(momentum, 0.4),
])
# 3. Backtest
result = portfolio.backtest(prices)
print(f"Sortino: {result.sortino:.2f}")
print(f"Return: {result.total_return:.2%}")
# 4. Validate
p_value = portfolio.validate(prices)
if p_value < 0.05:
print("Strategy is significant!")
# 5. Optimize
portfolio.optimize(prices)
print(f"Optimized weights: {portfolio.weights}")
# 6. View report
result.tear_sheet()
Deployment
WayyFin Paper Trading (Recommended)
The easiest way to test your strategy with real-time market data - no broker credentials needed.
# Deploy to WayyFin paper trading
wrtrade wayyfin deploy my_strategy.py --symbol BTC-USD
# Watch it live on the leaderboard
open http://localhost:5173 # or https://wayy.finance
Your strategy will:
- Auto-register with a randomized name (no alpha leakage)
- Run backtest validation
- Start paper trading with live Coinbase data
- Appear on the public leaderboard with real-time P&L
# Check strategy status
wrtrade wayyfin status <strategy-id>
# Stop paper trading
wrtrade wayyfin stop <strategy-id>
# View leaderboard
wrtrade wayyfin leaderboard
Strategy file format:
# my_strategy.py
import polars as pl
def signal(prices: pl.Series) -> pl.Series:
"""
Generate trading signals from price data.
Args:
prices: Polars Series of prices
Returns:
Series with values: -1 (short), 0 (flat), 1 (long)
"""
fast = prices.rolling_mean(10)
slow = prices.rolling_mean(30)
return (fast > slow).cast(int) - (fast < slow).cast(int)
Broker Deployment (Live Trading)
For real money trading with supported brokers:
# my_strategy.py
import wrtrade as wrt
def trend(prices):
fast = prices.rolling_mean(10)
slow = prices.rolling_mean(30)
return (fast > slow).cast(int) - (fast < slow).cast(int)
def build_portfolio():
return wrt.Portfolio(trend, name="Trend_Strategy")
Deploy:
wrtrade strategy deploy my_strategy.py \
--name my_strategy \
--broker alpaca \
--symbols AAPL,TSLA
wrtrade strategy start my_strategy
Signal Functions
Signal functions take a price series and return signals:
def my_signal(prices: pl.Series) -> pl.Series:
"""
Args:
prices: Polars Series of prices
Returns:
Polars Series with values:
-1 = short
0 = flat
1 = long
"""
# Your logic here
return signals
Advanced Usage
All advanced features remain accessible:
# Permutation testing with full control
from wrtrade import PermutationTester, PermutationConfig
config = PermutationConfig(
n_permutations=5000,
parallel=True,
preserve_gaps=True,
)
tester = PermutationTester(config)
results = tester.run_walkforward_test(prices, strategy_func, train_window=252)
# Kelly optimization with parameters
from wrtrade import KellyOptimizer, KellyConfig
config = KellyConfig(
lookback_window=252,
max_leverage=1.0,
min_weight=0.0,
max_weight=1.0,
)
optimizer = KellyOptimizer(config)
CLI Reference
WayyFin Paper Trading
wrtrade wayyfin deploy <file> # Deploy to paper trading with live data
wrtrade wayyfin status <id> # Check strategy status
wrtrade wayyfin stop <id> # Stop paper trading
wrtrade wayyfin leaderboard # View public leaderboard
Broker Trading
wrtrade strategy deploy <file> # Deploy strategy to broker
wrtrade strategy start <name> # Start trading
wrtrade strategy stop <name> # Stop trading
wrtrade strategy status # Check status
wrtrade strategy logs <name> # View logs
Why wrtrade?
- Fast: Built on Polars, 10-50x faster than pandas
- Simple:
Portfoliois a data type, not a framework - Validated: Built-in permutation testing catches overfitting
- Production-ready: CLI deployment with monitoring
License
MIT
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
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 wrtrade-2.1.1.tar.gz.
File metadata
- Download URL: wrtrade-2.1.1.tar.gz
- Upload date:
- Size: 92.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
34ad6d69e578e5ae403b9aa32665af51102fb69bb7c6c46ac724c9e3694c5e01
|
|
| MD5 |
5c273b24b54c74c72e18359472279715
|
|
| BLAKE2b-256 |
a3b685edfba3173f4c9a105e5055e6ea1e677e5ed9b4d6b668a2166ddf8b59cf
|
Provenance
The following attestation bundles were made for wrtrade-2.1.1.tar.gz:
Publisher:
publish.yml on Wayy-Research/wrtrade
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
wrtrade-2.1.1.tar.gz -
Subject digest:
34ad6d69e578e5ae403b9aa32665af51102fb69bb7c6c46ac724c9e3694c5e01 - Sigstore transparency entry: 925238444
- Sigstore integration time:
-
Permalink:
Wayy-Research/wrtrade@53ec63fcb3efb65233f2bd8659ea353584f3e439 -
Branch / Tag:
refs/tags/v2.1.1 - Owner: https://github.com/Wayy-Research
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@53ec63fcb3efb65233f2bd8659ea353584f3e439 -
Trigger Event:
release
-
Statement type:
File details
Details for the file wrtrade-2.1.1-py3-none-any.whl.
File metadata
- Download URL: wrtrade-2.1.1-py3-none-any.whl
- Upload date:
- Size: 80.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
57acd542d51c0f890d6f3380aa48d836950cc3816123502cbfaeba562daf03b5
|
|
| MD5 |
250e7841be11d02ab23ee6bdca0200a8
|
|
| BLAKE2b-256 |
7489c4d52c80df7c64b407e969917a5383db5256d8e0f732d7751e25444f352f
|
Provenance
The following attestation bundles were made for wrtrade-2.1.1-py3-none-any.whl:
Publisher:
publish.yml on Wayy-Research/wrtrade
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
wrtrade-2.1.1-py3-none-any.whl -
Subject digest:
57acd542d51c0f890d6f3380aa48d836950cc3816123502cbfaeba562daf03b5 - Sigstore transparency entry: 925238510
- Sigstore integration time:
-
Permalink:
Wayy-Research/wrtrade@53ec63fcb3efb65233f2bd8659ea353584f3e439 -
Branch / Tag:
refs/tags/v2.1.1 - Owner: https://github.com/Wayy-Research
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@53ec63fcb3efb65233f2bd8659ea353584f3e439 -
Trigger Event:
release
-
Statement type: