Format related strategy and test files
This commit is contained in:
@@ -236,11 +236,7 @@ impl PlatformExprStrategy {
|
|||||||
engine.register_fn(
|
engine.register_fn(
|
||||||
"iff",
|
"iff",
|
||||||
|condition: bool, when_true: Dynamic, when_false: Dynamic| {
|
|condition: bool, when_true: Dynamic, when_false: Dynamic| {
|
||||||
if condition {
|
if condition { when_true } else { when_false }
|
||||||
when_true
|
|
||||||
} else {
|
|
||||||
when_false
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
engine.register_fn("contains", |value: &str, needle: &str| {
|
engine.register_fn("contains", |value: &str, needle: &str| {
|
||||||
@@ -404,11 +400,7 @@ impl PlatformExprStrategy {
|
|||||||
0
|
0
|
||||||
} else {
|
} else {
|
||||||
let next = quantity.saturating_sub(order_step_size.max(1));
|
let next = quantity.saturating_sub(order_step_size.max(1));
|
||||||
if next < minimum {
|
if next < minimum { 0 } else { next }
|
||||||
0
|
|
||||||
} else {
|
|
||||||
next
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -971,9 +963,7 @@ impl PlatformExprStrategy {
|
|||||||
minimum_order_quantity: instrument
|
minimum_order_quantity: instrument
|
||||||
.map(|item| item.minimum_order_quantity())
|
.map(|item| item.minimum_order_quantity())
|
||||||
.unwrap_or(100) as i64,
|
.unwrap_or(100) as i64,
|
||||||
order_step_size: instrument
|
order_step_size: instrument.map(|item| item.order_step_size()).unwrap_or(100) as i64,
|
||||||
.map(|item| item.order_step_size())
|
|
||||||
.unwrap_or(100) as i64,
|
|
||||||
paused: market.paused || candidate.is_paused,
|
paused: market.paused || candidate.is_paused,
|
||||||
is_st: candidate.is_st || self.special_name(ctx, symbol),
|
is_st: candidate.is_st || self.special_name(ctx, symbol),
|
||||||
is_kcb: candidate.is_kcb,
|
is_kcb: candidate.is_kcb,
|
||||||
|
|||||||
@@ -178,11 +178,7 @@ impl CnSmallCapRotationStrategy {
|
|||||||
let (sum, count) = window.fold((0.0, 0usize), |(sum, count), value| {
|
let (sum, count) = window.fold((0.0, 0usize), |(sum, count), value| {
|
||||||
(sum + value, count + 1)
|
(sum + value, count + 1)
|
||||||
});
|
});
|
||||||
if count == 0 {
|
if count == 0 { 0.0 } else { sum / count as f64 }
|
||||||
0.0
|
|
||||||
} else {
|
|
||||||
sum / count as f64
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn gross_exposure(&self, closes: &[f64]) -> f64 {
|
fn gross_exposure(&self, closes: &[f64]) -> f64 {
|
||||||
@@ -332,7 +328,7 @@ impl Strategy for CnSmallCapRotationStrategy {
|
|||||||
order_intents: Vec::new(),
|
order_intents: Vec::new(),
|
||||||
notes: vec![format!("warmup: {}", message)],
|
notes: vec![format!("warmup: {}", message)],
|
||||||
diagnostics: vec![
|
diagnostics: vec![
|
||||||
"insufficient history; skip trading on warmup dates".to_string()
|
"insufficient history; skip trading on warmup dates".to_string(),
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -628,11 +624,7 @@ impl JqMicroCapStrategy {
|
|||||||
0
|
0
|
||||||
} else {
|
} else {
|
||||||
let next = quantity.saturating_sub(order_step_size.max(1));
|
let next = quantity.saturating_sub(order_step_size.max(1));
|
||||||
if next < minimum {
|
if next < minimum { 0 } else { next }
|
||||||
0
|
|
||||||
} else {
|
|
||||||
next
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1538,7 +1530,7 @@ impl Strategy for JqMicroCapStrategy {
|
|||||||
order_intents: Vec::new(),
|
order_intents: Vec::new(),
|
||||||
notes: vec![format!("warmup: {}", message)],
|
notes: vec![format!("warmup: {}", message)],
|
||||||
diagnostics: vec![
|
diagnostics: vec![
|
||||||
"insufficient history; skip trading on warmup dates".to_string()
|
"insufficient history; skip trading on warmup dates".to_string(),
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -252,10 +252,12 @@ fn engine_settles_delisted_position_before_missing_market_snapshot_breaks_run()
|
|||||||
.any(|fill| fill.reason.contains("delisted_cash_settlement")
|
.any(|fill| fill.reason.contains("delisted_cash_settlement")
|
||||||
&& fill.symbol == "000001.SZ")
|
&& fill.symbol == "000001.SZ")
|
||||||
);
|
);
|
||||||
assert!(result
|
assert!(
|
||||||
|
result
|
||||||
.holdings_summary
|
.holdings_summary
|
||||||
.iter()
|
.iter()
|
||||||
.all(|holding| holding.symbol != "000001.SZ"));
|
.all(|holding| holding.symbol != "000001.SZ")
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -477,9 +479,11 @@ fn engine_applies_successor_conversion_before_delisted_cash_settlement() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
let result = engine.run().expect("backtest succeeds");
|
let result = engine.run().expect("backtest succeeds");
|
||||||
assert!(result.equity_curve.iter().any(|point| point
|
assert!(result.equity_curve.iter().any(|point| {
|
||||||
|
point
|
||||||
.notes
|
.notes
|
||||||
.contains("successor_conversion 000001.SZ->000002.SZ")));
|
.contains("successor_conversion 000001.SZ->000002.SZ")
|
||||||
|
}));
|
||||||
assert!(result.fills.iter().all(
|
assert!(result.fills.iter().all(
|
||||||
|fill| !fill.reason.contains("delisted_cash_settlement") || fill.symbol != "000001.SZ"
|
|fill| !fill.reason.contains("delisted_cash_settlement") || fill.symbol != "000001.SZ"
|
||||||
));
|
));
|
||||||
@@ -489,12 +493,16 @@ fn engine_applies_successor_conversion_before_delisted_cash_settlement() {
|
|||||||
.find(|holding| holding.symbol == "000002.SZ")
|
.find(|holding| holding.symbol == "000002.SZ")
|
||||||
.expect("successor holding exists");
|
.expect("successor holding exists");
|
||||||
assert_eq!(successor_holding.quantity, 500);
|
assert_eq!(successor_holding.quantity, 500);
|
||||||
assert!(result
|
assert!(
|
||||||
|
result
|
||||||
.holdings_summary
|
.holdings_summary
|
||||||
.iter()
|
.iter()
|
||||||
.all(|holding| holding.symbol != "000001.SZ"));
|
.all(|holding| holding.symbol != "000001.SZ")
|
||||||
assert!(result.account_events.iter().any(|event| event
|
);
|
||||||
|
assert!(result.account_events.iter().any(|event| {
|
||||||
|
event
|
||||||
.note
|
.note
|
||||||
.contains("successor_conversion 000001.SZ->000002.SZ")
|
.contains("successor_conversion 000001.SZ->000002.SZ")
|
||||||
&& event.note.contains("cash=1000.00")));
|
&& event.note.contains("cash=1000.00")
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,17 +22,17 @@ impl Strategy for HookProbeStrategy {
|
|||||||
"hook-probe"
|
"hook-probe"
|
||||||
}
|
}
|
||||||
|
|
||||||
fn before_trading(&mut self, ctx: &StrategyContext<'_>) -> Result<(), fidc_core::BacktestError> {
|
fn before_trading(
|
||||||
|
&mut self,
|
||||||
|
ctx: &StrategyContext<'_>,
|
||||||
|
) -> Result<(), fidc_core::BacktestError> {
|
||||||
self.log
|
self.log
|
||||||
.borrow_mut()
|
.borrow_mut()
|
||||||
.push(format!("before:{}", ctx.execution_date));
|
.push(format!("before:{}", ctx.execution_date));
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn open_auction(
|
fn open_auction(&mut self, ctx: &StrategyContext<'_>) -> Result<(), fidc_core::BacktestError> {
|
||||||
&mut self,
|
|
||||||
ctx: &StrategyContext<'_>,
|
|
||||||
) -> Result<(), fidc_core::BacktestError> {
|
|
||||||
self.log
|
self.log
|
||||||
.borrow_mut()
|
.borrow_mut()
|
||||||
.push(format!("auction:{}", ctx.execution_date));
|
.push(format!("auction:{}", ctx.execution_date));
|
||||||
|
|||||||
Reference in New Issue
Block a user