# 金融数量分析2：Markowitz均值方差模型

Portfolio在金融投资理论中占有非常重要的地位，Markowitz根据每一种证券的预期收益率、方差和所有证券间的协方差矩阵，得到证券组合的有效边界，再根据投资者的效用无差异曲线，确定一组Portfolio。

Markowitz均值方差模型为：

min sigma^2=X'MX

max E(r)=X'R

s.t. x1+x2+...+xn=1

[PortRisk,PortReturn]=portstats(ExpReturn,ExpCovariance,PortWts)

ExpReturn=[ 0.0082    0.0072    0.0426    0.0056]
ExpCovariance=     0.0106    0.0053    0.0055    0.0004
0.0053    0.0092    0.0043    0.0026
0.0055    0.0043    0.0306    0.0071
0.0004    0.0026    0.0071    0.0095

>>[PortRisk,PortReturn]=portstats(ExpReturn,ExpCovariance,PortWts)

PortRisk =

0.0830
PortReturn =

0.0159

Markowitz均值方差模型是经典的带约束的二次优化问题，给定期望收益时，方差最小解唯一，frontcon使用matlab优化工具箱的fmincon函数进行求解。(也可以参见 )

[PortRisk, PortReturn, PortWts] = frontcon(ExpReturn, ExpCovariance, NumPorts, PortReturn, AssetBounds, Groups, GroupBounds, varargin)

ExpReturn=[ 0.0082 0.0072 0.0426 0.0056]
ExpCovariance= 0.0106 0.0053 0.0055 0.0004
0.0053 0.0092 0.0043 0.0026
0.0055 0.0043 0.0306 0.0071
0.0004 0.0026 0.0071 0.0095

NumPorts=10

>>[PortRisk, PortReturn, PortWts] = frontcon(ExpReturn, ExpCovariance, NumPorts)

PortRisk =

0.0702
0.0737
0.0806
0.0901
0.1014
0.1141
0.1278
0.1427
0.1585
0.1750
PortReturn =

0.0068
0.0108
0.0148
0.0187
0.0227
0.0267
0.0307
0.0346
0.0386
0.0426
PortWts =

0.3404    0.2133         0    0.4463
0.3058    0.2219    0.1095    0.3628
0.2673    0.2305    0.2193    0.2829
0.2288    0.2391    0.3291    0.2030
0.1903    0.2478    0.4389    0.1230
0.1518    0.2564    0.5486    0.0431
0.1067    0.2330    0.6602         0
0.0538    0.1722    0.7740         0
0.0009    0.1114    0.8877         0
0         0    1.0000         0

>> frontcon(ExpReturn,ExpCovariance, NumPorts)

[PortRisk, PortReturn, PortWts] = portopt(ExpReturn, ExpCovariance, NumPorts, PortReturn, ConSet, varargin)

>>NumAssets = 4;
>>PVal = 1; % Scale portfolio value to 1.
>>AssetMin = 0;
>>AssetMax = [0.5 0.6 0.4 0.7];
>>GroupA = [1 1 0 0];
>>GroupB = [0 0 1 1];
>>AtoBmax = 1.5 % Value of assets in Group A at most 1.5 times value in group B.

>>ConSet = portcons('PortValue', PVal, NumAssets,'AssetLims',...
AssetMin, AssetMax, NumAssets, 'GroupComparison',GroupA, NaN,...
AtoBmax, GroupB)

>>Numports=10

>>[PortRisk,PortReturn,PortWts]=portopt(ExpReturn,ExpCovariance,Numports,[],ConSet)

PortRisk =

0.0702
0.0713
0.0729
0.0752
0.0781
0.0814
0.0852
0.0894
0.0940
0.1037
PortReturn =

0.0068
0.0085
0.0102
0.0118
0.0135
0.0152
0.0168
0.0185
0.0202
0.0218
PortWts =

0.3404    0.2133         0    0.4463
0.3281    0.2169    0.0458    0.4092
0.3119    0.2205    0.0919    0.3756
0.2958    0.2241    0.1380    0.3420
0.2796    0.2278    0.1841    0.3085
0.2635    0.2314    0.2302    0.2749
0.2473    0.2350    0.2764    0.2413
0.2311    0.2386    0.3225    0.2078
0.2150    0.2423    0.3686    0.1742
0.5000    0.1000    0.4000    0.0000

>> portopt(ExpReturn,ExpCovariance,Numports,[],ConSet)