-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanalyze_volatility.py
60 lines (46 loc) · 1.53 KB
/
analyze_volatility.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
56
57
58
59
60
import utils
import numpy as np
fname = "volatility_data/gold_daily.pkl"
df = utils.load_pickle(fname)
utils.standard_plot(df, column_name='Volatility')
num_data = df.shape[0]
dates = []
signs = []
count_plus = 0
count_minus = 0
count_zero = 0
spread = 2
bigger_than_spread_dates = []
vols_of_bigger_than_spread_dates = []
how_biggers = []
for idx in range(num_data):
curr_date = df.loc[idx]["Date"]
curr_vol = df.loc[idx]["Volatility"]
if curr_vol > 2:
bigger_than_spread_dates.append(curr_date)
vols_of_bigger_than_spread_dates.append(curr_vol)
print(curr_date, " ", curr_vol, " ", curr_vol-spread)
how_biggers.append(curr_vol-spread)
#print(curr_vol)
sign = np.sign(curr_vol)
#print(sign)
if sign == 1:
count_plus +=1
elif sign == -1:
count_minus +=1
elif sign == 0:
count_zero +=1
dates.append(curr_date)
signs.append(sign)
df_sign = utils.make_as_pandas_df(dates_list=dates,
content_list=signs,
content_name="sign_of_volatility")
utils.pickle_object(df_sign, "volatility_data/sign_daily_gold.pkl")
utils.standard_plot(df_sign[:100],
column_name="sign_of_volatility",
scatter=True)
print("count_plus: {}, count_minus: {}, conut_zero: {}".format(count_plus,
count_minus,
count_zero))
if __name__ == "__main__":
pass