Expected returns
PortfolioOptimisers.ExpectedReturn — Type
struct ExpectedReturn{__T_settings, __T_rt} <: NonOptimisationRiskMeasureRisk measure whose value is the expected portfolio return of a prior result.
ExpectedReturn is a NonOptimisationRiskMeasure, so an optimiser cannot use it as an objective or as a constraint. Use it where a function takes a risk measure and the figure must be the expected return. For example, it is the default y axis of plot_measures and of plot_efficient_frontier. A larger value is a better value, as PerfRM states.
Mathematical definition
\[\begin{align} \mathrm{ER}(\boldsymbol{w}) &= \sum_{j \,:\, e_{j}} s_j\, R_j(\boldsymbol{w})\,. \end{align}\]
Where:
- $\mathrm{ER}(\boldsymbol{w})$: Expected portfolio return, the value of the measure.
- $\boldsymbol{w}$: Portfolio weights vector $N \times 1$.
- $R_j$: Expected return of the $j$-th term in
rt, net offees. - $s_j$:
settings.scaleof the $j$-th term. A singlerthas one term. - $e_j$:
settings.rteof the $j$-th term. The sum runs over the terms whose flag istrue.
Fields
settings: Risk measure settings.
rt: Return estimator, or a vector of them. The measure sums a vector at thesettings.scaleweights of its terms, and it skips a term whosesettings.rteisfalse. The return axis has no scalariser.
Constructors
ExpectedReturn(; settings::HierarchicalRiskMeasureSettings = HierarchicalRiskMeasureSettings(), rt::JRE_VecJRE = ArithmeticReturn()) -> ExpectedReturnKeywords correspond to the struct's fields.
Multiplicity
rt takes one return term or a vector of them, so ExpectedReturn(; rt = res.ret) works after a solve with many terms. The measure sums a vector at the settings.scale weights of its terms, and it skips a term whose settings.rte is false.
The type has no scalariser. The return axis sums and never scalarises.
Validation
- If
rtis a vector:!isempty(rt).
Propagated parameters
factory passes its arguments on to these @fprop fields:
rt: Recursively updated throughfactory.
Examples
julia> ExpectedReturn()ExpectedReturn settings ┼ HierarchicalRiskMeasureSettings │ scale ┴ Float64: 1.0 rt ┼ ArithmeticReturn │ settings ┼ JuMPReturnsSettings │ │ scale ┼ Float64: 1.0 │ │ lb ┼ nothing │ │ rte ┼ Bool: true │ │ fee ┼ Bool: true │ │ mic ┴ Bool: true │ ucs ┼ nothing │ mu ┼ nothing │ mtx_sqrt ┴ EigenFallbackSquareRoot()Related
PortfolioOptimisers.ExpectedReturnRiskRatio — Type
struct ExpectedReturnRiskRatio{__T_settings, __T_rt, __T_rk, __T_sca, __T_rf} <: NonOptimisationRiskMeasureRisk measure whose value is the ratio of the expected return of a portfolio to its expected risk.
ExpectedReturnRiskRatio holds a return estimator, a risk measure and a risk-free rate. Its value is the risk-adjusted return ratio of expected_ratio, for example the Sharpe ratio when rk is a StandardDeviation. It is a NonOptimisationRiskMeasure, so an optimiser cannot use it as an objective or as a constraint. A larger value is a better value, as PerfRM states.
Mathematical definition
\[\begin{align} \mathrm{ERRR}(\boldsymbol{w}) &= \frac{\sum_{j \,:\, e_{j}} s_j\, R_j(\boldsymbol{w}) - r_f}{\mathrm{sca}\left(\left\{c_i\, \rho_i(\boldsymbol{w})\right\}\right)}\,. \end{align}\]
Where:
- $\mathrm{ERRR}(\boldsymbol{w})$: Expected return to risk ratio.
- $\boldsymbol{w}$: Portfolio weights vector $N \times 1$.
- $R_j$: Expected return of the $j$-th term in
rt, net offees. - $s_j$:
settings.scaleof the $j$-th term ofrt. - $e_j$:
settings.rteof the $j$-th term ofrt. The sum runs over the terms whose flag istrue. - $r_f$: Risk-free rate, the
rffield. - $\rho_i$: The $i$-th risk measure in
rk. - $c_i$:
settings.scaleof the $i$-th risk measure. - $\mathrm{sca}$: Scalariser held in
sca, which reduces the risk axis to one number.
Fields
settings: Risk measure settings.
rt: Return estimator, or a vector of them. The measure sums a vector at thesettings.scaleweights of its terms, and it skips a term whosesettings.rteisfalse. The return axis has no scalariser.
rk: Risk measure for ratio computation, or a vector of them scalarised bysca.
sca: Scalariser combining the risk measures inrkinto one number.nothinggives the sum ofSumScalariser. Inert whenrkholds a single measure. The field beats ascakeyword supplied at the call site.
rf: Risk-free rate.
Constructors
ExpectedReturnRiskRatio(; settings::HierarchicalRiskMeasureSettings = HierarchicalRiskMeasureSettings(), rt::JRE_VecJRE = ArithmeticReturn(), rk::BaseRM_VecBaseRM = Variance(), sca::Option{<:Scalariser} = nothing, rf::Number = 0.0,) -> ExpectedReturnRiskRatioKeywords correspond to the struct's fields.
Multiplicity
Each axis takes one item or a vector of items, and only the risk axis has a scalariser. rt sums its terms at their settings.scale weights, and it skips a term whose settings.rte is false. sca scalarises rk into one number. Then the ratio divides one aggregate by the other. The return axis sums and never scalarises.
The field takes precedence over a sca keyword of the caller. A sca that the caller gives at the call site goes no further than this type. So the figure of an ExpectedReturnRiskRatio is always the figure that the type names.
Validation
- If
rtis a vector:!isempty(rt). - If
rkis a vector:!isempty(rk). isfinite(rf).
Propagated parameters
factory passes its arguments on to these @fprop fields:
Examples
julia> ExpectedReturnRiskRatio()ExpectedReturnRiskRatio settings ┼ HierarchicalRiskMeasureSettings │ scale ┴ Float64: 1.0 rt ┼ ArithmeticReturn │ settings ┼ JuMPReturnsSettings │ │ scale ┼ Float64: 1.0 │ │ lb ┼ nothing │ │ rte ┼ Bool: true │ │ fee ┼ Bool: true │ │ mic ┴ Bool: true │ ucs ┼ nothing │ mu ┼ nothing │ mtx_sqrt ┴ EigenFallbackSquareRoot() rk ┼ Variance │ settings ┼ RiskMeasureSettings │ │ scale ┼ Float64: 1.0 │ │ ub ┼ nothing │ │ rke ┴ Bool: true │ sigma ┼ nothing │ chol ┼ nothing │ rc ┼ nothing │ alg ┼ SquaredSOCRiskExpr() │ mtx_sqrt ┼ EigenFallbackSquareRoot() │ ratio_alg ┼ SquareRootRatio() │ corner ┴ nothing sca ┼ nothing rf ┴ Float64: 0.0Related
PortfolioOptimisers.expected_risk — Function
expected_risk(r::ExpectedReturn, w::VecNum, pr::AbstractPriorResult,
fees::Option{<:Fees} = nothing; kwargs...)Compute the value of an ExpectedReturn, the expected return of a portfolio.
The method calls expected_return on the rt field of the measure. ExpectedReturn states the closed form.
The measure also has a route on a returns matrix. It declares WeightsReturnsFeesInput, and its functor r(w, X, fees) calls resolved_expected_return on rt. That route needs the mu of an rt that factory resolved, and the prior route of risk_contribution, risk_gradient and of each composite measure gives it. Both routes read one ladder, so they give the same value.
Arguments
r:ExpectedReturnthat holds a return estimator.w: Portfolio weights.pr: Prior result.fees: Optional transaction fees.kwargs...: Keyword arguments that go toexpected_return,strictincluded.
Returns
risk::Number: Expected portfolio return, net offeeswhen they are given.
Related
PortfolioOptimisers.expected_risk — Function
expected_risk(r::ExpectedReturnRiskRatio, w::VecNum, pr::AbstractPriorResult,
fees::Option{<:Fees} = nothing; kwargs...)Compute the value of an ExpectedReturnRiskRatio, the risk-adjusted return ratio of a portfolio.
The method calls expected_ratio with the fields of the measure. ExpectedReturnRiskRatio states the closed form.
The call puts kwargs... first and the sca and rf fields of the measure after it. So the fields take precedence over a sca or an rf that the caller gives at the call site. The figure of an ExpectedReturnRiskRatio is always the figure that the type names.
The measure is also a composite on a returns matrix, as MeanReturnRiskRatio is. Its methods of expected_risk, worst_case_distribution and linearised_risk on X::MatNum divide resolved_expected_return of rt, minus rf, by the risk of rk. They need an rt that factory resolved, and the prior route of risk_contribution, risk_gradient and of each composite measure gives it. A weight path, w::MatNum, throws an ArgumentError.
Arguments
r:ExpectedReturnRiskRatiothat holds a return estimator, a risk measure and a risk-free rate.w: Portfolio weights.pr: Prior result.fees: Optional transaction fees.kwargs...: Keyword arguments that go toexpected_ratio,strictincluded. Ascaor anrfamong them has no effect.
Returns
risk::Number: Risk-adjusted return ratio.
Related
PortfolioOptimisers.expected_risk — Method
expected_risk(::Option{<:Scalariser}, r::PrRM,
pred::PredictionResult{<:PredictionReturnsResult{<:Any, <:VecNum}};
kwargs...)
expected_risk(::Option{<:Scalariser}, r::PrRM,
pred::PredictionResult{<:PredictionReturnsResult{<:Any, <:VecVecNum}};
kwargs...)
expected_risk(::Option{<:Scalariser}, r::PrRM, pred::MultiPeriodPredictionResult; kwargs...)
expected_risk(::Option{<:Scalariser}, r::PrRM, pred::PopulationPredictionResult; kwargs...)Refuse to compute a risk measure that reads a prior on a prediction result.
A PrRM reads a prior result. It multiplies the expected returns of the prior by the weights. A prediction result holds a realised return series and no expected returns, so the two measures have nothing to read. Each of the four methods raises an error, and none gives a figure from the wrong input.
The four methods are positional forms, which take the scalariser first and ignore it. The keyword form expected_risk(r, pred; kwargs...) of a prediction calls them, so both forms raise the error.
The caller has two routes:
- To measure the realised series, use
MeanReturnorMeanReturnRiskRatioasaltin place of the measure, and callexpected_risk(alt, pred). - To measure the prior, call
expected_risk(r, w, pr)with the weights and the prior result. Theexpected_riskmethods for anExpectedReturnand for anExpectedReturnRiskRatiodocument that route.
Arguments
::Option{<:Scalariser}: The scalariser of the call, which none of the four methods reads.r:ExpectedReturnorExpectedReturnRiskRatio.pred: The prediction result that the caller gave.kwargs...: Keyword arguments that none of the four methods reads.
Validation
- Every method raises an
ArgumentError, with the message thatprrm_prediction_messagebuilds. No method returns for any input.
Related
PrRMprrm_prediction_message: It builds the message of the error.MeanReturn: The replacement for anExpectedReturn.MeanReturnRiskRatio: The replacement for anExpectedReturnRiskRatio.PredictionResultMultiPeriodPredictionResultPopulationPredictionResult
PortfolioOptimisers.expected_return — Function
expected_return(ret::ArithmeticReturn, w::VecNum, pr::AbstractPriorResult,
fees::Option{<:Fees} = nothing; strict::Bool = false, kwargs...)
expected_return(ret::LogarithmicReturn, w::VecNum, pr::AbstractPriorResult,
fees::Option{<:Fees} = nothing; strict::Bool = false, kwargs...)
expected_return(ret::NoReturn, w::VecNum, pr::AbstractPriorResult,
fees::Option{<:Fees} = nothing; kwargs...)
expected_return(ret::JRE_VecJRE, w::VecVecNum, pr::AbstractPriorResult,
fees::Option{<:Fees} = nothing; strict::Bool = false, kwargs...)Compute the expected return of a portfolio with a return estimator.
expected_return reads the portfolio weights, a prior result and optional transaction fees. fees is a positional argument after pr on every method.
The prior route reduces to the Investable Mask. A prior result holds every asset of the universe, and an asset that it cannot estimate carries NaN in mu and down its column of pr.X. On the whole universe, dot(w, mu) and X * w are NaN at every weight, a zero weight included. So each method reduces the prior, the weights and the fees once at its entry, through investable_reduction. An optimiser does the same reduction at its entry. NoReturn gives zero at every weight, so it reads nothing and reduces nothing.
The reduction changes nothing on a prior that is already reduced. The moments of a reduced prior are finite everywhere, so investable_mask gives nothing. Thus a vector of terms, a population and a composite such as expected_ratio each give one diagnostic only.
Each method is the scalar twin of the ret expression that set_return_constraints! builds for the same estimator, so the two sides charge the same fee. For a NoReturn, the model builds a zero expression and charges no fee on it. settings.fee has no effect on that term, and the scalar twin charges no fee either.
An ArithmeticReturn whose ucs holds a fitted set gives the worst-case return over the set, ucs_expected_return, in place of $\boldsymbol{w}^{\intercal} \boldsymbol{\mu}$. The model expression of that term is the worst case, so a lower bound on the term holds at w exactly when this value meets it. An estimator in ucs gives the nominal return, because no set exists until an optimiser fits it. The functor of UncertaintySetVariance reads its set by the same rule. The resolved return terms of an optimisation, in the ret of its ResolvedJuMPOptimiser, hold the fitted sets.
The fourth method takes a vector of weight vectors. It applies one of the first three methods to each weight vector, and returns one expected return for each.
Mathematical definition
\[\begin{align} R_{\mathrm{a}}(\boldsymbol{w}) &= \boldsymbol{w}^{\intercal} \boldsymbol{\mu} - F(\boldsymbol{w})\\ R_{\mathrm{l}}(\boldsymbol{w}) &= \dfrac{\sum\limits_{t=1}^{T} v_{t} \ln\left(1 + \boldsymbol{x}_{t}^{\intercal} \boldsymbol{w}\right)}{\sum\limits_{t=1}^{T} v_{t}} - F(\boldsymbol{w})\\ R_{\mathrm{n}}(\boldsymbol{w}) &= 0\,. \end{align}\]
Where:
- $R_{\mathrm{a}}(\boldsymbol{w})$: Expected return of an
ArithmeticReturn. - $R_{\mathrm{l}}(\boldsymbol{w})$: Expected return of a
LogarithmicReturn, the mean log-growth rate of the portfolio. - $R_{\mathrm{n}}(\boldsymbol{w})$: Expected return of a
NoReturn. It has no fee term, so it is zero for every value offees. - $\boldsymbol{w}$: Portfolio weights vector $N \times 1$.
- $\boldsymbol{\mu}$: Expected returns vector $N \times 1$.
- $\boldsymbol{x}_t$: Asset returns for observation $t$, the $t$-th row of the returns matrix.
- $T$: Number of observations.
- $v_{t}$: Observation weight of observation $t$, the $t$-th entry of the
wfield of aLogarithmicReturn, or of the observation weightspr.wof the prior when that field isnothing. Every weight is one when both arenothing, and the quotient is then the unweighted mean. - $F(\boldsymbol{w})$: Fee term of
term_fees. It iscalc_feesofwandfeeswhen the term'ssettings.feeistrue, and zero otherwise.
Arguments
ret: Return estimator, or a vector of them on the fourth method.w: Portfolio weights, or a vector of portfolio weight vectors on the fourth method.pr: Prior result. It resolves a Deferred Quantity ofret, throughfactory. It givesmuto anArithmeticReturnwhose ownmuisnothing, and its observation weights to aLogarithmicReturnwhose ownwisnothing.fees: Optional fees.strict: Iftrue, weights that hold an asset outside the Investable Mask raise anArgumentErrorthat names the assets. Iffalse, a warning names the assets, and the function drops their weights. ANoReturnreads no weights, sostricthas no effect on it.kwargs...: Keyword arguments that the methods do not read.
Returns
rt::Number: Expected portfolio return, net of fees, on the first three methods.rt::VecNum: One expected portfolio return for each weight vector, on the fourth method.
Related
ArithmeticReturnLogarithmicReturnNoReturnJuMPReturnsEstimatorJRE_VecJREAbstractPriorResultVecNumVecVecNumNum_VecNumOptionexpected_ratioexpected_risk_ret_ratioexpected_sricexpected_risk_ret_sricterm_fees: It charges $F(\boldsymbol{w})$, and it holds the rule that decides when to charge it.calc_fees
expected_return(
ret::AbstractVector{<:JuMPReturnsEstimator},
w::AbstractVector{<:Union{Number, AbstractJuMPScalar}},
pr::AbstractPriorResult;
...
) -> Any
expected_return(
ret::AbstractVector{<:JuMPReturnsEstimator},
w::AbstractVector{<:Union{Number, AbstractJuMPScalar}},
pr::AbstractPriorResult,
fees::Union{Nothing, Fees};
strict,
kwargs...
) -> Any
Sum the value-level returns of many return terms, each at its own scale.
This method is the scalar twin of the ret expression of the model, which is the same weighted sum over the same terms. The method skips a term whose settings.rte is false, and the model skips it too.
The barrier of NearOptimalCentering reads the aggregate return of all the terms as one number, and this method gives that number. expected_ratio and the other value-level functions of this file call this method when ret is a vector.
Mathematical definition
\[\begin{align} R(\boldsymbol{w}) &= \sum_{j \,:\, e_{j}} s_{j} \, R_{j}(\boldsymbol{w})\,. \end{align}\]
Where:
- $R(\boldsymbol{w})$: Aggregate expected return of the whole vector of terms.
- $\boldsymbol{w}$: Portfolio weights vector $N \times 1$.
- $R_{j}(\boldsymbol{w})$: Expected return of the $j$-th term, net of its own fee.
- $s_{j}$:
settings.scaleof the $j$-th term. - $e_{j}$:
settings.rteof the $j$-th term. The sum runs over the terms whose flag istrue.
Algorithm
- Reduce the prior, the weights and the fees to the Investable Mask once, with
investable_reduction. A held asset outside the mask gives one diagnostic, and not one for each term. - Resolve each term against the prior with
factory, as the model does. - Return
resolved_expected_returnof the resolved terms. It skips each term whosesettings.rteisfalse, and it sums thesettings.scaleof each other term times its return. The method for one term reads the same function, so the two give the same value.
Arguments
ret: Vector of return estimators.w: Portfolio weights.pr: Prior result.fees: Optional fees.strict: Iftrue, weights that hold an asset outside the Investable Mask raise anArgumentErrorthat names the assets. Iffalse, a warning names the assets, and the function drops their weights.kwargs...: Keyword arguments that the method does not read.
Returns
rt::Number: Aggregate expected portfolio return of the terms whosesettings.rteistrue.
Related
PortfolioOptimisers.expected_ratio — Function
expected_ratio(r::BaseRM_VecBaseRM, ret::JRE_VecJRE, w::VecNum,
pr::AbstractPriorResult, fees::Option{<:Fees} = nothing;
rf::Number = 0, sca::Option{<:Scalariser} = nothing,
strict::Bool = false, kwargs...)Compute the ratio of the expected return of a portfolio to its expected risk.
expected_ratio divides the expected portfolio return, net of the fees and of the risk-free rate, by the expected portfolio risk. The risk measure r gives the risk, and the return estimator ret gives the return.
Mathematical definition
\[\begin{align} \mathrm{ratio}(\boldsymbol{w}) &= \dfrac{R(\boldsymbol{w}) - r_{f}}{\mathrm{sca}\left(\left\{c_{i}\, \rho_{i}(\boldsymbol{w})\right\}\right)}\,. \end{align}\]
Where:
- $\mathrm{ratio}(\boldsymbol{w})$: Risk-adjusted return ratio.
- $\boldsymbol{w}$: Portfolio weights vector $N \times 1$.
- $R(\boldsymbol{w})$: Aggregate expected return of
ret, the sum of its terms at their ownsettings.scaleweights, each net offees. - $r_{f}$: Risk-free rate, the
rfkeyword. - $\rho_{i}$: The $i$-th risk measure in
r. - $c_{i}$:
settings.scaleof the $i$-th risk measure. - $\mathrm{sca}$: Scalariser held in
sca, which reduces the risk axis to one number.
Multiplicity
Each axis takes one item or a vector of items, and the ratio divides one aggregate by the other. sca scalarises the risk axis into one number. The return axis sums at the settings.scale weights of its terms. Then the function divides the two aggregates.
Only the risk axis has a scalariser. The return axis sums and never scalarises.
Resolution
Both axes receive pr itself, so both apply the same precedence rule. A stated slot comes first, then the estimator of the slot, then the field of the prior. The risk axis goes through the prior route of expected_risk. That route resolves the measure through resolve_risk_inputs once for each call. It fits a Deferred Quantity against pr, and an unstated slot takes the field of the prior.
Arguments
r: Risk measure, or a vector of them.ret: Return estimator, or a vector of them.w: Portfolio weights.pr: Prior result.fees: Optional transaction fees.rf: Risk-free rate.sca: Scalariser that reduces a vectorrto one number. It has no effect on a single measure.strict: Iftrue, weights that hold an asset outside the Investable Mask raise anArgumentErrorthat names the assets. Iffalse, a warning names the assets, and the function drops their weights.kwargs...: Keyword arguments that go toexpected_riskand toexpected_return.
Returns
ratio::Number: Risk-adjusted return ratio.
Related
PortfolioOptimisers.expected_risk_ret_ratio — Function
expected_risk_ret_ratio(r::BaseRM_VecBaseRM, ret::JRE_VecJRE, w::VecNum,
pr::AbstractPriorResult, fees::Option{<:Fees} = nothing;
rf::Number = 0, sca::Option{<:Scalariser} = nothing,
strict::Bool = false, kwargs...)Compute the expected risk, the expected return and the risk-adjusted return ratio of a portfolio.
expected_risk_ret_ratio returns the three numbers as a tuple. The risk measure r gives the risk, and the return estimator ret gives the return.
Mathematical definition
\[\begin{align} \mathrm{risk}(\boldsymbol{w}) &= \mathrm{sca}\left(\left\{c_{i}\, \rho_{i}(\boldsymbol{w})\right\}\right)\\ \mathrm{return}(\boldsymbol{w}) &= R(\boldsymbol{w})\\ \mathrm{ratio}(\boldsymbol{w}) &= \dfrac{\mathrm{return}(\boldsymbol{w}) - r_{f}}{\mathrm{risk}(\boldsymbol{w})}\,. \end{align}\]
Where:
- $\mathrm{risk}(\boldsymbol{w})$, $\mathrm{return}(\boldsymbol{w})$, $\mathrm{ratio}(\boldsymbol{w})$: The three entries of the returned tuple, in that order.
- $\boldsymbol{w}$: Portfolio weights vector $N \times 1$.
- $R(\boldsymbol{w})$: Aggregate expected return of
ret, the sum of its terms at their ownsettings.scaleweights, each net offees. - $r_{f}$: Risk-free rate, the
rfkeyword. - $\rho_{i}$: The $i$-th risk measure in
r. - $c_{i}$:
settings.scaleof the $i$-th risk measure. - $\mathrm{sca}$: Scalariser held in
sca, which reduces the risk axis to one number.
Multiplicity
The rule is the same as for expected_ratio. Each axis takes one item or a vector of items, and the ratio divides one aggregate by the other. sca scalarises the risk axis into one number, and the return axis sums at the settings.scale weights of its terms. The returned risk and return are those two aggregates. They are never a breakdown for each item.
Only the risk axis has a scalariser. The return axis sums and never scalarises.
The figures of an optimisation result
Use this function to get the figures of an optimisation result. A result holds the measure and the scalariser of its solve, so the call can read them from the result:
rk, rt, rr = expected_risk_ret_ratio(res.r, res.ret, res.w, res.pr; sca = res.sca, rf = rf)A result stores res.r and res.ret resolved. So this call gives the aggregates that the optimisation optimised, for one item or for many items on each axis. A caller can also name the measures by hand. Then the figure is equal to that of the optimisation only when the caller names the same measures and the same scalariser. The same holds for fees and rf.
A NonRiskJuMPOptimisationResult has no r, because its solve resolved no measure. With such a result, the caller must name a measure.
Arguments
r: Risk measure, or a vector of them.ret: Return estimator, or a vector of them.w: Portfolio weights.pr: Prior result.fees: Optional transaction fees.rf: Risk-free rate.sca: Scalariser that reduces a vectorrto one number. It has no effect on a single measure.strict: Iftrue, weights that hold an asset outside the Investable Mask raise anArgumentErrorthat names the assets. Iffalse, a warning names the assets, and the function drops their weights.kwargs...: Keyword arguments that go toexpected_riskand toexpected_return.
Returns
risk::Number: Expected portfolio risk.return::Number: Expected portfolio return.ratio::Number: Risk-adjusted return ratio.
Related
PortfolioOptimisers.expected_sric — Function
expected_sric(r::BaseRM_VecBaseRM, ret::JRE_VecJRE, w::VecNum,
pr::AbstractPriorResult, fees::Option{<:Fees} = nothing;
rf::Number = 0, sca::Option{<:Scalariser} = nothing,
strict::Bool = false, kwargs...)Compute the Sharpe ratio information criterion (SRIC) of a portfolio.
The SRIC corrects the risk-adjusted return ratio for the estimation error of an optimisation, which makes the in-sample ratio too large. expected_sric subtracts from the ratio a penalty that reads the number of assets and the number of observations.
Mathematical definition
\[\begin{align} \mathrm{SRIC}(\boldsymbol{w}) &= \mathrm{ratio}(\boldsymbol{w}) - P\left(\mathrm{ratio}(\boldsymbol{w})\right)\,. \end{align}\]
Where:
- $\mathrm{SRIC}(\boldsymbol{w})$: Sharpe ratio information criterion.
- $\boldsymbol{w}$: Portfolio weights vector $N \times 1$.
- $\mathrm{ratio}(\boldsymbol{w})$: Risk-adjusted return ratio of
expected_ratio, which states its own closed form. - $P$: Estimation-error penalty of
sric_penalty, which states its own closed form.
Multiplicity
The function penalises the ratio of expected_ratio, so the rule is the same as for that function. The ratio divides one aggregate by the other. sca scalarises the risk axis, and the return axis sums at the settings.scale weights of its terms. The function subtracts the penalty once from the scalar ratio, and not from each item.
Arguments
r: Risk measure, or a vector of them.ret: Return estimator, or a vector of them.w: Portfolio weights.pr: Prior result.fees: Optional transaction fees.rf: Risk-free rate.sca: Scalariser that reduces a vectorrto one number. It has no effect on a single measure.strict: Iftrue, weights that hold an asset outside the Investable Mask raise anArgumentErrorthat names the assets. Iffalse, a warning names the assets, and the function drops their weights. The reduction also sets the number of assets of the penalty to the number of assets that the prior can estimate.kwargs...: Keyword arguments that go toexpected_ratio.
Returns
sric::Number: Sharpe ratio information criterion.
Related
PortfolioOptimisers.expected_risk_ret_sric — Function
expected_risk_ret_sric(r::BaseRM_VecBaseRM, ret::JRE_VecJRE, w::VecNum,
pr::AbstractPriorResult, fees::Option{<:Fees} = nothing;
rf::Number = 0, sca::Option{<:Scalariser} = nothing,
strict::Bool = false, kwargs...)Compute the expected risk, the expected return and the SRIC of a portfolio.
expected_risk_ret_sric returns the three numbers as a tuple. The Sharpe ratio information criterion (SRIC) corrects the risk-adjusted return ratio for estimation error, as expected_sric states.
Mathematical definition
\[\begin{align} \mathrm{SRIC}(\boldsymbol{w}) &= \mathrm{ratio}(\boldsymbol{w}) - P\left(\mathrm{ratio}(\boldsymbol{w})\right)\,. \end{align}\]
Where:
- $\mathrm{SRIC}(\boldsymbol{w})$: Sharpe ratio information criterion, the third entry of the returned tuple. The first two entries are those of
expected_risk_ret_ratio, which states their closed forms. - $\boldsymbol{w}$: Portfolio weights vector $N \times 1$.
- $\mathrm{ratio}(\boldsymbol{w})$: Risk-adjusted return ratio of
expected_risk_ret_ratio. - $P$: Estimation-error penalty of
sric_penalty, which states its own closed form.
Multiplicity
The tuple is the tuple of expected_risk_ret_ratio, with the penalty subtracted from its third entry. So the rule is the same as for that function, and the ratio divides one aggregate by the other. The returned risk and return are the two aggregates, and never a breakdown for each item. The function subtracts the penalty once from the scalar ratio.
Arguments
r: Risk measure, or a vector of them.ret: Return estimator, or a vector of them.w: Portfolio weights.pr: Prior result. Its returns matrixXgives the two counts of the penalty.fees: Optional transaction fees.rf: Risk-free rate. It defaults to0.sca: Scalariser that reduces a vectorrto one number. It has no effect on a single measure.strict: Iftrue, weights that hold an asset outside the Investable Mask raise anArgumentErrorthat names the assets. Iffalse, a warning names the assets, and the function drops their weights.kwargs...: Keyword arguments that go toexpected_risk_ret_ratio.
Returns
risk::Number: Expected portfolio risk.return::Number: Expected portfolio return.sric::Number: Sharpe ratio information criterion.
Related
PortfolioOptimisers.factory — Method
factory(a, args...; kwargs...) -> a
factory(a::AbstractArray{<:Union{Nothing, AbstractEstimator, AbstractAlgorithm,
AbstractResult, StatsBase.CovarianceEstimator}},
args...; kwargs...) -> AbstractArrayRebuild an estimator, an algorithm or a result with runtime values. These two methods are the leaf and the array step of the traversal.
factory and port_opt_view are the two propagation mechanisms of this library. factory passes runtime values, such as prior moments, observation weights and previous portfolio weights, down a tree of composed structs. port_opt_view passes an index selection, a subset of the assets, down the same tree.
factory is a traversal, so it owns the identity on every leaf, as fmap in Functors.jl and adapt_structure in Adapt.jl do. A value that has no method of its own comes back with no change: a data field, a scalar, nothing, a set of observation weights and a covariance estimator of StatsBase. So a @propagatable struct sends each @fprop field to factory directly, whatever the field holds.
The array method is the one forwarding contract for every propagation field that holds an array of estimators, algorithms, results or covariance estimators. It applies factory to each element, and it forwards args... and kwargs... with no change. A family that accepts an array of them needs no method of its own. A family that needs more than the forward defines its own, more specific method. A concrete element type, through concrete_typed_array_if_abstract, is an example. An array of data, such as a vector of numbers, is a leaf, and it comes back with no change and with no copy.
Algorithm
The leaf method:
- Return
awith no change, and dropargs...andkwargs.... This method is the leaf of the recursion. Because of it, a call of the verb on a type with no tags returns the value and raises no error.
The array method:
- For each element
aiofa, callfactoryonai, and forwardargs...andkwargs...with no change. - Collect the results into a new array of the shape of
a, in the order ofa, and return it.
A @propagatable struct always has a generated method that is more specific than the leaf method. If the struct has at least one @fprop or @wprop field, that method builds the struct again with its keyword constructor. It sends each @fprop field through factory and each @wprop field through _wprop. If the struct has no such field, that method returns x.
The leaf method does not fill a nothing field. A weights field that must take the incoming weights when it holds nothing carries @wprop, and it goes to _wprop.
Arguments
a: Any value, which the leaf method returns with no change. For the array method, an array of estimators, algorithms, results, covariance estimators ornothing, which it rebuilds one element at a time.args...: Positional arguments. The leaf method ignores them, and the array method forwards them.kwargs...: Keyword arguments. The leaf method ignores them, and the array method forwards them.
Returns
a: The input with no change, for the leaf method.v::AbstractArray: The rebuilt elements, in an array of the shape ofa, for the array method.
Examples
julia> factory(nothing, 1, 2; x = 3)julia> factory([1.0, 2.0], 1, 2; x = 3)2-element Vector{Float64}: 1.0 2.0julia> factory(MeanValue())MeanValue w ┴ nothingRelated
PortfolioOptimisers.factory — Method
factory(a, args...; kwargs...) -> a
factory(a::AbstractArray{<:Union{Nothing, AbstractEstimator, AbstractAlgorithm,
AbstractResult, StatsBase.CovarianceEstimator}},
args...; kwargs...) -> AbstractArrayRebuild an estimator, an algorithm or a result with runtime values. These two methods are the leaf and the array step of the traversal.
factory and port_opt_view are the two propagation mechanisms of this library. factory passes runtime values, such as prior moments, observation weights and previous portfolio weights, down a tree of composed structs. port_opt_view passes an index selection, a subset of the assets, down the same tree.
factory is a traversal, so it owns the identity on every leaf, as fmap in Functors.jl and adapt_structure in Adapt.jl do. A value that has no method of its own comes back with no change: a data field, a scalar, nothing, a set of observation weights and a covariance estimator of StatsBase. So a @propagatable struct sends each @fprop field to factory directly, whatever the field holds.
The array method is the one forwarding contract for every propagation field that holds an array of estimators, algorithms, results or covariance estimators. It applies factory to each element, and it forwards args... and kwargs... with no change. A family that accepts an array of them needs no method of its own. A family that needs more than the forward defines its own, more specific method. A concrete element type, through concrete_typed_array_if_abstract, is an example. An array of data, such as a vector of numbers, is a leaf, and it comes back with no change and with no copy.
Algorithm
The leaf method:
- Return
awith no change, and dropargs...andkwargs.... This method is the leaf of the recursion. Because of it, a call of the verb on a type with no tags returns the value and raises no error.
The array method:
- For each element
aiofa, callfactoryonai, and forwardargs...andkwargs...with no change. - Collect the results into a new array of the shape of
a, in the order ofa, and return it.
A @propagatable struct always has a generated method that is more specific than the leaf method. If the struct has at least one @fprop or @wprop field, that method builds the struct again with its keyword constructor. It sends each @fprop field through factory and each @wprop field through _wprop. If the struct has no such field, that method returns x.
The leaf method does not fill a nothing field. A weights field that must take the incoming weights when it holds nothing carries @wprop, and it goes to _wprop.
Arguments
a: Any value, which the leaf method returns with no change. For the array method, an array of estimators, algorithms, results, covariance estimators ornothing, which it rebuilds one element at a time.args...: Positional arguments. The leaf method ignores them, and the array method forwards them.kwargs...: Keyword arguments. The leaf method ignores them, and the array method forwards them.
Returns
a: The input with no change, for the leaf method.v::AbstractArray: The rebuilt elements, in an array of the shape ofa, for the array method.
Examples
julia> factory(nothing, 1, 2; x = 3)julia> factory([1.0, 2.0], 1, 2; x = 3)2-element Vector{Float64}: 1.0 2.0julia> factory(MeanValue())MeanValue w ┴ nothingRelated
PortfolioOptimisers.needs_previous_weights — Method
needs_previous_weights(r::AbstractBaseRiskMeasure) -> Bool
needs_previous_weights(r::VecBaseRM) -> BoolReturn whether risk measure r requires previous portfolio weights as input.
The default returns false. Override to true for risk measures such as turnover or tracking constraints that depend on prior weights. The VecBaseRM overload returns true if any element returns true.
Returns
Bool:trueif prior weights are required;falseotherwise.
Related
needs_previous_weights(x::Any) -> Bool
needs_previous_weights(x::AbstractVector) -> BoolReturn true if an entry of a TimeDependent vector reads the weights of the previous fold.
A turnover, a fee, a tracking input, a risk measure, a budget cost, an optimisation estimator or result, a constraint and a nested schedule each give their own method. A vector gives true if any of its elements does. Every other value, such as a number or a bare function, gives false, because no code can find out what a bare function reads.
Related
needs_previous_weights(
_::Union{Nothing, AbstractAlgorithm, AbstractEstimator, AbstractResult}
) -> Any
Returns false, the fallback for nothing and for every estimator, algorithm and result that has no method of its own.
A type whose value reads the weights of the previous fold adds a method that returns true, for example a turnover, a tracking error or a fee.
Related
PortfolioOptimisers.supports_precomputed_returns — Method
supports_precomputed_returns(
_::Union{ExpectedReturn, ExpectedReturnRiskRatio}
) -> Bool
Return false, because a PrRM does not support precomputed returns.
Both members read the portfolio weights and the prior through their return estimator: an ArithmeticReturn multiplies the expected returns of the prior by the weights, and a LogarithmicReturn weights each observation by the observation weights of the prior and charges the fee of the weights once, after the mean. A bare series of net returns holds neither the prior nor the weights. So neither type defines r(x::VecNum), and expected_risk_from_returns refuses both with a message that names the cause.
To score a bare return series, use MeanReturn or MeanReturnRiskRatio. prrm_prediction_message names the same replacement for a prediction result.
Related
PrRMsupports_precomputed_returnsMeanReturn: TheNetReturnsInputmeasure that scores a bare series.expected_risk_from_returns: The entry of the contract that this predicate controls.