同步回测引擎改动
This commit is contained in:
@@ -8,7 +8,7 @@ use crate::portfolio::PortfolioState;
|
||||
use crate::universe::{DynamicMarketCapBandSelector, SelectionContext, UniverseSelector};
|
||||
|
||||
pub trait Strategy {
|
||||
fn name(&self) -> &'static str;
|
||||
fn name(&self) -> &str;
|
||||
fn on_day(&mut self, ctx: &StrategyContext<'_>) -> Result<StrategyDecision, BacktestError>;
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ pub struct StrategyDecision {
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct CnSmallCapRotationConfig {
|
||||
pub strategy_name: &'static str,
|
||||
pub strategy_name: String,
|
||||
pub refresh_rate: usize,
|
||||
pub stocknum: usize,
|
||||
pub xs: f64,
|
||||
@@ -55,7 +55,7 @@ pub struct CnSmallCapRotationConfig {
|
||||
impl CnSmallCapRotationConfig {
|
||||
pub fn demo() -> Self {
|
||||
Self {
|
||||
strategy_name: "cn-smallcap-rotation",
|
||||
strategy_name: "cn-smallcap-rotation".to_string(),
|
||||
refresh_rate: 3,
|
||||
stocknum: 2,
|
||||
xs: 4.0 / 500.0,
|
||||
@@ -79,7 +79,7 @@ impl CnSmallCapRotationConfig {
|
||||
|
||||
pub fn cn_dyn_smallcap_band() -> Self {
|
||||
Self {
|
||||
strategy_name: "cn-dyn-smallcap-band",
|
||||
strategy_name: "cn-dyn-smallcap-band".to_string(),
|
||||
refresh_rate: 15,
|
||||
stocknum: 40,
|
||||
xs: 4.0 / 500.0,
|
||||
@@ -97,7 +97,7 @@ impl CnSmallCapRotationConfig {
|
||||
take_profit_pct: 0.07,
|
||||
signal_symbol: Some("000852.SH".to_string()),
|
||||
skip_months: vec![],
|
||||
skip_month_day_ranges: vec![(4, 5, 30)],
|
||||
skip_month_day_ranges: vec![(1, 15, 30), (4, 15, 29), (8, 15, 31), (10, 20, 30), (12, 20, 30)],
|
||||
}
|
||||
}
|
||||
|
||||
@@ -239,8 +239,8 @@ impl CnSmallCapRotationStrategy {
|
||||
}
|
||||
|
||||
impl Strategy for CnSmallCapRotationStrategy {
|
||||
fn name(&self) -> &'static str {
|
||||
self.config.strategy_name
|
||||
fn name(&self) -> &str {
|
||||
self.config.strategy_name.as_str()
|
||||
}
|
||||
|
||||
fn on_day(&mut self, ctx: &StrategyContext<'_>) -> Result<StrategyDecision, BacktestError> {
|
||||
@@ -281,7 +281,7 @@ impl Strategy for CnSmallCapRotationStrategy {
|
||||
ctx.decision_date, ctx.execution_date, gross_exposure
|
||||
)];
|
||||
let mut diagnostics = vec![format!(
|
||||
"benchmark_close={:.2} signal_level={:.2} signal_symbol={} refresh_rate={} stocknum={} short_ma_days={} long_ma_days={} stock_ma={}/{}/{} stop=0.93 take=1.07",
|
||||
"benchmark_close={:.2} signal_level={:.2} signal_symbol={} refresh_rate={} stocknum={} short_ma_days={} long_ma_days={} stock_ma={}/{}/{} stop={:.4} take={:.4}",
|
||||
benchmark.close,
|
||||
signal_level,
|
||||
resolved_signal_symbol.as_str(),
|
||||
@@ -292,6 +292,8 @@ impl Strategy for CnSmallCapRotationStrategy {
|
||||
self.config.stock_short_ma_days,
|
||||
self.config.stock_mid_ma_days,
|
||||
self.config.stock_long_ma_days,
|
||||
1.0 - self.config.stop_loss_pct,
|
||||
1.0 + self.config.take_profit_pct,
|
||||
)];
|
||||
diagnostics.push("run_daily(10:17/10:18) approximated by daily decision/open execution".to_string());
|
||||
diagnostics.push("market_cap field mapped from daily_features[_enriched]_v1.market_cap to market_cap_bn without intraday fundamentals refresh".to_string());
|
||||
|
||||
Reference in New Issue
Block a user