pub struct VarEngine;Expand description
Stateless VaR calculation engine.
Implementations§
Source§impl VarEngine
impl VarEngine
Sourcepub fn historical_var(
returns: &[f64],
confidence: f64,
portfolio_value: f64,
) -> VarResult
pub fn historical_var( returns: &[f64], confidence: f64, portfolio_value: f64, ) -> VarResult
Historical VaR: sort returns, pick the loss at the (1-confidence) percentile.
Sourcepub fn parametric_var(
mean: f64,
std_dev: f64,
confidence: f64,
portfolio_value: f64,
horizon_days: u32,
) -> VarResult
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.
Sourcepub fn monte_carlo_var(
mean: f64,
std_dev: f64,
confidence: f64,
portfolio_value: f64,
simulations: usize,
seed: u64,
) -> VarResult
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.
Sourcepub fn cvar_from_var(sorted_returns: &[f64], var_idx: usize) -> f64
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.
Auto Trait Implementations§
impl Freeze for VarEngine
impl RefUnwindSafe for VarEngine
impl Send for VarEngine
impl Sync for VarEngine
impl Unpin for VarEngine
impl UnsafeUnpin for VarEngine
impl UnwindSafe for VarEngine
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more