#!/usr/bin/env bash # run_grid.sh — loop over timeframes and 2–6 bars-ahead horizons set -euo pipefail # Paths (edit if different) PROJ_DIR="${PROJ_DIR:-$HOME/Documents/Work/TCP/BTC_ETH_regime_predictor}" DATA_DIR="${DATA_DIR:-$PROJ_DIR/../data}" PY="${PY:-$PROJ_DIR/.venv/bin/python}" BTC_CSV="${BTC_CSV:-$DATA_DIR/btcusd_1-min_data.csv}" ETH_CSV="${ETH_CSV:-$DATA_DIR/ethusd_1min_ohlc.csv}" SPLIT_DATE="${SPLIT_DATE:-2023-01-01}" N_STATES="${N_STATES:-3}" # Timeframes to test: 20–60 min inclusive readarray -t RULES < <(seq 20 60 | awk '{printf "%dmin\n",$1}') # Convert a pandas-like offset to minutes: supports Nmin, NH, ND to_minutes() { local r="$1" if [[ "$r" =~ ^([0-9]+)min$ ]]; then echo "${BASH_REMATCH[1]}" elif [[ "$r" =~ ^([0-9]+)H$ ]]; then echo $(( ${BASH_REMATCH[1]} * 60 )) elif [[ "$r" =~ ^([0-9]+)D$ ]]; then echo $(( ${BASH_REMATCH[1]} * 1440 )) else echo "Unsupported rule: $r" >&2 exit 2 fi } # Logs OUT_DIR="${OUT_DIR:-$PROJ_DIR/run_logs}" mkdir -p "$OUT_DIR" TS="$(date +"%Y%m%d_%H%M%S")" LOG="$OUT_DIR/grid_${TS}.log" # Run grid for BARS in 2 3 4 5 6; do for RULE in "${RULES[@]}"; do BAR_MIN=$(to_minutes "$RULE") HORIZON=$(( BARS * BAR_MIN )) echo "Running rule='$RULE' bars_ahead=$BARS horizon_min=$HORIZON" | tee -a "$LOG" "$PY" "$PROJ_DIR/main.py" \ --btc "$BTC_CSV" \ --eth "$ETH_CSV" \ --rules "$RULE" \ --states "$N_STATES" \ --split "$SPLIT_DATE" \ --horizon "$HORIZON" | tee -a "$LOG" echo | tee -a "$LOG" done done