這期內(nèi)容當(dāng)中小編將會給大家?guī)碛嘘P(guān)怎么進(jìn)行針對vnpy的不同期貨品種行情數(shù)據(jù)清理,文章內(nèi)容豐富且以專業(yè)的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。
創(chuàng)新互聯(lián)主要從事網(wǎng)頁設(shè)計(jì)、PC網(wǎng)站建設(shè)(電腦版網(wǎng)站建設(shè))、wap網(wǎng)站建設(shè)(手機(jī)版網(wǎng)站建設(shè))、響應(yīng)式網(wǎng)站設(shè)計(jì)、程序開發(fā)、網(wǎng)站優(yōu)化、微網(wǎng)站、微信小程序等,憑借多年來在互聯(lián)網(wǎng)的打拼,我們在互聯(lián)網(wǎng)網(wǎng)站建設(shè)行業(yè)積累了豐富的做網(wǎng)站、成都網(wǎng)站建設(shè)、網(wǎng)站設(shè)計(jì)、網(wǎng)絡(luò)營銷經(jīng)驗(yàn),集策劃、開發(fā)、設(shè)計(jì)、營銷、管理等多方位專業(yè)化運(yùn)作于一體。vnpy自帶的行情清理功能較為簡單,只是在清除非交易時(shí)段,沒有考慮周六日;而且只是籠統(tǒng)給了一個(gè)大時(shí)間交易范圍,像股指期貨沒有夜盤,螺紋鋼晚上11點(diǎn)就結(jié)束,但是默認(rèn)只是結(jié)束在凌晨兩點(diǎn)半這個(gè)大交易時(shí)間。 所以寫了一個(gè)方法,按照不同品種,更細(xì)致的清理。
可以直接把這個(gè)方法插入\DataRecording\runDataCleaning.py, 然后替代原來方法。也可以自己另外調(diào)用。
# ---------------------------------------------------------------------- def cleanDataAdv(dbName, collectionName, start): """清洗數(shù)據(jù)""" #新的靜態(tài)數(shù)據(jù) # 這里以商品期貨為例 MORNING_START = time(9, 0) MORNING_REST = time(10, 15) MORNING_RESTART = time(10, 30) MORNING_END = time(11, 30) AFTERNOON_START = time(13, 30) AFTERNOON_END = time(15, 0) NIGHT_START = time(21, 0) NIGHT_END = time(2, 30) #股指期貨 STOCK_FUTURE = ["IC", "IF", "IH"] MORNING_START_STOCK = time(9, 30) AFTERNOON_START_STOCK = time(13,0) AFTERNOON_END_STOCK = time(15, 0) #晚上11點(diǎn)結(jié)束交易,不全,請自行維護(hù) PM11CLOSE_FUTURE = ['rb','ru','bu','hc','sp'] NIGHT_END_11 = time(23, 00) #晚上11點(diǎn)半結(jié)束交易,不全,請自行維護(hù),大連只有一位標(biāo)志,所以帶1 PM1130CLOSE_FUTURE = ['FG','MA','SR','TA','RM','OI','CF','CY','ZC','i1','j1','m1','p1','y1'] NIGHT_END_1130 = time(23, 30) #凌晨1點(diǎn)半結(jié)束交易,不全,請自行維護(hù) AM1CLOSE_FUTURE = ['cu','pd','al','zn'] NIGHT_END_AM1 = time(1, 00) print(u'\n清洗數(shù)據(jù)庫:%s, 集合:%s, 起始日:%s' % (dbName, collectionName, start)) mc = MongoClient('localhost', 27017) # 創(chuàng)建MongoClient cl = mc[dbName][collectionName] # 獲取數(shù)據(jù)集合 d = {'datetime': {'$gte': start}} # 只過濾從start開始的數(shù)據(jù) cx = cl.find(d) # 獲取數(shù)據(jù)指針 for data in cx: # 獲取時(shí)間戳對象 dt = data['datetime'].time() # 默認(rèn)需要清洗 cleanRequired = True ####如果是股指期貨,這沒有上午休息和夜盤,9點(diǎn)半到11點(diǎn)半,下午1點(diǎn)到下午三點(diǎn),周六日無行情 if collectionName[:2] in STOCK_FUTURE: if data['datetime'].weekday() is not (5 or 6): if ((MORNING_START_STOCK <= dt < MORNING_END) or (AFTERNOON_START_STOCK <= dt < AFTERNOON_END_STOCK)): cleanRequired = False ####如果是11點(diǎn)結(jié)束,則周六日無行情 elif collectionName[:2] in PM11CLOSE_FUTURE: if data['datetime'].weekday() is not (5 or 6): if ((MORNING_START <= dt < MORNING_REST) or (MORNING_RESTART <= dt < MORNING_END) or (AFTERNOON_START <= dt < AFTERNOON_END) or ( NIGHT_START <= dt= NIGHT_START) or (dt < NIGHT_END_AM1)): cleanRequired = False else: # 如果在交易事件內(nèi),則為有效數(shù)據(jù),無需清洗 if data['datetime'].weekday() is not 6: if ((MORNING_START <= dt < MORNING_REST) or (MORNING_RESTART <= dt < MORNING_END) or (AFTERNOON_START <= dt < AFTERNOON_END) or (dt >= NIGHT_START) or (dt < NIGHT_END)): cleanRequired = False # 如果需要清洗 if cleanRequired: print(u'刪除無效數(shù)據(jù),時(shí)間戳:%s' % data['datetime']) cl.delete_one(data) print(u'清洗完成,數(shù)據(jù)庫:%s, 集合:%s' % (dbName, collectionName))
上述就是小編為大家分享的怎么進(jìn)行針對vnpy的不同期貨品種行情數(shù)據(jù)清理了,如果剛好有類似的疑惑,不妨參照上述分析進(jìn)行理解。如果想知道更多相關(guān)知識,歡迎關(guān)注創(chuàng)新互聯(lián)-成都網(wǎng)站建設(shè)公司行業(yè)資訊頻道。