Rename engine strategy surfaces
This commit is contained in:
@@ -1479,7 +1479,7 @@ impl Strategy for CnSmallCapRotationStrategy {
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct JqMicroCapConfig {
|
||||
pub struct OmniMicroCapConfig {
|
||||
pub strategy_name: String,
|
||||
pub refresh_rate: usize,
|
||||
pub stocknum: usize,
|
||||
@@ -1500,10 +1500,10 @@ pub struct JqMicroCapConfig {
|
||||
pub skip_month_day_ranges: Vec<(u32, u32, u32)>,
|
||||
}
|
||||
|
||||
impl JqMicroCapConfig {
|
||||
pub fn jq_microcap() -> Self {
|
||||
impl OmniMicroCapConfig {
|
||||
pub fn omni_microcap() -> Self {
|
||||
Self {
|
||||
strategy_name: "jq-microcap".to_string(),
|
||||
strategy_name: "omni-microcap".to_string(),
|
||||
refresh_rate: 15,
|
||||
stocknum: 40,
|
||||
xs: 4.0 / 500.0,
|
||||
@@ -1520,9 +1520,8 @@ impl JqMicroCapConfig {
|
||||
trade_rate: 0.5,
|
||||
stop_loss_ratio: 0.93,
|
||||
take_profit_ratio: 1.07,
|
||||
// The source JQ script calls validate_date() but then immediately forces
|
||||
// g.OpenYN = 1 inside check_stocks(), so the seasonal stop windows are
|
||||
// effectively disabled in real execution logs.
|
||||
// The migrated reference logic disables seasonal stop windows in
|
||||
// production-style execution, so the default keeps that behavior.
|
||||
skip_month_day_ranges: Vec::new(),
|
||||
}
|
||||
}
|
||||
@@ -1536,12 +1535,12 @@ impl JqMicroCapConfig {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct JqMicroCapStrategy {
|
||||
config: JqMicroCapConfig,
|
||||
pub struct OmniMicroCapStrategy {
|
||||
config: OmniMicroCapConfig,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
struct JqTruthStockLists {
|
||||
struct OmniTruthStockLists {
|
||||
source_path: String,
|
||||
symbols_by_date: BTreeMap<NaiveDate, Vec<String>>,
|
||||
}
|
||||
@@ -1560,19 +1559,19 @@ struct ProjectedExecutionFill {
|
||||
next_cursor: NaiveDateTime,
|
||||
}
|
||||
|
||||
impl JqMicroCapStrategy {
|
||||
pub fn new(config: JqMicroCapConfig) -> Self {
|
||||
impl OmniMicroCapStrategy {
|
||||
pub fn new(config: OmniMicroCapConfig) -> Self {
|
||||
Self { config }
|
||||
}
|
||||
|
||||
fn truth_stock_list_for_date(&self, date: NaiveDate) -> Option<&Vec<String>> {
|
||||
jq_truth_stock_lists()
|
||||
omni_truth_stock_lists()
|
||||
.as_ref()
|
||||
.and_then(|lists| lists.symbols_by_date.get(&date))
|
||||
}
|
||||
|
||||
fn truth_stock_list_source_path(&self) -> Option<&str> {
|
||||
jq_truth_stock_lists()
|
||||
omni_truth_stock_lists()
|
||||
.as_ref()
|
||||
.map(|lists| lists.source_path.as_str())
|
||||
}
|
||||
@@ -2334,29 +2333,29 @@ impl JqMicroCapStrategy {
|
||||
}
|
||||
}
|
||||
|
||||
fn jq_truth_stock_lists() -> &'static Option<JqTruthStockLists> {
|
||||
static LISTS: OnceLock<Option<JqTruthStockLists>> = OnceLock::new();
|
||||
LISTS.get_or_init(load_jq_truth_stock_lists)
|
||||
fn omni_truth_stock_lists() -> &'static Option<OmniTruthStockLists> {
|
||||
static LISTS: OnceLock<Option<OmniTruthStockLists>> = OnceLock::new();
|
||||
LISTS.get_or_init(load_omni_truth_stock_lists)
|
||||
}
|
||||
|
||||
fn load_jq_truth_stock_lists() -> Option<JqTruthStockLists> {
|
||||
for path in jq_truth_stock_list_candidates() {
|
||||
fn load_omni_truth_stock_lists() -> Option<OmniTruthStockLists> {
|
||||
for path in omni_truth_stock_list_candidates() {
|
||||
if !path.is_file() {
|
||||
continue;
|
||||
}
|
||||
if let Ok(Some(lists)) = load_jq_truth_stock_lists_from_path(&path) {
|
||||
if let Ok(Some(lists)) = load_omni_truth_stock_lists_from_path(&path) {
|
||||
return Some(lists);
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
fn jq_truth_stock_list_candidates() -> Vec<PathBuf> {
|
||||
fn omni_truth_stock_list_candidates() -> Vec<PathBuf> {
|
||||
let mut candidates = Vec::new();
|
||||
for key in [
|
||||
"FIDC_BT_JQ_TRUTH_STOCK_LIST_CSV",
|
||||
"JQ_V104_STOCK_LIST_TRUTH_CSV",
|
||||
"JQ_V104_TRUTH_CSV",
|
||||
"FIDC_BT_TRUTH_STOCK_LIST_CSV",
|
||||
"OMNI_BT_TRUTH_STOCK_LIST_CSV",
|
||||
"OMNI_BACKTEST_TRUTH_STOCK_LIST_CSV",
|
||||
] {
|
||||
if let Ok(value) = env::var(key) {
|
||||
let trimmed = value.trim();
|
||||
@@ -2366,9 +2365,7 @@ fn jq_truth_stock_list_candidates() -> Vec<PathBuf> {
|
||||
}
|
||||
}
|
||||
|
||||
let suffix = PathBuf::from(
|
||||
"ai-quant-sever/services/backtest/logs/jq_v104_debug_parsed/jq_v104_ths_stock_list.csv",
|
||||
);
|
||||
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,
|
||||
@@ -2388,7 +2385,9 @@ fn push_unique_truth_path(paths: &mut Vec<PathBuf>, candidate: PathBuf) {
|
||||
}
|
||||
}
|
||||
|
||||
fn load_jq_truth_stock_lists_from_path(path: &Path) -> Result<Option<JqTruthStockLists>, String> {
|
||||
fn load_omni_truth_stock_lists_from_path(
|
||||
path: &Path,
|
||||
) -> Result<Option<OmniTruthStockLists>, String> {
|
||||
let text = fs::read_to_string(path)
|
||||
.map_err(|error| format!("read {} failed: {}", path.display(), error))?;
|
||||
let mut lines = text.lines().filter(|line| !line.trim().is_empty());
|
||||
@@ -2471,7 +2470,7 @@ fn load_jq_truth_stock_lists_from_path(path: &Path) -> Result<Option<JqTruthStoc
|
||||
})
|
||||
.collect::<BTreeMap<_, _>>();
|
||||
|
||||
Ok(Some(JqTruthStockLists {
|
||||
Ok(Some(OmniTruthStockLists {
|
||||
source_path: path.display().to_string(),
|
||||
symbols_by_date,
|
||||
}))
|
||||
@@ -2496,7 +2495,7 @@ fn normalize_truth_symbol(raw: &str) -> Option<String> {
|
||||
}
|
||||
}
|
||||
|
||||
impl Strategy for JqMicroCapStrategy {
|
||||
impl Strategy for OmniMicroCapStrategy {
|
||||
fn name(&self) -> &str {
|
||||
self.config.strategy_name.as_str()
|
||||
}
|
||||
@@ -2520,7 +2519,7 @@ impl Strategy for JqMicroCapStrategy {
|
||||
})
|
||||
.collect(),
|
||||
notes: vec![format!("seasonal stop window on {}", date)],
|
||||
diagnostics: vec!["jq-style skip window forced all cash".to_string()],
|
||||
diagnostics: vec!["platform-native skip window forced all cash".to_string()],
|
||||
});
|
||||
}
|
||||
|
||||
@@ -2685,7 +2684,7 @@ impl Strategy for JqMicroCapStrategy {
|
||||
|
||||
let mut diagnostics = vec![
|
||||
format!(
|
||||
"jq_microcap signal={} last={:.2} ma_short={:.2} ma_long={:.2} band={:.0}-{:.0} tr={:.2}",
|
||||
"omni_microcap signal={} last={:.2} ma_short={:.2} ma_long={:.2} band={:.0}-{:.0} tr={:.2}",
|
||||
self.config.benchmark_signal_symbol, index_level, ma_short, ma_long, band_low, band_high, trading_ratio
|
||||
),
|
||||
format!(
|
||||
@@ -2696,7 +2695,7 @@ impl Strategy for JqMicroCapStrategy {
|
||||
projected.positions().len(),
|
||||
order_intents.len()
|
||||
),
|
||||
"run_daily(10:17/10:18) approximated as same-day decision with snapshot last_price signals and bid1/ask1 side-aware execution".to_string(),
|
||||
"platform schedule 10:17/10:18 approximated as same-day decision with snapshot last_price signals and bid1/ask1 side-aware execution".to_string(),
|
||||
];
|
||||
if std::env::var("FIDC_BT_DEBUG_POSITION_ORDER")
|
||||
.map(|value| value == "1")
|
||||
@@ -2759,14 +2758,16 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn load_truth_stock_lists_preserves_rank_order() {
|
||||
let path = temp_csv_path("jq_truth_list");
|
||||
let path = temp_csv_path("omni_truth_list");
|
||||
fs::write(
|
||||
&path,
|
||||
"trade_date,index,symbol\n2025-01-02,2,300935.SZ\n2025-01-02,1,300321.XSHE\n2025-01-02,1,300321.SZ\n",
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let lists = load_jq_truth_stock_lists_from_path(&path).unwrap().unwrap();
|
||||
let lists = load_omni_truth_stock_lists_from_path(&path)
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
fs::remove_file(&path).ok();
|
||||
|
||||
let symbols = lists
|
||||
@@ -2780,7 +2781,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn normalize_truth_symbol_maps_joinquant_suffixes() {
|
||||
fn normalize_truth_symbol_maps_external_platform_suffixes() {
|
||||
assert_eq!(
|
||||
normalize_truth_symbol("300321.XSHE").as_deref(),
|
||||
Some("300321.SZ")
|
||||
|
||||
Reference in New Issue
Block a user