楼主: xixihahu1
871 0

[有偿编程] 求助 matlab中带比例限制的black-litterman模型求解结果异常 [推广有奖]

  • 0关注
  • 0粉丝

高中生

87%

还不是VIP/贵宾

-

威望
0
论坛币
6 个
通用积分
0
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
300 点
帖子
17
精华
0
在线时间
45 小时
注册时间
2008-4-21
最后登录
2021-4-2

楼主
xixihahu1 发表于 2021-2-1 11:02:09 |AI写论文
20论坛币
用matlab求解black-litterman模型
不加资产比例限制的时候表现正常
加入资产比例限制后输出资产比例变为[1,0,0,0,0,0,0,0,0,0]


代码如下:求教各位大神! matlab代码.zip (5.07 KB)


function [er, ps, w, posteriorSigma] = BL_constrained(delta, weq, sigma, tau, P, Q, Omega,CashRet)%#codegen
% hlblacklitterman
%   This function performs the Black-Litterman blending of the prior
%   and the views into a new posterior estimate of the returns as
%   described in the paper by He and Litterman.
% Inputs
%   delta  - Risk tolerance from the equilibrium portfolio
%   weq    - Weights of the assets in the equilibrium portfolio
%   sigma  - Prior covariance matrix
%   tau    - Coefficiet of uncertainty in the prior estimate of the mean (pi)
%   P      - Pick matrix for the view(s)
%   Q      - Vector of view returns
%   Omega  - Matrix of variance of the views (diagonal)
% Outputs
%   Er     - Posterior estimate of the mean returns
%   w      - constrained weights computed given the Posterior estimates
%            of the mean and covariance of returns.
%   lambda - A measure of the impact of each view on the posterior estimates.
%   theta  - A measure of the share of the prior and sample information in the
%            posterior precision.

% Reverse optimize and back out the equilibrium returns
% This is formula (12) page 6.
pi = weq * sigma * delta;
% We use tau * sigma many places so just compute it once
ts = tau * sigma;
% Compute posterior estimate of the mean
% This is a simplified version of formula (8) on page 4.
er = pi' + ts * P' * inv(P * ts * P' + Omega) * (Q - P * pi');
% We can also do it the long way to illustrate that d1 + d2 = I
d = inv(inv(ts) + P' * inv(Omega) * P);
d1 = d * inv(ts);
d2 = d * P' * inv(Omega) * P;
er2 = d1 * pi' + d2 * pinv(P) * Q;
% Compute posterior estimate of the uncertainty in the mean
% This is a simplified and combined version of formulas (9) and (15)
ps = ts - ts * P' * inv(P * ts * P' + Omega) * P * ts;
posteriorSigma = sigma + ps;

%用Portfolio函数计算约束条件下的权重
    p = Portfolio('RiskFreeRate', CashRet);
    p = p.setAssetMoments(er,posteriorSigma);
    p = p.setDefaultConstraints;
    w = estimateMaxSharpeRatio(p);

关键词:Litterman LITTER MATLAB atlab Black matlab 金融建模 资产组合 black-litterman

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2026-1-29 04:40