Struct lfest::account_tracker::FullAccountTracker
source · pub struct FullAccountTracker<M> { /* private fields */ }
Expand description
Keep track of many possible Account performance statistics This can be quite memory intensive, easily reaching beyond 10GB if using tick-by-tick data due to the storage of many returns
Implementations§
source§impl<M> FullAccountTracker<M>where
M: Currency + MarginCurrency + Send,
impl<M> FullAccountTracker<M>where M: Currency + MarginCurrency + Send,
TODO: create its own risk
crate out of these implementations for better
reusability and testability
sourcepub fn absolute_returns(&self, source: &ReturnsSource) -> &Vec<M>
pub fn absolute_returns(&self, source: &ReturnsSource) -> &Vec<M>
Vector of absolute returns the account has generated, including unrealized pnl # Parameters source: the sampling interval of pnl snapshots
sourcepub fn ln_returns(&self, source: &ReturnsSource) -> &Vec<f64>
pub fn ln_returns(&self, source: &ReturnsSource) -> &Vec<f64>
Vector of natural logarithmic returns the account has generated, including unrealized pnl # Parameters source: the sampling interval of pnl snapshots
sourcepub fn profit_loss_ratio(&self) -> Decimal
pub fn profit_loss_ratio(&self) -> Decimal
Ratio of cumulative trade profit over cumulative trade loss
sourcepub fn cumulative_fees(&self) -> M
pub fn cumulative_fees(&self) -> M
Cumulative fees paid to the exchange
sourcepub fn buy_and_hold_return(&self) -> M
pub fn buy_and_hold_return(&self) -> M
Would be return of buy and hold strategy
sourcepub fn sell_and_hold_return(&self) -> M
pub fn sell_and_hold_return(&self) -> M
Would be return of sell and hold strategy
sourcepub fn sharpe(
&self,
returns_source: ReturnsSource,
risk_free_is_buy_and_hold: bool
) -> f64
pub fn sharpe( &self, returns_source: ReturnsSource, risk_free_is_buy_and_hold: bool ) -> f64
Return the sharpe ratio using the selected returns as source
Parameters:
returns_source
: the sampling interval of pnl snapshots
risk_free_is_buy_and_hold
: if true, it will use the market returns as
the risk-free comparison else risk-free rate is zero
TODO: annualized depending on the ReturnsSource
sourcepub fn sortino(
&self,
returns_source: ReturnsSource,
risk_free_is_buy_and_hold: bool
) -> f64
pub fn sortino( &self, returns_source: ReturnsSource, risk_free_is_buy_and_hold: bool ) -> f64
Return the Sortino ratio based on daily returns data
Parameters:
returns_source: the sampling interval of pnl snapshots risk_free_is_buy_and_hold: if true, it will use the market returns as the risk-free comparison else risk-free rate is zero
TODO: annualized depending on the ReturnsSource
sourcepub fn historical_value_at_risk(
&self,
returns_source: ReturnsSource,
percentile: f64
) -> f64
pub fn historical_value_at_risk( &self, returns_source: ReturnsSource, percentile: f64 ) -> f64
Calculate the value at risk using the percentile method on daily returns
multiplied by starting wallet balance The time horizon N is assumed
to be 1 The literature says if you want a larger N, just multiply by
N.sqrt(), which assumes standard normal distribution # Arguments
returns_source: the sampling interval of pnl snapshots
percentile: value between [0.0, 1.0], smaller value will return more
worst case results
TODO: annualized depending on the ReturnsSource
sourcepub fn historical_value_at_risk_from_n_hourly_returns(
&self,
n: usize,
percentile: f64
) -> f64
pub fn historical_value_at_risk_from_n_hourly_returns( &self, n: usize, percentile: f64 ) -> f64
Calculate the historical value at risk from n consequtive hourly return values, This should have better statistical properties compared to using daily returns due to having more samples. Set n to 24 for daily value at risk, but with 24x more samples from which to take the percentile, giving a more accurate VaR
Parameters:
n: number of hourly returns to use percentile: value between [0.0, 1.0], smaller value will return more worst case results
sourcepub fn cornish_fisher_value_at_risk(
&self,
returns_source: ReturnsSource,
percentile: f64
) -> f64
pub fn cornish_fisher_value_at_risk( &self, returns_source: ReturnsSource, percentile: f64 ) -> f64
Calculate the cornish fisher value at risk based on daily returns of the account # Arguments returns_source: the sampling interval of pnl snapshots percentile: in range [0.0, 1.0], usually something like 0.01 or 0.05
sourcepub fn cornish_fisher_value_at_risk_from_n_hourly_returns(
&self,
n: usize,
percentile: f64
) -> f64
pub fn cornish_fisher_value_at_risk_from_n_hourly_returns( &self, n: usize, percentile: f64 ) -> f64
Calculate the corni fisher value at risk from n consequtive hourly return values This should have better statistical properties compared to using daily returns due to having more samples. Set n to 24 for daily value at risk, but with 24x more samples from which to take the percentile, giving a more accurate VaR
Parameters:
n: number of hourly returns to use percentile: value between [0.0, 1.0], smaller value will return more worst case results
sourcepub fn num_trading_days(&self) -> u64
pub fn num_trading_days(&self) -> u64
Return the number of trading days
sourcepub fn d_ratio(&self, returns_source: ReturnsSource) -> f64
pub fn d_ratio(&self, returns_source: ReturnsSource) -> f64
Also called discriminant-ratio, which focuses on the added value of the algorithm It uses the Cornish-Fish Value at Risk (CF-VaR) It better captures the risk of the asset as it is not limited by the assumption of a gaussian distribution It it time-insensitive from: https://papers.ssrn.com/sol3/papers.cfm?abstract_id=3927058
Parameters
returns_source: the sampling interval of pnl snapshots
sourcepub fn annualized_roi(&self) -> f64
pub fn annualized_roi(&self) -> f64
Annualized return on investment as a factor, e.g.: 100% -> 2x
sourcepub fn max_drawdown_wallet_balance(&self) -> Decimal
pub fn max_drawdown_wallet_balance(&self) -> Decimal
Maximum drawdown of the wallet balance
sourcepub fn max_drawdown_total(&self) -> Decimal
pub fn max_drawdown_total(&self) -> Decimal
Maximum drawdown of the wallet balance including unrealized profit and loss
sourcepub fn num_trades(&self) -> i64
pub fn num_trades(&self) -> i64
Return the number of trades the account made
sourcepub fn trade_percentage(&self) -> f64
pub fn trade_percentage(&self) -> f64
Return the ratio of executed trades vs total trading opportunities Higher values means a more active trading agent
sourcepub fn total_rpnl(&self) -> M
pub fn total_rpnl(&self) -> M
Return the total realized profit and loss of the account
sourcepub fn limit_order_fill_ratio(&self) -> f64
pub fn limit_order_fill_ratio(&self) -> f64
Return the ratio of filled limit orders vs number of submitted limit orders
sourcepub fn limit_order_cancellation_ratio(&self) -> f64
pub fn limit_order_cancellation_ratio(&self) -> f64
Return the ratio of limit order cancellations vs number of submitted limit orders
Trait Implementations§
source§impl<M> AccountTracker<M> for FullAccountTracker<M>where
M: Currency + MarginCurrency + Send,
impl<M> AccountTracker<M> for FullAccountTracker<M>where M: Currency + MarginCurrency + Send,
source§fn update(&mut self, timestamp: u64, price: QuoteCurrency, upnl: M)
fn update(&mut self, timestamp: u64, price: QuoteCurrency, upnl: M)
source§fn log_limit_order_submission(&mut self)
fn log_limit_order_submission(&mut self)
source§fn log_limit_order_cancellation(&mut self)
fn log_limit_order_cancellation(&mut self)
source§fn log_limit_order_fill(&mut self)
fn log_limit_order_fill(&mut self)
source§fn log_trade(&mut self, side: Side, price: QuoteCurrency, size: M::PairedCurrency)
fn log_trade(&mut self, side: Side, price: QuoteCurrency, size: M::PairedCurrency)
source§impl<M: Clone> Clone for FullAccountTracker<M>
impl<M: Clone> Clone for FullAccountTracker<M>
source§fn clone(&self) -> FullAccountTracker<M>
fn clone(&self) -> FullAccountTracker<M>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more