MPTCalculator

Struct MPTCalculator 

Source
pub struct MPTCalculator<'a> {
    pub values: &'a [f64],
    pub benchmark: &'a [f64],
    pub riskfree: &'a [f64],
}

Fields§

§values: &'a [f64]§benchmark: &'a [f64]§riskfree: &'a [f64]

Implementations§

Source§

impl<'a> MPTCalculator<'a>

Source

pub fn average(&self, avg: &mut f64) -> Errors

calculate the average value of an array not include NAN/INF values

§Examples
use mpt_lib::MPTCalculator;
use mpt_lib::enums::{self, Errors};
let data = vec![10.0, 20.0, 30.0];
let mut res = 0.0;
let mpt = MPTCalculator::from_v(&data);
let err = mpt.average(&mut res);
assert_eq!(err == Errors::ClErrorCodeNoError && res==20.0,true)
Source

pub fn standard_deviation( &self, freq: ClFrequency, is_annu: bool, standard_deviation_result: &mut f64, ) -> Errors

calculate the standard deviation value of an array,if the array has NAN/INF values,the result will be NAN

§Arguments

freq: the frequence of source data.

is_annu: the flag of annualize.

§Examples
use mpt_lib::MPTCalculator;
use mpt_lib::enums::{self, Errors};
let data = vec![
    -1.22072, -0.0668, 2.20588, -0.91563, -0.76766, -1.21429, 3.43456, 4.99825, 3.89481,
    1.59564, 0.86793, 2.41477, -1.80305, 0.6709, 3.57769, 4.77481, -0.37317, -3.52713,
    1.88831, 1.73502, 1.20155, -3.36542, -2.03551, -5.6145, -2.71663, -0.04815, 3.99807,
    1.66744, -9.68658, -0.46681, 4.22095, -6.7, -15.27331, -8.46123, 0.76369, -10.32347,
];
let mut res = 0.0;
let mpt = MPTCalculator::from_v(&data);
let err = mpt.standard_deviation(enums::ClFrequency::ClFrequencyMonthly, true, &mut res);
assert_eq!(
    err == Errors::ClErrorCodeNoError && MPTCalculator::is_eq_double(res, 15.99317),
    true
);
Source

pub fn mean_harmonic(&self, mean_res: &mut f64) -> Errors

calculate the harmonic mean value of an array, if the array has NAN/INF values,the result will be NAN

§Examples
use mpt_lib::MPTCalculator;
use mpt_lib::enums::{self, Errors};
let data = vec![
   -1.5,2.3,4.5
];
let mut res = 0.0;
let mpt = MPTCalculator::from_v(&data);
let err = mpt.mean_harmonic(&mut res);
assert_eq!(
   err == Errors::ClErrorCodeNoError && MPTCalculator::is_eq_double(res, -310.5),
   true
);
Source

pub fn weighted_mean_arithmetic( &self, weights: &[f64], mean_res: &mut f64, ) -> Errors

calculate the weighted arithmetic mean value of an array not include NAN/INF values,if the array or weights has NAN/INF values,the result will be NAN

§Arguments

weights: the weights for the values

§Examples
use mpt_lib::MPTCalculator;
use mpt_lib::enums::{self, Errors};
let data = vec![-1.5, 2.3, 4.5];
let mut res = 0.0;
let mpt = MPTCalculator::from_v(&data);
let weights = vec![0.1, 0.2, 0.3];
let err = mpt.weighted_mean_arithmetic(&weights, &mut res);
assert_eq!(
   err == Errors::ClErrorCodeNoError && MPTCalculator::is_eq_double(res, 2.76666667),
   true
);
Source

pub fn weighted_mean_geometric( &self, weights: &[f64], mean_res: &mut f64, ) -> Errors

calculate the weighted geometric mean value of an array,if the array or weights has NAN/INF values,the result will be NAN

§Arguments

weights: the weights for values

§Examples
use mpt_lib::MPTCalculator;
use mpt_lib::enums::{self, Errors};

let data = vec![
   1.22072, 0.0668, 2.20588, 0.91563, 0.76766, 1.21429, 3.43456, 4.99825, 3.89481,
   1.59564, 0.86793, 2.41477, 1.80305, 0.6709, 3.57769, 4.77481, 0.37317, 3.52713,
   1.88831, 1.73502, 1.20155, 3.36542, 2.03551, 5.6145, 2.71663, 0.04815, 3.99807,
   1.66744, 9.68658, 0.46681, 4.22095, 6.7, 15.27331, 8.46123, 0.76369, 10.32347,
];
let weighting = vec![
       3.683070486,2.698835031,2.615091784,2.829245119,4.197477687,
       3.747731115,1.428980992,1.490970258,3.776323531,1.126182408,
       4.589706355,2.213203472,3.290841193,1.574023637,2.7073515,
       2.067657476,2.715387407,3.782522676,4.737767273,3.587905857,
       1.00234693,3.598129659,2.182956354,2.399354298,0.893462788,
       1.636175797,1.182474797,4.58802791,3.983018253,4.741795995,
       2.837587798,2.613364024,4.084667264,0.443121313,1.119531868,
       3.833709695,
   ];
let mut res = 0.0;
let mpt = MPTCalculator::from_v(&data);
let err = mpt.weighted_mean_geometric(&weighting,&mut res);
assert_eq!(
   err == Errors::ClErrorCodeNoError && MPTCalculator::is_eq_double(res, 1.9433672988),
   true
);
Source

pub fn weighted_mean_harmonic( &self, weights: &[f64], mean_res: &mut f64, ) -> Errors

calculate the weighted harmonic mean value of an array,if the array or weights has NAN/INF values,the result will be NAN

§Arguments

weights: the weights for values

§Examples
use mpt_lib::MPTCalculator;
use mpt_lib::enums::{self, Errors};
let data = vec![
   1.22072, 0.0668, 2.20588, 0.91563, 0.76766, 1.21429, 3.43456, 4.99825, 3.89481,
   1.59564, 0.86793, 2.41477, 1.80305, 0.6709, 3.57769, 4.77481, 0.37317, 3.52713,
   1.88831, 1.73502, 1.20155, 3.36542, 2.03551, 5.6145, 2.71663, 0.04815, 3.99807,
   1.66744, 9.68658, 0.46681, 4.22095, 6.7, 15.27331, 8.46123, 0.76369, 10.32347,
];
let weighting = vec![
       3.683070486,2.698835031,2.615091784,2.829245119,4.197477687,
       3.747731115,1.428980992,1.490970258,3.776323531,1.126182408,
       4.589706355,2.213203472,3.290841193,1.574023637,2.7073515,
       2.067657476,2.715387407,3.782522676,4.737767273,3.587905857,
       1.00234693,3.598129659,2.182956354,2.399354298,0.893462788,
       1.636175797,1.182474797,4.58802791,3.983018253,4.741795995,
       2.837587798,2.613364024,4.084667264,0.443121313,1.119531868,
       3.833709695,
   ];
let mut res = 0.0;
let mpt = MPTCalculator::from_v(&data);
let err = mpt.weighted_mean_harmonic(&weighting, &mut res);
assert_eq!(
   err == Errors::ClErrorCodeNoError && MPTCalculator::is_eq_double(res, 0.726329928),
   true
);
Source

pub fn mean_geometric(&self, mean_res: &mut f64) -> Errors

calculate the geometric mean value of an array,if the array has NAN/INF values,the result will be NAN

§Examples
use mpt_lib::MPTCalculator;
use mpt_lib::enums::{self, Errors};

let data = vec![
   1.22072, 0.0668, 2.20588, 0.91563, 0.76766, 1.21429, 3.43456, 4.99825, 3.89481,
   1.59564, 0.86793, 2.41477, 1.80305, 0.6709, 3.57769, 4.77481, 0.37317, 3.52713,
   1.88831, 1.73502, 1.20155, 3.36542, 2.03551, 5.6145, 2.71663, 0.04815, 3.99807,
   1.66744, 9.68658, 0.46681, 4.22095, 6.7, 15.27331, 8.46123, 0.76369, 10.32347,
];
let mut res = 0.0;
let mpt = MPTCalculator::from_v(&data);
let err = mpt.mean_geometric(&mut res);
assert_eq!(
   err == Errors::ClErrorCodeNoError && MPTCalculator::is_eq_double(res, 1.920852518),
   true
);
Source

pub fn mean_arithmetic(&self, mean_res: &mut f64) -> Errors

calculate the arithmetic mean value of an array,if the array has NAN/INF values,the result will be NAN

§Examples
use mpt_lib::MPTCalculator;
use mpt_lib::enums::{self, Errors};

let data = vec![
   -1.22072, -0.0668, 2.20588, -0.91563, -0.76766, -1.21429, 3.43456, 4.99825, 3.89481,
   1.59564, 0.86793, 2.41477, -1.80305, 0.6709, 3.57769, 4.77481, -0.37317, -3.52713,
   1.88831, 1.73502, 1.20155, -3.36542, -2.03551, -5.6145, -2.71663, -0.04815, 3.99807,
   1.66744, -9.68658, -0.46681, 4.22095, -6.7, -15.27331, -8.46123, 0.76369, -10.32347,
];
let mut res = 0.0;
let mpt = MPTCalculator::from_v(&data);
let err = mpt.mean_arithmetic(&mut res);
assert_eq!(
   err == Errors::ClErrorCodeNoError && MPTCalculator::is_eq_double(res, -0.85194),
   true
);
Source

pub fn mean_arithmetic_annu( &self, freq: ClFrequency, is_annu: bool, mean_res: &mut f64, ) -> Errors

calculate the annulized arithmetic mean value of an array, if the array has NAN/INF values,the result will be NAN

§Arguments

freq: the frequence of source data.

is_annu: the flag of annualize.

§Examples
use mpt_lib::MPTCalculator;
use mpt_lib::enums::{self, Errors};

let data = vec![
   -1.22072, -0.0668, 2.20588, -0.91563, -0.76766, -1.21429, 3.43456, 4.99825, 3.89481,
   1.59564, 0.86793, 2.41477, -1.80305, 0.6709, 3.57769, 4.77481, -0.37317, -3.52713,
   1.88831, 1.73502, 1.20155, -3.36542, -2.03551, -5.6145, -2.71663, -0.04815, 3.99807,
   1.66744, -9.68658, -0.46681, 4.22095, -6.7, -15.27331, -8.46123, 0.76369, -10.32347,
];
let mut res = 0.0;
let mpt = MPTCalculator::from_v(&data);
let err = mpt.mean_arithmetic_annu(enums::ClFrequency::ClFrequencyMonthly, true, &mut res);
assert_eq!(
   err == Errors::ClErrorCodeNoError && MPTCalculator::is_eq_double(res, -10.223263),
   true
);
Source

pub fn gain_standard_deviation( &self, freq: ClFrequency, is_annu: bool, dev_res: &mut f64, ) -> Errors

calculate the gain standard deviation value of an array, if the array has NAN/INF values,the result will be NAN

§Arguments

freq: the frequence of source data.

is_annu: the flag of annuize.

§Examples
use mpt_lib::MPTCalculator;
use mpt_lib::enums::{self, Errors};
let data = vec![
   -1.22072, -0.0668, 2.20588, -0.91563, -0.76766, -1.21429, 3.43456, 4.99825, 3.89481,
   1.59564, 0.86793, 2.41477, -1.80305, 0.6709, 3.57769, 4.77481, -0.37317, -3.52713,
   1.88831, 1.73502, 1.20155, -3.36542, -2.03551, -5.6145, -2.71663, -0.04815, 3.99807,
   1.66744, -9.68658, -0.46681, 4.22095, -6.7, -15.27331, -8.46123, 0.76369, -10.32347,
];
let mut res = 0.0;
let mpt = MPTCalculator::from_v(&data);
let err =
mpt.gain_standard_deviation(enums::ClFrequency::ClFrequencyMonthly, true, &mut res);
assert_eq!(
err == Errors::ClErrorCodeNoError && MPTCalculator::is_eq_double(res, 5.03185),
true
);
Source

pub fn loss_standard_deviation( &self, freq: ClFrequency, is_annu: bool, dev_res: &mut f64, ) -> Errors

calculate the loss standard deviation value of an array, if the array has NAN/INF values,the result will be NAN

§Arguments

freq: the frequence of source data.

is_annu: the flag of annuize.

§Examples
use mpt_lib::MPTCalculator;
use mpt_lib::enums::{self, Errors};
let data = vec![
   -1.22072, -0.0668, 2.20588, -0.91563, -0.76766, -1.21429, 3.43456, 4.99825, 3.89481,
   1.59564, 0.86793, 2.41477, -1.80305, 0.6709, 3.57769, 4.77481, -0.37317, -3.52713,
   1.88831, 1.73502, 1.20155, -3.36542, -2.03551, -5.6145, -2.71663, -0.04815, 3.99807,
   1.66744, -9.68658, -0.46681, 4.22095, -6.7, -15.27331, -8.46123, 0.76369, -10.32347,
];
let mut res = 0.0;
let mpt = MPTCalculator::from_v(&data);
let err = mpt.loss_standard_deviation(enums::ClFrequency::ClFrequencyMonthly, true, &mut res);
assert_eq!(
   err == Errors::ClErrorCodeNoError && MPTCalculator::is_eq_double(res, 14.88251),
   true
);
Source

pub fn semi_standard_deviation( &self, freq: ClFrequency, is_annu: bool, dev_res: &mut f64, ) -> Errors

calculate the semi standard deviation value of an array, if the array has NAN/INF values,the result will be NAN

§Arguments

freq: the frequence of source data.

is_annu: the flag of annuize.

§Examples
use mpt_lib::MPTCalculator;
use mpt_lib::enums::{self, Errors};
let data = vec![
   -1.22072, -0.0668, 2.20588, -0.91563, -0.76766, -1.21429, 3.43456, 4.99825, 3.89481,
   1.59564, 0.86793, 2.41477, -1.80305, 0.6709, 3.57769, 4.77481, -0.37317, -3.52713,
   1.88831, 1.73502, 1.20155, -3.36542, -2.03551, -5.6145, -2.71663, -0.04815, 3.99807,
   1.66744, -9.68658, -0.46681, 4.22095, -6.7, -15.27331, -8.46123, 0.76369, -10.32347,
];
let mut res = 0.0;
let mpt = MPTCalculator::from_v(&data);
let err =
mpt.semi_standard_deviation(enums::ClFrequency::ClFrequencyMonthly, true, &mut res);
assert_eq!(
err == Errors::ClErrorCodeNoError && MPTCalculator::is_eq_double(res, 13.22398),
true
);
Source

pub fn weighted_standard_deviation( &self, weights: &[f64], dev_res: &mut f64, ) -> Errors

calculate the weighted standard deviation value of an array,if the array or weights has NAN/INF values,the result will be NAN

§Arguments

weights: the weights for values

§Examples
use mpt_lib::MPTCalculator;
use mpt_lib::enums::{self, Errors};

let data = vec![
   1.22072, 0.0668, 2.20588, 0.91563, 0.76766, 1.21429, 3.43456, 4.99825, 3.89481,
   1.59564, 0.86793, 2.41477, 1.80305, 0.6709, 3.57769, 4.77481, 0.37317, 3.52713,
   1.88831, 1.73502, 1.20155, 3.36542, 2.03551, 5.6145, 2.71663, 0.04815, 3.99807,
   1.66744, 9.68658, 0.46681, 4.22095, 6.7, 15.27331, 8.46123, 0.76369, 10.32347,
];
let weighting = vec![
       3.683070486,2.698835031,2.615091784,2.829245119,4.197477687,
       3.747731115,1.428980992,1.490970258,3.776323531,1.126182408,
       4.589706355,2.213203472,3.290841193,1.574023637,2.7073515,
       2.067657476,2.715387407,3.782522676,4.737767273,3.587905857,
       1.00234693,3.598129659,2.182956354,2.399354298,0.893462788,
       1.636175797,1.182474797,4.58802791,3.983018253,4.741795995,
       2.837587798,2.613364024,4.084667264,0.443121313,1.119531868,
       3.833709695,
   ];
let mut res = 0.0;
let mpt = MPTCalculator::from_v(&data);
let err = mpt.weighted_standard_deviation(&weighting,&mut res);
assert_eq!(
   err == Errors::ClErrorCodeNoError && MPTCalculator::is_eq_double(res, 3.586653428),
   true
);
Source

pub fn skewness(&self, skewness: &mut f64) -> Errors

calculate the skewness value of an array, if the array has NAN/INF values,the result will be NAN

§Arguments

freq: the frequence of source data.

is_annu: the flag of annuize.

§Examples
use mpt_lib::MPTCalculator;
use mpt_lib::enums::{self, Errors};
let data = vec![
   -1.22072, -0.0668, 2.20588, -0.91563, -0.76766, -1.21429, 3.43456, 4.99825, 3.89481,
   1.59564, 0.86793, 2.41477, -1.80305, 0.6709, 3.57769, 4.77481, -0.37317, -3.52713,
   1.88831, 1.73502, 1.20155, -3.36542, -2.03551, -5.6145, -2.71663, -0.04815, 3.99807,
   1.66744, -9.68658, -0.46681, 4.22095, -6.7, -15.27331, -8.46123, 0.76369, -10.32347,
];
let mut res = 0.0;
let mpt = MPTCalculator::from_v(&data);
let err =
mpt.skewness(&mut res);
assert_eq!(
err == Errors::ClErrorCodeNoError && MPTCalculator::is_eq_double(res, -1.31604),
true
);
Source

pub fn kurtosis(&self, kurtosis: &mut f64) -> Errors

calculate the kurtosis value of an array, if the array has NAN/INF values,the result will be NAN

§Arguments

freq: the frequence of source data.

is_annu: the flag of annuize.

§Examples
use mpt_lib::MPTCalculator;
use mpt_lib::enums::{self, Errors};
let data = vec![
   -1.22072, -0.0668, 2.20588, -0.91563, -0.76766, -1.21429, 3.43456, 4.99825, 3.89481,
   1.59564, 0.86793, 2.41477, -1.80305, 0.6709, 3.57769, 4.77481, -0.37317, -3.52713,
   1.88831, 1.73502, 1.20155, -3.36542, -2.03551, -5.6145, -2.71663, -0.04815, 3.99807,
   1.66744, -9.68658, -0.46681, 4.22095, -6.7, -15.27331, -8.46123, 0.76369, -10.32347,
];
let mut res = 0.0;
let mpt = MPTCalculator::from_v(&data);
let err =
mpt.kurtosis(&mut res);
assert_eq!(
err == Errors::ClErrorCodeNoError && MPTCalculator::is_eq_double(res, 1.76946),
true
);
Source

pub fn sharpe_ratio( &self, freq: ClFrequency, is_annu: bool, sharpe_ratio_result: &mut f64, ) -> Errors

calculate the sharpe ratio value of an array,it need riskfree data, if the array and riskfree have NAN/INF values,the result will be NAN

§Arguments

freq: the frequence of source data.

is_annu: the flag of annuize.

§Examples
use mpt_lib::MPTCalculator;
use mpt_lib::enums::{self, Errors};
let data = vec![
   -1.76334, -3.7317, -0.49068, 11.83432, 9.08289, 3.39531, 0.70368, 0.89286, -0.76953,
  6.39783, 1.38484, 2.33645, 2.80998, 0.5808, -0.61141, -0.20506, -0.47945, -0.13765,
   -3.4459, -0.85653, 1.83585, 0.84836, 3.61024, 3.99188, -1.7892, 2.02054, -0.81169,
   -1.40753, 3.02125, -0.67676, 1.07073, -2.21509, 0.29547, -2.65139, 2.62273, -0.65557,
   0.76463, -1.22072, -0.0668, 2.20588, -0.91563, -0.76766, -1.21429, 3.43456, 4.99825,
   3.89481, 1.59564, 0.86793,
];
let rf_data = vec![
   0.10075, 0.0999, 0.09735, 0.0982, 0.09311, 0.08124, 0.07785, 0.08209, 0.08124, 0.07955,
   0.0804, 0.07701, 0.07701, 0.07955, 0.0804, 0.0804, 0.08887, 0.10923, 0.11602, 0.12791,
   0.14235, 0.15085, 0.17806, 0.19083, 0.20105, 0.21894, 0.23855, 0.24111, 0.24708,
   0.25903, 0.27868, 0.30004, 0.3009, 0.32143, 0.34026, 0.33884, 0.36586, 0.38497,
   0.39406, 0.40057, 0.41237, 0.41911, 0.43358, 0.43548, 0.42107, 0.42743, 0.43278,
   0.4235,
];
let mut res = 0.0;
let mpt = MPTCalculator::from_v_r(&data, &rf_data);
let err =
mpt.sharpe_ratio(enums::ClFrequency::ClFrequencyMonthly, true, &mut res);
assert_eq!(
err == Errors::ClErrorCodeNoError && MPTCalculator::is_eq_double(res, 0.94596),
true
);
Source

pub fn sharpe_ratio_arithmetic( &self, freq: ClFrequency, is_annu: bool, sharpe_ratio_arithmetic: &mut f64, ) -> Errors

calculate the sharpe ratio arithmetic value of an array, it need riskfree data, if the array and riskfree have NAN/INF values,the result will be NAN

§Arguments

freq: the frequence of source data.

is_annu: the flag of annuize.

§Examples
use mpt_lib::MPTCalculator;
use mpt_lib::enums::{self, Errors};
let data = vec![
   -1.76334, -3.7317, -0.49068, 11.83432, 9.08289, 3.39531, 0.70368, 0.89286, -0.76953,
  6.39783, 1.38484, 2.33645, 2.80998, 0.5808, -0.61141, -0.20506, -0.47945, -0.13765,
   -3.4459, -0.85653, 1.83585, 0.84836, 3.61024, 3.99188, -1.7892, 2.02054, -0.81169,
   -1.40753, 3.02125, -0.67676, 1.07073, -2.21509, 0.29547, -2.65139, 2.62273, -0.65557,
   0.76463, -1.22072, -0.0668, 2.20588, -0.91563, -0.76766, -1.21429, 3.43456, 4.99825,
   3.89481, 1.59564, 0.86793,
];
let rf_data = vec![
   0.10075, 0.0999, 0.09735, 0.0982, 0.09311, 0.08124, 0.07785, 0.08209, 0.08124, 0.07955,
   0.0804, 0.07701, 0.07701, 0.07955, 0.0804, 0.0804, 0.08887, 0.10923, 0.11602, 0.12791,
   0.14235, 0.15085, 0.17806, 0.19083, 0.20105, 0.21894, 0.23855, 0.24111, 0.24708,
   0.25903, 0.27868, 0.30004, 0.3009, 0.32143, 0.34026, 0.33884, 0.36586, 0.38497,
   0.39406, 0.40057, 0.41237, 0.41911, 0.43358, 0.43548, 0.42107, 0.42743, 0.43278,
   0.4235,
];
let mut res = 0.0;
let mpt = MPTCalculator::from_v_r(&data, &rf_data);
let err =
mpt.sharpe_ratio_arithmetic(enums::ClFrequency::ClFrequencyMonthly, true, &mut res);
assert_eq!(
err == Errors::ClErrorCodeNoError && MPTCalculator::is_eq_double(res, 0.96502),
true
);
Source

pub fn sharpe_ratio_geometric( &self, freq: ClFrequency, is_annu: bool, sharpe_ratio_result: &mut f64, ) -> Errors

calculate the sharpe ratio geometric value of an array, it need riskfree data, if the array and riskfree have NAN/INF values,the result will be NAN

§Arguments

freq: the frequence of source data.

is_annu: the flag of annuize.

