Risk statistics
Sample volatility and its annualization, semideviation, adjusted skewness and excess kurtosis, and maximum drawdown.
- Model id
foundations.risk_statistics, version 1- Domain
- Foundations
- Evidence
- standard
- Cost class
- instant: A closed-form calculation; a hosted run may take up to 2 seconds.
Formula
Where
- Sample standard deviation of the returns
volatility - The return in period t
returns - Mean return
mean - Number of returns
observations - Volatility for a year
annualized_volatility - Periods in a year
periods_per_year - Semideviation: the deviation of the returns below the mean
below_mean - Downside deviation below the target
below_target - Target return per period
target - Sample skewness
skewness - Sample excess kurtosis
excess_kurtosis - The returns' second central moment; m_3 and m_4 are the third and fourth
- Maximum drawdown
max_drawdown - The value at observation j
values
Each symbol's field is named beside it; the inputs and outputs, with their units and bounds, are under Variables, and the citations give each formula's source.
Variables
Rates, returns and yields are decimals: 0.05 is five percent. Bounds in brackets include their end; in parentheses they exclude it.
Inputs
Sample volatility and its annualization (volatility): 3 inputs
| Name | Unit | Bounds | Description |
|---|---|---|---|
Calculationcalculationtext | text | Sample volatility and its annualization | |
Returnsreturnsreturn (array) · length min 2, max 10080; each [-1, 100] | return (array) | length min 2, max 10080; each [-1, 100] | Periodic returns |
Periods per yearperiods_per_yearperiods · (0, 100000] | periods | (0, 100000] | Periods in a year, such as 12 or 252 |
Downside deviation below the mean and a target (semideviation): 3 inputs
| Name | Unit | Bounds | Description |
|---|---|---|---|
Calculationcalculationtext | text | Downside deviation below the mean and a target | |
Returnsreturnsreturn (array) · length min 2, max 10080; each [-1, 100] | return (array) | length min 2, max 10080; each [-1, 100] | Periodic returns |
Targettargetreturn · [-1, 100] | return | [-1, 100] | Target return per period |
Adjusted skewness (G1) and excess kurtosis (G2) (moments): 2 inputs
| Name | Unit | Bounds | Description |
|---|---|---|---|
Calculationcalculationtext | text | Adjusted skewness (G1) and excess kurtosis (G2) | |
Returnsreturnsreturn (array) · length min 4, max 10080; each [-1, 100] | return (array) | length min 4, max 10080; each [-1, 100] | Periodic returns |
Maximum drawdown with its peak and trough (drawdown): 2 inputs
| Name | Unit | Bounds | Description |
|---|---|---|---|
Calculationcalculationtext | text | Maximum drawdown with its peak and trough | |
Valuesvaluesindex_level (array) · length min 1, max 10080; each (0, 1e+09] | index_level (array) | length min 1, max 10080; each (0, 1e+09] | Values in time order, each above zero |
Outputs
Sample volatility and its annualization (volatility): 5 outputs
| Name | Unit | Bounds | Description |
|---|---|---|---|
Calculationcalculationtext | text | Sample volatility and its annualization | |
Meanmeanreturn · [-1, 100] | return | [-1, 100] | Mean periodic return |
Volatilityvolatilityvolatility · [0, 100] | volatility | [0, 100] | Sample standard deviation of the periodic returns (n - 1) |
Annualized volatilityannualized_volatilityvolatility · [0, 100000] | volatility | [0, 100000] | Volatility times the square root of periods_per_year |
Degrees of freedomdegrees_of_freedomcount · [1, 10080] | count | [1, 10080] | n - 1, the denominator of the variance |
Downside deviation below the mean and a target (semideviation): 3 outputs
| Name | Unit | Bounds | Description |
|---|---|---|---|
Calculationcalculationtext | text | Downside deviation below the mean and a target | |
Below meanbelow_meanvolatility · [0, 150] | volatility | [0, 150] | Semideviation below the sample mean, with n - 1 |
Below targetbelow_targetvolatility · [0, 150] | volatility | [0, 150] | Downside deviation below the target, with n |
Adjusted skewness (G1) and excess kurtosis (G2) (moments): 4 outputs
| Name | Unit | Bounds | Description |
|---|---|---|---|
Calculationcalculationtext | text | Adjusted skewness (G1) and excess kurtosis (G2) | |
Skewnessskewnessratio · [-1000, 1000] | ratio | [-1000, 1000] | Adjusted Fisher-Pearson skewness, G1 |
Excess kurtosisexcess_kurtosisratio · [-100000, 100000] | ratio | [-100000, 100000] | Adjusted excess kurtosis, G2 |
Observationsobservationscount · [4, 10080] | count | [4, 10080] | Number of returns |
Maximum drawdown with its peak and trough (drawdown): 4 outputs
| Name | Unit | Bounds | Description |
|---|---|---|---|
Calculationcalculationtext | text | Maximum drawdown with its peak and trough | |
Max drawdownmax_drawdownreturn · [0, 1] | return | [0, 1] | Largest decline from a peak, as a positive decimal |
Peak indexpeak_indexcount · [0, 10080] | count | [0, 10080] | Position of the peak, from 0 |
Trough indextrough_indexcount · [0, 10080] | count | [0, 10080] | Position of the trough, from 0 |
Calculator
Run the model on your own inputs, starting from its example. Rates are decimals: 0.05 is five percent. The run goes to the pyeconomics API on this site: your values travel only in the request, and nothing is stored.
Loading the calculator…
Worked example
Example monthly_volatility. Inputs:
{
"calculation": "volatility",
"periods_per_year": 12,
"returns": [0.02, -0.01, 0.03, 0.005, -0.02, 0.01]
}Outputs:
{
"annualized_volatility": 0.0642650760522385,
"calculation": "volatility",
"degrees_of_freedom": 5,
"mean": 0.005833333333333334,
"volatility": 0.018551729479125836
}Assumptions
- Returns are decimals over equal periods; annualizing by the square root of the periods in a year assumes they are independent and identically distributed.
- The variance divides by n - 1; the semideviation below the mean by n - 1 and below a given target by n.
- A drawdown is measured on values above zero, in time order.
Limitations
- Skewness and kurtosis are undefined for a series with no spread: DomainError.
- No statistic here corrects for autocorrelation or fat tails.
Evidence
Status: standard. Textbook consensus, such as bond duration or the CAPM formula.
Every model declares one status: standard (textbook consensus), practitioner (a widely used convention), contested (under active debate), rejected (failed out of sample) or historical (a superseded methodology).
Syllabus
The 2027 CFA® Program's topic areas this model relates to, as factual tags. Each links to CFA Institute's page for its level; pyeconomics holds none of the curriculum's text.
Citations
- Joanes, D. N. and Gill, C. A. (1998). Comparing measures of sample skewness and kurtosis. Journal of the Royal Statistical Society: Series D (The Statistician), 47(1), 183-189. doi:10.1111/1467-9884.00122 (Section 2 (the estimators b, g and G))
- Chan, T. F., Golub, G. H. and LeVeque, R. J. (1983). Algorithms for computing the sample variance: analysis and recommendations. The American Statistician, 37(3), 242-247. doi:10.1080/00031305.1983.10483115 (Section 2 (the corrected two-pass algorithm))
- NIST/SEMATECH (2012). e-Handbook of Statistical Methods, section 1.3.5.11, Measures of Skewness and Kurtosis. https://www.itl.nist.gov/div898/handbook/eda/section3/eda35b.htm (Section 1.3.5.11)
- Sortino, F. A. and Price, L. N. (1994). Performance measurement in a downside risk framework. The Journal of Investing, 3(3), 59-64. doi:10.3905/joi.3.3.59 (The downside deviation below a minimum acceptable return)
Changelog
- Version 1: First version.
Use it elsewhere
- Documentation
- The model's reference page
- REST API
GET or POST /v1/models/foundations.risk_statistics/run- MCP tool
run_modelwith the model's id,foundations.risk_statistics. Connect an assistant- Command line
pyeconomics models run foundations.risk_statistics --help
The worked example, from Python and from the command line:
import pyeconomics
inputs = {
"calculation": "volatility",
"periods_per_year": 12,
"returns": [0.02, -0.01, 0.03, 0.005, -0.02, 0.01],
}
result = pyeconomics.run("foundations.risk_statistics", inputs)
print(result.to_json())
pyeconomics models run foundations.risk_statistics --inputs - <<'JSON'
{
"calculation": "volatility",
"periods_per_year": 12,
"returns": [0.02, -0.01, 0.03, 0.005, -0.02, 0.01]
}
JSON