All Functions

PerformanceAnalytics.AssetPriceMethod
AssetPrice(ticker::String,from::TimeType,to::TimeType,freq::String;exchange_local_time=true)

Generates a AssetPrice struct using YFinance.jl.

Arguments

  • ticker the Yahoo Finance ticker
  • from a start time/date (either a ::Date or ::DateTime)
  • to a end time/date (either a ::Date or ::DateTime)
  • freq the frequency of data. One of "3mo","1mo","1wk","5d","1d",1h","90m","60m","30m","15m","5m","2m","1m"
  • exchangelocaltime use the local time of the exchange as the timestamp (defaults to true)

Returns

AssetPrice

source
PerformanceAnalytics.AssetReturnMethod
AssetReturn(ticker::String,from::TimeType,to::TimeType,freq::String)

Generates a AssetReturn struct using YFinance.jl. Internally calls AssetPrice and then calculates returns from the price series.

Arguments

  • ticker the Yahoo Finance ticker
  • from a start time/date (either a ::Date or ::DateTime)
  • to a end time/date (either a ::Date or ::DateTime)
  • freq the frequency of data. One of "3mo","1mo","1wk","5d","1d",1h","90m","60m","30m","15m","5m","2m","1m"
  • exchangelocaltime use the local time of the exchange as the timestamp (defaults to true)

Returns

AssetReturn

source
Base.valuesMethod
Base.values(x::AssetPrice)

Returns a vector of prices of the asset.

source
Base.valuesMethod
Base.values(x::AssetReturn)

Returns a vector of returns of the asset.

source
PerformanceAnalytics.adjustedsharpeFunction
AdjustedSharp(R::AbstractArray{<:Number},Rf::Number=0.;method::AbstractString="population")

Calculates the Adjusted Sharpe Ratio from Pezier and White (2006) for a return series.

method: specifies the method to be used in the estimation of the Skewness and Kurtosis. Can be one of sample, population, or fisher. Defaults to "population"

source
PerformanceAnalytics.adjustedsharpeFunction
AdjustedSharp(R::AbstractArray{<:Number},Rf::Number=0.;method::AbstractString="population")

Calculates the annualized Adjusted Sharpe Ratio from Pezier and White (2006) for a AssetReturn.

method: specifies the method to be used in the estimation of the Skewness and Kurtosis. Can be one of sample, population, or fisher. Defaults to "population"

source
PerformanceAnalytics.adjustedsharpeFunction
adjustedsharpe(R::Number,σ::Number,S::Number,K::Number,Rf::Number=0.)

Calculates the Adjusted Sharpe Ratio from Pezier and White (2006) for a preestimated return, standard deviation, skewness, and kurtosis. It adjusts for skewness and kurtosis.

\[AdjSR=SR * [1+\frac{2}{6}*SR - (\frac{K-3}{24})*SR^2]\]

source
PerformanceAnalytics.appraisalratioFunction
appraisalratio(Ra::AbstractArray{<:Number},Rb::AbstractArray{<:Number},Rf::Number=0,method::AbstractString = "appraisal",scale::Number=1)

Jensen's Alpha adjusted for risk. The modified version uses β as the risk measure. The appraisal version uses specific risk. The alternative version uses systematic risk.

\[\frac{\alpha}{risk measure}\]

source
PerformanceAnalytics.bernardoledoitratioMethod
bernardoledoitratio(R::AbstractVector{<:Number})

Calculates the Bernardo Ledoit ratio for a return series.

\[Bernardo Ledoit Ratio = \frac{\frac{1}{n}\sum_{t=1}^{n}max(r_t,0)}{\frac{1}{n}\sum_{t=1}^{n}max(-r_t,0)}\]

source
PerformanceAnalytics.burkeratioMethod
burkeratio(R::AbstractArray{<:Number}; Rf::Float64 = 0., modified::Bool = false, scale::Number=1)

Calculates the Burke Ratio from a return series and a risk free rate.

Arguments

  • Ra is a vector of returns.
  • Rf is a risk free rate
  • modified adjusted for the number of drawdowns (default is false)
  • scale to annualize (default to 1)
source
PerformanceAnalytics.burkeratioMethod
burkeratio(AR::AssetReturn; Rf::Float64 = 0., modified::Bool = false)

Calculates the Burke Ratio from a return series and a risk free rate.