§Examples
use mpt_lib::MPTCalculator;
use mpt_lib::enums::{self, Errors};
let data = vec![
    -1.76334, -3.7317, -0.49068, 11.83432, 9.08289, 3.39531, 0.70368, 0.89286, -0.76953,
   6.39783, 1.38484, 2.33645, 2.80998, 0.5808, -0.61141, -0.20506, -0.47945, -0.13765,
    -3.4459, -0.85653, 1.83585, 0.84836, 3.61024, 3.99188, -1.7892, 2.02054, -0.81169,
    -1.40753, 3.02125, -0.67676, 1.07073, -2.21509, 0.29547, -2.65139, 2.62273, -0.65557,
    0.76463, -1.22072, -0.0668, 2.20588, -0.91563, -0.76766, -1.21429, 3.43456, 4.99825,
    3.89481, 1.59564, 0.86793,
];
let rf_data = vec![
    0.10075, 0.0999, 0.09735, 0.0982, 0.09311, 0.08124, 0.07785, 0.08209, 0.08124, 0.07955,
    0.0804, 0.07701, 0.07701, 0.07955, 0.0804, 0.0804, 0.08887, 0.10923, 0.11602, 0.12791,
    0.14235, 0.15085, 0.17806, 0.19083, 0.20105, 0.21894, 0.23855, 0.24111, 0.24708,
    0.25903, 0.27868, 0.30004, 0.3009, 0.32143, 0.34026, 0.33884, 0.36586, 0.38497,
    0.39406, 0.40057, 0.41237, 0.41911, 0.43358, 0.43548, 0.42107, 0.42743, 0.43278,
    0.4235,
];
let mut res = 0.0;
let mpt = MPTCalculator::from_v_r(&data, &rf_data);
let err =
mpt.sharpe_ratio_geometric(enums::ClFrequency::ClFrequencyMonthly, true, &mut res);
assert_eq!(
err == Errors::ClErrorCodeNoError && MPTCalculator::is_eq_double(res, 0.93957),
true
);
Source

pub fn downside_deviation( &self, freq: ClFrequency, is_annu: bool, downside_deviation: &mut f64, ) -> Errors

Source

pub fn upside_deviation( &self, freq: ClFrequency, is_annu: bool, downside_deviation: &mut f64, ) -> Errors

Source

pub fn sortino_ratio( &self, freq: ClFrequency, is_annu: bool, sortino_ratio_result: &mut f64, ) -> Errors

calculate the sortino ratio value of an array, it need riskfree data, if the array and riskfree have NAN/INF values,the result will be NAN

§Arguments

freq: the frequence of source data.

is_annu: the flag of annuize.

§Examples
use mpt_lib::MPTCalculator;
use mpt_lib::enums::{self, Errors};
let data = vec![
    -1.76334, -3.7317, -0.49068, 11.83432, 9.08289, 3.39531, 0.70368, 0.89286, -0.76953,
    6.39783, 1.38484, 2.33645, 2.80998, 0.5808, -0.61141, -0.20506, -0.47945, -0.13765,
    -3.4459, -0.85653, 1.83585, 0.84836, 3.61024, 3.99188, -1.7892, 2.02054, -0.81169,
    -1.40753, 3.02125, -0.67676, 1.07073, -2.21509, 0.29547, -2.65139, 2.62273, -0.65557,
    0.76463, -1.22072, -0.0668, 2.20588, -0.91563, -0.76766, -1.21429, 3.43456, 4.99825,
    3.89481, 1.59564, 0.86793,
];
let rf_data = vec![
    0.10075, 0.0999, 0.09735, 0.0982, 0.09311, 0.08124, 0.07785, 0.08209, 0.08124, 0.07955,
    0.0804, 0.07701, 0.07701, 0.07955, 0.0804, 0.0804, 0.08887, 0.10923, 0.11602, 0.12791,
    0.14235, 0.15085, 0.17806, 0.19083, 0.20105, 0.21894, 0.23855, 0.24111, 0.24708,
    0.25903, 0.27868, 0.30004, 0.3009, 0.32143, 0.34026, 0.33884, 0.36586, 0.38497,
    0.39406, 0.40057, 0.41237, 0.41911, 0.43358, 0.43548, 0.42107, 0.42743, 0.43278,
    0.4235,
];
let mut res = 0.0;
let mpt = MPTCalculator::from_v_r(&data, &rf_data);
let err = mpt.sortino_ratio(enums::ClFrequency::ClFrequencyMonthly, true, &mut res);
assert_eq!(
    err == Errors::ClErrorCodeNoError && MPTCalculator::is_eq_double(res, 2.37108),
    true
);
Source

pub fn sortino_ratio_arithmetic( &self, freq: ClFrequency, is_annu: bool, sortino_ratio_res: &mut f64, ) -> Errors

calculate the sortino ratio arithmetic value of an array, it need riskfree data, if the array and riskfree have NAN/INF values,the result will be NAN

§Arguments

freq: the frequence of source data.

is_annu: the flag of annuize.

§Examples
use mpt_lib::MPTCalculator;
use mpt_lib::enums::{self, Errors};
let data = vec![
    -1.76334, -3.7317, -0.49068, 11.83432, 9.08289, 3.39531, 0.70368, 0.89286, -0.76953,
    6.39783, 1.38484, 2.33645, 2.80998, 0.5808, -0.61141, -0.20506, -0.47945, -0.13765,
    -3.4459, -0.85653, 1.83585, 0.84836, 3.61024, 3.99188, -1.7892, 2.02054, -0.81169,
    -1.40753, 3.02125, -0.67676, 1.07073, -2.21509, 0.29547, -2.65139, 2.62273, -0.65557,
    0.76463, -1.22072, -0.0668, 2.20588, -0.91563, -0.76766, -1.21429, 3.43456, 4.99825,
    3.89481, 1.59564, 0.86793,
];
let rf_data = vec![
    0.10075, 0.0999, 0.09735, 0.0982, 0.09311, 0.08124, 0.07785, 0.08209, 0.08124, 0.07955,
    0.0804, 0.07701, 0.07701, 0.07955, 0.0804, 0.0804, 0.08887, 0.10923, 0.11602, 0.12791,
    0.14235, 0.15085, 0.17806, 0.19083, 0.20105, 0.21894, 0.23855, 0.24111, 0.24708,
    0.25903, 0.27868, 0.30004, 0.3009, 0.32143, 0.34026, 0.33884, 0.36586, 0.38497,
    0.39406, 0.40057, 0.41237, 0.41911, 0.43358, 0.43548, 0.42107, 0.42743, 0.43278,
    0.4235,
];
let mut res = 0.0;
let mpt = MPTCalculator::from_v_r(&data, &rf_data);
let err =
    mpt.sortino_ratio_arithmetic(enums::ClFrequency::ClFrequencyMonthly, true, &mut res);
assert_eq!(
    err == Errors::ClErrorCodeNoError && MPTCalculator::is_eq_double(res, 0.96502248),
    true
);
Source

pub fn sortino_ratio_geometric( &self, freq: ClFrequency, is_annu: bool, sortino_ratio_result: &mut f64, ) -> Errors

calculate the sortino ratio geometric value of an array, it need riskfree data, if the array and riskfree have NAN/INF values,the result will be NAN

§Arguments

freq: the frequence of source data.

is_annu: the flag of annuize.

§Examples
use mpt_lib::MPTCalculator;
use mpt_lib::enums::{self, Errors};
let data = vec![
    -1.76334, -3.7317, -0.49068, 11.83432, 9.08289, 3.39531, 0.70368, 0.89286, -0.76953,
    6.39783, 1.38484, 2.33645, 2.80998, 0.5808, -0.61141, -0.20506, -0.47945, -0.13765,
    -3.4459, -0.85653, 1.83585, 0.84836, 3.61024, 3.99188, -1.7892, 2.02054, -0.81169,
    -1.40753, 3.02125, -0.67676, 1.07073, -2.21509, 0.29547, -2.65139, 2.62273, -0.65557,
    0.76463, -1.22072, -0.0668, 2.20588, -0.91563, -0.76766, -1.21429, 3.43456, 4.99825,
    3.89481, 1.59564, 0.86793,
];
let rf_data = vec![
    0.10075, 0.0999, 0.09735, 0.0982, 0.09311, 0.08124, 0.07785, 0.08209, 0.08124, 0.07955,
    0.0804, 0.07701, 0.07701, 0.07955, 0.0804, 0.0804, 0.08887, 0.10923, 0.11602, 0.12791,
    0.14235, 0.15085, 0.17806, 0.19083, 0.20105, 0.21894, 0.23855, 0.24111, 0.24708,
    0.25903, 0.27868, 0.30004, 0.3009, 0.32143, 0.34026, 0.33884, 0.36586, 0.38497,
    0.39406, 0.40057, 0.41237, 0.41911, 0.43358, 0.43548, 0.42107, 0.42743, 0.43278,
    0.4235,
 ];
let mut res = 0.0;
let mpt = MPTCalculator::from_v_r(&data, &rf_data);
let err =
    mpt.sortino_ratio_geometric(enums::ClFrequency::ClFrequencyMonthly, true, &mut res);
assert_eq!(
    err == Errors::ClErrorCodeNoError && MPTCalculator::is_eq_double(res, 2.34312),
    true
);
Source

pub fn omega( &self, freq: ClFrequency, is_annu: bool, omega_res: &mut f64, ) -> Errors

calculate the omega value of an array, it need riskfree data, if the array and riskfree have NAN/INF values,the result will be NAN

§Arguments

freq: the frequence of source data.

is_annu: the flag of annuize.

§Examples
use mpt_lib::MPTCalculator;
use mpt_lib::enums::{self, Errors};
let data = vec![
    -1.76334, -3.7317, -0.49068, 11.83432, 9.08289, 3.39531, 0.70368, 0.89286, -0.76953,
    6.39783, 1.38484, 2.33645, 2.80998, 0.5808, -0.61141, -0.20506, -0.47945, -0.13765,
    -3.4459, -0.85653, 1.83585, 0.84836, 3.61024, 3.99188, -1.7892, 2.02054, -0.81169,
    -1.40753, 3.02125, -0.67676, 1.07073, -2.21509, 0.29547, -2.65139, 2.62273, -0.65557,
    0.76463, -1.22072, -0.0668, 2.20588, -0.91563, -0.76766, -1.21429, 3.43456, 4.99825,
    3.89481, 1.59564, 0.86793,
];
let rf_data = vec![
    0.10075, 0.0999, 0.09735, 0.0982, 0.09311, 0.08124, 0.07785, 0.08209, 0.08124, 0.07955,
    0.0804, 0.07701, 0.07701, 0.07955, 0.0804, 0.0804, 0.08887, 0.10923, 0.11602, 0.12791,
    0.14235, 0.15085, 0.17806, 0.19083, 0.20105, 0.21894, 0.23855, 0.24111, 0.24708,
    0.25903, 0.27868, 0.30004, 0.3009, 0.32143, 0.34026, 0.33884, 0.36586, 0.38497,
    0.39406, 0.40057, 0.41237, 0.41911, 0.43358, 0.43548, 0.42107, 0.42743, 0.43278,
    0.4235,
];
let mut res = 0.0;
let mpt = MPTCalculator::from_v_r(&data, &rf_data);
let err = mpt.omega(enums::ClFrequency::ClFrequencyMonthly, true, &mut res);
assert_eq!(
    err == Errors::ClErrorCodeNoError && MPTCalculator::is_eq_double(res, 2.2412239894355674),
    true
);
Source

pub fn kappa3( &self, freq: ClFrequency, is_annu: bool, kappa3_res: &mut f64, ) -> Errors

calculate the kapp3 value of an array,it need riskfree data, if the array and riskfree have NAN/INF values,the result will be NAN

§Arguments

freq: the frequence of source data.

is_annu: the flag of annuize.

§Examples
use mpt_lib::MPTCalculator;
use mpt_lib::enums::{self, Errors};
let data = vec![
    -1.76334, -3.7317, -0.49068, 11.83432, 9.08289, 3.39531, 0.70368, 0.89286, -0.76953,
    6.39783, 1.38484, 2.33645, 2.80998, 0.5808, -0.61141, -0.20506, -0.47945, -0.13765,
    -3.4459, -0.85653, 1.83585, 0.84836, 3.61024, 3.99188, -1.7892, 2.02054, -0.81169,
    -1.40753, 3.02125, -0.67676, 1.07073, -2.21509, 0.29547, -2.65139, 2.62273, -0.65557,
    0.76463, -1.22072, -0.0668, 2.20588, -0.91563, -0.76766, -1.21429, 3.43456, 4.99825,
    3.89481, 1.59564, 0.86793,
];
let rf_data = vec![
    0.10075, 0.0999, 0.09735, 0.0982, 0.09311, 0.08124, 0.07785, 0.08209, 0.08124, 0.07955,
    0.0804, 0.07701, 0.07701, 0.07955, 0.0804, 0.0804, 0.08887, 0.10923, 0.11602, 0.12791,
    0.14235, 0.15085, 0.17806, 0.19083, 0.20105, 0.21894, 0.23855, 0.24111, 0.24708,
    0.25903, 0.27868, 0.30004, 0.3009, 0.32143, 0.34026, 0.33884, 0.36586, 0.38497,
    0.39406, 0.40057, 0.41237, 0.41911, 0.43358, 0.43548, 0.42107, 0.42743, 0.43278,
    0.4235,
];
let mut res = 0.0;
let mpt = MPTCalculator::from_v_r(&data, &rf_data);
let err = mpt.kappa3(enums::ClFrequency::ClFrequencyMonthly, true, &mut res);
assert_eq!(
    err == Errors::ClErrorCodeNoError && MPTCalculator::is_eq_double(res, 2.77311069),
    true
);
Source

pub fn gain_loss_ratio(&self, gain_loss_res: &mut f64) -> Errors

calculate the gain loss ratio value of an array, if the array has NAN/INF values,the result will be NAN

§Examples
use mpt_lib::MPTCalculator;
use mpt_lib::enums::{self, Errors};
let data = vec![
    -1.22072, -0.0668, 2.20588, -0.91563, -0.76766, -1.21429, 3.43456, 4.99825, 3.89481,
    1.59564, 0.86793, 2.41477, -1.80305, 0.6709, 3.57769, 4.77481, -0.37317, -3.52713,
    1.88831, 1.73502, 1.20155, -3.36542, -2.03551, -5.6145, -2.71663, -0.04815, 3.99807,
    1.66744, -9.68658, -0.46681, 4.22095, -6.7, -15.27331, -8.46123, 0.76369, -10.32347,
];
let mut res = 0.0;
let mpt = MPTCalculator::from_v(&data);
let err = mpt.gain_loss_ratio(&mut res);
assert_eq!(
    err == Errors::ClErrorCodeNoError && MPTCalculator::is_eq_double(res, 0.58877),
    true
);
Source

pub fn coefficeient_viaiantion( &self, coefficeient_viaiantion_res: &mut f64, ) -> Errors

calculate the coefficeient viaiantion value of an array, if the array has NAN/INF values,the result will be NAN

§Examples
use mpt_lib::MPTCalculator;
use mpt_lib::enums::{self, Errors};
let data = vec![
    -1.22072, -0.0668, 2.20588, -0.91563, -0.76766, -1.21429, 3.43456, 4.99825, 3.89481,
    1.59564, 0.86793, 2.41477, -1.80305, 0.6709, 3.57769, 4.77481, -0.37317, -3.52713,
    1.88831, 1.73502, 1.20155, -3.36542, -2.03551, -5.6145, -2.71663, -0.04815, 3.99807,
    1.66744, -9.68658, -0.46681, 4.22095, -6.7, -15.27331, -8.46123, 0.76369, -10.32347,
];
let mut res = 0.0;
let mpt = MPTCalculator::from_v(&data);
let err = mpt.coefficeient_viaiantion(&mut res);
assert_eq!(
    err == Errors::ClErrorCodeNoError && MPTCalculator::is_eq_double(res, -5.41921),
    true
);
Source

pub fn efficiency_ratio_arthmetic( &self, freq: ClFrequency, is_annu: bool, result: &mut f64, ) -> Errors

calculate the efficiency ratio arthmetic value of an array, if the array has NAN/INF values,the result will be NAN

§Arguments

freq: the frequence of source data.

is_annu: the flag of annuize.

§Examples
use mpt_lib::MPTCalculator;
use mpt_lib::enums::{self, Errors};
let data = vec![
    2.8709, -1.6506, 0.8281, 4.8182, 4.0484, -0.4246, -1.8230, 1.1619, 6.2151, 5.3158,
   -3.7904, 0.3500, -8.9486, -1.6029, -2.1879, 6.5159, 3.0498, -8.3762, -3.9341, -0.0780,
    -17.9807, -21.5895, -11.3292, 4.8884, -7.5447, -7.5943, 13.9102, 13.6679, 6.2313,
    -1.3755, 8.7637, 2.1660, 5.3087, -5.4276, 5.4496, 4.3492,
];
let mut res = 0.0;
let mpt = MPTCalculator::from_v(&data);
let err =
    mpt.efficiency_ratio_arthmetic(enums::ClFrequency::ClFrequencyMonthly, false, &mut res);
assert_eq!(
    err == Errors::ClErrorCodeNoError && MPTCalculator::is_eq_double(res, -0.020986),
    true
);
Source

pub fn jarque_bera(&self, jarque_bera: &mut f64) -> Errors

calculate the jarque_bera value of an array, if the array has NAN/INF values,the result will be NAN

§Examples
use mpt_lib::MPTCalculator;
use mpt_lib::enums::{self, Errors};
let data = vec![
    -1.22072, -0.0668, 2.20588, -0.91563, -0.76766, -1.21429, 3.43456, 4.99825, 3.89481,
    1.59564, 0.86793, 2.41477, -1.80305, 0.6709, 3.57769, 4.77481, -0.37317, -3.52713,
    1.88831, 1.73502, 1.20155, -3.36542, -2.03551, -5.6145, -2.71663, -0.04815, 3.99807,
    1.66744, -9.68658, -0.46681, 4.22095, -6.7, -15.27331, -8.46123, 0.76369, -10.32347,
];
let mut res = 0.0;
let mpt = MPTCalculator::from_v(&data);
let err = mpt.jarque_bera(&mut res);
assert_eq!(
    err == Errors::ClErrorCodeNoError && MPTCalculator::is_eq_double(res, 15.08823),
    true
);
Source

pub fn median(&self, result: &mut f64) -> Errors

calculate the median value of an array, if the array has NAN/INF values,the result will be NAN

§Examples
use mpt_lib::MPTCalculator;
use mpt_lib::enums::{self, Errors};
let data = vec![
    -1.22072, -0.0668, 2.20588, -0.91563, -0.76766, -1.21429, 3.43456, 4.99825, 3.89481,
    1.59564, 0.86793, 2.41477, -1.80305, 0.6709, 3.57769, 4.77481, -0.37317, -3.52713,
    1.88831, 1.73502, 1.20155, -3.36542, -2.03551, -5.6145, -2.71663, -0.04815, 3.99807,
    1.66744, -9.68658, -0.46681, 4.22095, -6.7, -15.27331, -8.46123, 0.76369, -10.32347,
];
let mut res = 0.0;
let mpt = MPTCalculator::from_v(&data);
let err = mpt.median(&mut res);
assert_eq!(
    err == Errors::ClErrorCodeNoError && MPTCalculator::is_eq_double(res, -0.057475),
    true
);
Source

pub fn median_weighted(&self, result: &mut f64) -> Errors

calculate the median weighted value of an array, if the array has NAN/INF values,the result will be NAN

§Examples
use mpt_lib::MPTCalculator;
use mpt_lib::enums::{self, Errors};
let data = vec![
    -1.22072, -0.0668, 2.20588, -0.91563, -0.76766, -1.21429, 3.43456, 4.99825, 3.89481,
    1.59564, 0.86793, 2.41477, -1.80305, 0.6709, 3.57769, 4.77481, -0.37317, -3.52713,
    1.88831, 1.73502, 1.20155, -3.36542, -2.03551, -5.6145, -2.71663, -0.04815, 3.99807,
    1.66744, -9.68658, -0.46681, 4.22095, -6.7, -15.27331, -8.46123, 0.76369, -10.32347,
];
let mut res = 0.0;
let mpt = MPTCalculator::from_v(&data);
let err = mpt.median_weighted(&mut res);
assert_eq!(
    err == Errors::ClErrorCodeNoError && MPTCalculator::is_eq_double(res, -0.057475),
    true
);
Source

pub fn up_month_percent(&self, up_number_res: &mut f64) -> Errors

calculate the up month percent value of an array, if the array has NAN/INF values,the result will be NAN

§Examples
use mpt_lib::MPTCalculator;
use mpt_lib::enums::{self, Errors};
let data = vec![
    -1.22072, -0.0668, 2.20588, -0.91563, -0.76766, -1.21429, 3.43456, 4.99825, 3.89481,
    1.59564, 0.86793, 2.41477, -1.80305, 0.6709, 3.57769, 4.77481, -0.37317, -3.52713,
    1.88831, 1.73502, 1.20155, -3.36542, -2.03551, -5.6145, -2.71663, -0.04815, 3.99807,
    1.66744, -9.68658, -0.46681, 4.22095, -6.7, -15.27331, -8.46123, 0.76369, -10.32347,
];
let mut res = 0.0;
let mpt = MPTCalculator::from_v(&data);
let err = mpt.up_month_percent(&mut res);
assert_eq!(
    err == Errors::ClErrorCodeNoError && MPTCalculator::is_eq_double(res, 47.22222),
    true
);
Source

pub fn down_month_percent(&self, up_number_res: &mut f64) -> Errors

calculate the up month percent value of an array, if the array has NAN/INF values,the result will be NAN

§Examples
use mpt_lib::MPTCalculator;
use mpt_lib::enums::{self, Errors};
let data = vec![
    -1.22072, -0.0668, 2.20588, -0.91563, -0.76766, -1.21429, 3.43456, 4.99825, 3.89481,
    1.59564, 0.86793, 2.41477, -1.80305, 0.6709, 3.57769, 4.77481, -0.37317, -3.52713,
    1.88831, 1.73502, 1.20155, -3.36542, -2.03551, -5.6145, -2.71663, -0.04815, 3.99807,
    1.66744, -9.68658, -0.46681, 4.22095, -6.7, -15.27331, -8.46123, 0.76369, -10.32347,
];
let mut res = 0.0;
let mpt = MPTCalculator::from_v(&data);
let err = mpt.down_month_percent(&mut res);
assert_eq!(
    err == Errors::ClErrorCodeNoError && MPTCalculator::is_eq_double(res, 52.77778),
    true
);
Source

pub fn average_gain_loss( &self, avg_gain: &mut f64, avg_loss: &mut f64, ) -> Errors

calculate the average gain and loss value of an array, if the array has NAN/INF values,the result will be NAN

§Arguments

freq: the frequence of source data.

is_annu: the flag of annuize.

§Examples
use mpt_lib::MPTCalculator;
use mpt_lib::enums::{self, Errors};
let data = vec![
    -1.22072, -0.0668, 2.20588, -0.91563, -0.76766, -1.21429, 3.43456, 4.99825, 3.89481,
    1.59564, 0.86793, 2.41477, -1.80305, 0.6709, 3.57769, 4.77481, -0.37317, -3.52713,
    1.88831, 1.73502, 1.20155, -3.36542, -2.03551, -5.6145, -2.71663, -0.04815, 3.99807,
    1.66744, -9.68658, -0.46681, 4.22095, -6.7, -15.27331, -8.46123, 0.76369, -10.32347,
];
let mut avg_gain = 0.0;
let mut avg_loss = 0.0;
let mpt = MPTCalculator::from_v(&data);
let err = mpt.average_gain_loss(&mut avg_gain, &mut avg_loss);
assert_eq!(
    err == Errors::ClErrorCodeNoError && MPTCalculator::is_eq_double(avg_gain, 2.57330),
    true
);
assert_eq!(
    err == Errors::ClErrorCodeNoError && MPTCalculator::is_eq_double(avg_loss, -4.01982),
    true
);
Source

