You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
141 lines
2.9 KiB
141 lines
2.9 KiB
%投资利益与风险1998A题
|
|
|
|
|
|
%模型一 给定风险承受程度,求最大利益
|
|
f=[-0.05,-0.27,-0.19,-0.185,-0.185];
|
|
|
|
%A矩阵
|
|
%A=[0,0.025,0.015,0.055,0.026]; %错误
|
|
%b=[1,1,1,1,1];
|
|
A=[zeros(4,1),diag([0.025,0.015,0.055,0.026])];%不等式约束条件矩阵
|
|
|
|
%Aeq、beq
|
|
Aeq=[1,1.01,1.02,1.045,1.065];
|
|
beq=1;
|
|
|
|
%lb
|
|
%lb=0; %错误
|
|
lb=zeros(5,1);
|
|
|
|
|
|
%可承担风险率a
|
|
a=(0:0.001:0.05);
|
|
|
|
%保存最优解
|
|
Q=zeros(1,length(a));
|
|
xx=[];%空矩阵存放最优解对应x的值
|
|
for i=1:length(a)
|
|
b=a(i)*ones(4,1);
|
|
[x,y]=linprog(f,A,b,Aeq,beq,lb);
|
|
Q(i)=-y;%注意取负!!!
|
|
xx=[xx;x'];
|
|
end
|
|
plot(a,Q,'*r');
|
|
xlabel("风险率");
|
|
ylabel("最大收益");
|
|
|
|
|
|
%模型二 收益、风险按权重组合
|
|
% f0=[-0.05,-0.27,-0.19,-0.185,-0.185];
|
|
% w=(0:0.1:1);
|
|
% Aeq=[1,1.01,1.02,1.045,1.065,0];
|
|
% beq=1;
|
|
% lb=0;
|
|
% xx=[];
|
|
% Q=zeros(1,length(w));
|
|
% A=[zeros(5,1),diag([0.025,0.025,0.055,0.065,0])];
|
|
% b=ones(5,1);
|
|
% for i=1:length(w)
|
|
% f=[-w(i)*f0,1-w(i)];
|
|
% b=x(end)*b;
|
|
% [x,y]=linprog(f,A,b,Aeq,beq,lb);
|
|
% Q(i)=-y;
|
|
% xx=[xx,x'];
|
|
% end
|
|
% plot(w,Q,'*r');
|
|
|
|
%模型二 收益、风险按权重组合
|
|
clc; clear; close all; format long g;
|
|
|
|
M = 10000;
|
|
prob = optimproblem;
|
|
x = optimvar('x', 6, 1, 'LowerBound', 0);
|
|
r = [0.05, 0.28, 0.21, 0.23, 0.25];
|
|
p = [0, 0.01, 0.02, 0.045, 0.065];
|
|
q = [0, 0.025, 0.015, 0.055, 0.026]';
|
|
%w = 0:0.1:1;
|
|
w = 0.7:0.03:1;
|
|
V = [];
|
|
Q = [];
|
|
X = [];
|
|
|
|
prob.Constraints.con1 = (1 + p) * x(1:end-1) == M;
|
|
prob.Constraints.con2 = (q(2:end).* x(2:end-1))<= x(end); %下标从1开始
|
|
|
|
for i = 1:length(w)
|
|
prob.Objective = w(i) * x(end) - (1 - w(i)) * (r - p) * x(1:end-1); %注意大小写
|
|
[sol, fval, flag, out] = solve(prob);
|
|
xx = sol.x;
|
|
V = [V, max(q.* xx(1:end-1))];
|
|
Q = [Q, (r - p) * xx(1:end-1)];
|
|
X = [X, xx];
|
|
|
|
plot(V, Q, '*-');
|
|
grid on;
|
|
xlabel('风险');
|
|
ylabel('收益');
|
|
end
|
|
|
|
|
|
|
|
%模型三:达到一定盈利水平,极小化风险
|
|
|
|
clc; clear; close all; format long g;
|
|
M=10000;
|
|
k=1500:100:3000;
|
|
prob = optimproblem;
|
|
x = optimvar('x', 5, 1, 'LowerBound', 0);%下界为0
|
|
r = [0.05, 0.28, 0.21, 0.23, 0.25];
|
|
p = [0, 0.01, 0.02, 0.045, 0.065];
|
|
q = [0, 0.025, 0.015, 0.055, 0.026]';
|
|
|
|
V = [];
|
|
Q = [];
|
|
X = [];
|
|
t = optimvar('t', 'LowerBound', 0);
|
|
|
|
%prob.Objective=max(q.*x);%极小化风险
|
|
for i=1:length(k)
|
|
prob.Objective = t; % 极小化风险
|
|
prob.Constraints.con1 = (1 + p) * x == M;
|
|
prob.Constraints.con2=((r-p)*x>=k(i));%达到一定盈利水平
|
|
prob.Constraints.con3=(q.*x<=t);
|
|
[sol,fval,flag,out]=solve(prob);
|
|
if flag==1
|
|
xx=sol.x;
|
|
X=[X,xx];
|
|
Q=[Q,(r-p)*xx];
|
|
V=[V,fval];
|
|
else
|
|
xx=-1*ones(5,1);
|
|
X=[X,xx];
|
|
Q=[Q,-1];
|
|
V=[V,-1];
|
|
end
|
|
|
|
|
|
end
|
|
plot(k,V,'*-');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|