Kelly-inspired position sizing and backtesting methodology
The trading strategy uses a Kelly-inspired position sizing approach with configurable parameters. Unlike fixed-position strategies, this method adjusts exposure based on the model's confidence and predicted risk-adjusted returns.
# Kelly-inspired position sizing
raw_kelly = expected_return / variance
position_size = raw_kelly * kelly_fraction
# With constraints
if expected_return < min_expected_return:
position_size = 0 # Skip trade
position_size = min(position_size, max_position) # Cap exposure
| parameter | description | baseline | optimized |
|---|---|---|---|
kelly_fraction |
Fraction of Kelly to use | 0.5 | 0.7 |
min_expected_return |
Minimum expected return threshold | 0.0005 | 0.005 |
max_position |
Maximum position size | 1.0 | 1.0 |
Phase 7A testing discovered the configuration that achieved positive returns:
# Winning configuration (achieved +1.32% on AMZN)
kelly_fraction = 0.7 # More aggressive than half-Kelly
min_expected_return = 0.005 # Filter low-quality signals
max_position = 1.0 # Full position cap
# This configuration:
# - Uses 70% of Kelly (vs typical 50%)
# - Requires 0.5% minimum expected return (vs 0.05%)
# - Results in fewer but higher-quality trades
The high min_expected_return threshold (0.005 = 0.5%) filters out low-quality trades.
While this reduces trade frequency, the surviving signals have higher expected edge.
The aggressive kelly_fraction (0.7) capitalizes on this edge when signals pass the filter.
Key insight: Win rate improved from 35% to 44%, but more importantly, the quality of winning trades improved — leading to positive overall returns.
| configuration | stock | return | win rate | sharpe | trades |
|---|---|---|---|---|---|
| Kelly=0.7, Min=0.005 | AMZN | +1.32% | 43.9% | 0.52 | 312 |
| Kelly=0.7, Min=0.005 | META | -2.17% | 48.1% | -0.09 | 81 |
| Kelly=0.5, Min=0.0005 | META | -3.09% | 58.6% | -0.12 | 29 |
| Baseline (unoptimized) | AAPL | -17.8% | 28.5% | -56.21 | 3280 |
The winning configuration only works on AMZN — suggesting stock-specific pattern learning.
The backtesting engine simulates trading with realistic constraints:
# Run backtest with optimized parameters
python scripts/train_and_backtest_fast.py \
--symbol AMZN \
--kelly-fraction 0.7 \
--min-expected-return 0.005 \
--use-features \
--device cuda
# Test on all stocks
python scripts/test_winning_config_all_stocks.py \
--kelly-fraction 0.7 \
--min-expected-return 0.005
| metric | formula | interpretation |
|---|---|---|
win_rate |
profitable_trades / total_trades | % of trades with positive P&L |
return |
final_value / initial_value - 1 | Total percentage return |
sharpe |
mean(return) / std(return) | Risk-adjusted return (annualized) |
trades |
count(positions) | Number of positions taken |
| metric | description | target |
|---|---|---|
dir_accuracy |
% correct direction predictions | > 50% |
dir_accuracy_1pct |
% correct for moves > 1% | > 50% |
nll |
Negative log-likelihood (lower is better) | Minimize |
mse_close |
Mean squared error on close price | Minimize |
Phase 7C (Risk Management) was planned but not completed. Potential enhancements:
A critical finding from Phase 7E: the winning configuration only works on AMZN.
| stock | dataset | return | win rate | notes |
|---|---|---|---|---|
| AMZN | Test | +1.32% | 43.9% | Works! |
| META | Test | -2.17% | 48.1% | Higher win rate, negative return |
| AAPL | Train | -2.43% | 39.7% | Training data |
| TSLA | Train | -5.82% | 40.2% | High volatility hurts |
| MSFT | Train | -9.42% | 37.5% | Worst performance |
Interpretation: The model learned patterns during training (AAPL, MSFT, TSLA) that generalize to AMZN's microstructure but not META's. This suggests the model captured stock-specific rather than universal patterns.
# Run training with best config
python scripts/train_best_config.py --symbol AMZN --device cuda
# Run backtest with optimized parameters
python scripts/train_and_backtest_fast.py \
--symbol AMZN \
--kelly-fraction 0.7 \
--min-expected-return 0.005 \
--use-features
# Test on all stocks
python scripts/test_winning_config_all_stocks.py