コード例 #1
0
def turtle_test(loadtype='pgs', dataString='pyalg'):
    """
    :param dataString:
    :return:
    """
    # 从postgres 中加载
    if loadtype == 'pgs':
        from api.stock.histmd import to_postgres_md as tpd
        dat = tpd.get_h_data('600848')
    else:
        from api.stock.histmd.to_mongodb_md import k_data_dao as tmd
        w = tmd.KdataDbCache()
        dat = w.get_k_data(index=False,start='2015-02-05', end='2015-02-19',code='300426')
    feed = dataFramefeed.Feed()
    feed.addBarsFromDataFrame("orcl", dat)
    myStrategy = pdr.turtle(feed, "orcl", 20, 10)
    # Attach a returns analyzers to the strategy.
    returnsAnalyzer = returns.Returns()
    myStrategy.attachAnalyzer(returnsAnalyzer)

    # Attach the plotter to the strategy.
    plt = plotter.StrategyPlotter(myStrategy)
    # Plot the simple returns on each bar.
    plt.getOrCreateSubplot("returns").addDataSeries("Simple returns", returnsAnalyzer.getReturns())

    if dataString == 'pyalg_util':
        ds = pyalg_utils.dataSet(myStrategy)  # 抽取交易数据集语句,若使用系统自带画图功能则不需要该项
    myStrategy.run()
    myStrategy.info("Final portfolio value: $%.2f" % myStrategy.getResult())

    if dataString == 'pyalg_util':
        rs = ds.getDefault()  # 获取默认的交易信息,dic格式
        plot(rs["cumulativeReturns"][:, 0], rs["cumulativeReturns"][:, 1])  # 简单作图示例

    plt.plot()
コード例 #2
0
ファイル: csvDemo.py プロジェクト: zzprice/xuefu
def turtle_test(dataString='pyalg'):
    """
    :param dataString:
    :return:
    """
    feed = yahoofeed.Feed()
    feed.addBarsFromCSV(
        "orcl", "../../api/stock/csv/orcl-2000.csv")  #注意查看该csv的格式,Open为大写

    myStrategy = pdr.turtle(feed, "orcl", 20, 10)
    # Attach a returns analyzers to the trategy.
    returnsAnalyzer = returns.Returns()
    myStrategy.attachAnalyzer(returnsAnalyzer)

    # Attach the plotter to the strategy.
    plt = plotter.StrategyPlotter(myStrategy)
    # Plot the simple returns on each bar.
    plt.getOrCreateSubplot("returns").addDataSeries(
        "Simple returns", returnsAnalyzer.getReturns())

    if dataString == 'pyalg_util':
        ds = pyalg_utils.dataSet(myStrategy)  # 抽取交易数据集语句,若使用系统自带画图功能则不需要该项
    myStrategy.run()
    myStrategy.info("Final portfolio value: $%.2f" % myStrategy.getResult())

    if dataString == 'pyalg_util':
        rs = ds.getDefault()  # 获取默认的交易信息,dic格式
        plot(rs["cumulativeReturns"][:, 0],
             rs["cumulativeReturns"][:, 1])  # 简单作图示例

    plt.plot()
コード例 #3
0
ファイル: pandasDemo.py プロジェクト: bigfishkun/palgt3
def turtle_test(loadtype='tushare', dataString='pyalg'):
    """
    :param dataString:
    :return:
    """
    # 从dataFrame中加载,
    if loadtype == 'tushare':
        import tushare as ts
        dat = ts.get_h_data('600848')
        dat.index.name = 'date'
    else:
        dat = pd.read_csv("../../api/stock/csv/600848.csv",
                          index_col=0,
                          encoding='gbk')
        print(dat.head())
    feed = dataFramefeed.Feed()
    feed.addBarsFromDataFrame("orcl", dat)
    myStrategy = pdr.turtle(feed, "orcl", 20, 10)
    # Attach a returns analyzers to the strategy.
    returnsAnalyzer = returns.Returns()
    myStrategy.attachAnalyzer(returnsAnalyzer)

    # Attach the plotter to the strategy.
    plt = plotter.StrategyPlotter(myStrategy)
    # Plot the simple returns on each bar.
    plt.getOrCreateSubplot("returns").addDataSeries(
        "Simple returns", returnsAnalyzer.getReturns())

    if dataString == 'pyalg_util':
        ds = pyalg_utils.dataSet(myStrategy)  # 抽取交易数据集语句,若使用系统自带画图功能则不需要该项
    myStrategy.run()
    myStrategy.info("Final portfolio value: $%.2f" % myStrategy.getResult())

    if dataString == 'pyalg_util':
        rs = ds.getDefault()  # 获取默认的交易信息,dic格式
        plot(rs["cumulativeReturns"][:, 0],
             rs["cumulativeReturns"][:, 1])  # 简单作图示例

    plt.plot()