def data_transform(start_date,end_date): output_dir=directory() date_dir = os.listdir("D:/deri-bit/") datelist = [] for t in date_dir: temp = datetime.datetime.strptime(t,'%Y%m%d').date() datelist.append(temp) for d in np.arange(start_date, end_date): date = np.datetime64(d).astype(datetime.date) # Initiate the underlying values if d in datelist: arrList = "D:/deri-bit/" + str(date).replace("-","") arr_all = os.listdir(arrList) arr=[] for f in arr_all: f_1 = f.split("-") if f_1[0] == "BTC": arr.append("D:/deri-bit/"+str(date).replace("-","")+"/"+f) for f in arr: f_to_list = f.split('-') # Options: if len(f_to_list) > 3: cp_date=re.split('_(\d+)', f_to_list[4]) optionsDir = output_dir.data_download(type='option') + cp_date[1] + '_' + f_to_list[2] + '_' + f_to_list[3] + '_' + cp_date[0] +'.csv' if not os.path.exists(optionsDir): contractType = f_to_list[2].split('_')[0] if not contractType.startswith('PERP'): options = get_data(f) optionsDF = options.all_to_dataframe() optionsDF.to_csv(path_or_buf=optionsDir) # Perpetuals if len(f_to_list) == 3: cp_date=re.split('_(\d+)', f_to_list[2]) perpetualDir = output_dir.data_download(type='perpetual') + cp_date[1] + '_'+ cp_date[0] +'.csv' if not os.path.exists(perpetualDir): contractType = f_to_list[2].split('_')[0] if contractType.startswith('PERP'): perpetual = get_data(f) perpetualDF = perpetual.to_dataframe() perpetualDF.to_csv(path_or_buf=perpetualDir) # Futures if len(f_to_list) == 3: cp_date = re.split('_(\d+)', f_to_list[2]) futuresDir = output_dir.data_download(type='future') + cp_date[1] + '_' + cp_date[0] + '.csv' if not os.path.exists(futuresDir): contractType = f_to_list[2].split('_')[0] if not contractType.startswith('PERP'): futures = get_data(f) futuresDF = futures.to_dataframe() futuresDF.to_csv(path_or_buf=futuresDir) print('Finished: ', date, f)
def __init__(self, current_day_options, tradinghour, d, delta_t, maturity_T): self.maturity_T = maturity_T self.d = d self.tradinghour = tradinghour self.currentDate = np.datetime64(d).astype(datetime.date) self.current_day_options = current_day_options self.project_dir = directory() self.dailyTradeTime = datetime.datetime.combine( self.currentDate, self.tradinghour) self.delayTradeTime = self.dailyTradeTime + datetime.timedelta( minutes=delta_t) self.previousTradeTime = self.dailyTradeTime - datetime.timedelta( minutes=delta_t)
import os import re import datetime import pandas as pd import numpy as np import matplotlib.pyplot as plt from change_directory import directory project_dir = directory() perpListDir = project_dir.data_download(type='perpetual') perpList = os.listdir(perpListDir) dateList = [] for f in perpList: f_date = re.split('_', f) date = datetime.datetime.strptime(f_date[0], "%Y%m%d").date() dateList.append(date) quarterlyMonth = [3, 6, 9, 12] monthList = [ 'JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC' ] startDate = min(dateList) endDate = max(dateList) + datetime.timedelta(days=1) tradeHour = datetime.time(16, 0, 0) optionListDir = project_dir.data_download(type='option') optionList = os.listdir(optionListDir) optionDateList, optionMaturityList, optionStrikeList, optionCallPutList, optionMaturityMonthList = [], [], [], [], []
import pandas as pd import re import os import calendar import datetime import numpy as np from DataClient import DataClient from read_file import get_data from change_directory import directory start_date = datetime.date.today() - datetime.timedelta(days=2) end_date = datetime.date.today() - datetime.timedelta(days=1) output_dir = directory() for d in np.arange(start_date, end_date): date = np.datetime64(d).astype(datetime.date) # Initiate the underlying values client = DataClient('3.17.63.79', 22, 'ec2-user', 'Waa9b25xyk') client.connect() arr = client.getfiles(str(date).replace("-", ""), 'BTC') for f in arr: f_to_list = f.split('-') # Options: if len(f_to_list) > 3: cp_date = re.split('_(\d+)', f_to_list[4]) optionsDir = output_dir.data_download( type='option') + cp_date[1] + '_' + f_to_list[ 2] + '_' + f_to_list[3] + '_' + cp_date[0] + '.csv' if not os.path.exists(optionsDir):
def __init__(self): self.project_dir = directory()