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
    來源:简书
    著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

  • 相关阅读:
    轮播无缝
    项目开发的注意
    再聊移动端页面的适配
    如何在Vue项目中使用vw实现移动端适配
    移动端适配文章
    vue-cli 配置flexible px2rem-loader安装配置
    vuex复习笔记
    vue-router复习笔记
    vue-cli 笔记
    内置组件 -slot讲解
  • 原文地址:https://www.cnblogs.com/zhanglong8681/p/7569196.html
Copyright © 2011-2022 走看看