Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    1. Home
    2. Aill3urs 2019
    For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/
    • Profile
    • Following 0
    • Followers 0
    • Topics 3
    • Posts 9
    • Best 0
    • Groups 0

    Aill3urs 2019

    @Aill3urs 2019

    0
    Reputation
    9
    Profile views
    9
    Posts
    0
    Followers
    0
    Following
    Joined Last Online

    Aill3urs 2019 Unfollow Follow

    Latest posts made by Aill3urs 2019

    • RE: Alpha Vantage

      Thanks i try it but no result at all :-)
      Ouput nothing :-)

      posted in General Code/Help
      Aill3urs 2019
      Aill3urs 2019
    • RE: Is there a template for backtesting strategy

      I'm on page 486 for on python book :-)

      posted in General Discussion
      Aill3urs 2019
      Aill3urs 2019
    • RE: Alpha Vantage

      Thanks for your answer.
      Where do you get data ?

      posted in General Code/Help
      Aill3urs 2019
      Aill3urs 2019
    • RE: Alpha Vantage

      oops sorry, here is the code

      from alpha_vantage.timeseries import TimeSeries
      import backtrader as bt
      
      # Create a subclass of Strategy to define the indicators and logic
      
      class SmaCross(bt.Strategy):
          # list of parameters which are configurable for the strategy
          params = dict(
              pfast=10,  # period for the fast moving average
              pslow=30   # period for the slow moving average
          )
      
          def __init__(self):
              sma1 = bt.ind.SMA(period=self.p.pfast)  # fast moving average
              sma2 = bt.ind.SMA(period=self.p.pslow)  # slow moving average
              self.crossover = bt.ind.CrossOver(sma1, sma2)  # crossover signal
      
          def next(self):
              if not self.position:  # not in the market
                  if self.crossover > 0:  # if fast crosses slow to the upside
                      self.buy()  # enter long
      
              elif self.crossover < 0:  # in the market & cross to the downside
                  self.close()  # close long position
      
      
      cerebro = bt.Cerebro() 
      
      ts = TimeSeries(key='MYKEY', output_format='pandas')
      data = ts.get_intraday(symbol='BTCUSD',interval='1min', outputsize='full')
      print(data)
      cerebro.adddata(data)  # Add the data feed
      
      cerebro.addstrategy(SmaCross)  # Add the trading strategy
      cerebro.run()  # run it all
      cerebro.plot()  # and plot it with a single command
      
      posted in General Code/Help
      Aill3urs 2019
      Aill3urs 2019
    • RE: Alpha Vantage

      @Aill3urs-2019 My errors

      File "/xxxxxx/Trading001/Entrainement_Data_Ok.py", line 64, in <module>
      cerebro.adddata(data) # Add the data feed

      File "/xxxxxx/site-packages/backtrader/cerebro.py", line 758, in adddata
      data.setenvironment(self)

      File "/xxxxx/site-packages/pandas/core/generic.py", line 5274, in getattr
      return object.getattribute(self, name)

      AttributeError: 'DataFrame' object has no attribute 'setenvironment'

      posted in General Code/Help
      Aill3urs 2019
      Aill3urs 2019
    • Alpha Vantage

      Hello
      In this code i try to import data from alpha vantage but look like doesn't work

      Thanks for your help

      from alpha_vantage.timeseries import TimeSeries
      import backtrader as bt

      Create a subclass of Strategy to define the indicators and logic

      class SmaCross(bt.Strategy):
      # list of parameters which are configurable for the strategy
      params = dict(
      pfast=10, # period for the fast moving average
      pslow=30 # period for the slow moving average
      )

      def __init__(self):
          sma1 = bt.ind.SMA(period=self.p.pfast)  # fast moving average
          sma2 = bt.ind.SMA(period=self.p.pslow)  # slow moving average
          self.crossover = bt.ind.CrossOver(sma1, sma2)  # crossover signal
      
      def next(self):
          if not self.position:  # not in the market
              if self.crossover > 0:  # if fast crosses slow to the upside
                  self.buy()  # enter long
      
          elif self.crossover < 0:  # in the market & cross to the downside
              self.close()  # close long position
      

      cerebro = bt.Cerebro() # create a "Cerebro" engine instance

      Create a data feed

      #data = bt.feeds.YahooFinanceData(dataname='MSFT', fromdate=datetime(2011, 1, 1), todate=datetime(2012, 12, 31))
      ts = TimeSeries(key='MYKEY', output_format='pandas')
      data, meta_data = ts.get_intraday(symbol='MSF',interval='1min', outputsize='full')

      cerebro.adddata(data) # Add the data feed

      cerebro.addstrategy(SmaCross) # Add the trading strategy
      cerebro.run() # run it all
      cerebro.plot() # and plot it with a single command

      posted in General Code/Help
      Aill3urs 2019
      Aill3urs 2019
    • Is there a template for backtesting strategy

      Hello,
      I'm a little bit noob in python but i try :-)
      I would like to know if there is a template to backtest strategy and live test it for bitmex or other exchange.
      And after i would like to know if it s possible to connect it to exchange for real time trading ?

      Thanks a lot

      posted in General Discussion
      Aill3urs 2019
      Aill3urs 2019
    • RE: Bug

      Thanks you for your help

      posted in General Code/Help
      Aill3urs 2019
      Aill3urs 2019
    • Bug

      Hello
      When i try to run a just this test on Spyder , i have this error :
      ///-------ERROR-------------------//
      File "/Users/jxx/.spyder-py3/temp.py", line 25, in <module>
      cerebro.run()

      File "/Users/jxx/anaconda3/lib/python3.7/site-packages/backtrader/cerebro.py", line 1127, in run
      runstrat = self.runstrategies(iterstrat)

      File "/Users/jxx/anaconda3/lib/python3.7/site-packages/backtrader/cerebro.py", line 1210, in runstrategies
      data._start()

      File "/Users/jxx/anaconda3/lib/python3.7/site-packages/backtrader/feed.py", line 203, in _start
      self.start()

      File "/Users/jxx/anaconda3/lib/python3.7/site-packages/backtrader/feeds/yahoo.py", line 352, in start
      super(YahooFinanceData, self).start()

      File "/Users/jxx/anaconda3/lib/python3.7/site-packages/backtrader/feeds/yahoo.py", line 94, in start
      super(YahooFinanceCSVData, self).start()

      File "/Users/jxxx/anaconda3/lib/python3.7/site-packages/backtrader/feed.py", line 674, in start
      self.f = io.open(self.p.dataname, 'r')

      FileNotFoundError: [Errno 2] No such file or directory: 'BTC-USD'

      ///--------------------------------------------//

      from datetime import datetime
      import backtrader as bt

      class SmaCross(bt.SignalStrategy):
      def init(self):
      sma1, sma2 = bt.ind.SMA(period=10), bt.ind.SMA(period=30)
      crossover = bt.ind.CrossOver(sma1, sma2)
      self.signal_add(bt.SIGNAL_LONG, crossover)

      cerebro = bt.Cerebro()
      cerebro.addstrategy(SmaCross)

      data0 = bt.feeds.YahooFinanceData(dataname='BTC-USD', fromdate=datetime(2018, 1, 1),
      todate=datetime(2019, 12, 31))
      cerebro.adddata(data0)

      cerebro.run()
      cerebro.plot()

      posted in General Code/Help
      Aill3urs 2019
      Aill3urs 2019