Code From
https://github.com/rorysroes/SGX-Full-OrderBook-Tick-Data-Trading-Strategy/tree/master
def weight_pecentage(w1,w2,w3,ask_quantity_1,ask_quantity_2,ask_quantity_3,\
bid_quantity_1,bid_quantity_2,bid_quantity_3):
Weight_Ask = (w1 * ask_quantity_1 + w2 * ask_quantity_2 + w3 * ask_quantity_3)
Weight_Bid = (w1 * bid_quantity_1 + w2 * bid_quantity_2 + w3 * bid_quantity_3)
W_AB = Weight_Ask/Weight_Bid
W_A_B = (Weight_Ask - Weight_Bid)/(Weight_Ask + Weight_Bid)
return W_AB, W_A_B
각 시점의 bid_price_1 값이 600초 이후 ask_price_1들 중
최소값보다 큰 경우 1
현재 가장 비싸게 사는 가격이 미래 어느 시점의 가장 싸게 파는 가격보다 크다는 것은 가격 하락 의미하고, 현재 시점의 매수 호가가 Match 됨을 의미
손익 계산에 사용된 데이터는 공개되지 않음
# data_2014['65'] ?????
# data_2014['66'] best ask
# data_2014['67'] best bid
# compute cum_profit and Best_cv_score
dict_ = {}
dict_['cum_profit'] = []
dict_['Best_cv_score'] = []
for day in range(0,1,1):
cum_profit_label = []
cum_profit = []
best_cv_score = []
spread = 0.2 * data_2014[day]['65'][1800:][9::10].values
loss = 0.2*(data_2014[0]['67'][1800:9000-600][9::10].values - data_2014[day]['67'][1800+600:9000][9::10].values)
for j in range(0,len(pip.cv_acc_day.values()[0][day]),1):
max_al = {}
for i in range(0,len(pip.keys),1):
max_al[pip.keys[i]] = np.array(pip.cv_acc_day[pip.keys[i]])[day][j]
# select best algorithm in cv = 5
top_cv_acc = sorted(max_al.items(),key = lambda x : x[1], reverse = True)[0:1][0]
best_cv_score.append(top_cv_acc[1])
submission = pip.predict_values_day[top_cv_acc[0]][day][j][-1]
true_value = pip.true_values_day[top_cv_acc[0]][day][j][-1]
if submission == true_value:
if submission == 1:
cum_profit_label.append(1)
cum_profit.append(spread[j])
elif submission == 0:
cum_profit_label.append(0)
cum_profit.append(0)
elif submission != true_value:
if submission == 1:
cum_profit_label.append(-1)
cum_profit.append(loss[j])
elif submission == 0:
cum_profit_label.append(0)
cum_profit.append(0)
dict_['cum_profit'].append(cum_profit)
dict_['Best_cv_score'].append(best_cv_score)