pub fn max_draw_down( &self, dates: &[i32], freq: ClFrequency, max_draw_down: &mut f64, max_draw_down_peek_date: &mut i32, max_draw_down_valley_date: &mut i32, max_draw_down_month: &mut i32, recovery_month: &mut i32, recovery_date: &mut i32, ) -> Errors

calculate the max draw down value,peek date,valley date,recover month and recover date of an array, if the array has NAN/INF values,the result will be NAN freq: the frequence of source data.

dates: the date of value

§Examples
use mpt_lib::MPTCalculator;
use mpt_lib::enums::{self, Errors};
let data = vec![
    -1.22072, -0.0668, 2.20588, -0.91563, -0.76766, -1.21429, 3.43456, 4.99825, 3.89481,
    1.59564, 0.86793, 2.41477, -1.80305, 0.6709, 3.57769, 4.77481, -0.37317, -3.52713,
    1.88831, 1.73502, 1.20155, -3.36542, -2.03551, -5.6145, -2.71663, -0.04815, 3.99807,
    1.66744, -9.68658, -0.46681, 4.22095, -6.7, -15.27331, -8.46123, 0.76369, -10.32347,
];
let dates = vec![
   38776, 38807, 38837, 38868, 38898, 38929, 38960, 38990, 39021, 39051, 39082, 39113,
    39141, 39172, 39202, 39233, 39263, 39294, 39325, 39355, 39386, 39416, 39447, 39478,
    39507, 39538, 39568, 39599, 39629, 39660, 39691, 39721, 39752, 39782, 39813, 39844,
];
let mut max_draw_down = f64::NAN;
let mut max_draw_down_peek_date = 0;
let mut max_draw_down_valley_date = 0;
let mut max_draw_down_month = 0;
let mut recovery_month = 0;
let mut recovery_date = 0;
let mpt = MPTCalculator::from_v(&data);
let err = mpt.max_draw_down(
    &dates,
    enums::ClFrequency::ClFrequencyMonthly,
    &mut max_draw_down,
    &mut max_draw_down_peek_date,
    &mut max_draw_down_valley_date,
    &mut max_draw_down_month,
    &mut recovery_month,
    &mut recovery_date,
);
assert_eq!(
    err == Errors::ClErrorCodeNoError && MPTCalculator::is_eq_double(max_draw_down, -43.72595),
    true
);
assert_eq!(
    err == Errors::ClErrorCodeNoError && max_draw_down_peek_date == 39387,
    true
);
assert_eq!(
    err == Errors::ClErrorCodeNoError && max_draw_down_valley_date == 39844,
    true
);
assert_eq!(
   err == Errors::ClErrorCodeNoError && max_draw_down_month == 15,
   true
);
assert_eq!(
    err == Errors::ClErrorCodeNoError && recovery_month == 0,
    true
);
assert_eq!(
    err == Errors::ClErrorCodeNoError && recovery_date == 0,
   true
);
Source

pub fn max_gain( &self, dates: &[i32], freq: ClFrequency, max_gain: &mut f64, start_date: &mut i32, end_date: &mut i32, max_gain_month: &mut i32, ) -> Errors

calculate the max gain value,start date,end date,max gain month of an array, if the array has NAN/INF values,the result will be NAN freq: the frequence of source data.

dates: the date of value

§Examples
use mpt_lib::MPTCalculator;
use mpt_lib::enums::{self, Errors};
let data = vec![
   -2.57909, 0.0353, 3.56387, -3.88416, 0.0, -9.81106, -7.70466, -0.04348, -9.65637,
   3.37025, 7.68514, -6.79066, -1.76334, -3.7317, -0.49068, 11.83432, 9.08289, 3.39531,
   0.70368, 0.89286, -0.76953, 6.39783, 1.38484, 2.33645, 2.80998, 0.5808, -0.61141,
   -0.20506, -0.47945, -0.13765, -3.4459, -0.85653, 1.83585, 0.84836, 3.61024, 3.99188,
   -1.7892, 2.02054, -0.81169, -1.40753, 3.02125, -0.67676, 1.07073, -2.21509, 0.29547,
   -2.65139, 2.62273, -0.65557, 0.76463, -1.22072, -0.0668, 2.20588, -0.91563, -0.76766,
   -1.21429, 3.43456, 4.99825, 3.89481, 1.59564, 0.86793, 2.41477, -1.80305, 0.6709,
   3.57769, 4.77481, -0.37317, -3.52713, 1.88831, 1.73502, 1.20155, -3.36542, -2.03551,
   -5.6145, -2.71663, -0.04815, 3.99807, 1.66744, -9.68658, -0.46681, 4.22095, -6.7,
   -15.27331, -8.46123, 0.76369,
];

let dates = vec![
   37287, 37315, 37346, 37376, 37407, 37437, 37468, 37499, 37529, 37560, 37590, 37621,
   37652, 37680, 37711, 37741, 37772, 37802, 37833, 37864, 37894, 37925, 37955, 37986,
   38017, 38046, 38077, 38107, 38138, 38168, 38199, 38230, 38260, 38291, 38321, 38352,
   38383, 38411, 38442, 38472, 38503, 38533, 38564, 38595, 38625, 38656, 38686, 38717,
   38748, 38776, 38807, 38837, 38868, 38898, 38929, 38960, 38990, 39021, 39051, 39082,
   39113, 39141, 39172, 39202, 39233, 39263, 39294, 39325, 39355, 39386, 39416, 39447,
   39478, 39507, 39538, 39568, 39599, 39629, 39660, 39691, 39721, 39752, 39782, 39813,
];
let mut max_gain = f64::NAN;
let mut start_date = 0;
let mut end_date = 0;
let mut max_gain_month = 0;

let mpt = MPTCalculator::from_v(&data);
let err = mpt.max_gain(
   &dates,
   enums::ClFrequency::ClFrequencyMonthly,
   &mut max_gain,
   &mut start_date,
   &mut end_date,
   &mut max_gain_month,
);
assert_eq!(
   err == Errors::ClErrorCodeNoError && MPTCalculator::is_eq_double(max_gain, 89.10075),
   true
);
assert_eq!(
   err == Errors::ClErrorCodeNoError && start_date == 37712,
   true
);
assert_eq!(err == Errors::ClErrorCodeNoError && end_date == 39386, true);
assert_eq!(
   err == Errors::ClErrorCodeNoError && max_gain_month == 55,
   true
);
Source

pub fn calmar_ratio( &self, dates: &[i32], freq: ClFrequency, calmar_ratio: &mut f64, ) -> Errors

calculate the calmar ratio value of an array, the input data should sort by date,and should has not NA/INF, otherwrise result will be NAN

§Arguments

freq: the frequence of source data.

dates: the date of value

§Examples
use mpt_lib::MPTCalculator;
use mpt_lib::enums::{self, Errors};
let data = vec![
1.34278, -2.87814, 0.13557, 0.61685, 2.37931, 2.577, 3.25861, 1.9016, 1.40278, 1.51232,
-1.95588, 1.1185, 4.42953, 3.48951, -1.66133, -3.10048, 1.49901, 3.73988, 1.59068,
-4.18066, -0.69376, -5.99816, -3.24858, -0.4318, 4.87031, 1.29526, -8.43036, -0.84062,
1.44647, -8.91073, -16.79479, -7.17546, 1.06403, -8.42864, -10.64778, 8.75952,
];
let dates = vec![
38837, 38868, 38898, 38929, 38960, 38990, 39021, 39051, 39082, 39113, 39141, 39172,
39202, 39233, 39263, 39294, 39325, 39355, 39386, 39416, 39447, 39478, 39507, 39538,
39568, 39599, 39629, 39660, 39691, 39721, 39752, 39782, 39813, 39844, 39872, 39903,
];
let mut result = f64::NAN;
let mpt = MPTCalculator::from_v(&data);
let err = mpt.calmar_ratio(&dates, enums::ClFrequency::ClFrequencyMonthly, &mut result);
assert_eq!(
   err == Errors::ClErrorCodeNoError && MPTCalculator::is_eq_double(result, -0.2562775),
   true
);
Source

pub fn average_draw_down( &self, dates: &[i32], freq: ClFrequency, avg_draw_down: &mut f64, ) -> Errors

calculate the average draw down value of an array, the input data should sort by date,and should has not NA/INF,otherwrisethe result will be NAN

§Arguments

freq: the frequence of source data.

dates: the date of value

§Examples
use mpt_lib::MPTCalculator;
use mpt_lib::enums::{self, Errors};
let data = vec![
1.52768, 4.04616, 3.40287, -2.43748, 2.1044, -1.7708, -1.89656, 3.18186, 0.14197,
3.71883, -0.9124, 0.80994, -1.66708, 3.78221, 0.03481, 2.64778, 0.27133, 1.24475,
1.34278, -2.87814, 0.13557, 0.61685, 2.37931, 2.577, 3.25861, 1.9016, 1.40278, 1.51232,
-1.95588, 1.1185, 4.42953, 3.48951, -1.66133, -3.10048, 1.49901, 3.73988, 1.59068,
-4.18066, -0.69376, -5.99816, -3.24858, -0.4318, 4.87031, 1.29526, -8.43036, -0.84062,
1.44647, -8.91073, -16.79479, -7.17546, 1.06403, -8.42864, -10.64778, 8.75952,
];
let dates = vec![
38291, 38321, 38352, 38383, 38411, 38442, 38472, 38503, 38533, 38564, 38595, 38625,
38656, 38686, 38717, 38748, 38776, 38807, 38837, 38868, 38898, 38929, 38960, 38990,
 39021, 39051, 39082, 39113, 39141, 39172, 39202, 39233, 39263, 39294, 39325, 39355,
 39386, 39416, 39447, 39478, 39507, 39538, 39568, 39599, 39629, 39660, 39691, 39721,
 39752, 39782, 39813, 39844, 39872, 39903,
];
let mut result = f64::NAN;
let mpt = MPTCalculator::from_v(&data);
let err =
    mpt.average_draw_down(&dates, enums::ClFrequency::ClFrequencyMonthly, &mut result);
assert_eq!(
   err == Errors::ClErrorCodeNoError && MPTCalculator::is_eq_double(result, -15.76075),
   true
);
Source

pub fn sterling_ratio( &self, dates: &[i32], freq: ClFrequency, sterling_ration: &mut f64, ) -> Errors

calculate the sterling ratio value of an array, the input data should sort by date,and should has not NA/INF,otherwrise the result will be NAN

§Arguments

freq: the frequence of source data.

dates: the date of value.

§Examples
use mpt_lib::MPTCalculator;
use mpt_lib::enums::{self, Errors};
let data = vec![
1.52768, 4.04616, 3.40287, -2.43748, 2.1044, -1.7708, -1.89656, 3.18186, 0.14197,
3.71883, -0.9124, 0.80994, -1.66708, 3.78221, 0.03481, 2.64778, 0.27133, 1.24475,
1.34278, -2.87814, 0.13557, 0.61685, 2.37931, 2.577, 3.25861, 1.9016, 1.40278, 1.51232,
-1.95588, 1.1185, 4.42953, 3.48951, -1.66133, -3.10048, 1.49901, 3.73988, 1.59068,
-4.18066, -0.69376, -5.99816, -3.24858, -0.4318, 4.87031, 1.29526, -8.43036, -0.84062,
1.44647, -8.91073, -16.79479, -7.17546, 1.06403, -8.42864, -10.64778, 8.75952,
];
let dates = vec![
38291, 38321, 38352, 38383, 38411, 38442, 38472, 38503, 38533, 38564, 38595, 38625,
38656, 38686, 38717, 38748, 38776, 38807, 38837, 38868, 38898, 38929, 38960, 38990,
 39021, 39051, 39082, 39113, 39141, 39172, 39202, 39233, 39263, 39294, 39325, 39355,
 39386, 39416, 39447, 39478, 39507, 39538, 39568, 39599, 39629, 39660, 39691, 39721,
 39752, 39782, 39813, 39844, 39872, 39903,
];
let mut result = f64::NAN;
let mpt = MPTCalculator::from_v(&data);
let err = mpt.sterling_ratio(&dates, enums::ClFrequency::ClFrequencyMonthly, &mut result);
assert_eq!(
    err == Errors::ClErrorCodeNoError && MPTCalculator::is_eq_double(result, -0.2034894),
    true
);
Source

pub fn best_rolling_month( &self, dates: &[i32], best_months_num: i32, best_rolling_month_date: &mut i32, best_rolling_month_value: &mut f64, ) -> Errors

calculate the best rolling month value of an array, the input data should sort by date,and should has not NA/INF,the result will be NAN

§Arguments

best_months_num: the best month number

dates: the date of value

§Examples
use mpt_lib::MPTCalculator;
use mpt_lib::enums::{self, Errors};
let data = vec![
    -2.57909, 0.0353, 3.56387, -3.88416, 0.0, -9.81106, -7.70466, -0.04348, -9.65637,
    3.37025, 7.68514, -6.79066, -1.76334, -3.7317, -0.49068, 11.83432, 9.08289, 3.39531,
    0.70368, 0.89286, -0.76953, 6.39783, 1.38484, 2.33645, 2.80998, 0.5808, -0.61141,
    -0.20506, -0.47945, -0.13765, -3.4459, -0.85653, 1.83585, 0.84836, 3.61024, 3.99188,
    -1.7892, 2.02054, -0.81169, -1.40753, 3.02125, -0.67676, 1.07073, -2.21509, 0.29547,
    -2.65139, 2.62273, -0.65557, 0.76463, -1.22072, -0.0668, 2.20588, -0.91563, -0.76766,
    -1.21429, 3.43456, 4.99825, 3.89481, 1.59564, 0.86793, 2.41477, -1.80305, 0.6709,
    3.57769, 4.77481, -0.37317, -3.52713, 1.88831, 1.73502, 1.20155, -3.36542, -2.03551,
    -5.6145, -2.71663, -0.04815, 3.99807, 1.66744, -9.68658, -0.46681, 4.22095, -6.7,
    -15.27331, -8.46123, 0.76369,
];
let dates = vec![
    37287, 37315, 37346, 37376, 37407, 37437, 37468, 37499, 37529, 37560, 37590, 37621,
    37652, 37680, 37711, 37741, 37772, 37802, 37833, 37864, 37894, 37925, 37955, 37986,
    38017, 38046, 38077, 38107, 38138, 38168, 38199, 38230, 38260, 38291, 38321, 38352,
    38383, 38411, 38442, 38472, 38503, 38533, 38564, 38595, 38625, 38656, 38686, 38717,
    38748, 38776, 38807, 38837, 38868, 38898, 38929, 38960, 38990, 39021, 39051, 39082,
    39113, 39141, 39172, 39202, 39233, 39263, 39294, 39325, 39355, 39386, 39416, 39447,
    39478, 39507, 39538, 39568, 39599, 39629, 39660, 39691, 39721, 39752, 39782, 39813,
];
let mut best_rolling_month_date = 0;
let mut best_rolling_month_value = f64::NAN;
let mpt = MPTCalculator::from_v(&data);
let err = mpt.best_rolling_month(
    &dates,
    3,
    &mut best_rolling_month_date,
    &mut best_rolling_month_value,
);
assert_eq!(
    err == Errors::ClErrorCodeNoError
        && MPTCalculator::is_eq_double(best_rolling_month_value, 26.13411852),
    true
);
assert_eq!(
    err == Errors::ClErrorCodeNoError && best_rolling_month_date == 37802,
    true
);
Source

pub fn worst_rolling_month( &self, dates: &[i32], worst_months_num: i32, worst_rolling_month_date: &mut i32, worst_rolling_month_value: &mut f64, ) -> Errors

calculate the worst rolling month value of an array, the input data should sort by date,and should has not NA/INF,the result will be NAN

§Arguments

worst_months_num: the best month number

dates: the date of value

§Examples
use mpt_lib::MPTCalculator;
use mpt_lib::enums::{self, Errors};
let data = vec![
    -2.57909, 0.0353, 3.56387, -3.88416, 0.0, -9.81106, -7.70466, -0.04348, -9.65637,
    3.37025, 7.68514, -6.79066, -1.76334, -3.7317, -0.49068, 11.83432, 9.08289, 3.39531,
   0.70368, 0.89286, -0.76953, 6.39783, 1.38484, 2.33645, 2.80998, 0.5808, -0.61141,
   -0.20506, -0.47945, -0.13765, -3.4459, -0.85653, 1.83585, 0.84836, 3.61024, 3.99188,
   -1.7892, 2.02054, -0.81169, -1.40753, 3.02125, -0.67676, 1.07073, -2.21509, 0.29547,
   -2.65139, 2.62273, -0.65557, 0.76463, -1.22072, -0.0668, 2.20588, -0.91563, -0.76766,
   -1.21429, 3.43456, 4.99825, 3.89481, 1.59564, 0.86793, 2.41477, -1.80305, 0.6709,
   3.57769, 4.77481, -0.37317, -3.52713, 1.88831, 1.73502, 1.20155, -3.36542, -2.03551,
   -5.6145, -2.71663, -0.04815, 3.99807, 1.66744, -9.68658, -0.46681, 4.22095, -6.7,
   -15.27331, -8.46123, 0.76369,
];

let dates = vec![
   37287, 37315, 37346, 37376, 37407, 37437, 37468, 37499, 37529, 37560, 37590, 37621,
   37652, 37680, 37711, 37741, 37772, 37802, 37833, 37864, 37894, 37925, 37955, 37986,
   38017, 38046, 38077, 38107, 38138, 38168, 38199, 38230, 38260, 38291, 38321, 38352,
   38383, 38411, 38442, 38472, 38503, 38533, 38564, 38595, 38625, 38656, 38686, 38717,
   38748, 38776, 38807, 38837, 38868, 38898, 38929, 38960, 38990, 39021, 39051, 39082,
   39113, 39141, 39172, 39202, 39233, 39263, 39294, 39325, 39355, 39386, 39416, 39447,
   39478, 39507, 39538, 39568, 39599, 39629, 39660, 39691, 39721, 39752, 39782, 39813,
];

let mut worst_rolling_month_date = 0;
let mut worst_rolling_month_value = f64::NAN;
let mpt = MPTCalculator::from_v(&data);
let err = mpt.worst_rolling_month(
   &dates,
   3,
   &mut worst_rolling_month_date,
   &mut worst_rolling_month_value,
);
assert_eq!(
   err == Errors::ClErrorCodeNoError
       && MPTCalculator::is_eq_double(worst_rolling_month_value, -27.63860069),
   true
);
assert_eq!(
   err == Errors::ClErrorCodeNoError && worst_rolling_month_date == 39782,
   true
);
Source

pub fn longest_up_streak( &self, dates: &[i32], freq: ClFrequency, longest_up_down_streak: &mut f64, longest_up_down_start_date: &mut i32, longest_up_down_end_date: &mut i32, longest_up_down_periods: &mut i32, ) -> Errors

calculate the longest up streak value,longest up streak start date,end date,month numbers of an array, the input data should sort by date,and should has not NA/INF,the result will be NAN

§Arguments

freq: the frequence of source data.

dates: the date of value

§Examples
use mpt_lib::MPTCalculator;
use mpt_lib::enums::{self, Errors};

let data = vec![
   -2.57909, 0.0353, 3.56387, -3.88416, 0.0, -9.81106, -7.70466, -0.04348, -9.65637,
   3.37025, 7.68514, -6.79066, -1.76334, -3.7317, -0.49068, 11.83432, 9.08289, 3.39531,
   0.70368, 0.89286, -0.76953, 6.39783, 1.38484, 2.33645, 2.80998, 0.5808, -0.61141,
   -0.20506, -0.47945, -0.13765, -3.4459, -0.85653, 1.83585, 0.84836, 3.61024, 3.99188,
   -1.7892, 2.02054, -0.81169, -1.40753, 3.02125, -0.67676, 1.07073, -2.21509, 0.29547,
   -2.65139, 2.62273, -0.65557, 0.76463, -1.22072, -0.0668, 2.20588, -0.91563, -0.76766,
   -1.21429, 3.43456, 4.99825, 3.89481, 1.59564, 0.86793, 2.41477, -1.80305, 0.6709,
   3.57769, 4.77481, -0.37317, -3.52713, 1.88831, 1.73502, 1.20155, -3.36542, -2.03551,
   -5.6145, -2.71663, -0.04815, 3.99807, 1.66744, -9.68658, -0.46681, 4.22095, -6.7,
   -15.27331, -8.46123, 0.76369,
];

let dates = vec![
   37287, 37315, 37346, 37376, 37407, 37437, 37468, 37499, 37529, 37560, 37590, 37621,
   37652, 37680, 37711, 37741, 37772, 37802, 37833, 37864, 37894, 37925, 37955, 37986,
   38017, 38046, 38077, 38107, 38138, 38168, 38199, 38230, 38260, 38291, 38321, 38352,
   38383, 38411, 38442, 38472, 38503, 38533, 38564, 38595, 38625, 38656, 38686, 38717,
   38748, 38776, 38807, 38837, 38868, 38898, 38929, 38960, 38990, 39021, 39051, 39082,
   39113, 39141, 39172, 39202, 39233, 39263, 39294, 39325, 39355, 39386, 39416, 39447,
   39478, 39507, 39538, 39568, 39599, 39629, 39660, 39691, 39721, 39752, 39782, 39813,
];

let mut longest_up_down_streak = f64::NAN;
let mut longest_up_down_start_date = 0;
let mut longest_up_down_end_date = 0;
let mut longest_up_down_periods = 0;
let mpt = MPTCalculator::from_v(&data);
let err = mpt.longest_down_streak(
   &dates,
   enums::ClFrequency::ClFrequencyMonthly,
   &mut longest_up_down_streak,
   &mut longest_up_down_start_date,
   &mut longest_up_down_end_date,
   &mut longest_up_down_periods,
);
assert_eq!(
   err == Errors::ClErrorCodeNoError && MPTCalculator::is_eq_double(longest_up_down_streak, -5.63859),
   true
);
assert_eq!(
   err == Errors::ClErrorCodeNoError && longest_up_down_start_date == 38047,
   true
);
assert_eq!(
   err == Errors::ClErrorCodeNoError && longest_up_down_end_date == 38230,
   true
);
assert_eq!(
   err == Errors::ClErrorCodeNoError && longest_up_down_periods == 6,
   true
);
Source

pub fn longest_down_streak( &self, dates: &[i32], freq: ClFrequency, longest_up_down_streak: &mut f64, longest_up_down_start_date: &mut i32, longest_up_down_end_date: &mut i32, longest_up_down_periods: &mut i32, ) -> Errors

calculate the longest down streak value,longest up streak start date,end date,month numbersof an array, if the array has NAN/INF values,the result will be NAN

§Arguments

freq: the frequence of source data.

dates: the date of value

§Examples
use mpt_lib::MPTCalculator;
use mpt_lib::enums::{self, Errors};

