Add rqalpha-style position pnl runtime fields

This commit is contained in:
boris
2026-04-23 06:12:25 -07:00
parent f17aabc9d3
commit fae09afb86
5 changed files with 305 additions and 1 deletions

View File

@@ -2129,6 +2129,9 @@ where
.position_mut(symbol)
.sell(leg.quantity, leg.price)
.map_err(BacktestError::Execution)?;
if let Some(position) = portfolio.position_mut_if_exists(symbol) {
position.record_trade_cost(cost.total());
}
portfolio.apply_cash_delta(net_cash);
report.fill_events.push(FillEvent {
@@ -3332,6 +3335,9 @@ where
portfolio
.position_mut(symbol)
.buy(date, leg.quantity, leg.price);
if let Some(position) = portfolio.position_mut_if_exists(symbol) {
position.record_trade_cost(cost.total());
}
report.fill_events.push(FillEvent {
date,