Skip to main content

PortfolioRecorder

Struct PortfolioRecorder 

Source
pub struct PortfolioRecorder { /* private fields */ }
Expand description

Stateful quote and account recorder suitable for incremental runner use.

Implementations§

Source§

impl PortfolioRecorder

Source

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.

Source

pub fn with_fill_model(self, fill_model: FillModel) -> Self

Source

pub fn with_stale_quote_after_millis( self, stale_after_millis: Option<i64>, ) -> Self

Source

pub fn with_currency_plan(self, currency_plan: Option<RunCurrencyPlan>) -> Self

Source

pub fn set_default_contract_size(&mut self, contract_size: f64) -> bool

Source

pub fn set_contract_size( &mut self, symbol: impl Into<String>, contract_size: f64, ) -> bool

Source

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.

Source

pub fn quote(&self, symbol: &str) -> Option<&PriceQuote>

Source

pub fn initial_balance(&self) -> f64

Source

pub fn realized_pnl(&self) -> f64

Source

pub fn add_realized_pnl(&mut self, pnl: f64) -> bool

Add a realized close result. Non-finite values are rejected.

Source

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).

Source

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.

Source

pub fn observe( &mut self, ts: NaiveDateTime, positions: impl IntoIterator<Item = OpenPositionSnapshot>, ) -> EquityPoint

Source

pub fn record_with_currency( &mut self, ts: NaiveDateTime, positions: impl IntoIterator<Item = OpenPositionSnapshot>, conversion_quotes: Option<&ConversionQuoteBook>, ) -> EquityPoint

Source

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.

Source

pub fn campaign_excursion(&self, position_id: &str) -> Option<CampaignExcursion>

Source

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.

Source

pub fn latest_open_positions(&self) -> &[OpenPositionSnapshot]

Source

pub fn equity_curve(&self) -> &[EquityPoint]

Source

pub fn max_drawdown(&self) -> Option<f64>

Source

pub fn max_drawdown_pct(&self) -> Option<f64>

Trait Implementations§

Source§

impl Clone for PortfolioRecorder

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PortfolioRecorder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for PortfolioRecorder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for PortfolioRecorder

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for PortfolioRecorder

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V