Skip to content
6

Net returns and drawdowns

Net returns and drawdowns are two of the performance metrics of a portfolio. Here we define functions used to compute portfolio returns and related quantities.

PortfolioOptimisers.calc_net_returns Function
julia
calc_net_returns(w::VecNum, X::MatNum, args...)
calc_net_returns(w::VecNum, X::MatNum, fees::Fees)

Compute the net portfolio returns. If fees is provided, it deducts the computed fees from the gross returns.

Returns the portfolio returns as the product of the asset return matrix X and portfolio weights w.

R(X,w)=XwFt(w)

Where:

  • R(X,w): T × 1 vector of portfolio net returns.

  • X: T × N matrix of asset returns (observations × assets).

  • w: N × 1 vector of portfolio weights.

  • Ft(w): Total fees computed using calc_fees.

  • : Elementwise (Hadamard) subtraction.

Arguments

  • w: Portfolio weights.

  • X: Asset return matrix (observations × assets).

  • fees: Fees structure.

  • args...: Additional arguments (ignored).

Returns

  • val::VecNum: Portfolio net returns.

Examples

julia
julia> calc_net_returns([0.5, 0.5], [0.01 0.02; 0.03 0.04])
2-element Vector{Float64}:
 0.015
 0.035

Related

source
PortfolioOptimisers.calc_net_asset_returns Function
julia
calc_net_asset_returns(w::VecNum, X::MatNum, args...)
calc_net_asset_returns(w::VecNum, X::MatNum, fees::Fees)

Compute the per asset net portfolio returns. If fees is provided, it deducts the computed fees from the gross returns.

Returns the per asset portfolio returns as the product of the asset return matrix X and portfolio weights w.

R(X,w)=XwFt(w)

Where:

  • R(X,w): T × N matrix of per asset portfolio net returns.

  • X: T × N matrix of asset returns (observations × assets).

  • w: N × 1 vector of portfolio weights.

  • Ft(w): N × 1 per asset vector of total portfolio fees computed using calc_fees.

  • : Elementwise (Hadamard) multiplication.

  • : Elementwise (Hadamard) subtraction.

Arguments

  • w: Portfolio weights.

  • X: Asset return matrix (assets × periods).

  • fees: Fees structure.

  • args...: Additional arguments (ignored).

Returns

  • ret::MatNum: Per asset portfolio net returns.

Examples

julia
julia> calc_net_asset_returns([0.5, 0.5], [0.01 0.02; 0.03 0.04])
2×2 Matrix{Float64}:
 0.005  0.01
 0.015  0.02

Related

source
PortfolioOptimisers.cumulative_returns Function
julia
cumulative_returns(X::ArrNum, compound::Bool = false; dims::Int = 1)

Compute simple or compounded cumulative returns along a specified dimension.

cumulative_returns computes the cumulative returns for an array of asset or portfolio returns. By default, it computes simple cumulative returns using cumsum. If compound is true, it computes compounded cumulative returns using cumprod(one(eltype(X)) .+ X).

Portfolio cumulative returns

CRa(X)={j[1,T]|CRa,j}CRa,j(X)=i=1jXiCRr(X)={j[1,T]|CRr,j}CRr,j(X)=i=1j(1+Xi)

Where:

  • X: T × 1 vector of portfolio returns.

  • CRa,j(X): Simple cumulative portfolio returns at period j.

  • CRr,j(X): Compound cumulative portfolio returns at period j.

  • CRa: T × 1 vector of simple cumulative portfolio returns.

  • CRr: T × 1 vector of compound cumulative portfolio returns.

Per asset cumulative returns

The same definitions apply as above, but for each individual asset in the returns matrix X instead of the portfolio return Xw.

Arguments

  • X: Array of asset or portfolio returns (vector or matrix).

  • compound: If true, computes compounded cumulative returns; otherwise, computes simple cumulative returns.

  • dims: Dimension along which to compute cumulative returns.

Returns

  • ret::ArrNum: Array of cumulative returns, same shape as X.

Examples

julia
julia> cumulative_returns([0.01, 0.02, -0.01])
3-element Vector{Float64}:
 0.01
 0.03
 0.02

julia> cumulative_returns([0.01, 0.02, -0.01], true)
3-element Vector{Float64}:
 1.01
 1.0302
 1.019898

Related

source
PortfolioOptimisers.drawdowns Function
julia
drawdowns(X::ArrNum, compound::Bool = false; cX::Bool = false, dims::Int = 1)

Compute simple or compounded drawdowns along a specified dimension.

Portfolio drawdowns

DDa(X)={j[1,T]|DDa(X,j)}DDa(X,j)=i=1jXimaxt[1,j](i=1tXi)DDr(X)={j[1,T]|DDr(X,j)}DDr(X,j)=i=1j(1+Xi)maxt[1,j](i=1t(1+Xi))1

Where:

  • DDa(X): T × 1 vector of simple drawdowns.

  • DDa(X,j): Simple drawdown at period j.

  • DDr(X): T × 1 vector of compound drawdowns.

  • DDr(X,j): Compound drawdown at period j.

  • X: T × 1 vector of portfolio returns.

Per asset portfolio drawdowns

The same definitions apply as above, but for each individual asset in the returns matrix X instead of the portfolio return Xw.

Returns

  • dd::ArrNum: Array of drawdowns, same shape as X.

Details

drawdowns computes the drawdowns for an array of asset or portfolio returns. By default, it computes drawdowns from cumulative returns using cumulative_returns. If compound is true, it computes compounded drawdowns. If cX is true, treats X as cumulative returns; otherwise, computes cumulative returns first.

Examples

julia
julia> drawdowns([0.01, 0.02, -0.01])
3-element Vector{Float64}:
  0.0
  0.0
 -0.009999999999999998

julia> drawdowns([0.01, 0.02, -0.01], true)
3-element Vector{Float64}:
  0.0
  0.0
 -0.010000000000000009

Related

source