rainx / pytdx

Python tdx数据接口
1.34k stars 950 forks source link

建议:最好与BackTrader/PyAlgoTrade对接 #93

Open zfsamzfsam opened 7 years ago

zfsamzfsam commented 7 years ago

backtrader https://github.com/mementum/backtrader 成熟度比较高,演进速度很快,文档全,社区还是存在的!!!

PyAlgoTrade/PyAlgoTrade-cn https://github.com/gbeced/pyalgotrade https://github.com/Yam-cn/pyalgotrade-cn 个人感觉PyAlgoTrade比backtrader的成熟度,易用性要差!!!

JaysonAlbert commented 7 years ago

这个只是一个行情库而已,对其它回测框架的对接最好还是个人动手吧,毕竟回测框架一大堆,rainx有一些项目是用来对接zipline的,你可以看看

JaysonAlbert commented 7 years ago

我来打个广告吧。我用这个pytdx以及 @rainx 大神的另外几项目,写了一个对接zipline的项目,最近才开始写的,还在不断的改进,你可以去看看 @zfsamzfsam https://github.com/JaysonAlbert/cn_zipline

zfsamzfsam commented 7 years ago

我个人觉得zipline框架太大太复杂了,BackTrader/PyAlgoTrade比较小巧简单一些!!! 但zipline的一些模块单独来看还是很有意义的.

yutiansut commented 7 years ago

rainx大大好像自己有个回测框架的

rainx commented 7 years ago

@JaysonAlbert @zfsamzfsam @yutiansut 我们自己根据zipline1.0.2移植了一份,最初的版本是我来做的,现在交给同事在维护,目前主要是面向学校使用的.. backtrader 和 PyAlgoTrade 我用的比较少,还在摸索中.. 最近感觉自己各个方面的知识需要补充的比较多,主要是计算机科学的深入方面的知识和金融领域的入门知识,现在这个阶段还在学习中... ^_^ , 后面有了更深入的理解之后再下手来做

wuxin1030 commented 6 years ago

其实做一个回测系统不是本项目的重点,用rqalpha回测更好,或者改造rqalpha。

yutiansut commented 6 years ago

https://github.com/yutiansut/quantaxis 已经对接好了的框架

QUANTAXIS 量化金融策略框架

支持:

spidermachine commented 6 years ago

pytdx与backtrader对接

!/usr/bin/python

vim: set fileencoding=utf8 :

# author = 'keping.chu' from pytdx.hq import TdxHq_API from backtrader.feeds.pandafeed import PandasData import pandas

def select_market_code(code): code = str(code) if code[0] in ['5', '6', '9'] or code[:3] in ["009", "126", "110", "201", "202", "203", "204"]: return 1 return 0

cycle

WEEK = 5 DAY = 9 MONTH = 6 QUARTER = 10 YEAR = 11

class PyTdxPandasData(PandasData):

def __init__(self, host, port, symbol, mapsymbol, cyc=WEEK, period=5):
    api = TdxHq_API()
    with api.connect(host, port):
        if symbol.startswith('399'):
            pandasda = api.to_df(api.get_index_bars(cyc, select_market_code(symbol), symbol, 0, period))
        else:
            pandasda = api.to_df(api.get_security_bars(cyc, select_market_code(symbol), symbol, 0, period))
    pandasda.to_csv(symbol+'.csv')
    pandasda['datetime'] = pandas.to_datetime(pandasda['datetime'])
    self.p.dataname = pandasda
    if mapsymbol is None:
        self.p.name = symbol
    else:
        self.p.name = mapsymbol
    self.p.volume = 'vol'
    self.p.datetime = -1
    super(PyTdxPandasData, self).__init__()

class PyTdxPandasDataExt(PandasData):

def __init__(self, symbol, data):

    self.p.dataname = data
    self.p.name = symbol
    self.p.volume = 'vol'
    self.p.datetime = -1
    super(PyTdxPandasDataExt, self).__init__()

class BatchTDXPandasData:

def __init__(self, symbols, host, port, cyc):
    self.host = host
    self.port = port
    self.cyc = cyc
    self.symbols = symbols

def get_data_list(self, size):
    data = []
    api = TdxHq_API()
    with api.connect(self.host, self.port):
        for symbol in self.symbols:
            pandasda = api.to_df(api.get_security_bars(self.cyc, select_market_code(symbol), symbol, 0, size))
            pandasda['datetime'] = pandas.to_datetime(pandasda['datetime'])
            data.append(PyTdxPandasDataExt(symbol, pandasda))
        return data

def get_data_dict(self, size):
    data = {}
    api = TdxHq_API()
    with api.connect(self.host, self.port):
        for symbol in self.symbols:
            pandasda = api.to_df(api.get_security_bars(self.cyc, select_market_code(symbol), symbol, 0, size))
            pandasda['datetime'] = pandas.to_datetime(pandasda['datetime'])
            data[symbol] = PyTdxPandasDataExt(symbol, pandasda)
    return data
rainx commented 6 years ago

@spidermachine nice,我后面争取把和一些量化平台关联使用的方法更新到文档里