Arguments

  • Ra is a vector of returns.
  • Rf is the risk free rate.
  • modified adjusted for the number of drawdowns (default is false)
source
PerformanceAnalytics.burkeratioMethod
burkeratio(Ra::AbstractArray{<:Number}, Drawdowns::AbstractArray{<:Number};Rf::Number=0.,scale=1)

Calculates the Burke Ratio from a return series, a risk free rate, and drawdowns.

\[BurkeRatio = \frac{r_a-r_f}{\sqrt{\sum_{t=1}^{d}D_t^2}}\]

source
PerformanceAnalytics.calmarratioFunction
calmarratio(R::AbstractArray{<:Number},scale::Float64=1.)

Risk return metric. Gives the annualized return divided by the maximum drawdown. scale is the scaling factor used to annualize returns (defaults tol 1.)

\[CalmarRatio = \frac{r_a}{maxDD}\]

source
PerformanceAnalytics.cokurtMethod
cokurt(Ra::AbstractArray{<:Number},Rb::AbstractArray{<:Number})

Calculates the symmetric CoKurtosis of two returns (i.e. Cokurt(Ra,Ra,Rb,Rb))

\[CoKurtosis(r_a,r_b) = \frac{\frac{1}{n}\times\sum_{t=1}^n[(r_a - \overline{r_a})^2\times(r_b - \overline{r_b})^2]}{\sigma^2_{r_a}\times\sigma^2_{r_b}}\]

source
PerformanceAnalytics.coskewMethod
coskew(Ra::AbstractArray{<:Number},Rb::AbstractArray{<:Number})

Calculates the CoSkewness of returns. Note that coskew(x,y) != coskew(y,x).

\[Coskew(r_a,r_b) = \frac{cov(r_a,(r_b-\overline{r_b})^2)}{\sum_{i=1}^n(r_b - \overline{r_b})^3\times\frac{1}{n}}\]

source
PerformanceAnalytics.covarianceMethod
covariance(Ra::AbstractArray{<:Number},Rb::AbstractArray{<:Number};corrected::Bool=false)

Calculates the CoVariance of two asset returns.

\[CoVariance(R_a,R_b) = \sum_{i=1}^n([R_a - \overline{R_a}] \times [R_b - \overline{R_b}]) \times\frac{1}{n}\]

If corrected=true

\[CoVariance(R_a,R_b) = \sum_{i=1}^n([R_a - \overline{R_a}] \times [R_b - \overline{R_b}]) \times\frac{1}{n-1}\]

source
PerformanceAnalytics.downsidedeviationFunction
downsidedeviation(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}}}\]

source
PerformanceAnalytics.drawdownMethod
drawdown(x::AbstractArray{<:Number})

Is the drawdown of each return from the last peak. Is the same length as the return series provided.

source
PerformanceAnalytics.drawdown_tableMethod
drawdown_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.

source
PerformanceAnalytics.drawdown_tableMethod
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.

source
PerformanceAnalytics.expectedshortfallFunction
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
source
PerformanceAnalytics.expectedshortfallFunction
expectedshortfall(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}\]

source
PerformanceAnalytics.factor_loadingsMethod
factor_loadings(Y::AbstractArray{<:Number},X::AbstractArray{<:Number}...;intercept::Bool=true)

Returns the factor loadings (beta estimates) of a (factor) regression.

source
PerformanceAnalytics.hurstindexMethod
hurstindex(R::AbstractArray{<:Number})

Measures whether returns are random, peristent, or mean reverting.

  • 0 to 0.5: mean reverting
  • 0.5: random
  • 0.5 to 1: persistent

\[HurstIndex = \frac{log(\frac{[max(r) - min(r)]}{\sigma})}{log(n)}\]

source
PerformanceAnalytics.informationratioMethod
informationratio(Ra::AbstractArray{<:Number},Rb::AbstractArray{<:Number},scale::Number=1)

Calculates the Information Ratio. It is defined as the Active Premium over the Tracking Error. The tracking error needs to be annualized therefore it is important to specify the periodecity of the data with scale.

\[InformationRatio(Ra,Rb,scale) = \frac{ActivePremium(r_a,r_b,scale)}{TrackingError(r_a,r_b,scale)} = \frac{(1+\overline{r_a})^{scale}- (1+\overline{r_b})^{scale}}{\sqrt{\sum_{t=1}^n\frac{(r_{a,t} -r_{b,t})^2}{n\times\sqrt{scale}}}}\]

