apaMeanVariance.Restricted.Bounded.Weights.MSR(ExpectedReturns, Covariances, LowerBounds, UpperBounds, PortfolioExposure, A, b, LowerPickMatrix, LowerValues, UpperPickMatrix, UpperValues, Q, c, DoShowVolRetOtherwiseWeightsOnly)
=apaMeanVariance.Restricted.Bounded.Weights.MSR(ExpectedReturns, Covariances, LowerBounds, UpperBounds, PortfolioExposure, A, b, LowerPickMatrix, LowerValues, UpperPickMatrix, UpperValues, Q, c, DoShowVolRetOtherwiseWeightsOnly)Result
Returns the 1 x n weights (optionally preceded by the portfolio volatility and expected return) of the restricted and bounded maximum Sharpe ratio portfolio with optional linear equality and inequality constraints and an optional quadratic constraint w'Q*w <= c. The Sharpe ratio is calculated with a risk-free rate of zero.
Syntax
ExpectedReturns: 1 x n vector with expected constituent returns (excess returns over the risk-free rate)
Covariances: n x n covariance matrix
LowerBounds: 1 x n vector of lower constituent exposure bounds
UpperBounds: 1 x n vector of upper constituent exposure bounds
PortfolioExposure: value of the equality constraint on total portfolio exposure, i.e. the sum of constituent exposures (a value of 1 is the “no leverage” constraint)
A: optional; m x n matrix of the linear equality constraints A*w = b, with m the number of equality constraints; supplied together with b; default: no equality constraints
b: optional; vector of the m values of the equality constraints A*w = b, supplied together with A; default: no equality constraints
LowerPickMatrix: optional; mL x n matrix of the inequality constraints LowerPickMatrix*w >= LowerValues, e.g. minimum group weights; supplied together with LowerValues; default: no lower inequality constraints
LowerValues: optional; vector of the mL lower constraint values, supplied together with LowerPickMatrix; default: no lower inequality constraints
UpperPickMatrix: optional; mU x n matrix of the inequality constraints UpperPickMatrix*w <= UpperValues, e.g. maximum group weights or a limit on the short book; supplied together with UpperValues; default: no upper inequality constraints
UpperValues: optional; vector of the mU upper constraint values, supplied together with UpperPickMatrix; default: no upper inequality constraints
Q: optional; n x n symmetric positive semidefinite matrix of the quadratic constraint w'Q*w <= c, e.g. a tracking error covariance matrix, or the identity matrix for a concentration limit; supplied together with c; default: no quadratic constraint
c: optional; upper limit of the quadratic constraint w'Q*w <= c, e.g. the squared tracking error, or 1/(effective number of assets) for Q = identity matrix; supplied together with Q; default: no quadratic constraint
DoShowVolRetOtherwiseWeightsOnly: optional; TRUE returns a 1 x (n + 2) row with the portfolio volatility sqrt(w'Σw), calculated from Covariances and therefore a sample or population volatility as Covariances is, the portfolio expected return e'w, and the n constituent weights; FALSE returns the 1 x n weights only; default: FALSE
Algorithm
The Sharpe ratio is calculated with a risk-free rate of zero:
If the maximum Sharpe ratio is positive, the maximizing portfolio lies on the efficient frontier. The function therefore calculates the corner portfolios of the efficient frontier with the critical line algorithm, as in apaMeanVariance.Restricted.Bounded.Frontier, or, with linear constraints, with the critical line algorithm generalized to linear equality and inequality constraints, following Niedermayer and Niedermayer, as in apaMeanVariance.Restricted.Bounded.Frontier.Axb, from the minimum variance portfolio to the maximum return portfolio. Between two adjacent corner portfolios w(k) and w(k + 1), the frontier is linear in the weights, its return is linear and its variance quadratic in the segment parameter t:
with d = w(k + 1) - w(k), ΔR = e'd, V0 = w(k)'Σw(k), L = 2 w(k)'Σd and Q = d'Σd. The derivative of R(t) / sqrt(V(t)) has the sign of a linear function of t, so the Sharpe ratio has at most one stationary point on each segment:
The function evaluates the Sharpe ratio at both corner portfolios of every segment and at the stationary point if 0 < t < 1, and returns the portfolio with the highest value. Apart from the corner portfolios of the critical line algorithm, the solution is exact and requires no iterations.
With Q and c, the quadratic constraint is handled by an exact homotopy: for θ in [0, 1], the critical line algorithm is applied to the trace-normalized matrix (1 - θ)Σ + θQ, subject to the bounds, the exposure constraint and the optional linear constraints. Where the quadratic constraint is slack, the frontier portfolio of θ = 0 (no quadratic constraint) is optimal. Otherwise θ is found by a safeguarded secant search such that w'Q*w = c at the target return, which gives the exact optimum of the constrained problem; θ/(1 - θ) is the multiplier of the quadratic constraint. The minimum variance and maximum return portfolios are determined taking the quadratic constraint into account. The variance V(r) of the constrained frontier portfolio with expected return r is convex and non-decreasing between the minimum variance return rMin and the maximum return rMax. Because V(r) is convex, the Sharpe ratio r / sqrt(V(r)) is unimodal in r and is maximized by a golden-section search on r in [rMin, rMax], each candidate being the exact constrained frontier portfolio; the search stops when the return interval is below 1E-12 times rMax - rMin, and the end points are compared as well.
Remarks
Because the risk-free rate is zero, the expected returns should be excess returns over the risk-free rate. A cash asset is then entered with an expected return of 0 and a zero row and column in the covariance matrix. All combinations of cash and the tangency portfolio have the same Sharpe ratio; in that case the function returns the tangency portfolio without cash. If the minimum variance portfolio has zero volatility and a positive expected return, e.g. a cash asset with a positive excess return, the Sharpe ratio is unbounded and the function returns an error message. To absorb round-off errors, returns below 1E-12 times the largest absolute expected return and variances below 1E-14 times the largest variance (both scaled with the portfolio exposure) are treated as zero.
If no feasible portfolio has a positive expected return, the function returns the frontier portfolio with the least negative Sharpe ratio. That portfolio is not a tangency portfolio and should be interpreted with care.
The Sharpe ratio does not change if all weights are multiplied by a positive factor. With bounds proportional to the portfolio exposure, the weights therefore scale with the exposure. With a portfolio exposure of 0, the maximum is in general not unique, and the function returns the first maximizing frontier portfolio, whose leverage depends on the bounds. Negative portfolio exposures are allowed but the resulting Sharpe ratios are difficult to interpret.
Duplicate assets, i.e. assets with identical covariances, leave the efficient portfolios non-unique, and the function returns the error message of the critical line algorithm. apaMeanVariance.Strategies.MostDiversified.Weights.FromCovars uses the same algorithm with the volatilities as expected returns.
The results do not depend on the solver: a non-binding quadratic constraint gives the same portfolio as no quadratic constraint, up to round-off.
Each row of a pick matrix defines one constraint, e.g. a row with ones for the equity constituents and zeros elsewhere limits the total equity weight. Leave A and b empty if only inequality constraints are needed. The equality constraints must be linearly independent, and all constraints must be jointly feasible.
With Q equal to the identity matrix, the quadratic constraint limits the Herfindahl concentration index of the weights, i.e. c = 1/N enforces at least N effective assets.
Pressing Esc aborts the calculation; the function then returns "Calculation aborted by user."
