<jupyter_start><jupyter_text>Negative weight means this strategy calls for selling the MSCI EAFE short and using the proceeds to finance additional purchases of the other assets  Question b ii: use two fund seperation: if tangency portfolio is weighted k, then the minimum variance protfolio is weighted 1-k<jupyter_code>from matplotlib import pyplot as plt
import math 
a=w_G
b= a.transpose()[0]
c=np.vstack((b,w_T))
c
#weightage for the four assets 
mean= np.array([0.838333,1.029063,0.846458,0.4875])/100
mean_j = np.array(mean)
mean_j = mean_j.reshape((1,-1))
mean_j = mean_j.transpose()
print(mean_j)
c.transpose()
x=[]
y=[]
# k=0.5
# allows 25 times shorting
for k in np.linspace(-8,10,100):
    d=c.transpose()@np.array([[1-k], [k]])
    Ep=mean@d
    x.append(Ep[0])
    varp = d.transpose()@V@d
    stdp=np.sqrt(varp[0,0])
    y.append(stdp)
    
# plt.plot(0.65476,0.7823517815011644,'ro')
# plt.annotate('min-variance',(0.65476,0.7823517815011644))
# plt.plot(0.69642695973,0.8850867677459338,'ro')
# plt.annotate('tangency portfolio',(0.6964269,0.8850867677459338))
plt.plot(y, x);
E_P_s_list = []
V_P_s_list = []
for i in range(1000):
    w_ran_s = np.array([np.random.uniform(-1,1), np.random.uniform(-1,1), np.random.uniform(-1,1), np.random.uniform(-1,1)])
    w_ran_s /= w_ran_s.sum()
    if (w_ran_s <= 1).all():
        w_ran_s = np.array(w_ran_s)
        w_ran_s = w_ran_s.reshape((1,-1))
        w_ran_s = w_ran_s.transpose()
        E_P_s_temp = portfolio_return(mean_j, w_ran_s)
        V_s_temp = V_G.values
        V_P_s_temp = portfolio_variance(V_s_temp, w_ran_s)
        E_P_s_list.append(E_P_s_temp)
        V_P_s_list.append(V_P_s_temp)
E_P_s = np.array(E_P_s_list)
V_P_s = np.array(V_P_s_list)

print(E_P_s.shape)
print(V_P_s.shape)
df_plot_s = pd.DataFrame()
df_plot_s = pd.DataFrame(data={'Expected Return': E_P_s[:, 0, 0]})
df_plot_s['Std'] = np.sqrt(V_P_s[:, 0, 0])
df_plot_s
plt.xlabel('Std')
plt.ylabel('Expected Return')
plt.plot(df_plot_s['Std'], df_plot_s['Expected Return'],'ro')
plt.plot(y, x);<jupyter_output><empty_output><jupyter_text>This is to validate our efficient frontier is correct<jupyter_code>plt.xlabel('Std')
plt.ylabel('Expected Return')
plt.plot(0.036699,0.00838333,'ro')
plt.annotate('SB Non-US Bonds',(0.036699,0.007))
plt.plot(0.058724,0.01029063,'ro')
plt.annotate('MSCI EAFE',(0.058724,0.01029063))
plt.plot(0.047337,0.00846458,'ro')
plt.annotate('CRSP VW US common stocks',(0.047337,0.00846458))
plt.plot(0.015708,0.004875,'ro')
plt.annotate('US Corp Bonds',(0.015708,0.004875))
# combined line
# plt.plot(0.65476,0.7823517815011644,'ro')
# plt.annotate('min-variance',(0.65476,0.7823517815011644))
# plt.plot(0.69642695973,0.8850867677459338,'ro')
# plt.annotate('tangency portfolio',(0.6964269,0.8850867677459338))
plt.plot(y, x);<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17091295116772823, 'fraction_numerical': 0.1362349610757254, 'mean_word_length': 5.310267857142857, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '90652', 'license': 'MIT', 'n_tokens_mistral': 1478, 'n_tokens_neox': 1268, 'n_words': 193, 'path': 'Assignment3_DongZheng.ipynb', 'repo_name': 'nusstu-dz/DBA5109-Quantitative-Risk-Management', 'size': '2826'}