Risk Measures
Standard Risk Metrics
PerformanceAnalytics.specificrisk
— Functionspecificrisk(Ra::AbstractArray{<:Number},Rb::AbstractArray{<:Number},Rf::Number=0)
The spicific risk is calculated as the standard deviation of the residuals from a factor regression.
\[SpecificRisk = std(\epsilon_t) = std((r_{a,t} -r_f) - \alpha - \beta\times(r_{b,t}-r_f))\]
specificrisk(Ra::AssetReturn,Rb::AssetReturn,Rf::Number=0)
The spicific risk is calculated as the standard deviation of the residuals from a factor regression.
PerformanceAnalytics.systematicrisk
— Functionsystematicrisk(Ra::AbstractArray{<:Number},Rb::AbstractArray{<:Number},Rf::Number=0)
Is the systematic risk of the return. It is calculated by multipling the factor loading from a linear factor model of the return against the benchmark return by the standard deviation of the benchmark return.
\[SystematicRisk = \beta_{r_a,r_b}\times std(R_b)\]
systematicrisk(Ra::AssetReturn,Rb::AssetReturn,Rf::Number=0)
Calculated by multipling the factor loading from a linear factor model of the return against the benchmark return by the standard deviation of the benchmark return.
PerformanceAnalytics.totalrisk
— Functiontotalrisk(Ra::AbstractArray{<:Number},Rb::AbstractArray{<:Number},Rf::Number=0)
Total risk is defined as a combination of systematic and specific risk.
\[TotalRisk = \sqrt{SystematicRisk^2+SpecificRisk^2}\]
totalrisk(Ra::AssetReturn,Rb::AssetReturn,Rf::Number=0)
Total risk is defined as a combination of systematic and specific risk.
Drawdown Metrics
PerformanceAnalytics.drawdown
— Functiondrawdown(x::AbstractArray{<:Number})
Is the drawdown of each return from the last peak. Is the same length as the return series provided.
drawdown(x::AssetReturn)
Is the drawdown of each return from the last peak.
PerformanceAnalytics.maxdrawdown
— Functionmaxdrawdown(x::AbstractArray{<:Number})
Calculates the maximum drawdow for a return series.
maxdrawdown(x::AssetReturn)
Calculates the maximum drawdow for a return series.
PerformanceAnalytics.avgdrawdown
— Functionavgdrawdown(x::AbstractArray{<:Number})
Returns the average drowdown for a return series.
avgdrawdown(x::AssetReturn)
Returns the average drowdown for a return series.
PerformanceAnalytics.drawdown_table
— Functiondrawdown_table(x::AbstractArray{<:Number},dates::AbstractArray{<:TimeType})
Returns a matrix of drawdowns sorted by depth. The second column returns the depth of the drawdown. The 3rd, 4th, and 5th columns return the start, deepest point, and final date of the drawdown. The last column returns the length of the drawdown from the start to the end.
drawdown_table(x::AssetReturn)
Returns a matrix of drawdowns sorted by depth. The second column returns the depth of the drawdown. The 3rd, 4th, and 5th columns return the start, deepest point, and final date of the drawdown. The last column returns the length of the drawdown from the start to the end.
PerformanceAnalytics.painindex
— Functionpainindex(R::AbstractArray{<:Number})
Mean value of drawdowns over entire period.
\[PainIndex = \sum_{t=1}^n \frac{|D_t|}{n}\text{ where }D_t\text{ is the drawdown at time t since the last peak}\]
painindex(R::AssetReturn)
Calculates the Pain Index.
Downside Risk Metrics
PerformanceAnalytics.downsidedeviation
— Functiondownsidedeviation(R::AbstractArray{<:Number},MAR::Number = 0)
Calculates the downside deviation of a return series. MAR = Minimum Acceptable Returns
\[DownsideDeviation = \sqrt{\sum_{t=1}^n{\frac{min[(r_t-MAR),0]^2}{n}}}\]
downsidedeviation(R::AssetReturn,MAR::Number = 0)
Calculates the downside deviation of a return series. MAR = Minimum Acceptable Returns
PerformanceAnalytics.downsidepotential
— FunctionDonwsidePotential(R::AbstractArray{<:Number}, MAR::Number=0)
Calculates the downside potential of a return series. MAR = Minimum Acceptable Returns
PerformanceAnalytics.semideviation
— Functionsemideviation((R::AbstractArray{<:Number})
Calculates the semi deviation of a return series. This is equal to the downside deviation where the MAR is set to the arithmetic mean of the return series.
\[SemiDeviation = \sqrt{\sum_{t=1}^n{\frac{min[(r_t-\overline{r}),0]^2}{n}}}\]
semideviation(R::AssetReturn)
Calculates the semi deviation of a Asset Return.
PerformanceAnalytics.semivariance
— Functionsemivariance(R::AbstractArray{<:Number})
Calculates the semi variance of a return series. This is equal to the square of the semi deviation.
\[SemiVariance = SemiDeviation^2 = \sum_{t=1}^n{\frac{min[(r_t-\overline{r}),0]^2}{n}}\]
semivariance(R::AbstractArray{<:Number})
Calculates the semi variance of a AssetReturn.
VaR & ES
PerformanceAnalytics.valueatrisk
— Functionvalueatrisk(R::AbstractArray{<:Number},p::Number,method::AbstractString="gaussian")
Calculates the Value at Risk (VaR) for a return series and a probility level p
Methods:
- gaussian (Default)
- historical
- cornish_fisher
Gaussian:
\[VaR_p = = \overline{r} + \sigma*\Phi^{-1}(p)\]
valueatrisk(R::AssetReturn,p::Number,method::AbstractString="gaussian")
Calculates the Value at Risk (VaR) for a return series and a probility level p
Methods:
- gaussian (Default)
- historical
- cornish_fisher
PerformanceAnalytics.expectedshortfall
— Functionexpectedshortfall(R::AbstractArray{<:Number},p::Number,method::AbstractString="gaussian")
Calculates the Expected Shortfall for a return series and a probility level p
Methods:
- gaussian (Default)
- historical
- cornish_fisher
Gaussian:
\[ExpectedShortfall_p = \overline{r} + \sigma*\frac{\phi(\Phi^{-1}(p))}{1-p} \text{ where }\Phi^{-1}\text{ is the inverse of the normal CDF (quantile) and }\phi\text{ is the pdf or the standard normal}\]
expectedshortfall(R::AssetReturn,p::Number,method::AbstractString="gaussian")
Calculates the Expected Shortfall for a return series and a probility level p
Methods:
- gaussian (Default)
- historical
- cornish_fisher
Other
PerformanceAnalytics.trackingerror
— Functiontrackingerror(Ra::AbstractArray{<:Number},Rb::AbstractArray{<:Number},scale::Number=1)
Measures how well a return tracks its benchmark.
\[TrackingError(r_a,r_b) = \sqrt{\sum_{t=1}^n\frac{(r_{a,t} -r_{b,t})^2}{n}}\]
trackingerror(Ra::AssetReturn,Rb::AssetReturn)
Measures how well a return tracks its benchmark.