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/

    With my data it prints only portfolio value

    General Code/Help
    2
    3
    48
    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.
    • M
      MatteWannabe last edited by

      I have tried this code with two diiferent data.
      'AAPL.csv' from yahoo finance (daily) and a csv from alphavantage (minute). I need to work with minutes, the strategy works with the daily csv and not with the other csv.
      I have tried also with the strategy from the quickstartguide, the result is the same, with the csv from yahoo everything is fine, with the one from alphavantage the strategy seems not to run.

      import backtrader as bt
      import backtrader.feeds as btfeeds
      import datetime
      
      class StrategiaProva1(bt.Strategy):
          def next(self):
              if self.data.close > 126:
                  print(dataYF.datetime)
      
      if __name__ == '__main__':
          cerebro = bt.Cerebro()
          cerebro.addstrategy(StrategiaProva1)
      
          dataAP = btfeeds.GenericCSVData(
              dataname = 'extended_intraday_AAPL_1min_year1month1_adjusted.csv',
              fromdate = datetime.datetime(2020, 8, 24, 4, 1, 00),
              todate = datetime.datetime(2020, 9, 21, 20, 00, 00),
              openinterest = -1
          )
      
          dataYF = bt.feeds.GenericCSVData(
              dataname = 'AAPL.csv',
              dtformat = ('%Y-%m-%d'), 
              fromdate = datetime.datetime(2020, 8, 24), 
              todate = datetime.datetime(2020, 9, 18),
              openinterest = -1
          )
      
          cerebro.adddata(dataYF)
          cerebro.broker.setcash(1000.00)
      
          print('Saldo pre-trading: %.2f' %cerebro.broker.getvalue())
      
          cerebro.run()
      
          print('Saldo post-trading: %.2f' %cerebro.broker.getvalue())
      

      The output when I use AlphaVantage data is this:

      Saldo pre-trading: 1000.00
      Saldo post-trading: 1000.00
      

      The output when I use Yahoo data is correct and is this:

      Saldo pre-trading: 1000.00
      <backtrader.linebuffer.LineBuffer object at 0x05252FD0>
      <backtrader.linebuffer.LineBuffer object at 0x05252FD0>
      <backtrader.linebuffer.LineBuffer object at 0x05252FD0>
      <backtrader.linebuffer.LineBuffer object at 0x05252FD0>
      Saldo post-trading: 1000.00
      

      Here's the datas:
      This daily 20 row csv from yahoo finance
      Yahoo data.png
      And this 18147 rows csv from AlphaVantage
      Ap data.png
      It's a lot of days I'm working on this, please help.

      run-out 1 Reply Last reply Reply Quote 0
      • run-out
        run-out @MatteWannabe last edited by

        @mattewannabe said in With my data it prints only portfolio value:

        dataYF = bt.feeds.GenericCSVData(
        dataname = 'AAPL.csv',
        dtformat = ('%Y-%m-%d'),
        fromdate = datetime.datetime(2020, 8, 24),
        todate = datetime.datetime(2020, 9, 18),
        openinterest = -1
        )

        On this page look for Data Feed Common Parameters.

        timeframe (default: TimeFrame.Days)

        Potential values: Ticks, Seconds, Minutes, Days, Weeks, Months and Years

        RunBacktest.com

        M 1 Reply Last reply Reply Quote 2
        • M
          MatteWannabe @run-out last edited by

          @run-out Thank you so much!!!!

          1 Reply Last reply Reply Quote 1
          • 1 / 1
          • First post
            Last post
          Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors