-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathF1.py
56 lines (41 loc) · 1.21 KB
/
F1.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
import matplotlib as plt
import pandas as pd
str = "----------------------------------------------------------------------\n"
#computing annualized returns
def annualized_returns(returns):
c = returns/100
rpm = (c+1).prod()**(1/(c.shape[0]))-1
anr = (rpm+1)**12 -1
print(str)
print("Annualized returns are :\n")
print(anr)
return anr
# Computing volatility
def volatility(returns):
c = returns/100
vol = c.std()*(12**(.5))
print(str)
print("Volatilities are :\n")
print(vol)
return vol
#computing drawdowns
def drawdowns(returns):
st = 1000 # Started with Rs.1000
c = returns/100
wi = st*(1+c).cumprod()
pk = wi.cummax()
drawdown = (wi-pk)/pk
print(str)
print("Drawdowns are")
print(drawdown.min())
print("\nDrawdown indexes are")
print(drawdown.idxmin())
k = pd.DataFrame([wi,pk,drawdown])
return k
returns = pd.read_csv('Portfolios_Formed_on_ME_monthly_EW.csv',parse_dates=True,header = 0,index_col=0, na_values=-99.99)
#changing to date format
returns.index = pd.to_datetime(returns.index,format = "%Y%m")
returns.index = returns.index.to_period('M')
drawdowns(returns)
volatility(returns)
annualized_returns(returns)