pub struct ScenarioAnalyzer { /* private fields */ }Expand description
Scenario analyzer
Implementations§
Source§impl ScenarioAnalyzer
impl ScenarioAnalyzer
pub fn new() -> Self
pub fn initialize(&mut self) -> Result<(), FinancialError>
Sourcepub fn add_scenario(&mut self, scenario: MarketScenario)
pub fn add_scenario(&mut self, scenario: MarketScenario)
Register a MarketScenario for later use by run_scenarios.
Sourcepub fn run_monte_carlo(
&self,
portfolio: &Portfolio,
num_simulations: usize,
volatility: f64,
) -> Result<StressTestResult, FinancialError>
pub fn run_monte_carlo( &self, portfolio: &Portfolio, num_simulations: usize, volatility: f64, ) -> Result<StressTestResult, FinancialError>
Run a Monte Carlo stress-test simulation over portfolio.
For each of num_simulations trials, every asset receives an
independent multiplicative shock drawn from a normal distribution with
mean 0.0 and standard deviation volatility (i.e. a simple return
model: new_price = price * (1 + z * volatility) where z ~ N(0,1)
via an inline Box-Muller transform). The portfolio value after shocks
is recorded and aggregated into a StressTestResult.
A fixed deterministic seed is used so results are reproducible across
runs (important for test stability). Returns
FinancialError::PortfolioError if the portfolio has no assets or no
positive value, and FinancialError::ValidationError if
num_simulations is zero or volatility is negative.
Sourcepub fn run_scenarios(
&self,
portfolio: &Portfolio,
) -> Result<Vec<ScenarioResult>, FinancialError>
pub fn run_scenarios( &self, portfolio: &Portfolio, ) -> Result<Vec<ScenarioResult>, FinancialError>
Apply each registered MarketScenario to portfolio and compute its
impact. Returns one ScenarioResult per registered scenario, in
registration order. An empty scenario set yields an empty result list.
pub fn add_named_scenario(&mut self, scenario: Scenario)
pub fn get_named_scenario(&self, scenario_id: &str) -> Option<&Scenario>
pub fn list_named_scenarios(&self) -> Vec<String>
pub fn add_stress_test(&mut self, test: StressTest)
pub fn get_stress_test(&self, test_id: &str) -> Option<&StressTest>
pub fn list_stress_tests(&self) -> Vec<String>
pub fn sensitivity_analyzer(&self) -> &SensitivityAnalyzer
pub fn sensitivity_analyzer_mut(&mut self) -> &mut SensitivityAnalyzer
Auto Trait Implementations§
impl Freeze for ScenarioAnalyzer
impl RefUnwindSafe for ScenarioAnalyzer
impl Send for ScenarioAnalyzer
impl Sync for ScenarioAnalyzer
impl Unpin for ScenarioAnalyzer
impl UnsafeUnpin for ScenarioAnalyzer
impl UnwindSafe for ScenarioAnalyzer
Blanket Implementations§
§impl<S, A> Aggregate<Result<S, Error>> for Awhere
A: Aggregate<S>,
impl<S, A> Aggregate<Result<S, Error>> for Awhere
A: Aggregate<S>,
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more