最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

股票量化軟件:赫茲量化利用 CatBoost 算法尋找外匯市場的季節(jié)性變動

2023-10-12 15:07 作者:大牛啊呢  | 我要投稿

另外兩篇關(guān)于季節(jié)性模式搜索的文章已經(jīng)發(fā)表(1,2)。我想知道機器學(xué)習(xí)算法如何處理模式搜索任務(wù)。上述文章中的交易系統(tǒng)是在統(tǒng)計分析的基礎(chǔ)上構(gòu)建的?,F(xiàn)在,只要簡單地指示模型在一周中某一天的某個時間進行交易,就可以消除人為因素。模式搜索可以由單獨的算法提供。


時間過濾器函數(shù)

通過添加過濾函數(shù),可以很容易地擴展開發(fā)庫。

def time_filter(data, count): ? ?# filter by hour ? ?hours=[15] ? ?if data.index[count].hour not in hours: ? ? ? ?return False ? ?# filter by day of week ? ?days = [1] ? ?if data.index[count].dayofweek not in days: ? ? ? ?return False ? ?return True

函數(shù)檢查其中指定的條件,可以實現(xiàn)其他附加條件(不僅僅是時間過濾器)。但由于本文專門討論季節(jié)性模式,因此我將只使用時間過濾器。如果滿足所有條件,函數(shù)將返回True,并將適當(dāng)?shù)臉颖咎砑拥接?xùn)練集中。例如,在這種特殊情況下,我們指示模型僅在周二15:00進行交易?!癶ours”和“days”列表可以包括其他小時和天。通過注釋掉所有條件,您可以讓算法無條件地工作,就像前一篇文章中的工作方式一樣。

add_labels 函數(shù)現(xiàn)在接收這個條件作為輸入。在Python中,函數(shù)是一級對象,因此可以將它們作為參數(shù)安全地傳遞給其他函數(shù)。

def add_labels(dataset, min, max, filter=time_filter): ? ?labels = [] ? ?for i in range(dataset.shape[0]-max): ? ? ? ?rand = random.randint(min, max) ? ? ? ?curr_pr = dataset['close'][i] ? ? ? ?future_pr = dataset['close'][i + rand] ? ? ? ?if filter(dataset, i): ? ? ? ? ? ?if future_pr + MARKUP < curr_pr: ? ? ? ? ? ? ? ?labels.append(1.0) ? ? ? ? ? ?elif future_pr - MARKUP > curr_pr: ? ? ? ? ? ? ? ?labels.append(0.0) ? ? ? ? ? ?else: ? ? ? ? ? ? ? ?labels.append(2.0) ? ? ? ?else: ? ? ? ? ? ?labels.append(2.0) ? ?dataset = dataset.iloc[:len(labels)].copy() ? ?dataset['labels'] = labels ? ?dataset = dataset.dropna() ? ?dataset = dataset.drop( ? ? ? ?dataset[dataset.labels == 2].index) ? ?return dataset

一旦過濾器被傳遞給函數(shù),它就可以用來標記買入或賣出交易。過濾器接收原始數(shù)據(jù)集和當(dāng)前柱的索引。數(shù)據(jù)集中的索引表示為包含時間的“datetime index”。過濾器按第i個數(shù)字在數(shù)據(jù)幀的“datetime index”中搜索小時和天,如果未找到任何內(nèi)容,則返回 False。如果滿足條件,則交易標記為1或0,否則標記為2。最后,從訓(xùn)練數(shù)據(jù)集中刪除所有2,因此只留下由過濾器確定的特定天數(shù)和小時的示例。

還應(yīng)向自定義測試儀添加一個過濾器,以在特定時間啟用交易打開(或根據(jù)此過濾器設(shè)置的任何其他條件)。

def tester(dataset, markup=0.0, plot=False, filter=time_filter): ? ?last_deal = int(2) ? ?last_price = 0.0 ? ?report = [0.0] ? ?for i in range(dataset.shape[0]): ? ? ? ?pred = dataset['labels'][i] ? ? ? ?ind = dataset.index[i].hour ? ? ? ?if last_deal == 2 and filter(dataset, i): ? ? ? ? ? ?last_price = dataset['close'][i] ? ? ? ? ? ?last_deal = 0 if pred <= 0.5 else 1 ? ? ? ? ? ?continue ? ? ? ?if last_deal == 0 and pred > 0.5: ? ? ? ? ? ?last_deal = 2 ? ? ? ? ? ?report.append(report[-1] - markup + ? ? ? ? ? ? ? ? ? ? ? ? ?(dataset['close'][i] - last_price)) ? ? ? ? ? ?continue ? ? ? ?if last_deal == 1 and pred < 0.5: ? ? ? ? ? ?last_deal = 2 ? ? ? ? ? ?report.append(report[-1] - markup + ? ? ? ? ? ? ? ? ? ? ? ? ?(last_price - dataset['close'][i])) ? ?y = np.array(report).reshape(-1, 1) ? ?X = np.arange(len(report)).reshape(-1, 1) ? ?lr = LinearRegression() ? ?lr.fit(X, y) ? ?l = lr.coef_ ? ?if l >= 0: ? ? ? ?l = 1 ? ?else: ? ? ? ?l = -1 ? ?if(plot): ? ? ? ?plt.plot(report) ? ? ? ?plt.plot(lr.predict(X)) ? ? ? ?plt.title("Strategy performance") ? ? ? ?plt.xlabel("the number of trades") ? ? ? ?plt.ylabel("cumulative profit in pips") ? ? ? ?plt.show() ? ?return lr.score(X, y) * l

具體實現(xiàn)如下:當(dāng)沒有未平倉時使用數(shù)字2:last_deal=2。測試開始前沒有未平的倉位,因此設(shè)置2。遍歷整個數(shù)據(jù)集并檢查是否滿足篩選條件。如果條件滿足,就開始買賣交易。過濾條件不應(yīng)用于交易結(jié)束,因為它們可以在一周的另一個小時或一天結(jié)束。這些變化足以進行進一步的正確訓(xùn)練和測試。


股票量化軟件:赫茲量化利用 CatBoost 算法尋找外匯市場的季節(jié)性變動的評論 (共 條)

分享到微博請遵守國家法律
鄂托克前旗| 县级市| 渝中区| 阿勒泰市| 塘沽区| 东乌珠穆沁旗| 长宁区| 明光市| 五莲县| 苏尼特左旗| 察隅县| 马山县| 临海市| 张北县| 微博| 咸阳市| 巴彦淖尔市| 平江县| 呈贡县| 鄄城县| 静乐县| 乐至县| 盱眙县| 金昌市| 常山县| 广饶县| 安阳市| 博野县| 璧山县| 三亚市| 顺义区| 新郑市| 墨竹工卡县| 通州市| 自贡市| 喜德县| 潞城市| 利辛县| 隆安县| 苍山县| 资源县|