work on engine
This commit is contained in:
parent
a1e5a21847
commit
cbe8f0282c
12 changed files with 694 additions and 16 deletions
|
|
@ -76,14 +76,22 @@ pub struct BacktestFillSimulator {
|
|||
slippage_model: SlippageModel,
|
||||
impact_model: MarketImpactModel,
|
||||
microstructure_cache: Mutex<HashMap<String, MarketMicrostructure>>,
|
||||
commission_rate: f64,
|
||||
slippage_rate: f64,
|
||||
}
|
||||
|
||||
impl BacktestFillSimulator {
|
||||
pub fn new() -> Self {
|
||||
Self::with_config(0.001, 0.0001) // Default values
|
||||
}
|
||||
|
||||
pub fn with_config(commission_rate: f64, slippage_rate: f64) -> Self {
|
||||
Self {
|
||||
slippage_model: SlippageModel::default(),
|
||||
impact_model: MarketImpactModel::new(ImpactModelType::SquareRoot),
|
||||
microstructure_cache: Mutex::new(HashMap::new()),
|
||||
commission_rate,
|
||||
slippage_rate,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -146,10 +154,8 @@ impl FillSimulator for BacktestFillSimulator {
|
|||
}
|
||||
};
|
||||
|
||||
// Calculate realistic commission
|
||||
let commission_rate = 0.0005; // 5 bps for institutional
|
||||
let min_commission = 1.0;
|
||||
let commission = (order.quantity * price * commission_rate).max(min_commission);
|
||||
// Calculate commission using configured rate
|
||||
let commission = order.quantity * price * self.commission_rate;
|
||||
|
||||
Some(Fill {
|
||||
timestamp: Utc::now(), // Will be overridden by backtest engine
|
||||
|
|
@ -167,7 +173,7 @@ impl FillSimulator for BacktestFillSimulator {
|
|||
timestamp: Utc::now(),
|
||||
price: *limit_price,
|
||||
quantity: order.quantity,
|
||||
commission: order.quantity * limit_price * 0.001,
|
||||
commission: order.quantity * limit_price * self.commission_rate,
|
||||
})
|
||||
} else {
|
||||
None
|
||||
|
|
@ -179,7 +185,7 @@ impl FillSimulator for BacktestFillSimulator {
|
|||
timestamp: Utc::now(),
|
||||
price: *limit_price,
|
||||
quantity: order.quantity,
|
||||
commission: order.quantity * limit_price * 0.001,
|
||||
commission: order.quantity * limit_price * self.commission_rate,
|
||||
})
|
||||
} else {
|
||||
None
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue