Skip to main content

PricePathSolution

Struct PricePathSolution 

Source
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.045455

Paths 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

Source

pub fn prices(&self) -> &[f64]

Source

pub fn options(&self) -> &PricePathOptions

Source

pub fn n_prices(&self) -> usize

Source

pub fn n_returns(&self) -> usize

Source

pub fn years(&self) -> f64

Years used for CAGR.

Source

pub fn total_return(&self) -> f64

Source

pub fn cagr(&self) -> f64

Source

pub fn mean_return(&self) -> Option<f64>

None if fewer than one return (should not happen for valid paths).

Source

pub fn volatility(&self) -> Option<f64>

None if fewer than two returns (sample vol undefined).

Source

pub fn volatility_annualized(&self) -> Option<f64>

None if sample volatility is undefined.

Source

pub fn sharpe_ratio(&self) -> Option<f64>

None if volatility undefined or zero.

Source

pub fn sortino_ratio(&self) -> Option<f64>

None if no downside observations vs target (or vol path too short).

Source

pub fn max_drawdown(&self) -> f64

Source

pub fn formula(&self) -> &str

Source

pub fn symbolic_formula(&self) -> &str

Source

pub fn simple_returns(&self) -> FinanceResult<Vec<f64>>

Simple returns along the path.

Source

pub fn log_returns(&self) -> FinanceResult<Vec<f64>>

Log returns along the path.

Source

pub fn series(&self) -> PricePathSeries

Period-by-period detail (length n_prices - 1).

Source

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 panic

Sample 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.0278
Source

pub fn print_summary_locale(&self, locale: &Locale, precision: usize)

Locale-aware print_summary.

Source

pub fn print_table(&self)

Alias: print period series table with running wealth/drawdown columns.

Trait Implementations§

Source§

impl Clone for PricePathSolution

Source§

fn clone(&self) -> PricePathSolution

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PricePathSolution

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.