vn.py官网
你的开源社区量化交易平台
Member
avatar
加入于:
帖子: 14
声望: 0

新手 发帖
今天做了个通达信本地数据导入,
问题1 :时间处理不知对不对?
问题2 :turnover和open_interest 这俩字段是干嘛的呀?
代码如下:

#tdx reader local data
import os 
from pytdx.reader import TdxLCMinBarReader, TdxFileNotFoundException
from datetime import timedelta
from vnpy.trader.constant import Exchange, Interval
from vnpy.trader.object import BarData
from pytz import timezone
from vnpy.trader.utility import round_to
from vnpy.trader.database import BaseDatabase, get_database

INTERVAL_ADJUSTMENT_MAP = {
    Interval.MINUTE: timedelta(minutes=1),
    Interval.HOUR: timedelta(hours=1),
    Interval.DAILY: timedelta()         # no need to adjust for daily bar
}
interval=Interval.MINUTE
adjustment = INTERVAL_ADJUSTMENT_MAP[interval]
CHINA_TZ = timezone("Asia/Shanghai")
data_path=["C:\\new_jyplug\\vipdoc\\sh\\minline\\","C:\\new_jyplug\\vipdoc\\sz\\minline\\"]
database: BaseDatabase = get_database()
reader = TdxLCMinBarReader()
for p in data_path:
    file_list=os.listdir(p)
    for file_name in file_list:
        file_path=p+file_name
        print(file_path)
        df = reader.get_df(file_path)
        exchange=file_name[0:2]
        symbol=file_name[2:-4]
        exchange=Exchange.SSE if exchange=="sh" else Exchange.SZSE

        data = []
        if df is not None:
            df.sort_index(ascending=False)
            for ix, row in df.iterrows():
                dt = ix.to_pydatetime() - adjustment
                dt = CHINA_TZ.localize(dt)

                bar = BarData(
                    symbol=symbol,
                    exchange=exchange,
                    interval=interval,
                    datetime=dt,
                    open_price=round_to(row["open"], 0.000001),
                    high_price=round_to(row["high"], 0.000001),
                    low_price=round_to(row["low"], 0.000001),
                    close_price=round_to(row["close"], 0.000001),
                    volume=row["volume"],
                    turnover=row.get("total_turnover",0),
                    open_interest=row.get("open_interest", 0),
                    gateway_name="tdx"
                )

                data.append(bar)
        database.save_bar_data(data)
Administrator
avatar
加入于:
帖子: 58
声望: 5

1,想知道时间顺序对不对的话,可以直接在图形界面中启动data_manager模块查看。
2,turnover是成交额;open_interest是未平仓合约,是在某一交收月份期货市场中未通过抵消或交收套现的合约数。

© 2015-2019 上海韦纳软件科技有限公司
备案服务号:沪ICP备18006526号-3

沪公网安备 31011502017034号

【用户协议】
【隐私政策】