All Functions
PerformanceAnalytics.AssetPrice
— MethodAssetPrice(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
PerformanceAnalytics.AssetReturn
— MethodAssetReturn(x::AssetPrice)
Calculates the return from the price series of the AssetPrice and returns a AssetReturn.
PerformanceAnalytics.AssetReturn
— MethodAssetReturn(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
Base.values
— MethodBase.values(x::AssetPrice)
Returns a vector of prices of the asset.
Base.values
— MethodBase.values(x::AssetReturn)
Returns a vector of returns of the asset.
PerformanceAnalytics.activepremium
— Methodactivepremium(Ra::AssetReturn, Rb::AssetReturn)
Is defined as the annualized return minus the annualized benchmark return.
PerformanceAnalytics.activepremium
— Methodactivepremium(Ra::Number, Rb::Number; scalea=1, scaleb=1)
Is defined as the annualized return minus the annualized benchmark return.
PerformanceAnalytics.adjustedsharpe
— FunctionAdjustedSharp(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"
PerformanceAnalytics.adjustedsharpe
— FunctionAdjustedSharp(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"
PerformanceAnalytics.adjustedsharpe
— Functionadjustedsharpe(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]\]
PerformanceAnalytics.annualize
— Functionannualize(R::Number,scale::Float64=252)
Annualizes the return using the scaling factor.
PerformanceAnalytics.annualize
— Methodannualize(R::AssetReturn)
Annualizes the return.
PerformanceAnalytics.appraisalratio
— Functionappraisalratio(Ra::AssetReturn,Rb::AssetReturn,Rf::Number=0;method::AbstractString = "appraisal")
Jensen's Alpha adjusted for risk.
PerformanceAnalytics.appraisalratio
— Functionappraisalratio(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}\]
PerformanceAnalytics.avgdrawdown
— Methodavgdrawdown(x::AbstractArray{<:Number})
Returns the average drowdown for a return series.
PerformanceAnalytics.avgdrawdown
— Methodavgdrawdown(x::AssetReturn)
Returns the average drowdown for a return series.
PerformanceAnalytics.bernardoledoitratio
— Methodbernardoledoitratio(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)}\]
PerformanceAnalytics.bernardoledoitratio
— Methodbernardoledoitratio(R::AssetReturn)
Calculates the Bernardo Ledoit ratio for a AssetReturn.
PerformanceAnalytics.burkeratio
— Methodburkeratio(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)
PerformanceAnalytics.burkeratio
— Methodburkeratio(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)
PerformanceAnalytics.burkeratio
— Methodburkeratio(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}}\]
PerformanceAnalytics.calmarratio
— Functioncalmarratio(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}\]
PerformanceAnalytics.calmarratio
— Methodcalmarratio(R::AssetReturn)
Risk return metric. Gives the annualized return divided by the maximum drawdown.
PerformanceAnalytics.cokurt
— Methodcokurt(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}}\]
PerformanceAnalytics.cokurt
— Methodcokurt(Ra::AssetReturn,Rb::AssetReturn)
Calculates the symmetric CoKurtosis of two returns (i.e. Cokurt(Ra,Ra,Rb,Rb))
PerformanceAnalytics.coskew
— Methodcoskew(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}}\]
PerformanceAnalytics.coskew
— Methodcoskew(Ra::AssetReturn,Rb::AssetReturn)
Calculates the CoSkewness of returns.
PerformanceAnalytics.covariance
— Methodcovariance(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}\]
PerformanceAnalytics.covariance
— Methodcovariance(Ra::AssetReturn,Rb::AssetReturn;corrected::Bool=false)
Calculates the CoVariance of two asset returns.
PerformanceAnalytics.downsidedeviation
— Functiondownsidedeviation(R::AssetReturn,MAR::Number = 0)
Calculates the downside deviation of a return series. MAR = Minimum Acceptable Returns
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}}}\]
PerformanceAnalytics.downsidepotential
— FunctionDonwsidePotential(R::AbstractArray{<:Number}, MAR::Number=0)
Calculates the downside potential of a return series. MAR = Minimum Acceptable Returns
PerformanceAnalytics.drawdown
— Methoddrawdown(x::AbstractArray{<:Number})
Is the drawdown of each return from the last peak. Is the same length as the return series provided.
PerformanceAnalytics.drawdown
— Methoddrawdown(x::AssetReturn)
Is the drawdown of each return from the last peak.
PerformanceAnalytics.drawdown_table
— Methoddrawdown_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.
PerformanceAnalytics.drawdown_table
— Methoddrawdown_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.drawdownpeak
— Methoddrawdownpeak(x::AbstractArray{<:Number})
Calculates the cumulative drawdown since the last peak for each return in the time series.
PerformanceAnalytics.drawdownpeak
— Methoddrawdownpeak(x::AssetReturn)
Calculates the cumulative drawdown since the last peak for each return in the time series.
PerformanceAnalytics.expectedshortfall
— Functionexpectedshortfall(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
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}\]
PerformanceAnalytics.factor_alpha
— Methodfactor_alpha(Y::AbstractArray{<:Number},X::AbstractArray{<:Number}...)
Returns the α (intercept) of a (factor) regression.
PerformanceAnalytics.factor_loadings
— Methodfactor_loadings(Y::AbstractArray{<:Number},X::AbstractArray{<:Number}...;intercept::Bool=true)
Returns the factor loadings (beta estimates) of a (factor) regression.
PerformanceAnalytics.factor_regression
— Methodfactor_regression(Y::AbstractArray{<:Number},X::AbstractArray{<:Number}...;intercept::Bool=true)
Returns alpha and beta estimates of a regression.
PerformanceAnalytics.factor_resid
— Methodfactor_resid(Y::AbstractArray{<:Number},X::AbstractArray{<:Number}...;intercept::Bool=true)
Returns the residuals of a (factor) regression.
PerformanceAnalytics.hurstindex
— Methodhurstindex(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)}\]
PerformanceAnalytics.hurstindex
— Methodhurstindex(R::AssetReturn)
Measures whether returns are random, peristent, or mean reverting.
PerformanceAnalytics.id
— Methodid(x::AssetPrice)
Returns the id (ticker) of the asset.
PerformanceAnalytics.id
— Methodid(x::AssetReturn)
Returns the id (ticker) of the asset.
PerformanceAnalytics.informationratio
— Methodinformationratio(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}}}}\]
PerformanceAnalytics.informationratio
— Methodinformationratio(Ra::AssetReturn,Rb::AssetReturn)
Calculates the Information Ratio. It is defined as the Active Premium over the Tracking Error.
PerformanceAnalytics.jensensalpha
— Methodjensensalpha(Y::AbstractArray{<:Number},X::AbstractArray{<:Number}...;scale::Number=1)
Returns the annualized Jensens Alpha.
Arguments
Y
the assets returnX
the benchmark returnscale
the scaling number used to annualize returns (defaults to 1)
PerformanceAnalytics.jensensalpha
— Methodjensensalpha(Y::AssetReturn,X::AssetReturn...)
Returns the annualized Jensens Alpha.
PerformanceAnalytics.kappa
— Functionkappa(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}}\]
PerformanceAnalytics.kappa
— Functionkappa(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
PerformanceAnalytics.kurt
— Functionkurt(R, method="simple")
Calculates the kurtosis of a series.
Methods:
- population
- excess (population - 3)
- sample
- sampleexcess (sample - 3)
- fisher
PerformanceAnalytics.log_diff
— Methodlog_diff(x)
Returns the logarithmic difference. (Calculates log returns from a price series)
PerformanceAnalytics.maxdrawdown
— Methodmaxdrawdown(x::AbstractArray{<:Number})
Calculates the maximum drawdow for a return series.
PerformanceAnalytics.maxdrawdown
— Methodmaxdrawdown(x::AssetReturn)
Calculates the maximum drawdow for a return series.
PerformanceAnalytics.mean_arith
— Methodmean_arith(x)
Calculates the arithmetic mean of a series.
PerformanceAnalytics.mean_geo
— Methodmean_geo(returns::Vector{Float64})
Calculates the geometric mean of a series.
PerformanceAnalytics.mean_geo_log
— Methodmean_geo_log(returns::Vector{Float64})
Calculates the geometric mean of a series.
PerformanceAnalytics.painindex
— Methodpainindex(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}\]
PerformanceAnalytics.painindex
— Methodpainindex(R::AssetReturn)
Calculates the Pain Index.
PerformanceAnalytics.pct_change
— Methodpct_change(x)
Returns the percent change of an array. (Calculates returns from a price series)
PerformanceAnalytics.roll_apply
— Methodroll_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 withfill_with
.fill_with
: The value that should be returned for values that could not be calculated.always_return::Bool
: returns a vector withfill_with
equal to the initial data length if the window is longer than the length of the input data.
PerformanceAnalytics.scale
— Methodscale(x::AssetPrice)
Returns the scaling number for the asset. Used to for annualization.
PerformanceAnalytics.scale
— Methodscale(x::AssetReturn)
Returns the scaling number for the asset. Used to for annualization.
PerformanceAnalytics.semideviation
— Methodsemideviation((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}}}\]
PerformanceAnalytics.semideviation
— Methodsemideviation(R::AssetReturn)
Calculates the semi deviation of a Asset Return.
PerformanceAnalytics.semivariance
— Methodsemivariance(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}}\]
PerformanceAnalytics.semivariance
— Methodsemivariance(R::AbstractArray{<:Number})
Calculates the semi variance of a AssetReturn.
PerformanceAnalytics.sharperatio
— Functionsharperatio(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}\]
PerformanceAnalytics.sharperatio
— Functionsharperatio(R::AbstractArray{<:Number},Rf::Number=0.;scale)
Calculates the Sharpe Ratio from a given return series and a risk free rate.
PerformanceAnalytics.sharperatio
— Functionsharperatio(R::AssetReturn,Rf::Number=0.)
Calculates the annualized Sharpe Ratio.
PerformanceAnalytics.simple_diff
— Methodsimple_diff(x)
Returns the difference. (Calculates the absolut price change)
PerformanceAnalytics.skew
— Functionskew(R, method="simple")
Calculates the skewness of a series.
Methods:
- Population
- Sample
- Fisher
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))\]
PerformanceAnalytics.specificrisk
— Functionspecificrisk(Ra::AssetReturn,Rb::AssetReturn,Rf::Number=0)
The spicific risk is calculated as the standard deviation of the residuals from a factor regression.
PerformanceAnalytics.stdvp
— Methodstdvp(x)
Calculates the sample variance of a series.
PerformanceAnalytics.stdvs
— Methodstdvs(x)
Calculates the sample standard deviation of a series.
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)\]
PerformanceAnalytics.systematicrisk
— Functionsystematicrisk(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.timestamp
— Methodtimestamp(x::AssetPrice)
Returns a vector of the timestamps of the asset.
PerformanceAnalytics.timestamp
— Methodtimestamp(x::AssetReturn)
Returns a vector of the timestamps of the asset.
PerformanceAnalytics.to_annual_return
— Methodto_annual_return(R::AssetReturn)
Generates a new AssetReturn on a annual frequency. This uses calendar time i.e. start of year to end of calendar year.
PerformanceAnalytics.to_monthly_return
— Methodto_monthly_return(R::AssetReturn)
Generates a new AssetReturn on a monthly frequency. This uses calendar time i.e. start of calendar month to end of calendar month.
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}\]
PerformanceAnalytics.totalrisk
— Functiontotalrisk(Ra::AssetReturn,Rb::AssetReturn,Rf::Number=0)
Total risk is defined as a combination of systematic and specific risk.
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}}\]
PerformanceAnalytics.trackingerror
— Methodtrackingerror(Ra::AssetReturn,Rb::AssetReturn)
Measures how well a return tracks its benchmark.
PerformanceAnalytics.treynorratio
— Functiontreynorratio(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)}\]
PerformanceAnalytics.treynorratio
— Functiontreynorratio(Ra::AssetReturn,Rb::AssetReturn,Rf::Number=0;modified::Bool=false)
Calculates the Treynor Ratio.
PerformanceAnalytics.valueatrisk
— Functionvalueatrisk(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.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)\]
PerformanceAnalytics.varp
— Methodvarp(x)
Calculates the population variance of a series.
PerformanceAnalytics.vars
— Methodvars(x)
Calculates the population standard deviation of a series.