Skip to main content

VarEngine

Struct VarEngine 

Source
pub struct VarEngine;
Expand description

Stateless VaR calculation engine.

Implementations§

Source§

impl VarEngine

Source

pub fn historical_var( returns: &[f64], confidence: f64, portfolio_value: f64, ) -> VarResult

Historical VaR: sort returns, pick the loss at the (1-confidence) percentile.

Source

pub fn parametric_var( mean: f64, std_dev: f64, confidence: f64, portfolio_value: f64, horizon_days: u32, ) -> VarResult

Parametric VaR using Cornish-Fisher z-scores scaled by horizon.

z values: 2.326 for 99%, 1.645 for 95%, 1.282 for 90%, linear interpolation otherwise.

Source

pub fn monte_carlo_var( mean: f64, std_dev: f64, confidence: f64, portfolio_value: f64, simulations: usize, seed: u64, ) -> VarResult

Monte Carlo VaR using LCG random number generator and Box-Muller transform.

Source

pub fn cvar_from_var(sorted_returns: &[f64], var_idx: usize) -> f64

Compute CVaR as the mean loss of the tail beyond the VaR index.

sorted_returns must be sorted ascending. Returns the average negated return below index var_idx (exclusive), which is the expected shortfall.

Source

pub fn rolling_var( returns: &[f64], window: usize, confidence: f64, portfolio_value: f64, ) -> Vec<VarResult>

Rolling window VaR: slide a window of size window over returns.

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