-
Notifications
You must be signed in to change notification settings - Fork 0
/
UpdateDealBook.py
41 lines (36 loc) · 1.94 KB
/
UpdateDealBook.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
import pandas as pd
from datetime import datetime
import PandasConfig
from CalculateDelta import get_option_delta
from GetVN30F1M import get_vn30f1m_data
def update_book(prev_day, prev_month, prev_year, curr_day, curr_month, curr_year):
file_name = "DealBook"+"_"+str(prev_year)+"_"+str(prev_month)+"_"+str(prev_day)+".csv"
deal_book = pd.read_csv(file_name, parse_dates = ['Open Date', 'Expiry Date'], thousands = ',', dtype = {'Strike':float})
curr_date_str = str(curr_year)+"-"+str(curr_month)+"-"+str(curr_day)
spot = get_vn30f1m_data(curr_date_str, "VN30F1M")["price_closed"][0]
option_list = []
for idx, row in deal_book.iterrows():
option_type = deal_book.iloc[idx]["Type"]
open_date = deal_book.iloc[idx]["Open Date"]
maturity_date = deal_book.iloc[idx]["Expiry Date"]
strike = deal_book.iloc[idx]["Strike"]
no_contracts = deal_book.iloc[idx]["No. Contracts"]
iv = deal_book.iloc[idx]["Implied Vol"]
rf = deal_book.iloc[idx]["Risk Free Rate"]
new_delta = get_option_delta(strike, spot, maturity_date, curr_date_str, rf, iv, option_type)
updated_option = {
"Type": option_type,
"Open Date": open_date,
"Expiry Date": maturity_date,
"Strike": strike,
"No. Contracts": no_contracts,
"Implied Vol": iv,
"Risk Free Rate": rf,
"Delta": round(-new_delta*no_contracts)}
option_list.append(updated_option)
#print(pd.DataFrame(option_list))
updated_file_name = "DealBook"+"_"+str(curr_year)+"_"+str(curr_month)+"_"+str(curr_day)+".csv"
pd.DataFrame(option_list).to_csv(updated_file_name, index=False)
update_book(29,10,2024, 30,10,2024)
#deal_book = pd.read_csv(file_name, parse_dates = ['Open Date', 'Expiry Date'], thousands = ',', dtype = {'Strike':float})
#deal_data.to_csv('test.csv', date_format='%Y/%m/%d', index=False)