Files
foxhunt/scripts/run_cross_validation.sh
jgrusewski 8d89fe80ff chore: Second cleanup wave - organize root directory
- Archive: 85 agent .txt files → docs/archive/agents/legacy_txt/
- Scripts: Move 110 shell scripts → scripts/ (keep deploy.sh in root)
- Models: Move 18 .safetensors → ml/models/checkpoints/training_artifacts/
- Delete: 34 directories (~33GB freed) - target/, coverage_*, test artifacts
- Build: Clean 14 build artifacts (.rlib, .o, .pid, binaries)
- Tests: Move 14 .rs files → tests/standalone/
- SQL: Move 5 files → sql/ (keep init-db*.sql for Docker)
- Wave 153: Archive to docs/archive/historical/wave153/
- Docs: Archive 9 markdown files to wave_d/reports/ and historical/

Total impact: ~34GB freed (both waves), root directory cleaned from 583 to ~40 essential files
Directory count reduced from 65 to 31 (52% reduction)
All historical data preserved in organized archive structure
2025-10-30 01:26:02 +01:00

112 lines
3.6 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# Cross-Validation: Test top 3 models on held-out May 2024 data
# Models: DQN-30, DQN-310, PPO-130
# Objective: Validate generalization (Sharpe drop <20%, win rate >55%, max drawdown <15%)
set -e
RESULTS_DIR="/home/jgrusewski/Work/foxhunt/results/cross_validation"
mkdir -p "$RESULTS_DIR"
echo "=========================================="
echo "CROSS-VALIDATION ON HELD-OUT DATA (May 2024)"
echo "=========================================="
echo ""
echo "Models Under Test:"
echo " - DQN Epoch 30 (Early exploration, high Q-value)"
echo " - DQN Epoch 310 (Late convergence, conservative)"
echo " - PPO Epoch 130 (Mid-training, balanced)"
echo ""
echo "Held-Out Dataset: May 2024 (4 days × 4 symbols = 16 files)"
echo "Training Dataset: Jan-April 2024 (361 files)"
echo ""
echo "Success Criteria:"
echo " ✅ Sharpe ratio >8.0 on held-out (vs 10+ on training)"
echo " ✅ Win rate >55%"
echo " ✅ Max drawdown <15%"
echo " ✅ Generalization gap <20% (held-out Sharpe / training Sharpe)"
echo ""
# Test each model on each symbol's May data
MODELS=(
"dqn_epoch_30:DQN"
"dqn_epoch_310:DQN"
"ppo_actor_epoch_130:PPO"
)
SYMBOLS=("ES.FUT" "NQ.FUT" "ZN.FUT" "6E.FUT")
for model_info in "${MODELS[@]}"; do
IFS=':' read -r model_file model_type <<< "$model_info"
echo "=========================================="
echo "Testing: $model_file ($model_type)"
echo "=========================================="
for symbol in "${SYMBOLS[@]}"; do
echo ""
echo "📊 Symbol: $symbol (May 2024 held-out data)"
# Find May 2024 files for this symbol
DATA_FILES=$(find /home/jgrusewski/Work/foxhunt/test_data/real/databento/ml_training \
-name "${symbol}_ohlcv-1m_2024-05-*.dbn" | sort)
if [ -z "$DATA_FILES" ]; then
echo " ⚠️ No held-out data found for $symbol"
continue
fi
NUM_FILES=$(echo "$DATA_FILES" | wc -l)
echo " Found $NUM_FILES May 2024 data files"
# Create temporary directory for this symbol's May data
TEMP_DATA_DIR="$RESULTS_DIR/temp_${symbol}_may2024"
mkdir -p "$TEMP_DATA_DIR"
# Copy May files to temp directory
echo "$DATA_FILES" | while read -r file; do
cp "$file" "$TEMP_DATA_DIR/"
done
# Determine model path based on type
if [ "$model_type" = "DQN" ]; then
MODEL_PATH="/home/jgrusewski/Work/foxhunt/ml/trained_models/production/dqn_real_data/${model_file}.safetensors"
else
MODEL_PATH="/home/jgrusewski/Work/foxhunt/ml/trained_models/production/ppo_real_data/${model_file}.safetensors"
fi
# Run backtest
OUTPUT_FILE="$RESULTS_DIR/${model_file}_${symbol}_may2024.json"
echo " 🔄 Running backtest..."
echo " Model: $MODEL_PATH"
echo " Data: $TEMP_DATA_DIR"
echo " Output: $OUTPUT_FILE"
# Run comprehensive backtest (Note: This is a placeholder - actual implementation needed)
# The comprehensive_model_backtest.rs needs to be updated to accept CLI args
echo " ⏳ Backtest execution placeholder (requires CLI args implementation)"
# Cleanup temp directory
rm -rf "$TEMP_DATA_DIR"
echo " ✅ Backtest complete"
done
echo ""
done
echo ""
echo "=========================================="
echo "CROSS-VALIDATION COMPLETE"
echo "=========================================="
echo ""
echo "Results saved to: $RESULTS_DIR"
echo ""
echo "Next Steps:"
echo " 1. Analyze results: Compare training metrics vs held-out"
echo " 2. Calculate generalization gap: (training_sharpe - held_out_sharpe) / training_sharpe"
echo " 3. Identify overfitting: Gap >20% indicates poor generalization"
echo " 4. Generate CROSS_VALIDATION_REPORT.md"
echo ""