Struct lfest::FullAccountTracker
source · [−]pub struct FullAccountTracker { /* 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
sourceimpl FullAccountTracker
impl FullAccountTracker
sourcepub fn new(starting_wb: f64, futures_type: FuturesTypes) -> Self
pub fn new(starting_wb: f64, futures_type: FuturesTypes) -> Self
Create a new AccTracker struct
sourcepub fn absolute_returns(&self, source: &ReturnsSource) -> &Vec<f64>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A>where
A: Allocator,
pub fn absolute_returns(&self, source: &ReturnsSource) -> &Vec<f64>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A>where
A: Allocator,
A: Allocator,
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>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A>where
A: Allocator,
pub fn ln_returns(&self, source: &ReturnsSource) -> &Vec<f64>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A>where
A: Allocator,
A: Allocator,
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) -> f64
pub fn profit_loss_ratio(&self) -> f64
Ratio of cumulative trade profit over cumulative trade loss
sourcepub fn cumulative_fees(&self) -> f64
pub fn cumulative_fees(&self) -> f64
Cumulative fees paid to the exchange
sourcepub fn buy_and_hold_return(&self) -> f64
pub fn buy_and_hold_return(&self) -> f64
Would be return of buy and hold strategy
sourcepub fn sell_and_hold_return(&self) -> f64
pub fn sell_and_hold_return(&self) -> f64
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
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
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
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) -> f64
pub fn max_drawdown_wallet_balance(&self) -> f64
Maximum drawdown of the wallet balance
sourcepub fn max_drawdown_total(&self) -> f64
pub fn max_drawdown_total(&self) -> f64
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) -> f64
pub fn total_rpnl(&self) -> f64
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
sourceimpl AccountTracker for FullAccountTracker
impl AccountTracker for FullAccountTracker
sourcefn update(&mut self, timestamp: u64, price: f64, upnl: f64)
fn update(&mut self, timestamp: u64, price: f64, upnl: f64)
Update with each tick, using data provided in update_state method of Exchange # Arguments timestamp: timestamp of latest tick price: price of latest tick upnl: unrealized profit and loss of account in current tick Read more
sourcefn log_limit_order_submission(&mut self)
fn log_limit_order_submission(&mut self)
Log a limit order submission event
sourcefn log_limit_order_cancellation(&mut self)
fn log_limit_order_cancellation(&mut self)
Log a limit order cancellation event
sourcefn log_limit_order_fill(&mut self)
fn log_limit_order_fill(&mut self)
Log a limit order fill event
sourceimpl Clone for FullAccountTracker
impl Clone for FullAccountTracker
sourcefn clone(&self) -> FullAccountTracker
fn clone(&self) -> FullAccountTracker
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Debug for FullAccountTracker
impl Debug for FullAccountTracker
Auto Trait Implementations
impl RefUnwindSafe for FullAccountTracker
impl Send for FullAccountTracker
impl Sync for FullAccountTracker
impl Unpin for FullAccountTracker
impl UnwindSafe for FullAccountTracker
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more