let data = vec![
   -2.57909, 0.0353, 3.56387, -3.88416, 0.0, -9.81106, -7.70466, -0.04348, -9.65637,
   3.37025, 7.68514, -6.79066, -1.76334, -3.7317, -0.49068, 11.83432, 9.08289, 3.39531,
   0.70368, 0.89286, -0.76953, 6.39783, 1.38484, 2.33645, 2.80998, 0.5808, -0.61141,
   -0.20506, -0.47945, -0.13765, -3.4459, -0.85653, 1.83585, 0.84836, 3.61024, 3.99188,
   -1.7892, 2.02054, -0.81169, -1.40753, 3.02125, -0.67676, 1.07073, -2.21509, 0.29547,
   -2.65139, 2.62273, -0.65557, 0.76463, -1.22072, -0.0668, 2.20588, -0.91563, -0.76766,
   -1.21429, 3.43456, 4.99825, 3.89481, 1.59564, 0.86793, 2.41477, -1.80305, 0.6709,
   3.57769, 4.77481, -0.37317, -3.52713, 1.88831, 1.73502, 1.20155, -3.36542, -2.03551,
   -5.6145, -2.71663, -0.04815, 3.99807, 1.66744, -9.68658, -0.46681, 4.22095, -6.7,
   -15.27331, -8.46123, 0.76369,
];

let dates = vec![
   37287, 37315, 37346, 37376, 37407, 37437, 37468, 37499, 37529, 37560, 37590, 37621,
   37652, 37680, 37711, 37741, 37772, 37802, 37833, 37864, 37894, 37925, 37955, 37986,
   38017, 38046, 38077, 38107, 38138, 38168, 38199, 38230, 38260, 38291, 38321, 38352,
   38383, 38411, 38442, 38472, 38503, 38533, 38564, 38595, 38625, 38656, 38686, 38717,
   38748, 38776, 38807, 38837, 38868, 38898, 38929, 38960, 38990, 39021, 39051, 39082,
   39113, 39141, 39172, 39202, 39233, 39263, 39294, 39325, 39355, 39386, 39416, 39447,
   39478, 39507, 39538, 39568, 39599, 39629, 39660, 39691, 39721, 39752, 39782, 39813,
];

let mut longest_up_down_streak = f64::NAN;
let mut longest_up_down_start_date = 0;
let mut longest_up_down_end_date = 0;
let mut longest_up_down_periods = 0;
let mpt = MPTCalculator::from_v(&data);
let err = mpt.longest_down_streak(
   &dates,
   enums::ClFrequency::ClFrequencyMonthly,
   &mut longest_up_down_streak,
   &mut longest_up_down_start_date,
   &mut longest_up_down_end_date,
   &mut longest_up_down_periods,
);
assert_eq!(
   err == Errors::ClErrorCodeNoError && MPTCalculator::is_eq_double(longest_up_down_streak, -5.63859),
   true
);
assert_eq!(
   err == Errors::ClErrorCodeNoError && longest_up_down_start_date == 38047,
   true
);
assert_eq!(
   err == Errors::ClErrorCodeNoError && longest_up_down_end_date == 38230,
   true
);
assert_eq!(
   err == Errors::ClErrorCodeNoError && longest_up_down_periods == 6,
   true
);
Source

pub fn volatity(&self, freq: ClFrequency, result: &mut f64) -> Errors

calculate the volatity value of an array, if the array has NAN/INF values,the result will be NAN

§Arguments

freq: the frequence of source data.

§Examples
use mpt_lib::MPTCalculator;
use mpt_lib::enums::{self, Errors};
let data = vec![
   210.69, 195.58, 190.08, 179.72, 179.72, 165.24, 163.12, 160.8, 148.96, 153.29, 169.47,
   181.52, 174.86, 184.9, 174.12, 166.82, 167.46, 165.24, 150.86, 143.88, 151.07, 150.65,
   141.13,
];
let mut res = 0.0;
let mpt = MPTCalculator::from_v(&data);
let err = mpt.volatity(enums::ClFrequency::ClFrequencyDaily, &mut res);
assert_eq!(
   err == Errors::ClErrorCodeNoError && MPTCalculator::is_eq_double(res, 83.388666),
   true
);
Source

pub fn zscore(&self, observerd_value: f64, result: &mut f64) -> Errors

calculate the volatity value of an array, if the array has NAN/INF values,the result will be NAN

§Arguments

freq: the frequence of source data. observerd_value: the observerd value

§Examples
use mpt_lib::MPTCalculator;
use mpt_lib::enums::{self, Errors};

let data = vec![
   210.69, 195.58, 190.08, 179.72, 179.72, 165.24, 163.12, 160.8, 148.96, 153.29, 169.47,
   181.52, 174.86, 184.9, 174.12, 166.82, 167.46, 165.24, 150.86, 143.88, 151.07, 150.65,
   141.13,
];
let mut res = 0.0;
let mpt = MPTCalculator::from_v(&data);
let err = mpt.zscore(200.0, &mut res);
assert_eq!(
   err == Errors::ClErrorCodeNoError && MPTCalculator::is_eq_double(res, 1.813224655535872),
   true
);
Source§

impl<'a> MPTCalculator<'a>

Source

pub fn max(&self, max_value: &mut f64) -> Errors

calc the max values in an arrays not include NA/INF values

§Examples
 use mpt_lib::MPTCalculator;
 use mpt_lib::enums::{self, Errors};

let data = vec![
    4.487083398,1.651309218,0.912195263,2.995680315,9.98454554,
    2.32625796,8.175311666,7.566763025,5.010273527,1.479493882,
];
let mpt = MPTCalculator::from_v(&data);
let mut res = f64::NAN;
let err = mpt.max(&mut res);
assert_eq!(
    err == Errors::ClErrorCodeNoError && MPTCalculator::is_eq_double(res, 9.98454554),
    true
);
Source

pub fn first_double( &self, start_date: i32, end_date: i32, dates: &[i32], pos: &mut i32, ) -> Errors

find first valid double and its date in an array between start date and end date not include NA/INF values if not find anything, pos is -1 else pos is the first pos

§Arguments

start_date: the start date for calculation period

end_end: the end date for calculation period

dates: the dates array, the every date mapping to the value in the values

§Examples
use mpt_lib::MPTCalculator;
use mpt_lib::enums::{self, Errors};
let data = vec![
f64::NAN,1.651309218,0.912195263,2.995680315,9.98454554,
2.32625796,8.175311666,7.566763025,5.010273527,1.479493882,
];
let dates = vec![
    39445, 39801, 39817, 39522, 39514, 39602, 39760, 39493, 39686, 39752,
];
let mpt = MPTCalculator::from_v(&data);
let mut res = 0;
let err = mpt.first_double(39445, 39752, &dates, &mut res);
assert_eq!(err == Errors::ClErrorCodeNoError && res == 7, true);
Source

pub fn last_double( &self, start_date: i32, end_date: i32, dates: &[i32], pos: &mut i32, ) -> Errors

find last valid double and its date in an array between start date and end date if not find anything, pos is -1 else pos is the first pos

§Arguments

start_date: the start date for calculation period

end_end: the end date for calculation period

dates: the dates array, the every date mapping to the value in the values

§Examples
 use mpt_lib::MPTCalculator;
 use mpt_lib::enums::{self, Errors};

let data = vec![
    4.487083398,1.651309218,0.912195263,2.995680315,9.98454554,
    2.32625796,8.175311666,7.566763025,5.010273527,1.479493882,
];
let dates = vec![
    39445, 39801, 39817, 39522, 39514, 39602, 39760, 39493, 39686, 39752,
];
let mpt = MPTCalculator::from_v(&data);
let mut res = 0;
let err = mpt.last_double(39445, 39752, &dates, &mut res);
assert_eq!(err == Errors::ClErrorCodeNoError && res == 9, true);
Source

pub fn rate_of_change(&self, rate_of_change: &mut [f64]) -> Errors

Source

pub fn count( values1: &[f64], values2: &[f64], values3: &[f64], value_array_size: i32, count: &mut i32, ) -> Errors

Source

pub fn count_in_period( &self, start_date: i32, end_date: i32, dates: &[i32], count: &mut i32, ) -> Errors

get the numbers in an array between start date and end date and not inculde NA/INF

§Examples
 use mpt_lib::MPTCalculator;
 use mpt_lib::enums::{self, Errors};

let data = vec![
    8.6397889, 7.9137227, 10.847360, 11.727434, 12.136135, 8.0826517, 12.006847, 13.789638,
    9.4216315, 9.3328426, 9.9971608, 7.2958290,
];
let dates = vec![
    39478, 39507, 39538, 39568, 39599, 39629, 39660, 39691, 39721, 39752, 39782, 39813,
];
let mpt = MPTCalculator::from_v(&data);
let mut res = 0;
let err = mpt.count_in_period(39478, 39813, &dates, &mut res);
assert_eq!(err == Errors::ClErrorCodeNoError && res == 12, true);
Source

pub fn sum_in_period( &self, start_date: i32, end_date: i32, dates: &[i32], sum: &mut f64, ) -> Errors

get the sum for an array between start date and end date and not inculde NA/INF

§Arguments

start_date: the start date for calculation period

end_end: the end date for calculation period

dates: the dates array, the every date mapping to the value in the values

§Examples
 use mpt_lib::MPTCalculator;
 use mpt_lib::enums::{self, Errors};

let data = vec![
    8.6397889, 7.9137227, 10.847360, 11.727434, 12.136135, 8.0826517, 12.006847, 13.789638,
    9.4216315, 9.3328426, 9.9971608, 7.2958290,
];
let dates = vec![
    39478, 39507, 39538, 39568, 39599, 39629, 39660, 39691, 39721, 39752, 39782, 39813,
];
let mpt = MPTCalculator::from_v(&data);
let mut res = f64::NAN;
let err = mpt.sum_in_period(39478, 39813, &dates, &mut res);
assert_eq!(
    err == Errors::ClErrorCodeNoError && MPTCalculator::is_eq_double(res, 121.1910412),
    true
);
Source

pub fn max_in_period( &self, start_date: i32, end_date: i32, dates: &[i32], max: &mut f64, date: &mut i32, ) -> Errors

get the max of values and its date in an array between start date and end date and not inculde NA/INF

§Arguments

start_date: the start date for calculation period

end_end: the end date for calculation period

dates: the dates array, the every date mapping to the value in the values

§Examples
 use mpt_lib::MPTCalculator;
 use mpt_lib::enums::{self, Errors};

let data = vec![
    8.6397889, 7.9137227, 10.847360, 11.727434, 12.136135, 8.0826517, 12.006847, 13.789638,
    9.4216315, 9.3328426, 9.9971608, 7.2958290,
];
let dates = vec![
    39478, 39507, 39538, 39568, 39599, 39629, 39660, 39691, 39721, 39752, 39782, 39813,
];
let mpt = MPTCalculator::from_v(&data);
let mut res = f64::NAN;
let mut max_date = 0;
let err = mpt.max_in_period(39478, 39813, &dates, &mut res, &mut max_date);
assert_eq!(
    err == Errors::ClErrorCodeNoError && res == 13.789638 && max_date == 39691,
    true
);
Source

pub fn min_in_period( &self, start_date: i32, end_date: i32, dates: &[i32], min: &mut f64, date: &mut i32, ) -> Errors

get the minimum in an array and its date between start date and end date and not inculde NA/INF

§Arguments

start_date: the start date for calculation period

end_end: the end date for calculation period

dates: the dates array, the every date mapping to the value in the values

§Examples
 use mpt_lib::MPTCalculator;
 use mpt_lib::enums::{self, Errors};

let data = vec![
    8.6397889, 7.9137227, 10.847360, 11.727434, 12.136135, 8.0826517, 12.006847, 13.789638,
    9.4216315, 9.3328426, 9.9971608, 7.2958290,
];
let dates = vec![
    39478, 39507, 39538, 39568, 39599, 39629, 39660, 39691, 39721, 39752, 39782, 39813,
];
let mpt = MPTCalculator::from_v(&data);
let mut res = f64::NAN;
let mut min_date = 0;
let err = mpt.min_in_period(39478, 39813, &dates, &mut res, &mut min_date);
assert_eq!(
    err == Errors::ClErrorCodeNoError && MPTCalculator::is_eq_double(res, 7.2958290) && min_date == 39813,
    true
);
Source

pub fn min(&self, min_res: &mut f64) -> Errors

get the minimum in an array and its date not inculde NA/INF

§Examples
 use mpt_lib::MPTCalculator;
 use mpt_lib::enums::{self, Errors};

let data = vec![
    8.6397889, 7.9137227, 10.847360, 11.727434, 12.136135, 8.0826517, 12.006847, 13.789638,
    9.4216315, 9.3328426, 9.9971608, 7.2958290,
];
let mpt = MPTCalculator::from_v(&data);
let mut res = f64::NAN;
let err = mpt.min(&mut res);
assert_eq!(
    err == Errors::ClErrorCodeNoError && MPTCalculator::is_eq_double(res, 7.2958290),
    true
);
Source

pub fn sum(&self, sum_res: &mut f64) -> Errors

get the sum for an array not inculde NA/INF

§Examples
 use mpt_lib::MPTCalculator;
 use mpt_lib::enums::{self, Errors};

let data = vec![
    8.6397889, 7.9137227, 10.847360, 11.727434, 12.136135, 8.0826517, 12.006847, 13.789638,
    9.4216315, 9.3328426, 9.9971608, 7.2958290,
];
let mpt = MPTCalculator::from_v(&data);
let mut res = f64::NAN;
let err = mpt.sum(&mut res);
assert_eq!(
    err == Errors::ClErrorCodeNoError && MPTCalculator::is_eq_double(res,  121.1910412),
    true
);
Source

pub fn weighted_average(&self, weights: &[f64], avg_res: &mut f64) -> Errors

calculate the weigted average value for an array not inculde NA/INF

§Arguments

weights: the weights which mapping to every value

§Examples
 use mpt_lib::MPTCalculator;
 use mpt_lib::enums::{self, Errors};

let data = vec![
    0.1018520000,0.1379310000,0.1322920000,-0.0384620000,0.0041670000,
    0.1724510000,0.4257430000,0.2689870000,0.0540540000,1.0000000000,
    0.3307080000,f64::NAN,f64::NAN,0.0884350000,-0.0467840000,
    f64::NAN,0.3450980000,-0.0566040000,0.1000000000,
];

let weights = vec![
    26035.5600000000,118.7985000000,4012.4600000000,1.4294000000,422.7000120000,
    142074.0300000000,10214.1000000000,711.3405150000,35.5523990000,1.4975000000,
    36.8974990000,f64::NAN,f64::NAN,1609.7000000000,197.4942930000,
    f64::NAN,1618.0400000000,34.0756990000,7.9369000000,
];
let mpt = MPTCalculator::from_v(&data);
let mut res = f64::NAN;
let err = mpt.weighted_average(&weights, &mut res);
assert_eq!(err, Errors::ClErrorCodeNoError);
assert_eq!(MPTCalculator::is_eq_double(res, 0.1760653727), true);
Source

pub fn average_for_ts( &self, start_date: i32, end_date: i32, dates: &[i32], avg_res: &mut f64, ) -> Errors

Source

pub fn average_freq_for_ts( &self, start_date: i32, end_date: i32, freq: ClFrequency, dates: &[i32], avg_values: &mut Vec<f64>, avg_dates: &mut Vec<i32>, ) -> Errors

get the average value for the difference frequence between start date and end date

§Arguments

start_date: the start date for calculation period

end_end: the end date for calculation period

freq: the caculation frequece

dates: the date mapping to every value

§Examples
use mpt_lib::MPTCalculator;
use mpt_lib::enums::{self, Errors};
let data = vec![
   8.169969704, 17.53634366,5.344482043, 8.452863347,10.33126183,
   12.7683848,10.67265227,0.973782619,17.43341129,7.793032244,
   5.839265786,0.589181628,19.80643643,0.319166174,5.887448511,
   12.20015787,13.45983609,10.02752314,14.23095689,6.187832093,
   14.82583437,14.75803915,9.90970724,12.95576028,11.02894738,
   7.56902044,7.865732487,12.08801651,13.4391796,11.06652432,
   14.73725253,19.29441213,8.767635516,0.900297309,14.3543903,
   7.172694944,3.227678772,16.11482084,6.041044308,6.189942603,
   11.16458034,13.50079637,17.17207264,10.1869313,18.52252921,
   16.34204845,12.98478245,16.96478255,17.00365216,13.34776382,
   3.630459975,16.20671779,12.70671665,8.410486911,4.581037552,
   6.045530479,1.850320217,17.61496548,13.61665776, 10.14668818,
   9.9238987, 18.61926739,3.407462739,3.147958377,1.312209162,
   17.77142914,4.835527897,11.21452525,15.90649149,11.14175699,
   10.12361377,18.02892583,13.52113804,2.467934258,5.844192095,
   11.06558362,1.964113557,1.100482004,3.83922735,11.447917,
   0.545897803,15.3561911, 13.04722015,13.16691716,
];
let dates = vec![
   39441, 39441, 39445, 39452, 39461, 39461, 39467, 39476, 39484, 39485, 39493, 39500,
   39508, 39514, 39522, 39529, 39533, 39536, 39537, 39546, 39552, 39557, 39563, 39567,
   39569, 39570, 39576, 39581, 39583, 39591, 39595, 39595, 39602, 39609, 39613, 39615,
   39615, 39618, 39625, 39633, 39642, 39650, 39657, 39666, 39667, 39668, 39668, 39673,
   39681, 39681, 39686, 39688, 39691, 39692, 39693, 39693, 39694, 39700, 39703, 39706,
   39706, 39710, 39719, 39728, 39734, 39735, 39737, 39740, 39747, 39752, 39755, 39760,
   39762, 39770, 39779, 39785, 39787, 39792, 39792, 39801, 39802, 39810, 39812, 39817,
];

let excpted_values = vec![
   8.639788972, 7.913722736,10.84736073,11.72743463,12.13613567,
   8.082651712,12.00684799,13.78963844,9.421631542,9.332842614,
   9.9971608, 7.295829073,
];
let excpted_dates = vec![
   39478, 39507, 39538, 39568, 39599, 39629, 39660, 39691, 39721, 39752, 39782, 39813,
];
let mut avg_values = Vec::new();
let mut avg_dates = Vec::new();
let mpt = MPTCalculator::from_v(&data);
let err = mpt.average_freq_for_ts(
   39478,
   39813,
   enums::ClFrequency::ClFrequencyMonthly,
   &dates,
   &mut avg_values,
   &mut avg_dates,
);
assert_eq!(
   err == Errors::ClErrorCodeNoError && avg_dates == excpted_dates,
   true
);
assert_eq!(
   err == Errors::ClErrorCodeNoError && MPTCalculator::is_eq_double_array(&avg_values, &excpted_values),
   true
);
Source

pub fn array_addition(&self, values2: &[f64], output: &mut [f64]) -> Errors

Add the values in same position for two arrays, the output is same size array Array = valueArray1 + valueArray2

§Examples
 use mpt_lib::MPTCalculator;
 use mpt_lib::enums::{self, Errors};

let data = vec![
    4.487083398,1.651309218,0.912195263,2.995680315,9.98454554,
    2.32625796,8.175311666,7.566763025,5.010273527,1.479493882,
];

let data2 = vec![
    6.184582992,1.145629713,0.923955492,7.367172708,1.438963969,
    2.163394174,0.20035163,1.022927912, 9.43590199,1.056781513,
];

const EXPECTED_RES: [f64; 10] = [
    10.67166639,2.796938931,1.836150755,10.36285302,11.42350951,
    4.489652134,8.375663296,8.589690937,14.44617552,2.536275396,
];
let mpt = MPTCalculator::from_v(&data);
let mut res = [f64::NAN; 10];
let err = mpt.array_addition(&data2, &mut res);
assert_eq!(
    err == Errors::ClErrorCodeNoError && MPTCalculator::is_eq_double_array(&res, &EXPECTED_RES),
    true
);
Source

pub fn array_subtraction(&self, values2: &[f64], output: &mut [f64]) -> Errors

Subtract the values in same position for two arrays, the output is same size array Array = valueArray1 - valueArray2

§Examples
 use mpt_lib::MPTCalculator;
 use mpt_lib::enums::{self, Errors};

let data = vec![
    4.487083398,1.651309218,0.912195263,2.995680315,9.98454554,
    2.32625796,8.175311666,7.566763025,5.010273527,1.479493882,
];

let data2 = vec![
    6.184582992,1.145629713,0.923955492,7.367172708,1.438963969,
    2.163394174,0.20035163,1.022927912, 9.43590199,1.056781513,
];

const EXPECTED_RES: [f64; 10] = [
    -1.697499594,0.505679505,-0.011760229,-4.371492393,8.545581571,
    0.162863785,7.974960036,6.543835114,-4.425628463,0.422712369,
];
let mpt = MPTCalculator::from_v(&data);
let mut res = [f64::NAN; 10];
let err = mpt.array_subtraction(&data2, &mut res);
assert_eq!(
    err == Errors::ClErrorCodeNoError && MPTCalculator::is_eq_double_array(&res, &EXPECTED_RES),
    true
);
Source

pub fn array_multiplication( &self, values2: &[f64], output: &mut [f64], ) -> Errors

Multiply the values in same position for two arrays, the output is same size array Array = valueArray1 * valueArray2

Return Value: Return the error code

§Examples
 use mpt_lib::MPTCalculator;
 use mpt_lib::enums::{self, Errors};

let data = vec![
    4.487083398,1.651309218,0.912195263,2.995680315,9.98454554,
    2.32625796,8.175311666,7.566763025,5.010273527,1.479493882,
];

let data2 = vec![
    6.184582992,1.145629713,0.923955492,7.367172708,1.438963969,
    2.163394174,0.20035163,1.022927912, 9.43590199,1.056781513,
];

const EXPECTED_RES: [f64; 10] = [
    27.75073967,1.891788905,0.842827823,22.06969426,14.36740127,
    5.032612918,1.637937015,7.740253099,47.27644994,1.563501784,
];
let mpt = MPTCalculator::from_v(&data);
let mut res = [f64::NAN; 10];
let err = mpt.array_multiplication(&data2, &mut res);
assert_eq!(
    err == Errors::ClErrorCodeNoError && MPTCalculator::is_eq_double_array(&res, &EXPECTED_RES),
    true
);
Source

pub fn array_division(&self, values2: &[f64], output: &mut [f64]) -> Errors

Div the values in same position for two arrays, the output is same size array Array = valueArray1 / valueArray2

§Examples
 use mpt_lib::MPTCalculator;
 use mpt_lib::enums::{self, Errors};

let data = vec![
    4.487083398,1.651309218,0.912195263,2.995680315,9.98454554,
    2.32625796,8.175311666,7.566763025,5.010273527,1.479493882,
];

let data2 = vec![
    6.184582992,1.145629713,0.923955492,7.367172708,1.438963969,
    2.163394174,0.20035163,1.022927912, 9.43590199,1.056781513,
];

const EXPECTED_RES: [f64; 10] = [
    0.725527235,1.441398735,0.987271866,0.406625504,6.938704344,
    1.075281605,40.80481741,7.397161559,0.530979819,1.399999777,
];
let mpt = MPTCalculator::from_v(&data);
let mut res = [f64::NAN; 10];
let err = mpt.array_division(&data2, &mut res);
assert_eq!(
    err == Errors::ClErrorCodeNoError && MPTCalculator::is_eq_double_array(&res, &EXPECTED_RES),
    true
);
Source

pub fn array_additive_accumulation(&self, output: &mut [f64]) -> Errors

calculate accumulate the value for an array, the output is same size array

§Examples
 use mpt_lib::MPTCalculator;
 use mpt_lib::enums::{self, Errors};

