pub struct PricePathSolution { /* private fields */ }Expand description
Full analysis of an ordered price path.
Create with price_path_solution.
§Examples
use finance_solution::*;
let prices = [100.0, 110.0, 105.0, 120.0];
let opts = PricePathOptions::new(12.0).with_years(3.0 / 12.0);
let path = price_path_solution(&prices, opts).unwrap();
assert!(path.total_return() > 0.0);
assert_approx_equal!(path.max_drawdown(), max_drawdown(&prices).unwrap());
let series = path.series();
assert_eq!(series.len(), prices.len() - 1);
series.print_table();Sample series().print_table() (default formatting; columns match the live table):
period price_start price_end simple_return log_return wealth_index drawdown roll_max_dd
------ ----------- --------- ------------- ---------- ------------ -------- -----------
1 100.0000 110.0000 0.100000 0.095310 1.1000 0.000000 0.000000
2 110.0000 105.0000 -0.045455 -0.046520 1.0500 0.045455 0.045455
3 105.0000 120.0000 0.142857 0.133531 1.2000 0.000000 0.045455Paths with only two prices still work for total return / CAGR / drawdown; sample
volatility / Sharpe / Sortino are None until there are at least two period returns
(three prices) and, for Sortino, at least one return below the target.
Implementations§
Source§impl PricePathSolution
impl PricePathSolution
pub fn prices(&self) -> &[f64]
pub fn options(&self) -> &PricePathOptions
pub fn n_prices(&self) -> usize
pub fn n_returns(&self) -> usize
pub fn total_return(&self) -> f64
pub fn cagr(&self) -> f64
Sourcepub fn mean_return(&self) -> Option<f64>
pub fn mean_return(&self) -> Option<f64>
None if fewer than one return (should not happen for valid paths).
Sourcepub fn volatility(&self) -> Option<f64>
pub fn volatility(&self) -> Option<f64>
None if fewer than two returns (sample vol undefined).
Sourcepub fn volatility_annualized(&self) -> Option<f64>
pub fn volatility_annualized(&self) -> Option<f64>
None if sample volatility is undefined.
Sourcepub fn sharpe_ratio(&self) -> Option<f64>
pub fn sharpe_ratio(&self) -> Option<f64>
None if volatility undefined or zero.
Sourcepub fn sortino_ratio(&self) -> Option<f64>
pub fn sortino_ratio(&self) -> Option<f64>
None if no downside observations vs target (or vol path too short).
pub fn max_drawdown(&self) -> f64
pub fn formula(&self) -> &str
pub fn symbolic_formula(&self) -> &str
Sourcepub fn simple_returns(&self) -> FinanceResult<Vec<f64>>
pub fn simple_returns(&self) -> FinanceResult<Vec<f64>>
Simple returns along the path.
Sourcepub fn log_returns(&self) -> FinanceResult<Vec<f64>>
pub fn log_returns(&self) -> FinanceResult<Vec<f64>>
Log returns along the path.
Sourcepub fn series(&self) -> PricePathSeries
pub fn series(&self) -> PricePathSeries
Period-by-period detail (length n_prices - 1).
Sourcepub fn print_summary(&self)
pub fn print_summary(&self)
Summary metrics as a small table (not the period series).
Optional stats (vol / Sharpe / Sortino) print as n/a when undefined — e.g. fewer
than two period returns, or no downside observations for Sortino.
§Examples
use finance_solution::*;
let path = price_path_solution(&[100.0, 110.0, 105.0], PricePathOptions::default()).unwrap();
path.print_summary();
// Two prices: total return works; sample vol is n/a (only one return).
let short = price_path_solution(&[100.0, 110.0], PricePathOptions::default()).unwrap();
assert!(short.volatility().is_none());
short.print_summary(); // must not panicSample output (three+ prices, with vol):
metric value
-------------- -------
n_prices 10
years 0.8333
total_return 0.2500
cagr 0.3070
mean_return 0.0261
volatility 0.0477
volatility_ann 0.1653
sharpe 0.5469
sortino 1.7235
max_drawdown 0.0278Sourcepub fn print_summary_locale(&self, locale: &Locale, precision: usize)
pub fn print_summary_locale(&self, locale: &Locale, precision: usize)
Locale-aware print_summary.
Sourcepub fn print_table(&self)
pub fn print_table(&self)
Alias: print period series table with running wealth/drawdown columns.
Trait Implementations§
Source§impl Clone for PricePathSolution
impl Clone for PricePathSolution
Source§fn clone(&self) -> PricePathSolution
fn clone(&self) -> PricePathSolution
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for PricePathSolution
impl RefUnwindSafe for PricePathSolution
impl Send for PricePathSolution
impl Sync for PricePathSolution
impl Unpin for PricePathSolution
impl UnsafeUnpin for PricePathSolution
impl UnwindSafe for PricePathSolution
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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