Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

    Trouble with import 1 minute data feed

    General Code/Help
    1
    2
    190
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Pavel Vasyl'ev
      Pavel Vasyl'ev last edited by

      Hello guys, I had a problem importing data with a 1 minute timeframe. When I start cerebro, and the strategy, in the end, the size of my portfolio remains unchanged.

      import backtrader as bt
      import os
      import matplotlib.pyplot
      
      cerebro = bt.Cerebro()
      cerebro.broker.setcash(100.0)
      
      data = bt.feeds.GenericCSVData(
         dataname='data.csv',
         nullvalue = 0.0,
         datetime=0,
         timeframe=bt.TimeFrame.Minutes,
         compression=1,
         dtformat=('%Y-%m-%d %H:%M:%S'),
         open=1,
         high=2,
         low=3,
         close=4,
         volume=5,
         openinterest=None,
         reverse=False,
         header=0)
      
      cerebro.adddata(data)
      
      import backtrader.indicators as btind
      
      
      class MA_CrossOver(bt.Strategy):
      
         alias = ('SMA_CrossOver',)
      
         params = (
             # period for the fast Moving Average
             ('fast', 10),
             # period for the slow moving average
             ('slow', 30),
             # moving average to use
             ('_movav', btind.MovAv.SMA)
         )
      
         def __init__(self):
             sma_fast = self.p._movav(period=self.p.fast)
             sma_slow = self.p._movav(period=self.p.slow)
      
             self.buysig = btind.CrossOver(sma_fast, sma_slow)
      
         def next(self):
             if self.position.size:
                 if self.buysig < 0:
                     self.sell()
      
             elif self.buysig > 0:
                 self.buy()
      
      cerebro.addstrategy(MA_CrossOver)
      cerebro.run()
      print('Final Portfolio Value: %.2f' % cerebro.broker.getvalue())
      

      The data

      1 Reply Last reply Reply Quote 0
      • Pavel Vasyl'ev
        Pavel Vasyl'ev last edited by

        I fixed it. Most likely, the error was in a bad strategy and in the fact that the date was presented as an index.

        1 Reply Last reply Reply Quote 0
        • 1 / 1
        • First post
          Last post
        Copyright © 2016, 2017, 2018 NodeBB Forums | Contributors
        $(document).ready(function () { app.coldLoad(); }); }