zoukankan      html  css  js  c++  java
  • PyalgoTrade 打印收盘价(二)

    让我们从一个简单的策略开始,就是在打印收盘价格的过程中:

    from pyalgotrade import strategy
    from pyalgotrade.barfeed import yahoofeed
    
    
    class MyStrategy(strategy.BacktestingStrategy):
        def __init__(self, feed, instrument):
            super(MyStrategy, self).__init__(feed)
            self.__instrument = instrument
    
        def onBars(self, bars):
            bar = bars[self.__instrument]
            self.info(bar.getClose())
    
    # Load the yahoo feed from the CSV file
    feed = yahoofeed.Feed()
    feed.addBarsFromCSV("orcl", "orcl-2000.csv")
    
    # Evaluate the strategy with the feed's bars.
    myStrategy = MyStrategy(feed, "orcl")
    myStrategy.run()

    代码做三件主要事情:

    • 声明新策略 只有一种必须定义的方法,onBars,它被称为Feed中的每个栏。
    • 从CSV文件加载Feed。
    • 使用Feed提供的栏来运行策略。
      如果您运行脚本,您应该按顺序看到收盘价:
      2000-01-03 00:00:00 strategy [INFO] 118.12
      2000-01-04 00:00:00 strategy [INFO] 107.69
      2000-01-05 00:00:00 strategy [INFO] 102.0
      .
      .
      .
      2000-12-27 00:00:00 strategy [INFO] 30.69
      2000-12-28 00:00:00 strategy [INFO] 31.06
      2000-12-29 00:00:00 strategy [INFO] 29.06



    作者:readilen
    链接:http://www.jianshu.com/p/9f9658474df2
    來源:简书
    著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

  • 相关阅读:
    避免数据脏读
    OGG配置文件中参数化的运用
    GoldenGate基于中间队列文件的初始化
    一次linux中毒,挖矿病毒
    goldengate新版本中查看日志读取点
    dlopen用法参数flag介绍
    gdb调试带参数和调试core
    在现有的git服务器上面创建新的repo
    Play Old Diablo 2 on macOS Catalina
    Odoo中的Environment对象
  • 原文地址:https://www.cnblogs.com/zhanglong8681/p/7569196.html
Copyright © 2011-2022 走看看