修复FIDC策略滑点配置解析

This commit is contained in:
boris
2026-06-17 05:31:46 +08:00
parent 70695d8c92
commit bc39df0ee5
3 changed files with 189 additions and 65 deletions
+19 -57
View File
@@ -1539,6 +1539,8 @@ pub struct OmniMicroCapConfig {
pub stock_short_ma_days: usize,
pub stock_mid_ma_days: usize,
pub stock_long_ma_days: usize,
pub stock_volume_short_ma_days: usize,
pub stock_volume_long_ma_days: usize,
pub rsi_rate: f64,
pub trade_rate: f64,
pub stop_loss_ratio: f64,
@@ -1565,6 +1567,8 @@ impl OmniMicroCapConfig {
stock_short_ma_days: 5,
stock_mid_ma_days: 10,
stock_long_ma_days: 20,
stock_volume_short_ma_days: 5,
stock_volume_long_ma_days: 60,
rsi_rate: 1.0001,
trade_rate: 0.5,
stop_loss_ratio: 0.93,
@@ -1593,6 +1597,8 @@ impl OmniMicroCapConfig {
stock_short_ma_days: 5,
stock_mid_ma_days: 10,
stock_long_ma_days: 30,
stock_volume_short_ma_days: 5,
stock_volume_long_ma_days: 60,
rsi_rate: 1.0001,
trade_rate: 0.5,
stop_loss_ratio: 0.92,
@@ -2271,62 +2277,33 @@ impl OmniMicroCapStrategy {
return false;
};
// MA filter: ma_short > ma_mid * rsi_rate && ma_mid * rsi_rate > ma_long
let ma_pass =
ma_short > ma_mid * self.config.rsi_rate && ma_mid * self.config.rsi_rate > ma_long;
// Debug logging for ALL stocks on first decision date
static DEBUG_DATE: std::sync::Mutex<Option<NaiveDate>> = std::sync::Mutex::new(None);
let mut debug_date = DEBUG_DATE.lock().unwrap();
let should_debug = if let Some(d) = *debug_date {
d == date
} else {
*debug_date = Some(date);
true
};
if should_debug {
eprintln!(
"[MA_FILTER] {} cap={:.2} ma5={:.4} ma10={:.4} ma30={:.4} ma10*rsi={:.4} pass={} ({}>{:.4}? {} && {:.4}>{}? {})",
symbol,
ctx.data.market_decision_close(date, symbol).unwrap_or(0.0),
ma_short,
ma_mid,
ma_long,
ma_mid * self.config.rsi_rate,
ma_pass,
ma_short,
ma_mid * self.config.rsi_rate,
ma_short > ma_mid * self.config.rsi_rate,
ma_mid * self.config.rsi_rate,
ma_long,
ma_mid * self.config.rsi_rate > ma_long
);
}
if !ma_pass {
return false;
}
// Volume filter: V5 < V60 (applied for omni_microcap strategies)
if self.config.strategy_name.contains("aiquant")
|| self.config.strategy_name.contains("AiQuant")
|| self.config.strategy_name.contains("omni")
{
let Some(volume_ma5) = ctx
.data
.market_decision_volume_moving_average(date, symbol, 5)
else {
let Some(volume_ma5) = ctx.data.market_decision_volume_moving_average(
date,
symbol,
self.config.stock_volume_short_ma_days,
) else {
return false;
};
let Some(volume_ma60) = ctx
.data
.market_decision_volume_moving_average(date, symbol, 60)
else {
let Some(volume_ma_long) = ctx.data.market_decision_volume_moving_average(
date,
symbol,
self.config.stock_volume_long_ma_days,
) else {
return false;
};
if volume_ma5 >= volume_ma60 {
if volume_ma5 >= volume_ma_long {
return false;
}
}
@@ -2519,18 +2496,6 @@ fn omni_truth_stock_list_candidates() -> Vec<PathBuf> {
}
}
}
let suffix = PathBuf::from("data/demo/engine_truth_stock_list.csv");
let manifest_root = Path::new(env!("CARGO_MANIFEST_DIR"));
push_unique_truth_path(
&mut candidates,
manifest_root.join("../../../").join(&suffix),
);
if let Ok(current_dir) = env::current_dir() {
for ancestor in current_dir.ancestors() {
push_unique_truth_path(&mut candidates, ancestor.join(&suffix));
}
}
candidates
}
@@ -2699,10 +2664,6 @@ impl Strategy for OmniMicroCapStrategy {
};
// 使用前一交易日的指数价格计算市值区间(模拟实盘场景)
let (band_low, band_high) = self.market_cap_band(prev_index_level);
eprintln!(
"[DEBUG] date={} current_index={:.2} prev_index={:.2} band=[{:.0}, {:.0}]",
date, index_level, prev_index_level, band_low, band_high
);
let (stock_list, selection_notes) = self.select_symbols(ctx, date, band_low, band_high)?;
let periodic_rebalance = ctx.decision_index % self.config.refresh_rate == 0;
let mut projected = ctx.portfolio.clone();
@@ -2726,7 +2687,8 @@ impl Strategy for OmniMicroCapStrategy {
+ self.stop_loss_tolerance(market);
let profit_hit = current_price / position.average_cost > self.config.take_profit_ratio;
let can_sell = self.can_sell_position(ctx, date, &position.symbol);
if stop_hit || profit_hit {
let at_upper_limit = market.is_at_upper_limit_price(current_price);
if stop_hit || (profit_hit && !at_upper_limit) {
let sell_reason = if stop_hit {
"stop_loss_exit"
} else {