The brief
A portfolio team is building the lowest-risk mix of two funds for a cautious client. One is a global bond fund with a volatility of 7% a year; the other is a global equity fund at 16%.
The best mix depends on how the two funds move together, and that changes with the market. The team's risk model gives three correlation scenarios, and the client may not sell either fund short.
Your task
- Write
min_variance_mix(sA, sB, rho): the pair(w, vol). Herewis the weight in fund A with the lowest variance, short sales allowed, andvolis the volatility at that weight. RaiseValueErrorfor a volatility of zero or below, a correlation outside , or when every weight gives the same variance. - Write
long_only_mix(sA, sB, rho): the same pair when neither fund may be sold short, so that . - Write
short_sale_threshold(sA, sB): the correlation above which the lowest-variance mix sells the riskier fund short.
The data
BOND_VOL and EQUITY_VOL in the code are the two funds' yearly volatilities. SCENARIOS gives the correlation between them in a calm, a normal and a stressed market. The tests take the bond fund as fund A.
Hint: Where to start
With weight in fund A, the portfolio's variance is a quadratic in , and its lowest point is the vertex (lesson 1.2.2). Case study 1.2.4 writes out the coefficients and the minimum-variance weight.
Hint: Without short sales
If the vertex lies outside , the variance keeps falling towards the nearer end of that range. So the best allowed weight is that end (case study 1.2.4).
Hint: When the mix needs a short sale
Case study 1.2.4 shows the vertex leaving once the correlation rises above the smaller volatility divided by the larger one. Check the leading coefficient before you divide by it: it is zero only when and the two volatilities are equal.