refactor: CLI binaries use shared fxcache::discover_and_load()
Replace 40-line inline fxcache discovery block in train_baseline_rl.rs with a single call to ml::fxcache::discover_and_load(). precompute_features.rs already uses correct symbol/data_source args — no changes needed there. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -542,51 +542,18 @@ fn run_training(args: &Args) -> Result<Vec<RlTrainingResult>> {
|
|||||||
info!("Step 1/5: Loading data...");
|
info!("Step 1/5: Loading data...");
|
||||||
let data_load_start = std::time::Instant::now();
|
let data_load_start = std::time::Instant::now();
|
||||||
|
|
||||||
// Auto-discover fxcache: CLI arg > env var > sibling feature-cache/ dir
|
let cache_dir_override = args.feature_cache_dir.as_ref().map(|s| std::path::PathBuf::from(s));
|
||||||
let fxcache_dir = args.feature_cache_dir.as_ref()
|
let mbp10 = args.mbp10_data_dir.as_ref().filter(|p| p.exists());
|
||||||
.map(PathBuf::from)
|
let trades = args.trades_data_dir.as_ref().filter(|p| p.exists());
|
||||||
.filter(|p| p.exists())
|
|
||||||
.or_else(|| std::env::var("FOXHUNT_FEATURE_CACHE_DIR").ok().map(PathBuf::from))
|
|
||||||
.or_else(|| {
|
|
||||||
let symbol_dir = args.data_dir.join(&args.symbol);
|
|
||||||
let mut dir = symbol_dir.as_path();
|
|
||||||
loop {
|
|
||||||
if let Some(parent) = dir.parent() {
|
|
||||||
let candidate = parent.join("feature-cache");
|
|
||||||
if candidate.exists() { return Some(candidate); }
|
|
||||||
if parent == dir { break; }
|
|
||||||
dir = parent;
|
|
||||||
} else { break; }
|
|
||||||
}
|
|
||||||
None
|
|
||||||
});
|
|
||||||
|
|
||||||
// Try loading from fxcache
|
let fxcache_data = ml::fxcache::discover_and_load(
|
||||||
let fxcache_data = fxcache_dir.and_then(|cache_dir| {
|
&args.data_dir,
|
||||||
// Key must match precompute_features: data_dir (not symbol_dir)
|
&args.symbol,
|
||||||
let default_mbp10 = PathBuf::from("test_data/futures-baseline-mbp10");
|
mbp10.map(|p| p.as_path()),
|
||||||
let default_trades = PathBuf::from("test_data/futures-baseline-trades");
|
trades.map(|p| p.as_path()),
|
||||||
let mbp10 = args.mbp10_data_dir.as_deref().unwrap_or(&default_mbp10);
|
"ohlcv",
|
||||||
let trades = args.trades_data_dir.as_deref().unwrap_or(&default_trades);
|
cache_dir_override.as_deref(),
|
||||||
let mbp10: Option<&Path> = if mbp10.exists() { Some(mbp10) } else { None };
|
);
|
||||||
let trades: Option<&Path> = if trades.exists() { Some(trades) } else { None };
|
|
||||||
|
|
||||||
let key_hex = ml::feature_cache::calculate_dbn_cache_key_full(
|
|
||||||
&args.data_dir, mbp10, trades, &args.symbol, "ohlcv",
|
|
||||||
).ok()?;
|
|
||||||
let key: [u8; 32] = hex::decode(&key_hex).ok()?.try_into().ok()?;
|
|
||||||
let path = ml::fxcache::find_fxcache(&cache_dir, &key)?;
|
|
||||||
match ml::fxcache::load_fxcache(&path) {
|
|
||||||
Ok(data) => {
|
|
||||||
info!("fxcache hit: {} bars from {:?}", data.bar_count, path);
|
|
||||||
Some(data)
|
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
warn!("fxcache load failed: {e}");
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Load data into fxcache-compatible arrays: features, targets, timestamps, ofi
|
// Load data into fxcache-compatible arrays: features, targets, timestamps, ofi
|
||||||
let fxcache = if let Some(cached) = fxcache_data {
|
let fxcache = if let Some(cached) = fxcache_data {
|
||||||
|
|||||||
Reference in New Issue
Block a user