let data = vec![
    4.487083398,1.651309218,0.912195263,2.995680315,9.98454554,
    2.32625796,8.175311666,7.566763025,5.010273527,1.479493882,
];

const EXPECTED_RES: [f64; 10] = [
    4.487083398,6.138392616,7.050587879,10.04626819,20.03081373,
    22.35707169,30.53238336,38.09914639,43.10941991,44.58891379,
];
let mpt = MPTCalculator::from_v(&data);
let mut res = [f64::NAN; 10];
let err = mpt.array_additive_accumulation(&mut res);
assert_eq!(
    err == Errors::ClErrorCodeNoError && MPTCalculator::is_eq_double_array(&res, &EXPECTED_RES),
    true
);
Source

pub fn rescale_array(&self, rescale_factor: f64, output: &mut [f64]) -> Errors

calulate rescale the value for an array, the output is an same size array #Arguments: rescale_factor: the rescale factor

§Examples
 use mpt_lib::MPTCalculator;
 use mpt_lib::enums::{self, Errors};

let data = vec![
    4.487083398,1.651309218,0.912195263,2.995680315,9.98454554,
    2.32625796,8.175311666,7.566763025,5.010273527,1.479493882,
];

const EXPECTED_RES: [f64; 10] = [
    22.43541699,8.25654609, 4.560976314, 14.97840158, 49.9227277,
    11.6312898,40.87655833,37.83381513,25.05136763,7.397469412,
];
let mpt = MPTCalculator::from_v(&data);
let mut res = [f64::NAN; 10];
let err = mpt.rescale_array(5.0, &mut res);
assert_eq!(
    err == Errors::ClErrorCodeNoError && MPTCalculator::is_eq_double_array(&res, &EXPECTED_RES),
    true
);
Source

pub fn bottom_n( &self, in_n: i32, top_values: &mut Vec<f64>, top_pos: &mut Vec<i32>, ) -> Errors

get the top values for an array, the output is an array include n bottom numbers #Arguments: in_n:the bottom numbers

§Examples
 use mpt_lib::MPTCalculator;
 use mpt_lib::enums::{self, Errors};

let data = vec![10.0, 11.0, 15.0, f64::NAN, 4.0, 13.24, f64::NAN, 9.45];
let excepted_values = vec![4.0, 9.45, 10.0];
let excepted_pos = vec![4, 7, 0];
let mpt = MPTCalculator::from_v(&data);
let mut top_pos = Vec::new();
let mut top_values = Vec::new();
let err = mpt.bottom_n(3, &mut top_values, &mut top_pos);
assert_eq!(err, Errors::ClErrorCodeNoError);
assert_eq!(MPTCalculator::is_eq_double_array(&top_values, &excepted_values), true);
assert_eq!(excepted_pos, top_pos);
Source

pub fn top_n( &self, in_n: i32, top_values: &mut Vec<f64>, top_pos: &mut Vec<i32>, ) -> Errors

get the top values for an array, the output is an array include n top numbers
#Arguments: in_n:the top numbers

§Examples
 use mpt_lib::MPTCalculator;
 use mpt_lib::enums::{self, Errors};

let data = vec![10.0, 11.0, 15.0, f64::NAN, 4.0, 13.24, f64::NAN, 9.45];
let excepted_values = vec![15.0, 13.24, 11.0];
let excepted_pos = vec![2, 5, 1];
let mpt = MPTCalculator::from_v(&data);
let mut top_pos = Vec::new();
let mut top_values = Vec::new();
let err = mpt.top_n(3, &mut top_values, &mut top_pos);
assert_eq!(err, Errors::ClErrorCodeNoError);
assert_eq!(MPTCalculator::is_eq_double_array(&top_values, &excepted_values), true);
assert_eq!(excepted_pos, top_pos);
Source

pub fn top_percent( &self, percentage: f64, min_n: i32, top_values: &mut Vec<f64>, top_pos: &mut Vec<i32>, ) -> Errors

get the top values for an array base on the percent, the output is an array includ the top values #Arguments: percentage: the output percentage
min_n: the minumn output numbers

§Examples
 use mpt_lib::MPTCalculator;
 use mpt_lib::enums::{self, Errors};

let data = vec![10.0, 11.0, 15.0, f64::NAN, 4.0, 13.24, f64::NAN, 9.45];
let excepted_values = vec![15.0, 13.24, 11.0];
let excepted_pos = vec![2, 5, 1];
let mpt = MPTCalculator::from_v(&data);
let mut top_pos = Vec::new();
let mut top_values = Vec::new();
let err = mpt.top_percent(10.0, 3, &mut top_values, &mut top_pos);
assert_eq!(err, Errors::ClErrorCodeNoError);
assert_eq!(MPTCalculator::is_eq_double_array(&top_values, &excepted_values), true);
assert_eq!(excepted_pos, top_pos);
Source

pub fn bottom_percent( &self, percentage: f64, min_n: i32, top_values: &mut Vec<f64>, top_pos: &mut Vec<i32>, ) -> Errors

get the bottoms values for an array base on the percent, the output is an array includ the bottom values #Arguments: percentage: the output percentage
min_n: the minumn output numbers

§Examples
use mpt_lib::MPTCalculator;
use mpt_lib::enums::{self, Errors};

let data = vec![10.0, 11.0, 15.0, f64::NAN, 4.0, 13.24, f64::NAN, 9.45];
let excepted_values = vec![4.0, 9.45, 10.0];
let excepted_pos = vec![4, 7, 0];
let mpt = MPTCalculator::from_v(&data);
let mut top_pos = Vec::new();
let mut top_values = Vec::new();
let err = mpt.bottom_percent(10.0, 3, &mut top_values, &mut top_pos);
assert_eq!(err, Errors::ClErrorCodeNoError);
assert_eq!(MPTCalculator::is_eq_double_array(&top_values, &excepted_values), true);
assert_eq!(excepted_pos, top_pos);
Source

pub fn percentile(&self, nth: i32, percentile: &mut f64) -> Errors

calulate the percentile value for an array, #Arguments: nth: the percent for the array

§Examples
 use mpt_lib::MPTCalculator;
 use mpt_lib::enums::{self, Errors};

let data = vec![
    0.08010, 0.24430, 0.15230, -0.62630, -0.00830, 0.06930, -0.01550, 0.07080, 0.08270,
    0.17080, 1.10610, -0.79380, 0.05430, 0.13480, 0.13430, 0.08520, 0.09350, -0.19120,
    0.21420,
];
let mpt = MPTCalculator::from_v(&data);
let mut res = f64::NAN;
let err = mpt.percentile(75, &mut res);
assert_eq!(err, Errors::ClErrorCodeNoError);
assert_eq!(MPTCalculator::is_eq_double(res, 0.14355), true);
Source§

impl<'a> MPTCalculator<'a>

Source

pub const MIN_DOUBLE: f64 = 9.0000000000000002E-6f64

Source

