From 65ff3bee2537fe9dd94035851c75b7c0bf064b60 Mon Sep 17 00:00:00 2001 From: phzrjyvu9 <2026074240@qq.com> Date: Sun, 14 Jul 2024 14:15:24 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8A=95=E8=B5=84=E9=A3=8E=E9=99=A9=E6=94=B6?= =?UTF-8?q?=E7=9B=8A=E3=80=81=E5=A4=9A=E7=9B=AE=E6=A0=87=E8=A7=84=E5=88=92?= =?UTF-8?q?=EF=BC=88=E7=BA=A6=E6=9D=9F=E6=B3=95=E3=80=81=E7=BA=BF=E6=80=A7?= =?UTF-8?q?=E5=8A=A0=E6=9D=83=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mm1.m | 140 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 140 insertions(+) create mode 100644 mm1.m diff --git a/mm1.m b/mm1.m new file mode 100644 index 0000000..fafc5c7 --- /dev/null +++ b/mm1.m @@ -0,0 +1,140 @@ +%投资利益与风险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,'*-'); + + + + + + + + + + + +