forked from thinklancer/Financial-Engineering
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhw3.py
47 lines (36 loc) · 791 Bytes
/
hw3.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
'''
homework 3
==========
'''
import numpy as np
from bfc.portf import *
np.set_printoptions(precision=4)
mu = np.array([6,2,4])/100.
V = np.matrix("8 -2 4; -2 2 -2; 4 -2 8")*1e-3
rf = 0.01
if __name__=="__main__":
por = portf()
por.mu = mu
por.sig = V
por.rf = rf
# qs1
por.x = np.array([1,1,1])/3.
print por.calcReturn()*100
# qs2
print por.calcVolatility()*100
# qs3
por.x = min_var_risk_asset(por.mu,por.sig)
print por.calcReturn()*100
# qs4
por.x = var_riskfree_asset(por.mu,por.sig,por.rf)
mus =por.calcReturn()*100
print mus
# qs5
sigs = por.calcVolatility()*100
print sigs
# qs6
cml = (mus-por.rf*100)/sigs
print cml
# qs7
req = cml*5+por.rf*100
print req