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.
mycode/盘荣博/线性规划/optimiaze模块/5.4投资的收益和风险模型1.py

19 lines
593 B

from matplotlib import pyplot as plt
from numpy import ones , diag , c_ , zeros
from scipy.optimize import linprog
import time
start = time.time()
c=list( [-0.05,-0.27,-0.19,-0.185,-0.185])
A=c_[zeros(4),diag([0.025,0.015,0.055,0.026])]
Aeq = [[1,1.01,1.02,1.045,1.065]];beq=[[1]]
a=0;aa=[];ss = []
while a<=0.05:
b=list(ones(4)*a)
res= linprog(c,A,b,Aeq,beq)
aa.append(a);ss.append(-res.fun)
a=a+0.001
end = time.time()
print("花费时间:",end-start)
plt.plot(aa,ss,"r*")
plt.xlabel("$a$");plt.ylabel("$Q$",rotation=90)
plt.savefig("figure5_1_1.png",dpi=500) ;plt.show()