-
Notifications
You must be signed in to change notification settings - Fork 0
/
0013.py
55 lines (47 loc) · 1.75 KB
/
0013.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import numpy as np
import matplotlib.pyplot as plt
import pylab as pl
from constants import *
from matplotlib import rcParams as rcp
from matplotlib.cm import ScalarMappable
from tqdm import tqdm
from matplotlib import cm
from matplotlib.ticker import LinearLocator
rcp['font.family'],rcp['font.serif'] = 'serif', ['Computer Modern Roman']
rcp['text.usetex'] = True
rcp['font.size'], rcp['axes.labelsize'],rcp['axes.titlesize'] = 16, 16,18
rcp['xtick.labelsize'],rcp['ytick.labelsize'] = 14, 14
str1 = "Number of Stocks"
try:
nf = np.load("data/EfficientFrontierNumStocks.npz")
except:
nf = np.load("data/0013.npz")
returns, variance = nf["returns"], nf["variance"]
obj_val = nf["obj_val"]
num_stocks = nf["num_stocks"]
### Get meshgrid
var1, var2 = np.meshgrid(risk_pref_vec,num_stocks)
### Plot Returns
fig, ax = plt.subplots(subplot_kw={"projection":"3d"})
surf = ax.plot_surface(var1, var2, returns,cmap=cm.coolwarm,linewidth=0, antialiased=False)
ax.set_title("Returns")
ax.set_xlabel("Risk")
ax.set_ylabel(str1)
fig.colorbar(surf, shrink=0.5,aspect=5)
fig.savefig("img/0013a.pdf", bbox_inches='tight')
### Plot Variance
fig, ax = plt.subplots(subplot_kw={"projection":"3d"})
surf = ax.plot_surface(var1, var2, variance,cmap=cm.coolwarm,linewidth=0, antialiased=False)
ax.set_title("Variance")
ax.set_xlabel("Risk")
ax.set_ylabel(str1)
fig.colorbar(surf, shrink=0.5,aspect=5)
fig.savefig("img/0013b.pdf", bbox_inches='tight')
### Plot Objective Function Value
fig, ax = plt.subplots(subplot_kw={"projection":"3d"})
surf = ax.plot_surface(var1, var2, obj_val,cmap=cm.coolwarm,linewidth=0, antialiased=False)
ax.set_title("Objective Value")
ax.set_xlabel("Risk")
ax.set_ylabel(str1)
fig.colorbar(surf, shrink=0.5,aspect=5)
fig.savefig("img/0013c.pdf", bbox_inches='tight')