MRFFL: MR Fortran Finance Library 2024-12-28
Computational Tools For Finance
|
Some statstical utilities supporting other MRFFL modules. More...
Functions/Subroutines | |
integer(kind=ik) function, public | rand_int (upper_bound, optional_lower_bound) |
Return random integer in U([optional_lower_bound,upper_bound)) – optional_lower_bound is 0 if missing. | |
real(kind=rk) function, public | rand_real (upper_bound, optional_lower_bound) |
Return random real value in U([optional_lower_bound,upper_bound)) – optional_lower_bound is 0 if missing. | |
real(kind=rk) function, public | resample_tail (data, tail_length) |
Return random value from among the last tail_length elements of data. | |
real(kind=rk) function, public | resample_head (data, head_length) |
Return random value from among the first head_length elements of data. | |
subroutine, public | mean_and_variance (mean, variance, data) |
Return mean & variance of elements in an array. | |
real(kind=rk) function, public | rand_norm_std () |
Return random value from the standard normal distribution. | |
real(kind=rk) function, public | rand_norm_std_box () |
Return random value from the standard normal distribution using the Box-Muller transform. | |
real(kind=rk) function, public | rand_norm_std_probit_clip () |
Return random value from the standard normal distribution in [-5.612, 5.612] using the Probit function. | |
real(kind=rk) function, public | rand_norm_std_probit () |
Return random value from the standard normal distribution using the Probit function. | |
real(kind=rk) function, public | rand_norm (mean, variance) |
Return random value from the specified normal distribution. | |
real(kind=rk) function, public | rand_log_norm (mu, sigma) |
Return random value from the specified log-normal distribution. | |
real(kind=rk) function, public | probit (p) |
Probit function – i.e. | |
real(kind=rk) function | poly_eval (p, x) |
Evaluate a univariate polynomial. | |
subroutine, public | geometric_brownian_motion (step_values, s0, mu, sigma) |
Compute a set of random steps in a GBM process. | |
subroutine, public | zero_clipped_brownian_motion (step_values, s0, mu, sigma) |
Compute a set of random steps in a zero clipped browinan motion. | |
Some statstical utilities supporting other MRFFL modules.
integer(kind=ik) function, public mrffl_stats::rand_int | ( | integer(kind=ik), intent(in) | upper_bound, |
integer(kind=ik), intent(in), optional | optional_lower_bound ) |
Return random integer in U([optional_lower_bound,upper_bound)) – optional_lower_bound is 0 if missing.
upper_bound | Upper bound for random number |
optional_lower_bound | Lower bound for random number |
Definition at line 62 of file mrffl_stats.f90.
References rand_int().
Referenced by mrffl_life_table::rand_age(), rand_int(), resample_head(), and resample_tail().
real(kind=rk) function, public mrffl_stats::rand_real | ( | real(kind=rk), intent(in) | upper_bound, |
real(kind=rk), intent(in), optional | optional_lower_bound ) |
Return random real value in U([optional_lower_bound,upper_bound)) – optional_lower_bound is 0 if missing.
upper_bound | Upper bound for random number |
optional_lower_bound | Lower bound for random number |
Definition at line 82 of file mrffl_stats.f90.
References rand_real().
Referenced by rand_real().
real(kind=rk) function, public mrffl_stats::resample_tail | ( | real(kind=rk), dimension(:), intent(in) | data, |
integer(kind=ik), intent(in) | tail_length ) |
Return random value from among the last tail_length elements of data.
data | The data set – a rank 1 array. |
tail_length | Number of elements to consider for resample. |
Definition at line 102 of file mrffl_stats.f90.
References rand_int(), and resample_tail().
Referenced by mrffl_us_markets::dgs10_resample(), mrffl_us_markets::dow_resample(), mrffl_us_inflation::inf_resample(), mrffl_us_markets::nas_resample(), resample_tail(), mrffl_us_markets::rut_resample(), and mrffl_us_markets::snp_resample().
real(kind=rk) function, public mrffl_stats::resample_head | ( | real(kind=rk), dimension(:), intent(in) | data, |
integer(kind=ik), intent(in) | head_length ) |
Return random value from among the first head_length elements of data.
data | The data set – a rank 1 array. |
head_length | Number of elements to consider for resample. |
Definition at line 119 of file mrffl_stats.f90.
References rand_int(), and resample_head().
Referenced by resample_head().
subroutine, public mrffl_stats::mean_and_variance | ( | real(kind=rk), intent(out) | mean, |
real(kind=rk), intent(out) | variance, | ||
real(kind=rk), dimension(:), intent(in) | data ) |
Return mean & variance of elements in an array.
mean | Holds the mean upon exit. |
variance | Holds the variance (standard deviation squared) upon exit. |
data | The data set – a rank 1 array. |
Definition at line 137 of file mrffl_stats.f90.
real(kind=rk) function, public mrffl_stats::rand_norm_std |
Return random value from the standard normal distribution.
This function simply calls the preferred rand_norm_std_* function. Currently that's rand_norm_std_probit().
Definition at line 150 of file mrffl_stats.f90.
References rand_norm_std(), and rand_norm_std_probit().
Referenced by rand_log_norm(), rand_norm(), and rand_norm_std().
real(kind=rk) function, public mrffl_stats::rand_norm_std_box |
Return random value from the standard normal distribution using the Box-Muller transform.
Reference: Box, G. E. P., and Mervin E. Muller. 1958. "A Note on the Generation of Random Normal Deviates." The Annals of Mathematical Statistics 29 (2): 610-11.
Definition at line 161 of file mrffl_stats.f90.
References rand_norm_std_box().
Referenced by rand_norm_std_box().
real(kind=rk) function, public mrffl_stats::rand_norm_std_probit_clip |
Return random value from the standard normal distribution in [-5.612, 5.612] using the Probit function.
Definition at line 182 of file mrffl_stats.f90.
References probit(), rand_norm_std_probit_clip(), and mrffl_config::zero_epsilon.
Referenced by rand_norm_std_probit_clip().
real(kind=rk) function, public mrffl_stats::rand_norm_std_probit |
Return random value from the standard normal distribution using the Probit function.
Definition at line 197 of file mrffl_stats.f90.
References probit(), and rand_norm_std_probit().
Referenced by rand_norm_std(), and rand_norm_std_probit().
real(kind=rk) function, public mrffl_stats::rand_norm | ( | real(kind=rk), intent(in) | mean, |
real(kind=rk), intent(in) | variance ) |
Return random value from the specified normal distribution.
mean | Mean of the distribution |
variance | Variance (standard deviation squared) of the distribution |
Definition at line 215 of file mrffl_stats.f90.
References rand_norm(), and rand_norm_std().
Referenced by geometric_brownian_motion(), rand_norm(), and zero_clipped_brownian_motion().
real(kind=rk) function, public mrffl_stats::rand_log_norm | ( | real(kind=rk), intent(in) | mu, |
real(kind=rk), intent(in) | sigma ) |
Return random value from the specified log-normal distribution.
\[ \text{mean} = e^\left(\mu+\frac{\sigma^2}{2}\right) \]
\[ \text{median} = e^\mu \]
\[ \text{variance} = \left[e^{\sigma^2}-1\right] e^{2\mu+\sigma^2} \]
mu | Mean of the distribution |
sigma | Standard deviation of the distribution |
Definition at line 231 of file mrffl_stats.f90.
References rand_log_norm(), and rand_norm_std().
Referenced by rand_log_norm().
real(kind=rk) function, public mrffl_stats::probit | ( | real(kind=rk), intent(in) | p | ) |
Probit function – i.e.
inverse of standard normal CDF. Return $z_p$ such that \( P(\mathcal{N}(0, 1)<=z_p) = p \)
Reference: Wichura, Michael J. 1988. "Algorithm AS 241: The Percentage Points of the Normal Distribution." Journal of the Royal Statistical Society. Series C (Applied Statistics) 37 (3): 477-84.
p | Probablity in \( (0,1) \). |
Definition at line 246 of file mrffl_stats.f90.
References poly_eval(), and probit().
Referenced by probit(), rand_norm_std_probit(), and rand_norm_std_probit_clip().
|
private |
Evaluate a univariate polynomial.
Used by probit. Not exported from the module.
The polynomial is ordered in the natural way with the highest coefficient first in the array:
\[ p=\sum_{k=1}^{d+1} p_kx^{1+d-k} \]
Note that $k$ in the above formula is the index in the array p.
p | A $d+1$ element, rank 1 array holding the coefficients of a polynomial |
x | The value at which to evaluate the polynomial |
Definition at line 315 of file mrffl_stats.f90.
References poly_eval().
Referenced by poly_eval(), and probit().
subroutine, public mrffl_stats::geometric_brownian_motion | ( | real(kind=rk), dimension(:), intent(out) | step_values, |
real(kind=rk), intent(in) | s0, | ||
real(kind=rk), intent(in) | mu, | ||
real(kind=rk), intent(in) | sigma ) |
Compute a set of random steps in a GBM process.
s0 | Initial value of an asset |
mu | Mean gain for the assest over 1 unit of time |
sigma | Standard deviation of gain for the assest over 1 unit of time |
step_values | A rank 1 array which will hold the values of the asset over time |
Definition at line 334 of file mrffl_stats.f90.
References rand_norm().
subroutine, public mrffl_stats::zero_clipped_brownian_motion | ( | real(kind=rk), dimension(:), intent(out) | step_values, |
real(kind=rk), intent(in) | s0, | ||
real(kind=rk), intent(in) | mu, | ||
real(kind=rk), intent(in) | sigma ) |
Compute a set of random steps in a zero clipped browinan motion.
s0 | Initial value of an asset |
mu | Mean gain for the assest over 1 unit of time |
sigma | Standard deviation of gain for the assest over 1 unit of time |
step_values | A rank 1 array which will hold the values of the asset over time |
Definition at line 358 of file mrffl_stats.f90.
References rand_norm(), and mrffl_config::zero_epsilon.