Files
lowkey_backtest/train_daily.sh
Simon Moisy b5550f4ff4 Add daily model training scripts and terminal UI for live trading
- Introduced `train_daily.sh` for automating daily model retraining, including data download and model training steps.
- Added `install_cron.sh` for setting up a cron job to run the daily training script.
- Created `setup_schedule.sh` for configuring Systemd timers for daily training tasks.
- Implemented a terminal UI using Rich for real-time monitoring of trading performance, including metrics display and log handling.
- Updated `pyproject.toml` to include the `rich` dependency for UI functionality.
- Enhanced `.gitignore` to exclude model and log files.
- Added database support for trade persistence and metrics calculation.
- Updated README with installation and usage instructions for the new features.
2026-01-18 11:08:57 +08:00

51 lines
1.4 KiB
Bash
Executable File

#!/bin/bash
# Daily ML Model Training Script
#
# Downloads fresh data and retrains the regime detection model.
# Can be run manually or scheduled via cron.
#
# Usage:
# ./train_daily.sh # Full workflow
# ./train_daily.sh --skip-research # Skip research validation
set -e # Exit on error
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
LOG_DIR="logs"
mkdir -p "$LOG_DIR"
TIMESTAMP=$(date +"%Y-%m-%d %H:%M:%S")
echo "[$TIMESTAMP] Starting daily training..."
# 1. Download fresh data
echo "Downloading BTC-USDT 1h data..."
uv run python main.py download -p BTC-USDT -t 1h
echo "Downloading ETH-USDT 1h data..."
uv run python main.py download -p ETH-USDT -t 1h
# 2. Research optimization (find best horizon)
echo "Running research optimization..."
uv run python research/regime_detection.py --output-horizon data/optimal_horizon.txt
# 3. Read best horizon
if [[ -f "data/optimal_horizon.txt" ]]; then
BEST_HORIZON=$(cat data/optimal_horizon.txt)
echo "Found optimal horizon: ${BEST_HORIZON} bars"
else
BEST_HORIZON=102
echo "Warning: Could not find optimal horizon file. Using default: ${BEST_HORIZON}"
fi
# 4. Train model
echo "Training ML model with horizon ${BEST_HORIZON}..."
uv run python train_model.py --horizon "$BEST_HORIZON"
# 5. Cleanup
rm -f data/optimal_horizon.txt
TIMESTAMP=$(date +"%Y-%m-%d %H:%M:%S")
echo "[$TIMESTAMP] Daily training complete."