Navigator
PortfolioCVaR object workflow
建立PortfolioCVaR
流程如下
- 创建
CVaR
对象 - 定义资产收益率(
returns
)和场景(scenarios
) - 设置CVaR的约束
- 验证CVaR投资组合
- 估计投资组合的有效前沿
- 结果处理
Creation
p = PortfolioCVaR % empty portfolio
p = PortfolioCVaR(Name, Value) % For example, p=PortfolioCVaR('AssetList', Assets(1:12))
p = PortfolioCVaR(p, Name, Value) % p is a previouslu constructed PortfolioCVaR object
PortfolioCVaR的属性如下表所示
Items | Meaning |
---|---|
AssetList | Names or symbols of assets in universe |
InitPort | Initial portfolio |
Name | Name for instance of PortfolioCVaR object |
NumAssets | Number of assets in the universe |
Constraints
CVaR
模型中的约束条件如下表所示
Constraints | Meanings |
---|---|
AEquality | Linear quality constraint matrix |
AInequality | Linear inequality constraint matrix |
bEquality | Linear equality constraint vector |
bInequality | Linear inequality constraint |
GroupA | Group A weights to be bounded by weights in group B |
GroupB | Group B weights |
GroupMatrix | Group membership matrix |
LowerBound | Lower bound constraint |
LowerBudget | Lower bound budget constrant |
LowerGroup | Lower bound group constraint |
LowerRatio | Minimum ratio of allocations between Groups A and B |
UpperBound | Upper bound constraint |
UpperBudget | Upper bound budget constraint |
UpperGroup | Upper bound group constraint |
UpperRatio | Maximum ratio of allocations between Groups A and B |
BoundType | simple or conditional |
MinNumAssets | Minimum number of assets allocated in portfolio |
MaxNumAssets | Maximum number of assets allocated in portfolio |
Turnover | Turnover constraint |
SellTurnover | Turnover constraint on sales |
BuyTurnover | Turnover constraint on purchases |
Portfolio Object Modeling
objects | Meanings |
---|---|
BuyCost | Proportional purchase costs |
RiskFreeRate | 无风险利率 |
ProbabilityLevel | 水平为1-loss prob. 的在险价值 |
NumScenarios | 场景的数量 |
SellCost | Proportional sales costs |
Demos
PortfolioCVaR Object build
设置资产的收益率和方差-协方差矩阵参数,使用Monte-Carlo模拟出n
种scenarios
. 模拟可以使用函数mvnrnd
完成
R=mvnrnd(mu, sigma, n)
returns a matrix R of n random vectors chosen from the same multivariate normal distribution, with mean vectormu
and covariance matrixsigma
%% CVaR object using single step setup
m = [0.05; 0.1; 0.12; 0.18]; % 设置资产年收益率
C = [ 0.0064 0.00408 0.00192 0; % 设置资产的方差-协方差矩阵
0.00408 0.0289 0.0204 0.0119;
0.00192 0.0204 0.0576 0.0336;
0 0.0119 0.0336 0.1225 ];
m = m/12;
C = C/12;
N = 20000;
AssetScenarios=mvnrnd(m, C, N); % 模拟20000种scenarios
p = PortfolioCVaR('Scenarios', AssetScenarios, 'LowerBound', 0, 'LowerBudget', 1, 'UpperBudget', 1, 'ProbabilityLevel', 0.95);
也可以分步骤建立
p = PortfolioCVaR;
p = setScenarios(p, AssetScenarios);
p = PortfolioCVaR(p, 'LowerBound', 0);
p = PortfolioCVaR(p, 'LowerBudget', 1, 'UpperBudget', 1);
p = setProbabilityLevel(p, 0.95);
绘制有效前沿(由于mean-CVaR在求解QP规划时用到了和mosek
中的同名函数,但是函数接口不同,为了解决冲突,可以在设置路径中将mosek
至于底端,提高quadprog
系统函数的优先级)
%%
p = PortfolioCVaR;
p = setSolver(p, 'fmincon');
p = setScenarios(p, AssetScenarios);
p = PortfolioCVaR(p, 'LowerBound', 0);
p = PortfolioCVaR(p, 'LowerBudget', 1, 'UpperBudget', 1);
p = setProbabilityLevel(p, 0.95);
plotFrontier(p);
也可以使用属性名称的简写
m = [ 0.05; 0.1; 0.12; 0.18 ];
C = [ 0.0064 0.00408 0.00192 0;
0.00408 0.0289 0.0204 0.0119;
0.00192 0.0204 0.0576 0.0336;
0 0.0119 0.0336 0.1225 ];
m = m/12;
C = C/12;
AssetScenarios = mvnrnd(m, C, 20000);
p = PortfolioCVaR('scenario', AssetScenarios, 'lb', 0, 'budget', 1, 'plevel', 0.95)
或者显式使用属性设置
AssetScenarios = mvnrnd(m, C, 20000);
p = PortfolioCVaR;
p = setScenarios(p, AssetScenarios);
p.ProbabilityLevel = 0.95;
p.LowerBudget = 1;
p.UpperBudget = 1;
p.LowerBound = zeros(size(m));
Case
读入12只股票的历史数据集,使用函数simulateNormalScenariosByData
模拟场景
%% case
load CAPMuniverse.mat
N = 20000;
p = PortfolioCVaR('AssetList', Assets(1: 12)); % 读入股票数据
% 根据历史数据产生场景
p = simulateNormalScenariosByData(p, Data(:, 1:12), N, 'MissingData', true);
p = setDefaultConstraints(p);
p = setProbabilityLevel(p, 0.95);
plotFrontier(p);
从有效前沿上得到组合权重
% display
pwgt = estimateFrontier(p, 5); % 得到5种权重
pnames = cell(1,5);
for i = 1:5
pnames{i} = sprintf('Port%d',i);
end
Blotter = dataset([{pwgt},pnames],'obsnames',p.AssetList);
disp(Blotter);
CVaR optimization
CVaR优化问题有以下四种要素:
-
A universe of assets with scenarios of asset total returns for a period of interest, where scenarios comprise a collection of samples from the underlying probability distribution for asset total returns. This collection must be sufficiently large for asymptotic convergence of sample statistics. Asset return moments and related statistics are derived exclusively from the scenarios(场景需要包括资产收益率的概率分布情况)
-
A portfolio set that specifies the set of portfolio choices in terms of a collection of constraints.
-
A model for portfolio return and risk proxies, which, for CVaR optimization, is either the gross or net mean of portfolio returns and the conditional value-at-risk of portfolio returns.
-
A probability level that specifies the probability that a loss is less than or equal to the value-at-risk. Typical values are 0.9 and 0.95, which indicate 10% and 5% loss probabilities.
% valid portfolio optimization problem
[lb, ub, isbounded]=estimateBounds(p);
pwgt = estimateFrontier(p);
属性简写对照表如下