增强回测引擎第二版策略与快照层
This commit is contained in:
34
crates/fidc-core/tests/strategy_selection.rs
Normal file
34
crates/fidc-core/tests/strategy_selection.rs
Normal file
@@ -0,0 +1,34 @@
|
||||
use chrono::NaiveDate;
|
||||
use fidc_core::{CnSmallCapRotationConfig, CnSmallCapRotationStrategy, DataSet, Strategy, StrategyContext, PortfolioState};
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[test]
|
||||
fn strategy_emits_target_weights_and_diagnostics() {
|
||||
let data_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../../data/demo");
|
||||
let data = DataSet::from_csv_dir(&data_dir).expect("demo data");
|
||||
let decision_date = NaiveDate::from_ymd_opt(2024, 1, 10).unwrap();
|
||||
let execution_date = NaiveDate::from_ymd_opt(2024, 1, 11).unwrap();
|
||||
let portfolio = PortfolioState::new(1_000_000.0);
|
||||
let mut cfg = CnSmallCapRotationConfig::demo();
|
||||
cfg.base_index_level = 3000.0;
|
||||
cfg.base_cap_floor = 38.0;
|
||||
cfg.cap_span = 25.0;
|
||||
let mut strategy = CnSmallCapRotationStrategy::new(cfg);
|
||||
|
||||
let decision = strategy
|
||||
.on_day(&StrategyContext {
|
||||
execution_date,
|
||||
decision_date,
|
||||
decision_index: 0,
|
||||
data: &data,
|
||||
portfolio: &portfolio,
|
||||
})
|
||||
.expect("decision");
|
||||
|
||||
assert!(decision.rebalance);
|
||||
assert!(!decision.target_weights.is_empty());
|
||||
assert!(decision
|
||||
.diagnostics
|
||||
.iter()
|
||||
.any(|line| line.contains("selected=")));
|
||||
}
|
||||
Reference in New Issue
Block a user