Add rqalpha-style scheduler primitives
This commit is contained in:
@@ -11,10 +11,21 @@ use crate::data::{DataSet, PriceField};
|
||||
use crate::engine::BacktestError;
|
||||
use crate::events::OrderSide;
|
||||
use crate::portfolio::PortfolioState;
|
||||
use crate::scheduler::ScheduleRule;
|
||||
use crate::universe::{DynamicMarketCapBandSelector, SelectionContext, UniverseSelector};
|
||||
|
||||
pub trait Strategy {
|
||||
fn name(&self) -> &str;
|
||||
fn schedule_rules(&self) -> Vec<ScheduleRule> {
|
||||
Vec::new()
|
||||
}
|
||||
fn on_scheduled(
|
||||
&mut self,
|
||||
_ctx: &StrategyContext<'_>,
|
||||
_rule: &ScheduleRule,
|
||||
) -> Result<StrategyDecision, BacktestError> {
|
||||
Ok(StrategyDecision::default())
|
||||
}
|
||||
fn before_trading(&mut self, _ctx: &StrategyContext<'_>) -> Result<(), BacktestError> {
|
||||
Ok(())
|
||||
}
|
||||
@@ -51,6 +62,26 @@ pub struct StrategyDecision {
|
||||
pub diagnostics: Vec<String>,
|
||||
}
|
||||
|
||||
impl StrategyDecision {
|
||||
pub fn merge_from(&mut self, mut other: StrategyDecision) {
|
||||
self.rebalance |= other.rebalance;
|
||||
self.target_weights.append(&mut other.target_weights);
|
||||
self.exit_symbols.append(&mut other.exit_symbols);
|
||||
self.order_intents.append(&mut other.order_intents);
|
||||
self.notes.append(&mut other.notes);
|
||||
self.diagnostics.append(&mut other.diagnostics);
|
||||
}
|
||||
|
||||
pub fn is_empty(&self) -> bool {
|
||||
!self.rebalance
|
||||
&& self.target_weights.is_empty()
|
||||
&& self.exit_symbols.is_empty()
|
||||
&& self.order_intents.is_empty()
|
||||
&& self.notes.is_empty()
|
||||
&& self.diagnostics.is_empty()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum OrderIntent {
|
||||
TargetValue {
|
||||
|
||||
Reference in New Issue
Block a user