增强回测引擎第二版策略与快照层
This commit is contained in:
@@ -26,7 +26,11 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||
fs::create_dir_all(&output_dir)?;
|
||||
|
||||
let data = DataSet::from_csv_dir(&data_dir)?;
|
||||
let strategy = CnSmallCapRotationStrategy::new(CnSmallCapRotationConfig::demo());
|
||||
let mut strategy_cfg = CnSmallCapRotationConfig::demo();
|
||||
strategy_cfg.base_index_level = 3000.0;
|
||||
strategy_cfg.base_cap_floor = 38.0;
|
||||
strategy_cfg.cap_span = 25.0;
|
||||
let strategy = CnSmallCapRotationStrategy::new(strategy_cfg);
|
||||
let broker = BrokerSimulator::new(ChinaAShareCostModel::default(), ChinaEquityRuleHooks::default());
|
||||
let config = BacktestConfig {
|
||||
initial_cash: 1_000_000.0,
|
||||
@@ -60,17 +64,18 @@ fn workspace_root() -> PathBuf {
|
||||
|
||||
fn write_equity_curve_csv(path: &Path, rows: &[DailyEquityPoint]) -> Result<(), Box<dyn Error>> {
|
||||
let mut file = fs::File::create(path)?;
|
||||
writeln!(file, "date,cash,market_value,total_equity,benchmark_close,notes")?;
|
||||
writeln!(file, "date,cash,market_value,total_equity,benchmark_close,notes,diagnostics")?;
|
||||
for row in rows {
|
||||
writeln!(
|
||||
file,
|
||||
"{},{:.2},{:.2},{:.2},{:.2},{}",
|
||||
"{},{:.2},{:.2},{:.2},{:.2},{},{}",
|
||||
row.date,
|
||||
row.cash,
|
||||
row.market_value,
|
||||
row.total_equity,
|
||||
row.benchmark_close,
|
||||
sanitize_csv_field(&row.notes),
|
||||
sanitize_csv_field(&row.diagnostics),
|
||||
)?;
|
||||
}
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user