這篇文章主要為大家展示了“怎么使用Joinquant做實盤行情數(shù)據(jù)”,內(nèi)容簡而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領(lǐng)大家一起研究并學習一下“怎么使用Joinquant做實盤行情數(shù)據(jù)”這篇文章吧。
創(chuàng)新互聯(lián)公司于2013年創(chuàng)立,是專業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項目網(wǎng)站設(shè)計制作、成都網(wǎng)站設(shè)計網(wǎng)站策劃,項目實施與項目整合能力。我們以讓每一個夢想脫穎而出為使命,1280元鐵門關(guān)做網(wǎng)站,已為上家服務(wù),為鐵門關(guān)各地企業(yè)和個人服務(wù),聯(lián)系電話:18982081108
如下圖,如果運行行情數(shù)據(jù)下載時候,是在交易日中的話比如2點半或者上午8點,如果填寫的endDate是當天或者之后的日期,那么返回數(shù)據(jù)會自動填充到下午3點交易時候。此時之后的數(shù)據(jù)都是交易量為0,價格就是2點半時候價格。
所以在用作實盤數(shù)據(jù)分析時候,必須要填入endDate的分鐘時間為當前時間,才可以確保不會出現(xiàn)控制。整體代碼更新如下:
# encoding: UTF-8 from __future__ import print_function import sys import json from datetime import datetime,date,timedelta from time import time, sleep from pymongo import MongoClient, ASCENDING import pandas as pd from vnpy.trader.vtObject import VtBarData, VtTickData from vnpy.trader.app.ctaStrategy.ctaBase import (MINUTE_DB_NAME, DAILY_DB_NAME, TICK_DB_NAME) import jqdatasdk as jq # 加載配置 config = open('config.json') setting = json.load(config) mc = MongoClient() # Mongo連接 dbMinute = mc[MINUTE_DB_NAME] # 數(shù)據(jù)庫 # dbDaily = mc[DAILY_DB_NAME] # dbTick = mc[TICK_DB_NAME] USERNAME = setting['Username'] PASSWORD = setting['Password'] jq.auth(USERNAME, PASSWORD) FIELDS = ['open', 'high', 'low', 'close', 'volume'] # ---------------------------------------------------------------------- def generateVtBar(row, symbol): """生成K線""" bar = VtBarData() bar.symbol = symbol bar.exchange = "SHFE" bar.vtSymbol = bar.vtSymbol = '.'.join([bar.symbol, bar.exchange]) bar.open = row['open'] bar.high = row['high'] bar.low = row['low'] bar.close = row['close'] bar.volume = row['volume'] bardatetime = row.name bar.date = bardatetime.strftime("%Y%m%d") bar.time = bardatetime.strftime("%H%M%S") # 將bar的時間改成提前一分鐘 hour = bar.time[0:2] minute = bar.time[2:4] sec = bar.time[4:6] if minute == "00": minute = "59" h = int(hour) if h == 0: h = 24 hour = str(h - 1).rjust(2, '0') else: minute = str(int(minute) - 1).rjust(2, '0') bar.time = hour + minute + sec bar.datetime = datetime.strptime(' '.join([bar.date, bar.time]), '%Y%m%d %H%M%S') return bar # ---------------------------------------------------------------------- def jqdownloadMinuteBarBySymbol(symbol,startDate,endDate): """下載某一合約的分鐘線數(shù)據(jù)""" start = time() cl = dbMinute[symbol] cl.ensure_index([('datetime', ASCENDING)], unique=True) # 添加索引 df = jq.get_price(setting[symbol],start_date = startDate,end_date = endDate, frequency='1m', fields=FIELDS,skip_paused = True) for ix, row in df.iterrows(): bar = generateVtBar(row, symbol) d = bar.__dict__ flt = {'datetime': bar.datetime} cl.replace_one(flt, d, True) end = time() cost = (end - start) * 1000 print(u'合約%s的分鐘K線數(shù)據(jù)下載完成%s - %s,耗時%s毫秒' % (symbol, df.index[0], df.index[-1], cost)) print(jq.get_query_count()) def jqdownloadMappingExcel(exportpath = "C:\Project\\"): getfuture = jq.get_all_securities(types=['futures'], date=None) # list: 用來過濾securities的類型, list元素可選: ‘stock’, ‘fund’, ‘index’, ‘futures’, ‘etf’, ‘lof’, ‘fja’, ‘fjb’.types為空時返回所有股票, 不包括基金, 指數(shù)和期貨 getfuture.to_excel( exportpath + "Mapping" + str(date.today()) + "futures.xls", index=True, header=True) # ---------------------------------------------------------------------- def downloadAllMinuteBar(days=10): """下載所有配置中的合約的分鐘線數(shù)據(jù)""" print('-' * 50) print(u'開始下載合約分鐘線數(shù)據(jù)') print('-' * 50) startDt = datetime.today() - days * timedelta(1) startDate = startDt.strftime('%Y-%m-%d') # 添加下載任務(wù) enddt = datetime.today() endDate = enddt.strftime('%Y-%m-%d %H:%M:%S') jqdownloadMinuteBarBySymbol('rb1910', startDate, endDate) print('-' * 50) print u'合約分鐘線數(shù)據(jù)下載完成' print('-' * 50) if __name__ == '__main__': # jqdownloadMappingExcel() #下載主力合約 downloadAllMinuteBar(days=10) #下載單個品種 # jqdownloadMinuteBarBySymbol('510050.XSHG',startDate,endDate)
以上是“怎么使用Joinquant做實盤行情數(shù)據(jù)”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學習更多知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!
本文標題:怎么使用Joinquant做實盤行情數(shù)據(jù)
文章出自:http://aaarwkj.com/article42/gjdihc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站導(dǎo)航、電子商務(wù)、商城網(wǎng)站、面包屑導(dǎo)航、網(wǎng)站排名、品牌網(wǎng)站設(shè)計
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)