pub struct PortfolioRecorder { /* private fields */ }Expand description
Stateful quote and account recorder suitable for incremental runner use.
Implementations§
Source§impl PortfolioRecorder
impl PortfolioRecorder
Sourcepub fn new(
initial_balance: f64,
contract_sizes: impl IntoIterator<Item = (String, f64)>,
) -> Self
pub fn new( initial_balance: f64, contract_sizes: impl IntoIterator<Item = (String, f64)>, ) -> Self
Create a recorder. Missing symbols use contract size 1.0, matching the
current backtest executor’s backward-compatible behavior.
pub fn with_fill_model(self, fill_model: FillModel) -> Self
pub fn with_stale_quote_after_millis( self, stale_after_millis: Option<i64>, ) -> Self
pub fn with_currency_plan(self, currency_plan: Option<RunCurrencyPlan>) -> Self
pub fn set_default_contract_size(&mut self, contract_size: f64) -> bool
pub fn set_contract_size( &mut self, symbol: impl Into<String>, contract_size: f64, ) -> bool
Sourcepub fn record_quote(&mut self, quote: PriceQuote) -> bool
pub fn record_quote(&mut self, quote: PriceQuote) -> bool
Retain the newest quote for a symbol. Returns false for an out-of-order
older quote that was ignored.
pub fn quote(&self, symbol: &str) -> Option<&PriceQuote>
pub fn initial_balance(&self) -> f64
pub fn realized_pnl(&self) -> f64
Sourcepub fn add_realized_pnl(&mut self, pnl: f64) -> bool
pub fn add_realized_pnl(&mut self, pnl: f64) -> bool
Add a realized close result. Non-finite values are rejected.
Sourcepub fn set_realized_pnl(&mut self, pnl: f64) -> bool
pub fn set_realized_pnl(&mut self, pnl: f64) -> bool
Replace the cumulative realized P&L (useful when adapting an executor that already owns the authoritative realized total).
Sourcepub fn record(
&mut self,
ts: NaiveDateTime,
positions: impl IntoIterator<Item = OpenPositionSnapshot>,
) -> EquityPoint
pub fn record( &mut self, ts: NaiveDateTime, positions: impl IntoIterator<Item = OpenPositionSnapshot>, ) -> EquityPoint
Mark normalized open positions at the latest per-symbol quotes and append one equity point.
pub fn observe( &mut self, ts: NaiveDateTime, positions: impl IntoIterator<Item = OpenPositionSnapshot>, ) -> EquityPoint
pub fn record_with_currency( &mut self, ts: NaiveDateTime, positions: impl IntoIterator<Item = OpenPositionSnapshot>, conversion_quotes: Option<&ConversionQuoteBook>, ) -> EquityPoint
Sourcepub fn observe_with_currency(
&mut self,
ts: NaiveDateTime,
positions: impl IntoIterator<Item = OpenPositionSnapshot>,
conversion_quotes: Option<&ConversionQuoteBook>,
) -> EquityPoint
pub fn observe_with_currency( &mut self, ts: NaiveDateTime, positions: impl IntoIterator<Item = OpenPositionSnapshot>, conversion_quotes: Option<&ConversionQuoteBook>, ) -> EquityPoint
Mark positions and update exact accounting state without appending to the legacy curve.
pub fn campaign_excursion(&self, position_id: &str) -> Option<CampaignExcursion>
Sourcepub fn finish_campaign(
&mut self,
position_id: &str,
final_net_pnl: f64,
) -> Option<CampaignExcursion>
pub fn finish_campaign( &mut self, position_id: &str, final_net_pnl: f64, ) -> Option<CampaignExcursion>
Finalize and remove campaign excursion state, including final realized net P&L as the last observation.
pub fn latest_open_positions(&self) -> &[OpenPositionSnapshot]
pub fn equity_curve(&self) -> &[EquityPoint]
pub fn max_drawdown(&self) -> Option<f64>
pub fn max_drawdown_pct(&self) -> Option<f64>
Trait Implementations§
Source§impl Clone for PortfolioRecorder
impl Clone for PortfolioRecorder
Source§fn clone(&self) -> PortfolioRecorder
fn clone(&self) -> PortfolioRecorder
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more