source
PerformanceAnalytics.jensensalphaMethod
jensensalpha(Y::AbstractArray{<:Number},X::AbstractArray{<:Number}...;scale::Number=1)

Returns the annualized Jensens Alpha.

Arguments

  • Y the assets return
  • X the benchmark return
  • scale the scaling number used to annualize returns (defaults to 1)
source
PerformanceAnalytics.kappaFunction
kappa(R::AbstractArray{<:Number},MAR::Number=0.,k::Number=2)

If k=1 this returns the Sharpe-Omega Ratio. If k=2 this returns the Sortino Ratio

\[Kappa = \frac{r-MAR}{\sqrt[k]{\frac{1}{n}*\sum_{t=1}^nmax(MAR - r_t,0)^k}}\]

source
PerformanceAnalytics.kappaFunction
kappa(R::AssetReturn,MAR::Number=0.;k::Number=2)

If k=1 this returns the Sharpe-Omega Ratio. If k=2 this returns the Sortino Ratio

source
PerformanceAnalytics.kurtFunction
kurt(R, method="simple")

Calculates the kurtosis of a series.

Methods:

  • population
  • excess (population - 3)
  • sample
  • sampleexcess (sample - 3)
  • fisher
source
PerformanceAnalytics.painindexMethod
painindex(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}\]

source
PerformanceAnalytics.roll_applyMethod
roll_apply(data::AbstractVector{<:Number}...;fun::Function, window::Int,retain_length::Bool=false,fill_with = NaN,always_return::Bool=false)

Applies a fun::Function over a rolling window.

Arguments:

  • data::AbstractArray{<:Number}: one or multiple arrays.
  • fun::Function: the function to be applied. Has to return a single value (not a Vector of values).
  • window::Int: the window length.
  • retain_length::Bool: whether to original length of the data provided should be retained. If true fills the observations that could not be calculated with fill_with.
  • fill_with: The value that should be returned for values that could not be calculated.
  • always_return::Bool: returns a vector with fill_with equal to the initial data length if the window is longer than the length of the input data.
source
PerformanceAnalytics.semideviationMethod
semideviation((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}}}\]

source
PerformanceAnalytics.semivarianceMethod
semivariance(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}}\]

source
PerformanceAnalytics.sharperatioFunction
sharperatio(R::Number,σ::Number,Rf::Number=0.;scale=1)

Calculates the Sharpe Ratio from a given return, standard deviation, and risk free rate.

\[SR=\frac{r_a - r_f}{\sigma_a}\]

source
PerformanceAnalytics.specificriskFunction
specificrisk(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))\]

source
PerformanceAnalytics.specificriskFunction
specificrisk(Ra::AssetReturn,Rb::AssetReturn,Rf::Number=0)

The spicific risk is calculated as the standard deviation of the residuals from a factor regression.

source
PerformanceAnalytics.systematicriskFunction
systematicrisk(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)\]

source
PerformanceAnalytics.systematicriskFunction
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.

source
PerformanceAnalytics.totalriskFunction
totalrisk(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}\]

source
PerformanceAnalytics.trackingerrorFunction
trackingerror(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}}\]

source
PerformanceAnalytics.treynorratioFunction
treynorratio(Ra::AbstractArray{<:Number},Rb::AbstractArray{<:Number},Rf::Number=0;modified::Bool=false,scale=1)

Scale argument used to annualize all numbers for daily data use 252 (default is 1), for monthly 12, etc.

SharpeRatio that uses beta as risk rather than the assets standard deviation of returns. The modified TreynorRatio uses the systematic risk rather than the beta.

\[TreynorRatio = \frac{\frac{1}{n}\times\sum_{t=1}^n (r_{a,t}-r_{f,t})}{\beta_{r_a,r_b}}\]

\[ModifiedTreynorRatio = \frac{\frac{1}{n}\times\sum_{t=1}^n (r_{a,t}-r_{f,t})}{\beta_{r_a,r_b}\times std(R_b)}\]

source
PerformanceAnalytics.valueatriskFunction
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
source
PerformanceAnalytics.valueatriskFunction
valueatrisk(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)\]

source