Get the App
SLTechnology News&Howtos  ›  Development  › 

How to clean up the market data of different futures varieties for vnpy

Shulou Source: shulou.com Published: 2022-06-02 08:06:46 09月20日 Update

In this issue, the editor will bring you about how to clean up the market data of different futures varieties for vnpy. The article is rich in content and analyzes and describes for you from a professional point of view. I hope you can get something after reading this article.

Vnpy comes with a relatively simple market clean-up function, but in the removal of non-trading hours, not taking into account Saturdays and Sundays; and just generally gives a maximum time trading range, such as stock index futures without night plate, rebar ends at 11:00 in the evening, but the default is only to end at 02:30 this maximum trading time. So I wrote a method to clean it up in more detail according to different varieties.

You can insert this method directly into\ DataRecording\ runDataCleaning.py and replace the original method. You can also call it yourself.

#-def cleanDataAdv (dbName, collectionName, start): "" Clean data "" # New static data # here take commodity futures as an example 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 index futures STOCK_FUTURE = ["IC", "IF", "IH"] MORNING_START_STOCK = time (9 30) AFTERNOON_START_STOCK = time (136.0) AFTERNOON_END_STOCK = time (15,0) # end trading at 11:00 in the evening, incomplete Please maintain by yourself PM11CLOSE_FUTURE = ['rb','ru','bu','hc','sp'] NIGHT_END_11 = time (23,00) # end trading at 11:30 in the evening, incomplete, please maintain by yourself, there is only one sign in Dalian So with 1 PM1130CLOSE_FUTURE = ['FG','MA','SR','TA','RM','OI','CF','CY','ZC','i1','j1','m1','p1','y1'] NIGHT_END_1130 = time (23,30) # close trading at 01:30, incomplete Please maintain AM1CLOSE_FUTURE = ['cu','pd','al','zn'] NIGHT_END_AM1 = time (1,00) print (u'\ nClean database:% s, collection:% s, start date:% s'% (dbName, collectionName, start)) mc = MongoClient ('localhost') 27017) # create MongoClient cl = mc [dbName] [collectionName] # get data collection d = {'datetime': {' $gte': start}} # filter only data starting from start cx = cl.find (d) # get data pointer for data in cx: # get timestamp object dt = data ['datetime'] .time () # default To clean cleanRequired = True # if it is stock index futures There is no morning rest or night plate, 09:30 to 11:30, 1pm to 3pm, no market on Saturday and Sunday if collectionName [: 2] in STOCK_FUTURE: if data ['datetime'] .weekday () is not (5 or 6): if ((MORNING_START_STOCK)

Tags: Data trading cleaning futures time different variety market just method maximum effective event content database analysis general detailed professional small and medium-sized Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Docker Shulou Technology Xiaomi Apple