pub fn from( values: &'a [f64], benchmark: &'a [f64], riskfree: &'a [f64], ) -> MPTCalculator<'a>

Source

pub fn from_v(values: &'a [f64]) -> MPTCalculator<'a>

Source

pub fn from_v_b(values: &'a [f64], benchmark: &'a [f64]) -> MPTCalculator<'a>

Source

pub fn from_v_r(values: &'a [f64], riskfree: &'a [f64]) -> MPTCalculator<'a>

Source

pub fn is_eq_double(a: f64, b: f64) -> bool

Source

pub fn is_eq_double_array(a: &[f64], b: &[f64]) -> bool

Source§

impl<'a> MPTCalculator<'a>

Source

pub fn absolute_rank( &self, _fractional_weight: &[f64], is_asc: bool, rank: &mut [f64], ) -> Errors

calculate the absolute rank value of a series not include NAN/INF values.

§Arguments

is_asc is the order for sort.

§Examples
 use mpt_lib::MPTCalculator;
 use mpt_lib::enums::{self, Errors};
const EXPECTED_RES: [f64; 382] = [
        67.0, 84.0, 241.0, 168.0, 39.0, 262.0, 211.0, 198.0, 305.0, 12.0, 339.0, 30.0, 275.0,
        110.0, 103.0, 312.0, 5.0, 374.0, 224.0, 299.0, 87.0, 191.0, 284.0, 206.0, 253.0, 301.0,
        275.0, 260.0, 270.0, 73.0, 236.0, 99.0, 182.0, 52.0, 209.0, 127.0, 201.0, 299.0, 154.0,
        374.0, 1.0, 216.0, 252.0, 17.0, 135.0, 1.0, 323.0, 30.0, 369.0, 164.0, 64.0, 269.0,
        164.0, 172.0, 55.0, 149.0, 15.0, 253.0, 373.0, 28.0, 155.0, 291.0, 280.0, 94.0, 360.0,
        334.0, 382.0, 151.0, 290.0, 107.0, 378.0, 90.0, 159.0, 13.0, 224.0, 318.0, 112.0,
        341.0, 267.0, 344.0, 377.0, 196.0, 49.0, 141.0, 201.0, 362.0, 124.0, 113.0, 174.0,
        361.0, 16.0, 257.0, 376.0, 32.0, 188.0, 380.0, 22.0, 63.0, 287.0, 176.0, 325.0, 126.0,
        90.0, 179.0, 108.0, 218.0, 20.0, 56.0, 48.0, 179.0, 353.0, 215.0, 119.0, 211.0, 349.0,
        58.0, 34.0, 271.0, 182.0, 336.0, 136.0, 368.0, 40.0, 26.0, 253.0, 50.0, 295.0, 201.0,
        332.0, 124.0, 118.0, 217.0, 66.0, 19.0, 17.0, 158.0, 249.0, 47.0, 274.0, 1.0, 335.0,
        316.0, 144.0, 81.0, 146.0, 282.0, 346.0, 343.0, 5.0, 106.0, 370.0, 196.0, 356.0, 294.0,
        69.0, 330.0, 148.0, 298.0, 325.0, 319.0, 356.0, 35.0, 93.0, 315.0, 103.0, 140.0, 297.0,
        113.0, 302.0, 263.0, 327.0, 314.0, 321.0, 88.0, 38.0, 79.0, 211.0, 246.0, 199.0, 72.0,
        53.0, 308.0, 279.0, 233.0, 344.0, 185.0, 150.0, 117.0, 272.0, 292.0, 277.0, 162.0,
        131.0, 169.0, 242.0, 205.0, 163.0, 277.0, 289.0, 372.0, 233.0, 22.0, 94.0, 306.0,
        238.0, 259.0, 310.0, 328.0, 59.0, 83.0, 152.0, 239.0, 287.0, 61.0, 98.0, 313.0, 284.0,
        8.0, 144.0, 121.0, 80.0, 304.0, 351.0, 230.0, 129.0, 130.0, 381.0, 342.0, 235.0, 194.0,
        268.0, 244.0, 379.0, 214.0, 321.0, 247.0, 232.0, 85.0, 94.0, 182.0, 133.0, 22.0, 160.0,
        187.0, 228.0, 132.0, 303.0, 20.0, 100.0, 317.0, 347.0, 64.0, 177.0, 266.0, 281.0,
        142.0, 293.0, 105.0, 1.0, 155.0, 227.0, 50.0, 61.0, 195.0, 250.0, 272.0, 219.0, 181.0,
        111.0, 147.0, 296.0, 122.0, 167.0, 123.0, 190.0, 29.0, 90.0, 113.0, 44.0, 221.0, 41.0,
        250.0, 263.0, 53.0, 10.0, 263.0, 370.0, 175.0, 248.0, 339.0, 69.0, 136.0, 192.0, 329.0,
        14.0, 10.0, 311.0, 138.0, 226.0, 43.0, 35.0, 347.0, 306.0, 324.0, 77.0, 143.0, 204.0,
        367.0, 283.0, 139.0, 42.0, 133.0, 74.0, 56.0, 355.0, 46.0, 358.0, 108.0, 74.0, 193.0,
        221.0, 352.0, 350.0, 240.0, 237.0, 220.0, 166.0, 102.0, 228.0, 157.0, 178.0, 37.0,
        25.0, 82.0, 120.0, 200.0, 338.0, 100.0, 171.0, 366.0, 256.0, 161.0, 223.0, 210.0,
        308.0, 27.0, 78.0, 331.0, 86.0, 76.0, 286.0, 208.0, 337.0, 68.0, 206.0, 186.0, 333.0,
        189.0, 354.0, 364.0, 320.0, 359.0, 33.0, 257.0, 364.0, 169.0, 60.0, 45.0, 5.0, 260.0,
        243.0, 245.0, 113.0, 9.0, 89.0, 94.0, 152.0, 71.0, 127.0, 231.0, 362.0, 173.0,
    ];

    const DATA: [f64; 382] = [
        -4.14747, -4.48808, -5.89226, -5.31972, -3.79032, -6.08696, -5.714292, -5.6541,
        -6.44905, -1.65468, -6.9869, -3.698444, -6.22951, -4.6875, -4.64701, -6.49606,
        -0.230949, -8.66808, -5.80808, -6.43432, -4.51941, -5.55556, -6.32411, -5.67901,
        -6.043512, -6.43631, -6.22951, -6.07477, -6.13139, -4.21607, -5.85366, -4.57143,
        -5.444657, -4.00276, -5.69767, -4.812467, -5.665031, -6.43432, -5.08021, -8.66808,
        0.000003, -5.73806, -6.03654, -2.908285, -4.8583, 0.000007, -6.61831, -3.69844,
        -7.88177, -5.26316, -4.07808, -6.11746, -5.263168, -5.36364, -4.01009, -5.02901,
        -2.15606, -6.043514, -8.58995, -3.64964, -5.143343, -6.37623, -6.29921, -4.545463,
        -7.48466, -6.814, -14.43396, -5.04386, -6.3762, -4.67797, -8.90688, -4.532588,
        -5.20951, -1.65587, -5.808085, -6.58135, -4.69027, -6.98878, -6.10221, -7.06215,
        -8.84354, -5.65111, -3.99449, -4.92958, -5.665036, -7.75463, -4.79651, -4.694849,
        -5.37736, -7.55668, -2.52226, -6.06509, -8.75203, -3.71267, -5.47667, -11.16585,
        -3.347732, -4.0602, -6.33803, -5.39262, -6.62983, -4.80816, -4.532581, -5.437795,
        -4.68019, -5.74163, -3.344123, -4.01648, -3.98909, -5.43779, -7.33229, -5.73248,
        -4.7191, -5.714295, -7.11111, -4.01786, -3.73514, -6.14035, -5.444654, -6.93493,
        -4.87445, -7.85276, -3.82883, -3.36257, -6.043515, -3.994543, -6.39778, -5.665035,
        -6.74419, -4.796514, -4.71698, -5.74074, -4.08587, -3.33817, -2.90828, -5.17435,
        -6.02583, -3.98489, -6.20805, 0.000004, -6.8917, -6.55629, -4.983396, -4.35459,
        -4.98915, -6.31164, -7.0632, -7.05882, -0.2309446, -4.6729, -8.04795, -5.651113,
        -7.42794, -6.38298, -4.202231, -6.7029, -5.01882, -6.42276, -6.62983, -6.59341,
        -7.42794, -3.73832, -4.53401, -6.54122, -4.64701, -4.89796, -6.42202, -4.694841,
        -6.44139, -6.100223, -6.63507, -6.51409, -6.60793, -4.52261, -3.74153, -4.2735,
        -5.71429, -5.99415, -5.65416, -4.21348, -4.00891, -6.47292, -6.28218, -5.847957,
        -7.06215, -5.46559, -5.03324, -4.69531, -6.14173, -6.37625, -6.27954, -5.23918,
        -4.83651, -5.32258, -5.89286, -5.66667, -5.25409, -6.27954, -6.35135, -8.49546,
        -5.84795, -3.34773, -4.545461, -6.46976, -5.86767, -6.06725, -6.48749, -6.64858,
        -4.02597, -4.42478, -5.049514, -5.87276, -6.33803, -4.050283, -4.56522, -6.50577,
        -6.32411, -1.55258, -4.98339, -4.7486, -4.29066, -6.44666, -7.15596, -5.82121,
        -4.82456, -4.82612, -11.21951, -7.02988, -5.85284, -5.6338, -6.11354, -5.95745,
        -9.25197, -5.716599, -6.60793, -6.00667, -5.84, -4.49612, -4.545457, -5.444651,
        -4.85021, -3.347728, -5.21814, -5.47599, -5.81583, -4.83749, -6.44258, -3.34412,
        -4.59402, -6.55885, -7.07965, -4.078084, -5.40541, -6.1017, -6.30841, -4.969883,
        -6.37627, -4.65116, 0.000001, -5.14334, -5.8156, -3.99454, -4.05028, -5.63486,
        -6.03015, -6.141734, -5.7508, -5.44355, -4.68933, -4.99168, -6.41638, -4.74865,
        -5.2921, -4.75515, -5.54324, -3.67107, -4.532585, -4.694844, -3.93836, -5.775323,
        -3.84615, -6.030154, -6.100227, -4.008915, -1.618582, -6.10022, -8.04795, -5.38922,
        -6.01156, -6.9869, -4.20223, -4.874457, -5.60579, -6.67285, -2.15385, -1.61858,
        -6.48801, -4.8855, -5.81015, -3.8961, -3.738323, -7.07965, -6.46976, -6.62252,
        -4.23729, -4.98084, -5.6664, -7.84077, -6.32384, -4.88911, -3.85064, -4.850213,
        -4.216872, -4.016486, -7.41139, -3.96988, -7.43671, -4.68019, -4.21687, -5.61331,
        -5.77532, -7.27532, -7.12166, -5.87558, -5.85664, -5.76577, -5.28351, -4.59588,
        -5.815833, -5.15638, -5.43188, -3.7415, -3.35135, -4.38067, -4.71914, -5.65657,
        -6.98497, -4.59402, -5.3442, -7.79377, -6.060618, -5.23156, -5.78778, -5.69823,
        -6.47292, -3.45821, -4.24028, -6.72116, -4.51011, -4.22961, -6.32754, -5.6872,
        -6.96296, -4.19274, -5.679014, -5.46875, -6.74646, -5.5371, -7.40203, -7.77903,
        -6.60634, -7.4392, -3.73396, -6.06509, -7.77903, -5.322586, -4.03121, -3.96175,
        -0.230952, -6.07477, -5.91667, -5.96798, -4.694845, -1.61744, -4.53125, -4.545465,
        -5.04951, -4.20463, -4.81246, -5.83039, -7.75463, -5.36981,
    ];
    let mut res = [f64::NAN; DATA.len()];
    let mpt = MPTCalculator::from_v(&DATA);
    let err = mpt.absolute_rank(&[0.0; 0], false, &mut res);
    println!("{:?}", res);
    assert_eq!(
        err == Errors::ClErrorCodeNoError && MPTCalculator::is_eq_double_array(&res, &EXPECTED_RES),
        true
    );
Source

pub fn rank_position( &self, value: f64, rank_type: i16, rank: &mut f64, ) -> Errors

calculate the position of a value in a series.

§Arguments

value is the value should be found.

rank_type is the rank type

§Examples
 use mpt_lib::MPTCalculator;
 use mpt_lib::enums::{self, Errors};
const DATA: [f64; 382] = [
    -6.50577, -4.51011, -7.07965, -5.65657, -4.98084, -6.32411, -4.69027, -8.58995,
    -6.29921, -5.322586, -6.47292, -7.15596, -7.75463, -5.665036, -5.99415, -5.84795,
    -4.68019, -4.68019, -6.11746, -4.82612, -6.33803, -7.41139, -6.00667, -6.28218,
    -8.84354, -8.66808, -6.814, -3.98489, -6.31164, -7.42794, -5.65416, -4.71698, -6.41638,
    -5.40541, -4.874457, -4.21607, -5.55556, -5.01882, -4.53125, -5.23918, -8.75203,
    -6.43432, -7.43671, -6.63507, -3.35135, -11.21951, -5.71429, -6.42276, -3.98909,
    -4.02597, -7.0632, -5.86767, -6.61831, -4.812467, -6.43432, -5.04386, -5.716599, -5.84,
    -5.76577, -3.93836, -4.83749, -7.11111, -6.07477, -4.694841, -6.06725, -5.32258,
    -6.043512, -6.96296, -3.96175, -5.65111, -6.55885, -7.85276, -7.05882, -6.32754,
    -6.44666, -4.850213, -6.43631, -5.80808, -4.59402, -8.49546, -3.64964, -4.80816,
    -3.71267, -7.07965, -5.43188, -2.908285, -4.65116, -6.51409, -5.54324, -6.10022,
    -6.27954, -4.68933, -0.2309446, -7.77903, -6.14035, -5.6872, -4.01009, -4.81246,
    -5.437795, -4.545457, -1.61858, -5.73806, -6.62252, -6.98878, -1.618582, -6.33803,
    -3.99454, -5.714292, -4.20463, -4.6875, -4.532588, -6.38298, -1.55258, -5.28351,
    -7.48466, -6.47292, -4.83651, -5.04951, -3.82883, -4.216872, -4.016486, -5.47667,
    -5.815833, -4.2735, -4.38067, -5.143343, -4.008915, -3.99449, -5.6338, -3.738323,
    -6.141734, -5.39262, -5.81583, -6.27954, -6.08696, -8.04795, -3.347732, -7.02988,
    -7.33229, -2.15385, -5.6541, -7.42794, -7.06215, -6.20805, -5.89226, -5.17435,
    -5.444654, -3.34773, -7.55668, -3.96988, -5.46559, -4.983396, -6.03654, -5.43779,
    -3.994543, -6.59341, -4.82456, -6.37623, -3.698444, -6.07477, -6.32411, -0.230949,
    -6.02583, -6.9869, -4.67797, -4.694849, -5.20951, -6.100223, -5.78778, -6.32384,
    -7.77903, -3.74153, -14.43396, -6.46976, -4.694845, -6.01156, -3.347728, -4.74865,
    -4.64701, -6.11354, -4.79651, -4.21687, -4.796514, -6.7029, -0.230952, -4.53401,
    -4.98339, -5.83039, -5.66667, -4.89796, -8.90688, -4.14747, -4.03121, -6.22951,
    -9.25197, -5.74163, -5.81015, -6.06509, -6.22951, -4.545465, -4.7191, -4.694844,
    -6.64858, -6.14173, -6.62983, -6.030154, -3.344123, -4.6729, -3.33817, -5.74074,
    -7.12166, -4.8855, -4.99168, -4.532581, -4.24028, -6.98497, -4.29066, -5.89286,
    -6.72116, -5.7508, -5.02901, -4.20223, -5.03324, -4.92958, -4.050283, -3.36257,
    -6.043515, -4.078084, -3.73832, -5.714295, -5.15638, -3.85064, 0.000004, -6.35135,
    -3.73396, -4.35459, -4.00276, -4.88911, -5.049514, -1.65587, 0.000001, -6.3762,
    -6.37625, -3.79032, -7.75463, -4.00891, -6.44139, -5.85366, -5.847957, -6.8917,
    -5.61331, -6.49606, -2.15606, -3.69844, -4.21348, -5.444651, -6.67285, -4.56522,
    -4.85021, -4.969883, -4.51941, -5.95745, -6.37627, -4.532585, -5.25409, -4.05028,
    -5.31972, -6.10221, -4.8583, -5.63486, -5.77532, -5.44355, -4.23729, -4.545463,
    -3.73514, -6.62983, -4.59402, -4.08587, -4.98915, -5.3442, -5.47599, -5.5371,
    -11.16585, -5.85284, -4.7486, -5.808085, -4.49612, -4.64701, -2.52226, -7.40203,
    -4.71914, -5.37736, -6.9869, -6.74419, -6.60793, -6.39778, -4.69531, -4.57143,
    -4.59588, -5.23156, -6.100227, -4.87445, -4.0602, -5.651113, -6.42202, -4.22961,
    -6.13139, -3.34412, -5.263168, -7.06215, -5.665031, -5.6664, -5.775323, -3.8961,
    -1.65468, 0.000003, -6.60634, -7.79377, -5.46875, -5.14334, -6.043514, -4.52261,
    -5.36364, -6.44905, -7.84077, -4.01786, -5.69767, -6.44258, -5.679014, -3.67107,
    -5.73248, -6.46976, -5.91667, -1.61744, -6.1017, -7.4392, -4.19274, -6.060618,
    -6.55629, -6.93493, -3.7415, -6.03015, -8.04795, -8.66808, -3.84615, -5.69823,
    -4.202231, -6.74646, -5.36981, -5.08021, -5.38922, -5.85664, -5.67901, -6.60793,
    -4.07808, -5.21814, -6.30841, -6.06509, -5.96798, -4.01648, -4.75515, -4.545461,
    -4.48808, -2.90828, -6.54122, -6.48801, -5.87276, -6.58135, -5.2921, -5.8156, -4.42478,
    -7.27532, -5.60579, -7.88177, -5.82121, -6.48749, -5.665035, -3.45821, -5.444657,
    -5.26316, -5.87558, 0.000007,
];
let mut res = f64::NAN;
let mpt = MPTCalculator::from_v(&DATA);
let err = mpt.rank_position(-6.406382, 2, &mut res);
assert_eq!(err == Errors::ClErrorCodeNoError && MPTCalculator::is_eq_double(res,87.0), true);
Source

pub fn rank(&self, rank_type: i16, rank: &mut [f64]) -> Errors

calculate the rank series for a series.

§Arguments

rank_type is the rank type

§Examples
 use mpt_lib::MPTCalculator;
 use mpt_lib::enums::{self, Errors};
const DATA: [f64; 180] = [
    2.000, 1.910, 1.790, 1.720, 1.530, 1.450, 1.250, 1.100, 1.080, 1.070, 0.960, 0.960,
    0.920, 0.920, 0.790, 0.650, 0.600, 0.560, 0.440, 0.410, 0.400, 0.400, 0.300, 0.250,
    0.230, 0.230, 0.230, 0.200, 0.160, 0.150, 0.140, 0.110, 0.100, 0.100, 0.100, 0.060,
    0.040, 0.040, 0.040, 0.040, 0.030, 0.010, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000,
    0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000,
    0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000,
    0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000,
    0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000,
    0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000,
    0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000,
    0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000,
    0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000,
    0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000,
    0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000,
    0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000,
];

const EXPECTED_RES: [f64; 180] = [
    1.0, 3.0, 5.0, 8.0, 10.0, 12.0, 15.0, 17.0, 20.0, 22.0, 24.0, 24.0, 29.0, 29.0, 34.0,
    36.0, 39.0, 41.0, 43.0, 46.0, 48.0, 48.0, 53.0, 55.0, 58.0, 58.0, 58.0, 65.0, 67.0,
    70.0, 72.0, 74.0, 77.0, 77.0, 77.0, 84.0, 86.0, 86.0, 86.0, 86.0, 96.0, 98.0, 100.0,
    100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0,
    100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0,
    100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0,
    100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0,
    100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0,
    100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0,
    100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0,
    100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0,
    100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0,
    100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0,
    100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0,
    100.0, 100.0, 100.0, 100.0, 100.0,
];
let mut res = [f64::NAN; DATA.len()];
let mpt = MPTCalculator::from_v(&DATA);
let err = mpt.rank(5, &mut res);
assert_eq!(
    err == Errors::ClErrorCodeNoError && MPTCalculator::is_eq_double_array(&res, &EXPECTED_RES),
    true
);
Source

pub fn percentile_rank_breakpoints( &self, _fract_weights: &[f64], is_asc: bool, break_points: &mut [f64], ) -> Errors

calculate the position of a value in a series.

§Arguments

value is the value should be found.

rank_type is the rank type

§Examples
 use mpt_lib::MPTCalculator;
 use mpt_lib::enums::{self, Errors};
const DATA: [f64; 382] = [
    0.0, 0.0, 0.0, 0.0, -0.23095, -0.23095, -0.23095, -1.55258, -1.61744, -1.61858,
    -1.61858, -1.65468, -1.65587, -2.15385, -2.15606, -2.52226, -2.90828, -2.90828,
    -3.33817, -3.34412, -3.34412, -3.34773, -3.34773, -3.34773, -3.35135, -3.36257,
    -3.45821, -3.64964, -3.67107, -3.69844, -3.69844, -3.71267, -3.73396, -3.73514,
    -3.73832, -3.73832, -3.7415, -3.7415, -3.79032, -3.82883, -3.84615, -3.85064, -3.8961,
    -3.93836, -3.96175, -3.96988, -3.98489, -3.98909, -3.99449, -3.99454, -3.99454,
    -4.00276, -4.00891, -4.00891, -4.01009, -4.01648, -4.01648, -4.01786, -4.02597,
    -4.03121, -4.05028, -4.05028, -4.0602, -4.07808, -4.07808, -4.08587, -4.14747,
    -4.19274, -4.20223, -4.20223, -4.20463, -4.21348, -4.21607, -4.21687, -4.21687,
    -4.22961, -4.23729, -4.24028, -4.2735, -4.29066, -4.35459, -4.38067, -4.42478,
    -4.48808, -4.49612, -4.51011, -4.51941, -4.52261, -4.53125, -4.53258, -4.53258,
    -4.53258, -4.53401, -4.54546, -4.54546, -4.54546, -4.54546, -4.56522, -4.57143,
    -4.59402, -4.59402, -4.59588, -4.64701, -4.64701, -4.65116, -4.6729, -4.67797,
    -4.68019, -4.68019, -4.6875, -4.68933, -4.69027, -4.69484, -4.69484, -4.69484,
    -4.69484, -4.69531, -4.71698, -4.7191, -4.7191, -4.7486, -4.7486, -4.75515, -4.79651,
    -4.79651, -4.80816, -4.81246, -4.81246, -4.82456, -4.82612, -4.83651, -4.83749,
    -4.85021, -4.85021, -4.8583, -4.87445, -4.87445, -4.8855, -4.88911, -4.89796, -4.92958,
    -4.96988, -4.98084, -4.98339, -4.98339, -4.98915, -4.99168, -5.01882, -5.02901,
    -5.03324, -5.04386, -5.04951, -5.04951, -5.08021, -5.14334, -5.14334, -5.15638,
    -5.17435, -5.20951, -5.21814, -5.23156, -5.23918, -5.25409, -5.26316, -5.26316,
    -5.28351, -5.2921, -5.31972, -5.32258, -5.32258, -5.3442, -5.36364, -5.36981, -5.37736,
    -5.38922, -5.39262, -5.40541, -5.43188, -5.43779, -5.43779, -5.44355, -5.44465,
    -5.44465, -5.44465, -5.46559, -5.46875, -5.47599, -5.47667, -5.5371, -5.54324,
    -5.55556, -5.60579, -5.61331, -5.6338, -5.63486, -5.65111, -5.65111, -5.6541, -5.6541,
    -5.65657, -5.66503, -5.66503, -5.66503, -5.6664, -5.66667, -5.67901, -5.67901, -5.6872,
    -5.69767, -5.69823, -5.71429, -5.71429, -5.71429, -5.71659, -5.73248, -5.73806,
    -5.74074, -5.74163, -5.7508, -5.76577, -5.77532, -5.77532, -5.78778, -5.80808,
    -5.80808, -5.81015, -5.8156, -5.81583, -5.81583, -5.82121, -5.83039, -5.84, -5.84795,
    -5.84795, -5.85284, -5.85366, -5.85664, -5.86767, -5.87276, -5.87558, -5.89226,
    -5.89286, -5.91667, -5.95745, -5.96798, -5.99415, -6.00667, -6.01156, -6.02583,
    -6.03015, -6.03015, -6.03654, -6.04351, -6.04351, -6.04351, -6.06061, -6.06509,
    -6.06509, -6.06725, -6.07477, -6.07477, -6.08696, -6.10022, -6.10022, -6.10022,
    -6.1017, -6.10221, -6.11354, -6.11746, -6.13139, -6.14035, -6.14173, -6.14173,
    -6.20805, -6.22951, -6.22951, -6.27954, -6.27954, -6.28218, -6.29921, -6.30841,
    -6.31164, -6.32384, -6.32411, -6.32411, -6.32754, -6.33803, -6.33803, -6.35135,
    -6.3762, -6.3762, -6.3762, -6.3762, -6.38298, -6.39778, -6.41638, -6.42202, -6.42276,
    -6.43432, -6.43432, -6.43631, -6.44139, -6.44258, -6.44666, -6.44905, -6.46976,
    -6.46976, -6.47292, -6.47292, -6.48749, -6.48801, -6.49606, -6.50577, -6.51409,
    -6.54122, -6.55629, -6.55885, -6.58135, -6.59341, -6.60634, -6.60793, -6.60793,
    -6.61831, -6.62252, -6.62983, -6.62983, -6.63507, -6.64858, -6.67285, -6.7029,
    -6.72116, -6.74419, -6.74646, -6.814, -6.8917, -6.93493, -6.96296, -6.98497, -6.9869,
    -6.9869, -6.98878, -7.02988, -7.05882, -7.06215, -7.06215, -7.0632, -7.07965, -7.07965,
    -7.11111, -7.12166, -7.15596, -7.27532, -7.33229, -7.40203, -7.41139, -7.42794,
    -7.42794, -7.43671, -7.4392, -7.48466, -7.55668, -7.75463, -7.75463, -7.77903,
    -7.77903, -7.79377, -7.84077, -7.85276, -7.88177, -8.04795, -8.04795, -8.49546,
    -8.58995, -8.66808, -8.66808, -8.75203, -8.84354, -8.90688, -9.25197, -11.16585,
    -11.21951, -14.43396,
];

const EXPECTED_RES: [f64; 100] = [
    0.0, -1.55258, -1.65468, -2.52226, -3.34412, -3.34773, -3.45821, -3.69844, -3.73832,
    -3.79032, -3.85064, -3.96988, -3.99454, -4.00891, -4.01786, -4.05028, -4.07808,
    -4.20223, -4.21607, -4.23729, -4.35459, -4.48808, -4.52261, -4.53258, -4.54546,
    -4.59402, -4.64701, -4.67797, -4.68933, -4.69484, -4.7191, -4.7486, -4.80816, -4.82612,
    -4.85021, -4.8855, -4.92958, -4.98339, -5.02901, -5.04951, -5.15638, -5.23156,
    -5.26316, -5.31972, -5.36364, -5.39262, -5.43779, -5.44465, -5.47599, -5.55556,
    -5.63486, -5.6541, -5.66503, -5.67901, -5.69823, -5.71659, -5.74163, -5.77532,
    -5.80808, -5.81583, -5.84795, -5.85664, -5.89226, -5.95745, -6.01156, -6.03654,
    -6.06061, -6.07477, -6.10022, -6.10221, -6.14035, -6.22951, -6.28218, -6.31164,
    -6.32754, -6.3762, -6.38298, -6.42276, -6.43631, -6.44905, -6.47292, -6.50577,
    -6.55885, -6.60793, -6.62252, -6.64858, -6.74419, -6.93493, -6.9869, -7.05882,
    -7.07965, -7.15596, -7.41139, -7.4392, -7.75463, -7.79377, -8.04795, -8.66808,
    -8.90688, -14.43396,
];
let mut res = [f64::NAN; 100];
let mpt = MPTCalculator::from_v(&DATA);
let err = mpt.percentile_rank_breakpoints(&[f64::NAN; 0], false, &mut res);
assert_eq!(
    err == Errors::ClErrorCodeNoError && MPTCalculator::is_eq_double_array(&res, &EXPECTED_RES),
    true
);
Source§

impl<'a> MPTCalculator<'a>

Source

pub fn beta(&self, beta: &mut f64) -> Errors

calculate the beta value of an array if the array has NAN/INF values,the result will be NAN.

§Arguments

freq: the frequence of source data

is_annu: the flag of annualize.

§Examples
use mpt_lib::MPTCalculator;
use mpt_lib::enums::{self, Errors};
let data = vec![
    -1.22072, -0.0668, 2.20588, -0.91563, -0.76766, -1.21429, 3.43456, 4.99825, 3.89481,
    1.59564, 0.86793, 2.41477, -1.80305, 0.6709, 3.57769, 4.77481, -0.37317, -3.52713,
    1.88831, 1.73502, 1.20155, -3.36542, -2.03551, -5.6145, -2.71663, -0.04815, 3.99807,
    1.66744, -9.68658, -0.46681, 4.22095, -6.7, -15.27331, -8.46123, 0.76369, -10.32347,
];
let bmk_data = vec![
    0.27133, 1.24475, 1.34278, -2.87814, 0.13557, 0.61685, 2.37931, 2.577, 3.25861, 1.9016,
    1.40278, 1.51232, -1.95588, 1.1185, 4.42953, 3.48951, -1.66133, -3.10048, 1.49901,
    3.73988, 1.59068, -4.18066, -0.69376, -5.99816, -3.24858, -0.4318, 4.87031, 1.29526,
    -8.43036, -0.84062, 1.44647, -8.91073, -16.79479, -7.17546, 1.06403, -8.42864,
];
let mut res = 0.0;
let mpt = MPTCalculator::from_v_b(&data, &bmk_data);
let err = mpt.beta(&mut res);
assert_eq!(
    err == Errors::ClErrorCodeNoError && MPTCalculator::is_eq_double(res, 0.97364),
    true
);
Source

pub fn alpha( &self, freq: ClFrequency, is_annu: bool, alpha_result: &mut f64, ) -> Errors

calculate the alpha value of an array if the array has NAN/INF values,the result will be NAN.

§Arguments

freq: the frequence of source data

is_annu: the flag of annualize.

§Examples
use mpt_lib::MPTCalculator;
use mpt_lib::enums::{self, Errors};
let data = vec![
    -1.22072, -0.0668, 2.20588, -0.91563, -0.76766, -1.21429, 3.43456, 4.99825, 3.89481,
    1.59564, 0.86793, 2.41477, -1.80305, 0.6709, 3.57769, 4.77481, -0.37317, -3.52713,
    1.88831, 1.73502, 1.20155, -3.36542, -2.03551, -5.6145, -2.71663, -0.04815, 3.99807,
    1.66744, -9.68658, -0.46681, 4.22095, -6.7, -15.27331, -8.46123, 0.76369, -10.32347,
];
let bmk_data = vec![
    0.27133, 1.24475, 1.34278, -2.87814, 0.13557, 0.61685, 2.37931, 2.577, 3.25861, 1.9016,
    1.40278, 1.51232, -1.95588, 1.1185, 4.42953, 3.48951, -1.66133, -3.10048, 1.49901,
    3.73988, 1.59068, -4.18066, -0.69376, -5.99816, -3.24858, -0.4318, 4.87031, 1.29526,
    -8.43036, -0.84062, 1.44647, -8.91073, -16.79479, -7.17546, 1.06403, -8.42864,
];
let mut res = 0.0;
let mpt = MPTCalculator::from_v_b(&data, &bmk_data);
let err = mpt.alpha(enums::ClFrequency::ClFrequencyMonthly, true, &mut res);
assert_eq!(
    err == Errors::ClErrorCodeNoError && MPTCalculator::is_eq_double(res, 0.66313),
    true
);
Source

pub fn tracking_error( &self, freq: ClFrequency, is_annu: bool, tracking_error_result: &mut f64, ) -> Errors

calculate the tracking value of an array if the array has NAN/INF values,the result will be NAN.

§Arguments

freq: the frequence of source data

is_annu: the flag of annualize.

§Examples
use mpt_lib::MPTCalculator;
use mpt_lib::enums::{self, Errors};
let data = vec![
    -1.22072, -0.0668, 2.20588, -0.91563, -0.76766, -1.21429, 3.43456, 4.99825, 3.89481,
    1.59564, 0.86793, 2.41477, -1.80305, 0.6709, 3.57769, 4.77481, -0.37317, -3.52713,
    1.88831, 1.73502, 1.20155, -3.36542, -2.03551, -5.6145, -2.71663, -0.04815, 3.99807,
    1.66744, -9.68658, -0.46681, 4.22095, -6.7, -15.27331, -8.46123, 0.76369, -10.32347,
];
let bmk_data = vec![
    0.27133, 1.24475, 1.34278, -2.87814, 0.13557, 0.61685, 2.37931, 2.577, 3.25861, 1.9016,
    1.40278, 1.51232, -1.95588, 1.1185, 4.42953, 3.48951, -1.66133, -3.10048, 1.49901,
    3.73988, 1.59068, -4.18066, -0.69376, -5.99816, -3.24858, -0.4318, 4.87031, 1.29526,
    -8.43036, -0.84062, 1.44647, -8.91073, -16.79479, -7.17546, 1.06403, -8.42864,
];
let mut res = 0.0;
let mpt = MPTCalculator::from_v_b(&data, &bmk_data);
let err = mpt.tracking_error(enums::ClFrequency::ClFrequencyMonthly, true, &mut res);
assert_eq!(
    err == Errors::ClErrorCodeNoError && MPTCalculator::is_eq_double(res, 4.37063),
    true
);
Source

pub fn information_ratio_arithmetic( &self, freq: ClFrequency, is_annu: bool, information_ratio_arithmetic_res: &mut f64, ) -> Errors

calculate the information ratio arithmetic value of an array if the array has NAN/INF values,the result will be NAN.

§Arguments

freq: the frequence of source data

is_annu: the flag of annualize.

§Examples
use mpt_lib::MPTCalculator;
use mpt_lib::enums::{self, Errors};
let data = vec![
    -1.22072, -0.0668, 2.20588, -0.91563, -0.76766, -1.21429, 3.43456, 4.99825, 3.89481,
    1.59564, 0.86793, 2.41477, -1.80305, 0.6709, 3.57769, 4.77481, -0.37317, -3.52713,
    1.88831, 1.73502, 1.20155, -3.36542, -2.03551, -5.6145, -2.71663, -0.04815, 3.99807,
    1.66744, -9.68658, -0.46681, 4.22095, -6.7, -15.27331, -8.46123, 0.76369, -10.32347,
];
let bmk_data = vec![
    0.27133, 1.24475, 1.34278, -2.87814, 0.13557, 0.61685, 2.37931, 2.577, 3.25861, 1.9016,
    1.40278, 1.51232, -1.95588, 1.1185, 4.42953, 3.48951, -1.66133, -3.10048, 1.49901,
    3.73988, 1.59068, -4.18066, -0.69376, -5.99816, -3.24858, -0.4318, 4.87031, 1.29526,
    -8.43036, -0.84062, 1.44647, -8.91073, -16.79479, -7.17546, 1.06403, -8.42864,
];
let mut res = 0.0;
let mpt = MPTCalculator::from_v_b(&data, &bmk_data);
let err = mpt.information_ratio_arithmetic(
    enums::ClFrequency::ClFrequencyMonthly,
    true,
    &mut res,
);
assert_eq!(
    err == Errors::ClErrorCodeNoError && MPTCalculator::is_eq_double(res, 0.19228),
    true
);
Source

pub fn information_ratio_geometric( &self, freq: ClFrequency, is_annu: bool, information_ratio_geometric_res: &mut f64, ) -> Errors

calculate the information ratio geometric of an array if the array has NAN/INF values,the result will be NAN.

§Arguments

freq: the frequence of source data

is_annu: the flag of annualize.

§Examples
use mpt_lib::MPTCalculator;
use mpt_lib::enums::{self, Errors};
let data = vec![
    -1.22072, -0.0668, 2.20588, -0.91563, -0.76766, -1.21429, 3.43456, 4.99825, 3.89481,
    1.59564, 0.86793, 2.41477, -1.80305, 0.6709, 3.57769, 4.77481, -0.37317, -3.52713,
    1.88831, 1.73502, 1.20155, -3.36542, -2.03551, -5.6145, -2.71663, -0.04815, 3.99807,
    1.66744, -9.68658, -0.46681, 4.22095, -6.7, -15.27331, -8.46123, 0.76369, -10.32347,
];
let bmk_data = vec![
    0.27133, 1.24475, 1.34278, -2.87814, 0.13557, 0.61685, 2.37931, 2.577, 3.25861, 1.9016,
    1.40278, 1.51232, -1.95588, 1.1185, 4.42953, 3.48951, -1.66133, -3.10048, 1.49901,
    3.73988, 1.59068, -4.18066, -0.69376, -5.99816, -3.24858, -0.4318, 4.87031, 1.29526,
    -8.43036, -0.84062, 1.44647, -8.91073, -16.79479, -7.17546, 1.06403, -8.42864,
];
let mut res = 0.0;
let mpt = MPTCalculator::from_v_b(&data, &bmk_data);
let err =
mpt.information_ratio_geometric(enums::ClFrequency::ClFrequencyMonthly, true, &mut res);
assert_eq!(
err == Errors::ClErrorCodeNoError && MPTCalculator::is_eq_double(res, 0.21796),
true
);
Source

pub fn excess_return_geometric( &self, freq: ClFrequency, is_annu: bool, excess: &mut f64, ) -> Errors

calculate the excess return geometric value of an array if the array has NAN/INF values,the result will be NAN.

§Arguments

freq: the frequence of source data

is_annu: the flag of annualize.

§Examples
use mpt_lib::MPTCalculator;
use mpt_lib::enums::{self, Errors};
let data = vec![
    -1.22072, -0.0668, 2.20588, -0.91563, -0.76766, -1.21429, 3.43456, 4.99825, 3.89481,
    1.59564, 0.86793, 2.41477, -1.80305, 0.6709, 3.57769, 4.77481, -0.37317, -3.52713,
    1.88831, 1.73502, 1.20155, -3.36542, -2.03551, -5.6145, -2.71663, -0.04815, 3.99807,
    1.66744, -9.68658, -0.46681, 4.22095, -6.7, -15.27331, -8.46123, 0.76369, -10.32347,
];
let bmk_data = vec![
    0.27133, 1.24475, 1.34278, -2.87814, 0.13557, 0.61685, 2.37931, 2.577, 3.25861, 1.9016,
    1.40278, 1.51232, -1.95588, 1.1185, 4.42953, 3.48951, -1.66133, -3.10048, 1.49901,
    3.73988, 1.59068, -4.18066, -0.69376, -5.99816, -3.24858, -0.4318, 4.87031, 1.29526,
    -8.43036, -0.84062, 1.44647, -8.91073, -16.79479, -7.17546, 1.06403, -8.42864,
];
let mut res = 0.0;
let mpt = MPTCalculator::from_v_b(&data, &bmk_data);
let err =
mpt.excess_return_geometric(enums::ClFrequency::ClFrequencyMonthly, true, &mut res);
assert_eq!(
err == Errors::ClErrorCodeNoError && MPTCalculator::is_eq_double(res, 0.95263),
true
);
Source

pub fn excess_return_arithmetic( &self, freq: ClFrequency, is_annu: bool, excess: &mut f64, ) -> Errors

calculate the excess return arithmetic value of an array if the array has NAN/INF values,the result will be NAN.

§Arguments

freq: the frequence of source data

is_annu: the flag of annualize.

§Examples
use mpt_lib::MPTCalculator;
use mpt_lib::enums::{self, Errors};
let data = vec![
    -1.22072, -0.0668, 2.20588, -0.91563, -0.76766, -1.21429, 3.43456, 4.99825, 3.89481,
    1.59564, 0.86793, 2.41477, -1.80305, 0.6709, 3.57769, 4.77481, -0.37317, -3.52713,
    1.88831, 1.73502, 1.20155, -3.36542, -2.03551, -5.6145, -2.71663, -0.04815, 3.99807,
    1.66744, -9.68658, -0.46681, 4.22095, -6.7, -15.27331, -8.46123, 0.76369, -10.32347,
];
let bmk_data = vec![
    0.27133, 1.24475, 1.34278, -2.87814, 0.13557, 0.61685, 2.37931, 2.577, 3.25861, 1.9016,
    1.40278, 1.51232, -1.95588, 1.1185, 4.42953, 3.48951, -1.66133, -3.10048, 1.49901,
    3.73988, 1.59068, -4.18066, -0.69376, -5.99816, -3.24858, -0.4318, 4.87031, 1.29526,
    -8.43036, -0.84062, 1.44647, -8.91073, -16.79479, -7.17546, 1.06403, -8.42864,
];
let mut res = 0.0;
let mpt = MPTCalculator::from_v_b(&data, &bmk_data);
let err =
mpt.excess_return_arithmetic(enums::ClFrequency::ClFrequencyMonthly, true, &mut res);
assert_eq!(
err == Errors::ClErrorCodeNoError && MPTCalculator::is_eq_double(res, 0.84039),
true
);
Source

pub fn excess_return_relative_percentage( &self, freq: ClFrequency, is_annu: bool, excess: &mut f64, ) -> Errors

calculate the excess return arithmetic value of an array if the array has NAN/INF values,the result will be NAN.

§Arguments

freq: the frequence of source data

is_annu: the flag of annualize.

§Examples
use mpt_lib::MPTCalculator;
use mpt_lib::enums::{self, Errors};
let data = vec![
    -1.22072, -0.0668, 2.20588, -0.91563, -0.76766, -1.21429, 3.43456, 4.99825, 3.89481,
    1.59564, 0.86793, 2.41477, -1.80305, 0.6709, 3.57769, 4.77481, -0.37317, -3.52713,
    1.88831, 1.73502, 1.20155, -3.36542, -2.03551, -5.6145, -2.71663, -0.04815, 3.99807,
    1.66744, -9.68658, -0.46681, 4.22095, -6.7, -15.27331, -8.46123, 0.76369, -10.32347,
];
let bmk_data = vec![
    0.27133, 1.24475, 1.34278, -2.87814, 0.13557, 0.61685, 2.37931, 2.577, 3.25861, 1.9016,
    1.40278, 1.51232, -1.95588, 1.1185, 4.42953, 3.48951, -1.66133, -3.10048, 1.49901,
    3.73988, 1.59068, -4.18066, -0.69376, -5.99816, -3.24858, -0.4318, 4.87031, 1.29526,
    -8.43036, -0.84062, 1.44647, -8.91073, -16.79479, -7.17546, 1.06403, -8.42864,
];
let mut res = 0.0;
let mpt = MPTCalculator::from_v_b(&data, &bmk_data);
let err = mpt.excess_return_relative_percentage(
    enums::ClFrequency::ClFrequencyMonthly,
    true,
    &mut res,
);
assert_eq!(
    err == Errors::ClErrorCodeNoError && MPTCalculator::is_eq_double(res, 24.6508),
    true
);
Source

pub fn up_downside_standard_deviation( &self, freq: ClFrequency, is_annu: bool, cmp_fn: fn(f64, f64) -> bool, up_downside_standard_deviation: &mut f64, ) -> Errors

Source

pub fn downside_standard_deviation( &self, freq: ClFrequency, is_annu: bool, downside_standard_deviation: &mut f64, ) -> Errors

calculate the downside standard deviation value of an array if the array has NAN/INF values,the result will be NAN.

§Arguments

freq: the frequence of source data

is_annu: the flag of annualize.

§Examples
use mpt_lib::MPTCalculator;
use mpt_lib::enums::{self, Errors};
let data = vec![
    -1.22072, -0.0668, 2.20588, -0.91563, -0.76766, -1.21429, 3.43456, 4.99825, 3.89481,
    1.59564, 0.86793, 2.41477, -1.80305, 0.6709, 3.57769, 4.77481, -0.37317, -3.52713,
    1.88831, 1.73502, 1.20155, -3.36542, -2.03551, -5.6145, -2.71663, -0.04815, 3.99807,
    1.66744, -9.68658, -0.46681, 4.22095, -6.7, -15.27331, -8.46123, 0.76369, -10.32347,
];
let bmk_data = vec![
    0.27133, 1.24475, 1.34278, -2.87814, 0.13557, 0.61685, 2.37931, 2.577, 3.25861, 1.9016,
    1.40278, 1.51232, -1.95588, 1.1185, 4.42953, 3.48951, -1.66133, -3.10048, 1.49901,
    3.73988, 1.59068, -4.18066, -0.69376, -5.99816, -3.24858, -0.4318, 4.87031, 1.29526,
    -8.43036, -0.84062, 1.44647, -8.91073, -16.79479, -7.17546, 1.06403, -8.42864,
];
let mut res = 0.0;
let mpt = MPTCalculator::from_v_b(&data, &bmk_data);
let err = mpt.downside_standard_deviation(
    enums::ClFrequency::ClFrequencyMonthly,
    true,
    &mut res,
);
assert_eq!(
    err == Errors::ClErrorCodeNoError && MPTCalculator::is_eq_double(res, 2.00029),
    true
);
Source

pub fn upside_standard_deviation( &self, freq: ClFrequency, is_annu: bool, upside_standard_deviation: &mut f64, ) -> Errors

calculate the upside standard deviation value of an array if the array has NAN/INF values,the result will be NAN.

§Arguments

freq: the frequence of source data

is_annu: the flag of annualize.

§Examples
use mpt_lib::MPTCalculator;
use mpt_lib::enums::{self, Errors};
let data = vec![
    -1.22072, -0.0668, 2.20588, -0.91563, -0.76766, -1.21429, 3.43456, 4.99825, 3.89481,
    1.59564, 0.86793, 2.41477, -1.80305, 0.6709, 3.57769, 4.77481, -0.37317, -3.52713,
    1.88831, 1.73502, 1.20155, -3.36542, -2.03551, -5.6145, -2.71663, -0.04815, 3.99807,
    1.66744, -9.68658, -0.46681, 4.22095, -6.7, -15.27331, -8.46123, 0.76369, -10.32347,
];
let bmk_data = vec![
    0.27133, 1.24475, 1.34278, -2.87814, 0.13557, 0.61685, 2.37931, 2.577, 3.25861, 1.9016,
    1.40278, 1.51232, -1.95588, 1.1185, 4.42953, 3.48951, -1.66133, -3.10048, 1.49901,
    3.73988, 1.59068, -4.18066, -0.69376, -5.99816, -3.24858, -0.4318, 4.87031, 1.29526,
    -8.43036, -0.84062, 1.44647, -8.91073, -16.79479, -7.17546, 1.06403, -8.42864,
];
let mut res = 0.0;
let mpt = MPTCalculator::from_v_b(&data, &bmk_data);
let err =
mpt.upside_standard_deviation(enums::ClFrequency::ClFrequencyMonthly, true, &mut res);
assert_eq!(
err == Errors::ClErrorCodeNoError && MPTCalculator::is_eq_double(res, 2.70293),
true
);
Source

pub fn standard_error_alpha( &self, standard_error_alpha_result: &mut f64, ) -> Errors

calculate the standard error alpha value of an array if the array has NAN/INF values,the result will be NAN.

§Arguments

freq: the frequence of source data

is_annu: the flag of annualize.

§Examples
use mpt_lib::MPTCalculator;
use mpt_lib::enums::{self, Errors};
let data = vec![
    -1.22072, -0.0668, 2.20588, -0.91563, -0.76766, -1.21429, 3.43456, 4.99825, 3.89481,
    1.59564, 0.86793, 2.41477, -1.80305, 0.6709, 3.57769, 4.77481, -0.37317, -3.52713,
    1.88831, 1.73502, 1.20155, -3.36542, -2.03551, -5.6145, -2.71663, -0.04815, 3.99807,
    1.66744, -9.68658, -0.46681, 4.22095, -6.7, -15.27331, -8.46123, 0.76369, -10.32347,
];
let bmk_data = vec![
    0.27133, 1.24475, 1.34278, -2.87814, 0.13557, 0.61685, 2.37931, 2.577, 3.25861, 1.9016,
    1.40278, 1.51232, -1.95588, 1.1185, 4.42953, 3.48951, -1.66133, -3.10048, 1.49901,
    3.73988, 1.59068, -4.18066, -0.69376, -5.99816, -3.24858, -0.4318, 4.87031, 1.29526,
    -8.43036, -0.84062, 1.44647, -8.91073, -16.79479, -7.17546, 1.06403, -8.42864,
];
let mut res = 0.0;
let mpt = MPTCalculator::from_v_b(&data, &bmk_data);
let err = mpt.standard_error_alpha(&mut res);
assert_eq!(
    err == Errors::ClErrorCodeNoError && MPTCalculator::is_eq_double(res, 0.21689),
    true
);
Source

pub fn standard_error_beta( &self, standard_error_beta_result: &mut f64, ) -> Errors

calculate the standard error beta value of an array if the array has NAN/INF values,the result will be NAN.

§Arguments

freq: the frequence of source data

is_annu: the flag of annualize.

§Examples
use mpt_lib::MPTCalculator;
use mpt_lib::enums::{self, Errors};
let data = vec![
    -1.22072, -0.0668, 2.20588, -0.91563, -0.76766, -1.21429, 3.43456, 4.99825, 3.89481,
    1.59564, 0.86793, 2.41477, -1.80305, 0.6709, 3.57769, 4.77481, -0.37317, -3.52713,
    1.88831, 1.73502, 1.20155, -3.36542, -2.03551, -5.6145, -2.71663, -0.04815, 3.99807,
    1.66744, -9.68658, -0.46681, 4.22095, -6.7, -15.27331, -8.46123, 0.76369, -10.32347,
];
let bmk_data = vec![
    0.27133, 1.24475, 1.34278, -2.87814, 0.13557, 0.61685, 2.37931, 2.577, 3.25861, 1.9016,
    1.40278, 1.51232, -1.95588, 1.1185, 4.42953, 3.48951, -1.66133, -3.10048, 1.49901,
    3.73988, 1.59068, -4.18066, -0.69376, -5.99816, -3.24858, -0.4318, 4.87031, 1.29526,
    -8.43036, -0.84062, 1.44647, -8.91073, -16.79479, -7.17546, 1.06403, -8.42864,
];
let mut res = 0.0;
let mpt = MPTCalculator::from_v_b(&data, &bmk_data);
let err =
mpt.standard_error_beta(&mut res);
assert_eq!(
err == Errors::ClErrorCodeNoError && MPTCalculator::is_eq_double(res, 0.04720),
true
);
Source

pub fn treynor_ratio_arithmetic( &self, freq: ClFrequency, is_annu: bool, treynor_ratio_arithmetic_result: &mut f64, ) -> Errors

calculate the treynor ratio arithmetic value of an array if the array has NAN/INF values,the result will be NAN.

§Arguments

freq: the frequence of source data

is_annu: the flag of annualize.

§Examples
use mpt_lib::MPTCalculator;
use mpt_lib::enums::{self, Errors};
let data = vec![
    -1.22072, -0.0668, 2.20588, -0.91563, -0.76766, -1.21429, 3.43456, 4.99825, 3.89481,
    1.59564, 0.86793, 2.41477, -1.80305, 0.6709, 3.57769, 4.77481, -0.37317, -3.52713,
    1.88831, 1.73502, 1.20155, -3.36542, -2.03551, -5.6145, -2.71663, -0.04815, 3.99807,
    1.66744, -9.68658, -0.46681, 4.22095, -6.7, -15.27331, -8.46123, 0.76369, -10.32347,
];
let bmk_data = vec![
    0.27133, 1.24475, 1.34278, -2.87814, 0.13557, 0.61685, 2.37931, 2.577, 3.25861, 1.9016,
    1.40278, 1.51232, -1.95588, 1.1185, 4.42953, 3.48951, -1.66133, -3.10048, 1.49901,
    3.73988, 1.59068, -4.18066, -0.69376, -5.99816, -3.24858, -0.4318, 4.87031, 1.29526,
    -8.43036, -0.84062, 1.44647, -8.91073, -16.79479, -7.17546, 1.06403, -8.42864,
];
let rf_data = vec![
    0.38497, 0.39406, 0.40057, 0.41237, 0.41911, 0.43358, 0.43548, 0.42107, 0.42743,
    0.43278, 0.4235, 0.43403, 0.4394, 0.43558, 0.42739, 0.41784, 0.40578, 0.42384, 0.41252,
    0.35001, 0.34617, 0.30686, 0.26785, 0.2483, 0.19164, 0.1187, 0.11352, 0.14765, 0.16356,
    0.1443, 0.15408, 0.11971, 0.06686, 0.0254, 0.00313, 0.00321,
];
let mut res = 0.0;
let mpt = MPTCalculator::from(&data, &bmk_data, &rf_data);
let err =
    mpt.treynor_ratio_arithmetic(enums::ClFrequency::ClFrequencyMonthly, true, &mut res);
assert_eq!(
    err == Errors::ClErrorCodeNoError && MPTCalculator::is_eq_double(res, -14.9971),
    true
);
Source

pub fn treynor_ratio_geometric( &self, freq: ClFrequency, is_annu: bool, treynor_ratio_geometric_result: &mut f64, ) -> Errors

calculate the treynor ratio geometric value of an array if the array has NAN/INF values,the result will be NAN.

§Arguments

freq: the frequence of source data

is_annu: the flag of annualize.

§Examples
use mpt_lib::MPTCalculator;
use mpt_lib::enums::{self, Errors};
let data = vec![
    -1.22072, -0.0668, 2.20588, -0.91563, -0.76766, -1.21429, 3.43456, 4.99825, 3.89481,
    1.59564, 0.86793, 2.41477, -1.80305, 0.6709, 3.57769, 4.77481, -0.37317, -3.52713,
    1.88831, 1.73502, 1.20155, -3.36542, -2.03551, -5.6145, -2.71663, -0.04815, 3.99807,
    1.66744, -9.68658, -0.46681, 4.22095, -6.7, -15.27331, -8.46123, 0.76369, -10.32347,
];
let bmk_data = vec![
    0.27133, 1.24475, 1.34278, -2.87814, 0.13557, 0.61685, 2.37931, 2.577, 3.25861, 1.9016,
    1.40278, 1.51232, -1.95588, 1.1185, 4.42953, 3.48951, -1.66133, -3.10048, 1.49901,
    3.73988, 1.59068, -4.18066, -0.69376, -5.99816, -3.24858, -0.4318, 4.87031, 1.29526,
    -8.43036, -0.84062, 1.44647, -8.91073, -16.79479, -7.17546, 1.06403, -8.42864,
];
let rf_data = vec![
    0.38497, 0.39406, 0.40057, 0.41237, 0.41911, 0.43358, 0.43548, 0.42107, 0.42743,
    0.43278, 0.4235, 0.43403, 0.4394, 0.43558, 0.42739, 0.41784, 0.40578, 0.42384, 0.41252,
    0.35001, 0.34617, 0.30686, 0.26785, 0.2483, 0.19164, 0.1187, 0.11352, 0.14765, 0.16356,
    0.1443, 0.15408, 0.11971, 0.06686, 0.0254, 0.00313, 0.00321,
];
let mut res = 0.0;
let mpt = MPTCalculator::from(&data, &bmk_data, &rf_data);
let err =
    mpt.treynor_ratio_geometric(enums::ClFrequency::ClFrequencyMonthly, true, &mut res);
assert_eq!(
    err == Errors::ClErrorCodeNoError && MPTCalculator::is_eq_double(res, -14.47007),
    true
);
Source

pub fn up_down_side_capture( &self, cmp_fn: fn(f64, f64) -> bool, upside_capture_ratio: &mut f64, upside_capture_return: &mut f64, ) -> Errors

Source

pub fn upside_capture( &self, upside_capture_ratio: &mut f64, upside_capture_return: &mut f64, ) -> Errors

calculate the upside capture ration value of an array if the array has NAN/INF values,the result will be NAN.

§Arguments

freq: the frequence of source data

is_annu: the flag of annualize.

§Examples
use mpt_lib::MPTCalculator;
use mpt_lib::enums::{self, Errors};
let data = vec![
    -1.22072, -0.0668, 2.20588, -0.91563, -0.76766, -1.21429, 3.43456, 4.99825, 3.89481,
    1.59564, 0.86793, 2.41477, -1.80305, 0.6709, 3.57769, 4.77481, -0.37317, -3.52713,
    1.88831, 1.73502, 1.20155, -3.36542, -2.03551, -5.6145, -2.71663, -0.04815, 3.99807,
    1.66744, -9.68658, -0.46681, 4.22095, -6.7, -15.27331, -8.46123, 0.76369, -10.32347,
];
let bmk_data = vec![
    -0.34902, 4.72157, -0.07781, -5.69315, 0.50715, -3.32714, 2.85004, 0.70329, 5.68503,
    2.51328, 0.19667, 1.60986, -0.88035, 0.93436, 1.73095, 3.99893, -1.58709, -6.90567,
    2.15374, 1.58778, 2.80202, -7.2765, -0.22549, -6.8847, -3.80168, 0.26042, 4.1003,
    4.48299, -7.8344, 3.60549, 3.49499, -8.10192, -20.90433, -11.9778, 5.56181, -11.19773,
];
let mut upside_capture_ratio = f64::NAN;
let mut upside_capture_return = f64::NAN;
let mpt = MPTCalculator::from_v_b(&data, &bmk_data);
let err = mpt.upside_capture(&mut upside_capture_ratio, &mut upside_capture_return);
assert_eq!(
    err == Errors::ClErrorCodeNoError && MPTCalculator::is_eq_double(upside_capture_ratio, 75.25659),
    true
);

assert_eq!(
    err == Errors::ClErrorCodeNoError && MPTCalculator::is_eq_double(upside_capture_return, 2.00265),
    true
);
Source

pub fn downside_capture( &self, down_capture_ratio: &mut f64, down_capture_return: &mut f64, ) -> Errors

calculate the downside capture ration value of an array if the array has NAN/INF values,the result will be NAN.

§Arguments

freq: the frequence of source data

is_annu: the flag of annualize.

§Examples
use mpt_lib::MPTCalculator;
use mpt_lib::enums::{self, Errors};
let data = vec![
    -1.22072, -0.0668, 2.20588, -0.91563, -0.76766, -1.21429, 3.43456, 4.99825, 3.89481,
    1.59564, 0.86793, 2.41477, -1.80305, 0.6709, 3.57769, 4.77481, -0.37317, -3.52713,
    1.88831, 1.73502, 1.20155, -3.36542, -2.03551, -5.6145, -2.71663, -0.04815, 3.99807,
    1.66744, -9.68658, -0.46681, 4.22095, -6.7, -15.27331, -8.46123, 0.76369, -10.32347,
];
let bmk_data = vec![
    -0.34902, 4.72157, -0.07781, -5.69315, 0.50715, -3.32714, 2.85004, 0.70329, 5.68503,
    2.51328, 0.19667, 1.60986, -0.88035, 0.93436, 1.73095, 3.99893, -1.58709, -6.90567,
    2.15374, 1.58778, 2.80202, -7.2765, -0.22549, -6.8847, -3.80168, 0.26042, 4.1003,
    4.48299, -7.8344, 3.60549, 3.49499, -8.10192, -20.90433, -11.9778, 5.56181, -11.19773,
];
let mut down_capture_ratio = f64::NAN;
let mut down_capture_return = f64::NAN;
let mpt = MPTCalculator::from_v_b(&data, &bmk_data);
let err = mpt.downside_capture(&mut down_capture_ratio, &mut down_capture_return);
assert_eq!(
    err == Errors::ClErrorCodeNoError && MPTCalculator::is_eq_double(down_capture_ratio, 73.03436),
    true
);

assert_eq!(
    err == Errors::ClErrorCodeNoError && MPTCalculator::is_eq_double(down_capture_return, -4.54466),
    true
);
Source

pub fn bear_bull_beta(&self, bear_beta: &mut f64, bull_beta: &mut f64) -> Errors

calculate the bear bull beta value of an array if the array has NAN/INF values,the result will be NAN.

§Arguments

freq: the frequence of source data

is_annu: the flag of annualize.

§Examples
use mpt_lib::MPTCalculator;
use mpt_lib::enums::{self, Errors};
let data = vec![
    -1.22072, -0.0668, 2.20588, -0.91563, -0.76766, -1.21429, 3.43456, 4.99825, 3.89481,
    1.59564, 0.86793, 2.41477, -1.80305, 0.6709, 3.57769, 4.77481, -0.37317, -3.52713,
    1.88831, 1.73502, 1.20155, -3.36542, -2.03551, -5.6145, -2.71663, -0.04815, 3.99807,
    1.66744, -9.68658, -0.46681, 4.22095, -6.7, -15.27331, -8.46123, 0.76369, -10.32347,
];
let bmk_data = vec![
    0.27133, 1.24475, 1.34278, -2.87814, 0.13557, 0.61685, 2.37931, 2.577, 3.25861, 1.9016,
    1.40278, 1.51232, -1.95588, 1.1185, 4.42953, 3.48951, -1.66133, -3.10048, 1.49901,
    3.73988, 1.59068, -4.18066, -0.69376, -5.99816, -3.24858, -0.4318, 4.87031, 1.29526,
    -8.43036, -0.84062, 1.44647, -8.91073, -16.79479, -7.17546, 1.06403, -8.42864,
];
let mut bear_beta = f64::NAN;
let mut bull_beta = f64::NAN;
let mpt = MPTCalculator::from_v_b(&data, &bmk_data);
let err = mpt.bear_bull_beta(&mut bear_beta, &mut bull_beta);
assert_eq!(
    err == Errors::ClErrorCodeNoError
        && MPTCalculator::is_eq_double(bear_beta, 0.97732)
        && MPTCalculator::is_eq_double(bull_beta, 1.07004),
    true
);
Source

pub fn bear_bull_colleation( &self, bear_colleantion_res: &mut f64, bull_colleantion_res: &mut f64, ) -> Errors

calculate the bear bull colleation value of an array if the array has NAN/INF values,the result will be NAN.

§Arguments

freq: the frequence of source data

is_annu: the flag of annualize.

§Examples
use mpt_lib::MPTCalculator;
use mpt_lib::enums::{self, Errors};
let data = vec![
    -1.22072, -0.0668, 2.20588, -0.91563, -0.76766, -1.21429, 3.43456, 4.99825, 3.89481,
    1.59564, 0.86793, 2.41477, -1.80305, 0.6709, 3.57769, 4.77481, -0.37317, -3.52713,
    1.88831, 1.73502, 1.20155, -3.36542, -2.03551, -5.6145, -2.71663, -0.04815, 3.99807,
    1.66744, -9.68658, -0.46681, 4.22095, -6.7, -15.27331, -8.46123, 0.76369, -10.32347,
];
let bmk_data = vec![
    0.27133, 1.24475, 1.34278, -2.87814, 0.13557, 0.61685, 2.37931, 2.577, 3.25861, 1.9016,
    1.40278, 1.51232, -1.95588, 1.1185, 4.42953, 3.48951, -1.66133, -3.10048, 1.49901,
    3.73988, 1.59068, -4.18066, -0.69376, -5.99816, -3.24858, -0.4318, 4.87031, 1.29526,
    -8.43036, -0.84062, 1.44647, -8.91073, -16.79479, -7.17546, 1.06403, -8.42864,
];

let mut bear_colleantion_res = f64::NAN;
let mut bull_colleantion_res = f64::NAN;
let mpt = MPTCalculator::from_v_b(&data, &bmk_data);
let err = mpt.bear_bull_colleation(&mut bear_colleantion_res, &mut bull_colleantion_res);
assert_eq!(
    err == Errors::ClErrorCodeNoError
        && MPTCalculator::is_eq_double(bear_colleantion_res, 0.96025)
        && MPTCalculator::is_eq_double(bull_colleantion_res, 0.73785),
    true
);
Source

pub fn r_squared(&self, r_squard_result: &mut f64) -> Errors

calculate the r_squared value of an array if the array has NAN/INF values,the result will be NAN.

§Arguments

freq: the frequence of source data

is_annu: the flag of annualize.

§Examples
use mpt_lib::MPTCalculator;
use mpt_lib::enums::{self, Errors};
let data = vec![
    -1.22072, -0.0668, 2.20588, -0.91563, -0.76766, -1.21429, 3.43456, 4.99825, 3.89481,
    1.59564, 0.86793, 2.41477, -1.80305, 0.6709, 3.57769, 4.77481, -0.37317, -3.52713,
    1.88831, 1.73502, 1.20155, -3.36542, -2.03551, -5.6145, -2.71663, -0.04815, 3.99807,
    1.66744, -9.68658, -0.46681, 4.22095, -6.7, -15.27331, -8.46123, 0.76369, -10.32347,
];
let bmk_data = vec![
    0.27133, 1.24475, 1.34278, -2.87814, 0.13557, 0.61685, 2.37931, 2.577, 3.25861, 1.9016,
    1.40278, 1.51232, -1.95588, 1.1185, 4.42953, 3.48951, -1.66133, -3.10048, 1.49901,
    3.73988, 1.59068, -4.18066, -0.69376, -5.99816, -3.24858, -0.4318, 4.87031, 1.29526,
    -8.43036, -0.84062, 1.44647, -8.91073, -16.79479, -7.17546, 1.06403, -8.42864,
];

let mut result = f64::NAN;
let mpt = MPTCalculator::from_v_b(&data, &bmk_data);
let err = mpt.r_squared(&mut result);
assert_eq!(
    err == Errors::ClErrorCodeNoError
        && MPTCalculator::is_eq_double(result,92.59959),
    true
);
Source

pub fn batting_average(&self, batting: &mut f64) -> Errors

calculate the batting average value of an array if the array has NAN/INF values,the result will be NAN.

§Arguments

freq: the frequence of source data

is_annu: the flag of annualize.

§Examples
use mpt_lib::MPTCalculator;
use mpt_lib::enums::{self, Errors};
let data = vec![
    -1.22072, -0.0668, 2.20588, -0.91563, -0.76766, -1.21429, 3.43456, 4.99825, 3.89481,
    1.59564, 0.86793, 2.41477, -1.80305, 0.6709, 3.57769, 4.77481, -0.37317, -3.52713,
    1.88831, 1.73502, 1.20155, -3.36542, -2.03551, -5.6145, -2.71663, -0.04815, 3.99807,
    1.66744, -9.68658, -0.46681, 4.22095, -6.7, -15.27331, -8.46123, 0.76369, -10.32347,
];
let bmk_data = vec![
    0.27133, 1.24475, 1.34278, -2.87814, 0.13557, 0.61685, 2.37931, 2.577, 3.25861, 1.9016,
    1.40278, 1.51232, -1.95588, 1.1185, 4.42953, 3.48951, -1.66133, -3.10048, 1.49901,
    3.73988, 1.59068, -4.18066, -0.69376, -5.99816, -3.24858, -0.4318, 4.87031, 1.29526,
    -8.43036, -0.84062, 1.44647, -8.91073, -16.79479, -7.17546, 1.06403, -8.42864,
];

let mut result = f64::NAN;
let mpt = MPTCalculator::from_v_b(&data, &bmk_data);
let err = mpt.batting_average(&mut result);
assert_eq!(
    err == Errors::ClErrorCodeNoError
        && MPTCalculator::is_eq_double(result,52.77778),
    true
);
Source

pub fn correlation(&self, correlation_result: &mut f64) -> Errors

calculate the correlation value of an array if the array has NAN/INF values,the result will be NAN.

§Arguments

freq: the frequence of source data

is_annu: the flag of annualize.

§Examples
use mpt_lib::MPTCalculator;
use mpt_lib::enums::{self, Errors};
let data = vec![
    -1.22072, -0.0668, 2.20588, -0.91563, -0.76766, -1.21429, 3.43456, 4.99825, 3.89481,
    1.59564, 0.86793, 2.41477, -1.80305, 0.6709, 3.57769, 4.77481, -0.37317, -3.52713,
    1.88831, 1.73502, 1.20155, -3.36542, -2.03551, -5.6145, -2.71663, -0.04815, 3.99807,
    1.66744, -9.68658, -0.46681, 4.22095, -6.7, -15.27331, -8.46123, 0.76369, -10.32347,
];
let bmk_data = vec![
    0.27133, 1.24475, 1.34278, -2.87814, 0.13557, 0.61685, 2.37931, 2.577, 3.25861, 1.9016,
    1.40278, 1.51232, -1.95588, 1.1185, 4.42953, 3.48951, -1.66133, -3.10048, 1.49901,
    3.73988, 1.59068, -4.18066, -0.69376, -5.99816, -3.24858, -0.4318, 4.87031, 1.29526,
    -8.43036, -0.84062, 1.44647, -8.91073, -16.79479, -7.17546, 1.06403, -8.42864,
];

let mut result = f64::NAN;
let mpt = MPTCalculator::from_v_b(&data, &bmk_data);
let err = mpt.correlation(&mut result);
assert_eq!(
    err == Errors::ClErrorCodeNoError
        && MPTCalculator::is_eq_double(result,0.96229),
    true
);
Source

pub fn appraisal_ratio(&self, appraisal_ratio_result: &mut f64) -> Errors

calculate the appraisal ratio value of an array if the array has NAN/INF values,the result will be NAN.

§Arguments

freq: the frequence of source data

is_annu: the flag of annualize.

§Examples
use mpt_lib::MPTCalculator;
use mpt_lib::enums::{self, Errors};
let data = vec![
    -1.22072, -0.0668, 2.20588, -0.91563, -0.76766, -1.21429, 3.43456, 4.99825, 3.89481,
    1.59564, 0.86793, 2.41477, -1.80305, 0.6709, 3.57769, 4.77481, -0.37317, -3.52713,
    1.88831, 1.73502, 1.20155, -3.36542, -2.03551, -5.6145, -2.71663, -0.04815, 3.99807,
    1.66744, -9.68658, -0.46681, 4.22095, -6.7, -15.27331, -8.46123, 0.76369, -10.32347,
];
let bmk_data = vec![
    0.27133, 1.24475, 1.34278, -2.87814, 0.13557, 0.61685, 2.37931, 2.577, 3.25861, 1.9016,
    1.40278, 1.51232, -1.95588, 1.1185, 4.42953, 3.48951, -1.66133, -3.10048, 1.49901,
    3.73988, 1.59068, -4.18066, -0.69376, -5.99816, -3.24858, -0.4318, 4.87031, 1.29526,
    -8.43036, -0.84062, 1.44647, -8.91073, -16.79479, -7.17546, 1.06403, -8.42864,
];

let mut result = f64::NAN;
let mpt = MPTCalculator::from_v_b(&data, &bmk_data);
let err = mpt.appraisal_ratio(&mut result);
assert_eq!(
    err == Errors::ClErrorCodeNoError
        && MPTCalculator::is_eq_double(result,0.04337),
    true
);
Source

pub fn relative_risk(&self, relative_risk_res: &mut f64) -> Errors

calculate the relative risk value of an array if the array has NAN/INF values,the result will be NAN.

§Arguments

freq: the frequence of source data

is_annu: the flag of annualize.

§Examples
use mpt_lib::MPTCalculator;
use mpt_lib::enums::{self, Errors};
let data = vec![
    -1.22072, -0.0668, 2.20588, -0.91563, -0.76766, -1.21429, 3.43456, 4.99825, 3.89481,
    1.59564, 0.86793, 2.41477, -1.80305, 0.6709, 3.57769, 4.77481, -0.37317, -3.52713,
    1.88831, 1.73502, 1.20155, -3.36542, -2.03551, -5.6145, -2.71663, -0.04815, 3.99807,
    1.66744, -9.68658, -0.46681, 4.22095, -6.7, -15.27331, -8.46123, 0.76369, -10.32347,
];
let bmk_data = vec![
    0.27133, 1.24475, 1.34278, -2.87814, 0.13557, 0.61685, 2.37931, 2.577, 3.25861, 1.9016,
    1.40278, 1.51232, -1.95588, 1.1185, 4.42953, 3.48951, -1.66133, -3.10048, 1.49901,
    3.73988, 1.59068, -4.18066, -0.69376, -5.99816, -3.24858, -0.4318, 4.87031, 1.29526,
    -8.43036, -0.84062, 1.44647, -8.91073, -16.79479, -7.17546, 1.06403, -8.42864,
];

let mut result = f64::NAN;
let mpt = MPTCalculator::from_v_b(&data, &bmk_data);
let err = mpt.relative_risk(&mut result);
assert_eq!(
    err == Errors::ClErrorCodeNoError
        && MPTCalculator::is_eq_double(result,1.01180),
    true
);
Source

pub fn up_number_ratio(&self, up_number_ratio_result: &mut f64) -> Errors

calculate the up number value of an array if the array has NAN/INF values,the result will be NAN.

§Arguments

freq: the frequence of source data

is_annu: the flag of annualize.

§Examples
use mpt_lib::MPTCalculator;
use mpt_lib::enums::{self, Errors};
let data = vec![
    -1.22072, -0.0668, 2.20588, -0.91563, -0.76766, -1.21429, 3.43456, 4.99825, 3.89481,
    1.59564, 0.86793, 2.41477, -1.80305, 0.6709, 3.57769, 4.77481, -0.37317, -3.52713,
    1.88831, 1.73502, 1.20155, -3.36542, -2.03551, -5.6145, -2.71663, -0.04815, 3.99807,
    1.66744, -9.68658, -0.46681, 4.22095, -6.7, -15.27331, -8.46123, 0.76369, -10.32347,
];
let bmk_data = vec![
    -0.34902, 4.72157, -0.07781, -5.69315, 0.50715, -3.32714, 2.85004, 0.70329, 5.68503,
    2.51328, 0.19667, 1.60986, -0.88035, 0.93436, 1.73095, 3.99893, -1.58709, -6.90567,
    2.15374, 1.58778, 2.80202, -7.2765, -0.22549, -6.8847, -3.80168, 0.26042, 4.1003,
    4.48299, -7.8344, 3.60549, 3.49499, -8.10192, -20.90433, -11.9778, 5.56181, -11.19773,
];
let mut result = f64::NAN;
let mpt = MPTCalculator::from_v_b(&data, &bmk_data);
let err = mpt.up_number_ratio(&mut result);
assert_eq!(
    err == Errors::ClErrorCodeNoError && MPTCalculator::is_eq_double(result, 0.80000),
    true
);
Source

pub fn down_number_ratio(&self, down_number_ratio_result: &mut f64) -> Errors

calculate the down number value of an array if the array has NAN/INF values,the result will be NAN.

§Arguments

freq: the frequence of source data

is_annu: the flag of annualize.

§Examples
use mpt_lib::MPTCalculator;
use mpt_lib::enums::{self, Errors};
let data = vec![
    -1.22072, -0.0668, 2.20588, -0.91563, -0.76766, -1.21429, 3.43456, 4.99825, 3.89481,
    1.59564, 0.86793, 2.41477, -1.80305, 0.6709, 3.57769, 4.77481, -0.37317, -3.52713,
    1.88831, 1.73502, 1.20155, -3.36542, -2.03551, -5.6145, -2.71663, -0.04815, 3.99807,
    1.66744, -9.68658, -0.46681, 4.22095, -6.7, -15.27331, -8.46123, 0.76369, -10.32347,
];
let bmk_data = vec![
    -0.34902, 4.72157, -0.07781, -5.69315, 0.50715, -3.32714, 2.85004, 0.70329, 5.68503,
    2.51328, 0.19667, 1.60986, -0.88035, 0.93436, 1.73095, 3.99893, -1.58709, -6.90567,
    2.15374, 1.58778, 2.80202, -7.2765, -0.22549, -6.8847, -3.80168, 0.26042, 4.1003,
    4.48299, -7.8344, 3.60549, 3.49499, -8.10192, -20.90433, -11.9778, 5.56181, -11.19773,
];
let mut result = f64::NAN;
let mpt = MPTCalculator::from_v_b(&data, &bmk_data);
let err = mpt.down_number_ratio(&mut result);
assert_eq!(
    err == Errors::ClErrorCodeNoError && MPTCalculator::is_eq_double(result, 0.93750),
    true
);
Source

pub fn up_down_percent( &self, cmp_fn: fn(f64, f64) -> bool, up_percent_result: &mut f64, ) -> Errors

Source

pub fn up_percent(&self, up_percent_result: &mut f64) -> Errors

calculate the up percent value of an array if the array has NAN/INF values,the result will be NAN.

§Arguments

freq: the frequence of source data

is_annu: the flag of annualize.

§Examples
use mpt_lib::MPTCalculator;
use mpt_lib::enums::{self, Errors};
let data = vec![
    -1.22072, -0.0668, 2.20588, -0.91563, -0.76766, -1.21429, 3.43456, 4.99825, 3.89481,
    1.59564, 0.86793, 2.41477, -1.80305, 0.6709, 3.57769, 4.77481, -0.37317, -3.52713,
    1.88831, 1.73502, 1.20155, -3.36542, -2.03551, -5.6145, -2.71663, -0.04815, 3.99807,
    1.66744, -9.68658, -0.46681, 4.22095, -6.7, -15.27331, -8.46123, 0.76369, -10.32347,
];
let bmk_data = vec![
    -0.34902, 4.72157, -0.07781, -5.69315, 0.50715, -3.32714, 2.85004, 0.70329, 5.68503,
    2.51328, 0.19667, 1.60986, -0.88035, 0.93436, 1.73095, 3.99893, -1.58709, -6.90567,
    2.15374, 1.58778, 2.80202, -7.2765, -0.22549, -6.8847, -3.80168, 0.26042, 4.1003,
    4.48299, -7.8344, 3.60549, 3.49499, -8.10192, -20.90433, -11.9778, 5.56181, -11.19773,
];
let mut result = f64::NAN;
let mpt = MPTCalculator::from_v_b(&data, &bmk_data);
let err = mpt.up_percent(&mut result);
assert_eq!(
    err == Errors::ClErrorCodeNoError && MPTCalculator::is_eq_double(result, 0.40000),
    true
);
Source

pub fn down_percent(&self, up_percent_result: &mut f64) -> Errors

calculate the down percent value of an array if the array has NAN/INF values,the result will be NAN.

§Arguments

freq: the frequence of source data

is_annu: the flag of annualize.

§Examples
use mpt_lib::MPTCalculator;
use mpt_lib::enums::{self, Errors};
let data = vec![
    -1.22072, -0.0668, 2.20588, -0.91563, -0.76766, -1.21429, 3.43456, 4.99825, 3.89481,
    1.59564, 0.86793, 2.41477, -1.80305, 0.6709, 3.57769, 4.77481, -0.37317, -3.52713,
    1.88831, 1.73502, 1.20155, -3.36542, -2.03551, -5.6145, -2.71663, -0.04815, 3.99807,
    1.66744, -9.68658, -0.46681, 4.22095, -6.7, -15.27331, -8.46123, 0.76369, -10.32347,
];
let bmk_data = vec![
    -0.34902, 4.72157, -0.07781, -5.69315, 0.50715, -3.32714, 2.85004, 0.70329, 5.68503,
    2.51328, 0.19667, 1.60986, -0.88035, 0.93436, 1.73095, 3.99893, -1.58709, -6.90567,
    2.15374, 1.58778, 2.80202, -7.2765, -0.22549, -6.8847, -3.80168, 0.26042, 4.1003,
    4.48299, -7.8344, 3.60549, 3.49499, -8.10192, -20.90433, -11.9778, 5.56181, -11.19773,
];
let mut result = f64::NAN;
let mpt = MPTCalculator::from_v_b(&data, &bmk_data);
let err = mpt.down_percent(&mut result);
assert_eq!(
    err == Errors::ClErrorCodeNoError && MPTCalculator::is_eq_double(result, 0.75000),
    true
);
Source

pub fn m_squared( &self, freq: ClFrequency, is_annu: bool, m_squared_res: &mut f64, ) -> Errors

calculate the m_squared value of an array if the array has NAN/INF values,the result will be NAN.

§Arguments

freq: the frequence of source data

is_annu: the flag of annualize.

§Examples
use mpt_lib::MPTCalculator;
use mpt_lib::enums::{self, Errors};
let data = vec![
    2.4037, 1.1276, 2.9127, 2.5981, -0.5162, 2.8709, -1.6506, 0.8281, 4.8182, 4.0484,
    -0.4246, -1.8230, 1.1619, 6.2151, 5.3158, -3.7904, 0.3500, -8.9486, -1.6029, -2.1879,
    6.5159, 3.0498, -8.3762, -3.9341, -0.0780, -17.9807, -21.5895, -11.3292, 4.8884,
    -7.5447, -7.5943, 13.9102, 13.6679, 6.2313, -1.3755, 8.7637,
];
let bmk_data = vec![
    2.3793, 2.5770, 3.2586, 1.9016, 1.4028, 1.5123, -1.9559, 1.1185, 4.4295, 3.4895,
    -1.6613, -3.1005, 1.4990, 3.7399, 1.5907, -4.1807, -0.6938, -5.9982, -3.2486, -0.4318,
    4.8703, 1.2953, -8.4304, -0.8406, 1.4465, -8.9107, -16.7948, -7.1755, 1.0640, -8.4286,
    -10.6478, 8.7595, 9.5709, 5.5933, 0.1984, 7.5637,
];
let rf_data = vec![
    0.4355, 0.4211, 0.4274, 0.4328, 0.4235, 0.4340, 0.4394, 0.4356, 0.4274, 0.4178, 0.4058,
    0.4238, 0.4125, 0.3500, 0.3462, 0.3069, 0.2679, 0.2483, 0.1916, 0.1187, 0.1135, 0.1477,
    0.1636, 0.1443, 0.1541, 0.1197, 0.0669, 0.0254, 0.0031, 0.0105, 0.0265, 0.0213, 0.0145,
    0.0160, 0.0149, 0.0162,
];
let mut res = 0.0;
let mpt = MPTCalculator::from(&data, &bmk_data, &rf_data);
let err = mpt.m_squared(enums::ClFrequency::ClFrequencyMonthly, true, &mut res);
assert_eq!(
    err == Errors::ClErrorCodeNoError && MPTCalculator::is_eq_double(res, -1.60415),
    true
);
Source

pub fn market_risk(&self, market_risk_res: &mut f64) -> Errors

calculate the market risk value of an array if the array has NAN/INF values,the result will be NAN.

§Arguments

freq: the frequence of source data

is_annu: the flag of annualize.

§Examples
use mpt_lib::MPTCalculator;
use mpt_lib::enums::{self, Errors};
let data = vec![
    -3.64603, 8.80598, -1.4281, -10.48221, -2.80462, 2.98743, -12.2534, -13.75641,
    -3.99425, 14.01812, -6.33636, -8.40185,
];
let bmk_data = vec![
    -5.444254163,
    7.678667961,
    -0.037850949,
    -9.800858913,
    -3.001103688,
    2.626641337,
    -12.56062862,
    -11.84056062,
    1.146646578,
    15.55676217,
    -7.580194297,
    -8.479793853,
];
let mut result = f64::NAN;
let mpt = MPTCalculator::from_v_b(&data, &bmk_data);
let err = mpt.market_risk(&mut result);
assert_eq!(
    err == Errors::ClErrorCodeNoError && MPTCalculator::is_eq_double(result, 6.47447029),
    true
);
Source

pub fn stock_risk(&self, stock_risk_res: &mut f64) -> Errors

calculate the stock risk value of an array if the array has NAN/INF values,the result will be NAN.

§Arguments

freq: the frequence of source data

is_annu: the flag of annualize.

§Examples
use mpt_lib::MPTCalculator;
use mpt_lib::enums::{self, Errors};
let data = vec![
    -3.64603, 8.80598, -1.4281, -10.48221, -2.80462, 2.98743, -12.2534, -13.75641,
    -3.99425, 14.01812, -6.33636, -8.40185,
];
let bmk_data = vec![
    -5.444254163,
    7.678667961,
    -0.037850949,
    -9.800858913,
    -3.001103688,
    2.626641337,
    -12.56062862,
    -11.84056062,
    1.146646578,
    15.55676217,
    -7.580194297,
    -8.479793853,
];
let mut result = f64::NAN;
let mpt = MPTCalculator::from_v_b(&data, &bmk_data);
let err = mpt.stock_risk(&mut result);
assert_eq!(
    err == Errors::ClErrorCodeNoError && MPTCalculator::is_eq_double(result, 3.182966438),
    true
);
Source

pub fn covariance(&self, covariance: &mut f64) -> Errors

calculate the stock risk value of an array if the array has NAN/INF values,the result will be NAN.

§Arguments

freq: the frequence of source data

is_annu: the flag of annualize.

§Examples
use mpt_lib::MPTCalculator;
use mpt_lib::enums::{self, Errors};
let data = vec![
    -1.22072, -0.0668, 2.20588, -0.91563, -0.76766, -1.21429, 3.43456, 4.99825, 3.89481,
    1.59564, 0.86793, 2.41477, -1.80305, 0.6709, 3.57769, 4.77481, -0.37317, -3.52713,
    1.88831, 1.73502, 1.20155, -3.36542, -2.03551, -5.6145, -2.71663, -0.04815, 3.99807,
    1.66744, -9.68658, -0.46681, 4.22095, -6.7, -15.27331, -8.46123, 0.76369, -10.32347,
];
let bmk_data = vec![
    0.27133, 1.24475, 1.34278, -2.87814, 0.13557, 0.61685, 2.37931, 2.577, 3.25861, 1.9016,
    1.40278, 1.51232, -1.95588, 1.1185, 4.42953, 3.48951, -1.66133, -3.10048, 1.49901,
    3.73988, 1.59068, -4.18066, -0.69376, -5.99816, -3.24858, -0.4318, 4.87031, 1.29526,
    -8.43036, -0.84062, 1.44647, -8.91073, -16.79479, -7.17546, 1.06403, -8.42864,
];
let mut res = 0.0;
let mpt = MPTCalculator::from_v_b(&data, &bmk_data);
let err = mpt.covariance(&mut res);
assert_eq!(
    err == Errors::ClErrorCodeNoError && MPTCalculator::is_eq_double(res, 20.2720342),
    true
);

Auto Trait Implementations§

§

impl<'a> Freeze for MPTCalculator<'a>

§

impl<'a> RefUnwindSafe for MPTCalculator<'a>

§

impl<'a> Send for MPTCalculator<'a>

§

impl<'a> Sync for MPTCalculator<'a>

§

impl<'a> Unpin for MPTCalculator<'a>

§

impl<'a> UnwindSafe for MPTCalculator<'a>

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> 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, 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.