pub struct ScenarioAnalyzer { /* private fields */ }Expand description
Scenario analyzer
Implementations§
Source§impl ScenarioAnalyzer
impl ScenarioAnalyzer
Sourcepub fn initialize(&mut self) -> Result<(), FinancialError>
pub fn initialize(&mut self) -> Result<(), FinancialError>
Initialize ScenarioAnalyzer; Ok when ready.
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.
Sourcepub fn add_named_scenario(&mut self, scenario: Scenario)
pub fn add_named_scenario(&mut self, scenario: Scenario)
Add named_scenario to the ScenarioAnalyzer.
Sourcepub fn get_named_scenario(&self, scenario_id: &str) -> Option<&Scenario>
pub fn get_named_scenario(&self, scenario_id: &str) -> Option<&Scenario>
Look up named_scenario by id; None when absent.
Sourcepub fn list_named_scenarios(&self) -> Vec<String>
pub fn list_named_scenarios(&self) -> Vec<String>
Ids of every registered named_scenario.
Sourcepub fn add_stress_test(&mut self, test: StressTest)
pub fn add_stress_test(&mut self, test: StressTest)
Add stress_test to the ScenarioAnalyzer.
Sourcepub fn get_stress_test(&self, test_id: &str) -> Option<&StressTest>
pub fn get_stress_test(&self, test_id: &str) -> Option<&StressTest>
Look up stress_test by id; None when absent.
Sourcepub fn list_stress_tests(&self) -> Vec<String>
pub fn list_stress_tests(&self) -> Vec<String>
Ids of every registered stress_test.
Sourcepub fn sensitivity_analyzer(&self) -> &SensitivityAnalyzer
pub fn sensitivity_analyzer(&self) -> &SensitivityAnalyzer
The sensitivity_analyzer component.
Sourcepub fn sensitivity_analyzer_mut(&mut self) -> &mut SensitivityAnalyzer
pub fn sensitivity_analyzer_mut(&mut self) -> &mut SensitivityAnalyzer
The sensitivity_analyzer component (mutable).
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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> 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