#include
// This pseudo-code class entails the risk and expected return values for efficient frontier. In real code, accessors and mutators should be provided
class EfficientFrontier()
{
float[] return; // series of expected returns on efficient portfolios
float[] risk; // series of standard deviation of returns of efficient portfolios
float gmvpReturn; // expected return of Global Minimum Variance Portfolio
float gmvpRisk; // standard deviation of returns of Global Minimum Variance Portfolio
float tangentReturn; // expected return of the efficient portfolio tangent to Capital Market Line
float tangentRisk; // standard deviation of returns of the efficient portfolio tangent to Capital Market Line
float shortConstraintMaxReturn; // maximum expected return that an efficient portfolio can reach
float shortConstraintMaxRisk; // standard deviation of returns of the efficient portfolio with maxmimum return
}
// This pseudo-code function produces position of Markowitz Efficient Frontier
EfficientFrontier getEfficientFrontier(float[][] price)
{
const float c1 = 0.1; // first substitute of risk-free rate for Black's shortcut
const float c2 = 0.2; // second substitute of risk-free rate for Black's shortcut
float[] annualReturn = annualReturn(price);
float[][] annualVarcovar = annualVarcovarMatrix(price);
annualVarcovar = InverseMatrix(annualVarcovar);
for (i = 0 ; i < NUMBER_OF_VARIABLES ; i++)
{
for (j = 0 ; j < NUMBER_OF_VARIABLES ; j++)
{
z1[i] += annualVarcovar[i][j] * (annualReturn[j] - c1);
}
sumz1 += z1[i];
x1[i] = z1[i] / sumz1;
}
// repeat for z2 & x2;
float expectedReturn1, expectedReturn2;
for (i = 0 ; i < NUMBER_OF_VARIABLES ; i++) // calculate expected return
{
expectedReturn1 += annualReturn[i] * x[i];
}
// repeat for expectedReturn2;
variance1 = z1[] * annualVarcovar * z1[]; // this is a shorthand for tri-matrices multiplication. Actual code should extend the calculation of matrix multiplication
// repeat for variance2;
covariance = z1[] * annualVarcovar * z2[];
return = discreteReturn(price);
risk = stdDev(price);
for (i = 0 ; i < NUMBER_OF_OBSERVATIONS ; i++)
{
if (maxReturn < return[i]) maxReturn = return[i];
if (maxRisk < risk[i]) maxRisk = risk[i];
// the maximum return and standard deviation here are not exactly value due to limitation of the method
}
do
{
w2 = 1 - w1; // rebalance the two asset portfolio
EfficientFrontier.return[i] = w1 * expectedReturn1; // for demonstration only, a mutator should be used
EfficientFrontier.risk[i] = (w1^2 * variance1 + w2^2 * variance2 + 2 * w1 * w2 * covariance)^(1/2); // for demonstration only, a mutator should be used
w1 += INCREMENT;
i++;
}
while(EfficientFrontier.return[i] <= maxReturn); // for demonstration only, an accessor should be used
}
Xem đầy đủ bài viết tại http://feedproxy.google.com/~r/TaiTran/~3/81Iu98n7ttM/code-for-markowitz-efficient-frontier-calculation-using-blacks-shortcut.html
No comments:
Post a Comment