Backtrader Community

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

    GwadaMan

    @GwadaMan

    2
    Reputation
    605
    Profile views
    13
    Posts
    1
    Followers
    1
    Following
    Joined Last Online

    GwadaMan Unfollow Follow

    Best posts made by GwadaMan

    • RE: Pair Trading with minutes data

      :Here a part of the source code with the timeframe/compression setting

      def runstrategy():
          args = parse_args()
      
          # Create a cerebro
          cerebro = bt.Cerebro()
      
          # Get the dates from the args
          fromdate = datetime.datetime(2016, 11, 25) # datetime.datetime.strptime(args.fromdate, '%Y-%m-%d')
          todate = datetime.datetime(2016, 12, 02) # datetime.datetime.strptime(args.todate, '%Y-%m-%d')
      
          # Create the 1st data
          tframes = dict(
              secondes=bt.TimeFrame.Seconds,
              minutes=bt.TimeFrame.Minutes,
              days=bt.TimeFrame.Days,
              weeks=bt.TimeFrame.Weeks,
              months=bt.TimeFrame.Months,
              years=bt.TimeFrame.Years)
      
          # Create the 1st data
          """
          data0 = btfeeds.YahooFinanceCSVData(
              dataname=args.data0,
              fromdate=fromdate,
              todate=todate)
          """
          data0 = btfeeds.GenericCSVData(
              dataname=args.data0,
      
              fromdate=fromdate,
              todate=todate,
      
              nullvalue=0.0,
      
              dtformat=('%Y-%m-%d %H:%M:%S'),
              datetime=0,
              high=2,
              low=3,
              open=1,
              close=4,
              volume=5,
              openinterest=-1,
          )
      
          # Add the 1st data to cerebro
          cerebro.adddata(data0)
      
          # Create the 2nd data
          """
          data1 = btfeeds.YahooFinanceCSVData(
              dataname=args.data1,
              fromdate=fromdate,
              todate=todate)
          """
          data1 = btfeeds.GenericCSVData(
              dataname=args.data1,
      
              fromdate=fromdate,
              todate=todate,
      
              nullvalue=0.0,
      
              dtformat=('%Y-%m-%d %H:%M:%S'),
              datetime=0,
              high=2,
              low=3,
              open=1,
              close=4,
              volume=5,
              openinterest=-1,
          )
      
          # Add the 2nd data to cerebro
          cerebro.adddata(data1)
      
      
          cerebro.resampledata(data0,timeframe=tframes[args.timeframe], compression=args.compression)
          # Create the 2nd data
          # Add the 2nd data to cerebro
          #cerebro.adddata(data1)
          cerebro.resampledata(data1,timeframe=tframes[args.timeframe], compression=args.compression)
      
          # Add the strategy
          cerebro.addstrategy(PairTradingStrategy,
                              period=args.period,
                              stake=args.stake)
      
          # Add the commission - only stocks like a for each operation
          cerebro.broker.setcash(args.cash)
      
          # Add the commission - only stocks like a for each operation
          cerebro.broker.setcommission(commission=args.commperc)
      
          # And run it
          cerebro.run(runonce=not args.runnext,
                      preload=not args.nopreload,
                      oldsync=args.oldsync)
      
          # Plot if requested
          if args.plot:
              cerebro.plot(numfigs=args.numfigs, volume=False, zdown=False)
      
      
      def parse_args():
          parser = argparse.ArgumentParser(description='MultiData Strategy')
      
          parser.add_argument('--data0', '-d0',
                              default='intra-DDD.csv',
                              help='1st data into the system')
      
          parser.add_argument('--data1', '-d1',
                              default='intra-SSYS.csv',
                              help='2nd data into the system')
      
          parser.add_argument('--fromdate', '-f',
                              default='1997-01-01',
                              help='Starting date in YYYY-MM-DD format')
      
          parser.add_argument('--todate', '-t',
                              default='1998-06-01',
                              help='Starting date in YYYY-MM-DD format')
      
          group = parser.add_mutually_exclusive_group()
          group.add_argument('--tframe', default='years', required=False,
                             choices=['days', 'weeks', 'months', 'years'],
                             help='TimeFrame for the returns/Sharpe calculations')
      
          group.add_argument('--legacyannual', action='store_true',
                             help='Use legacy annual return analyzer')
      
      
          pgroup = parser.add_mutually_exclusive_group(required=False)
      
          pgroup.add_argument('--replay',
                              required=False, action='store_true',
                              help='replay to chosen timeframe')
      
          pgroup.add_argument('--resample', default = True,
                              required=False, action='store_true',
                              help='resample to chosen timeframe')
      
          parser.add_argument('--timeframe', default='minutes',
                              choices=bt.TimeFrame.Names,
                              required=False, action='store',
                              help='TimeFrame for Resample/Replay')
      
          parser.add_argument('--compression', default=1, type=int,
                              required=False, action='store',
                              help='Compression for Resample/Replay')
      
          parser.add_argument('--timeframe1', default=True,
                              choices=bt.TimeFrame.Names,
                              required=False, action='store',
                              help='TimeFrame for Resample/Replay - Data1')
      
          parser.add_argument('--compression1', default=None, type=int,
                              required=False, action='store',
                              help='Compression for Resample/Replay - Data1')
      
          parser.add_argument('--period', default=10, type=int,
                              help='Period to apply to the Simple Moving Average')
      
          parser.add_argument('--cash', default=100000, type=int,
                              help='Starting Cash')
      
          parser.add_argument('--runnext', action='store_true',
                              help='Use next by next instead of runonce')
      
          parser.add_argument('--nopreload', action='store_true',
                              help='Do not preload the data')
      
          parser.add_argument('--oldsync', action='store_true',
                              help='Use old data synchronization method')
      
          parser.add_argument('--commperc', default=0.005, type=float,
                              help='Percentage commission (0.005 is 0.5%%')
      
          parser.add_argument('--stake', default=10, type=int,
                              help='Stake to apply in each operation')
      
          parser.add_argument('--plot', '-p', default=True, action='store_true',
                              help='Plot the read data')
      
          parser.add_argument('--numfigs', '-n', default=1,
                              help='Plot using numfigs figures')
      
          return parser.parse_args()
      
      
      if __name__ == '__main__':
          runstrategy()
      
      posted in Indicators/Strategies/Analyzers
      G
      GwadaMan
    • RE: Make calcul with indicator

      Hi Curtis,

      Thank you very much for the correction. It works !!!
      We can close this case.
      Regards,

      posted in Indicators/Strategies/Analyzers
      G
      GwadaMan

    Latest posts made by GwadaMan

    • Real-Time feeding with Websocket

      Hi EveryBody !!!
      Hi Backtrader !!!
      Does BT is support and compatible with Full real-time feeding provided by websocket ?

      Does somebody have implement something like this ?

      posted in General Code/Help
      G
      GwadaMan
    • RE: Make calcul with indicator

      Hi Curtis,

      Thank you very much for the correction. It works !!!
      We can close this case.
      Regards,

      posted in Indicators/Strategies/Analyzers
      G
      GwadaMan
    • RE: Make calcul with indicator

      I would like to play with the indicator. @backtrader How can I do it ?
      I'm have a lots of fun working with this plateforme.

      Regards,

      posted in Indicators/Strategies/Analyzers
      G
      GwadaMan
    • RE: Make calcul with indicator

      @cgi1 said in Make calcul with indicator:

      a

      Hi cgi1
      thanks for your help.

      I would like to do something like this :

      def __init__(self):
      
          self.sma0 = btind.MovAv.SMA(self.data, period=12)
      
          self.sma1 = ((self.sma0.lines.sma(0) - self.sma0.lines.sma(1)) / 2)
      
      
      def next(self):
          print(" sma1: %s" %( self.sma1[0]))
      

      but the result I 've is "nan"

      sma1: nan
      sma1: nan
      sma1: nan
      sma1: nan
      sma1: nan

      posted in Indicators/Strategies/Analyzers
      G
      GwadaMan
    • Make calcul with indicator

      Hi BackTrader !!!
      How are you ?
      Could you explain to me how can I use the line values to use them in math formuler ?

      class MyStrategy(bt.Strategy):
      
      params = dict(period=20)
      def __init__(self):
      
          self.movav = btind.SimpleMovingAverage(self.data, period=self.p.period)
          self.test = ((self.movav.lines.sma(0) - self.movav.lines.sma(-2)) / 2
      
      def next(self):
          if self.movav.lines.sma[0] > self.data.lines.close[0]:
              print('Simple Moving Average is greater than the closing price')
      

      Regards

      posted in Indicators/Strategies/Analyzers
      G
      GwadaMan
    • Is that possible to do backtesting by donwloading live data frome Yahoo finance ?

      Hi,

      I would like to test my strategy with real live data to see how it reacts.

      Could you help me on that ?

      Regards,

      posted in General Code/Help
      G
      GwadaMan
    • RE: How to generate CrossOver signal with "slowK and slowD" from TALIB and or BT Stochastic fonction ?

      How can I generated Stochastic signal from other line like "ema of (data)" in Backtrader ?

      posted in Indicators/Strategies/Analyzers
      G
      GwadaMan
    • RE: Pair Trading with minutes data

      @backtrader thx I fixed it with your help !!!

      posted in Indicators/Strategies/Analyzers
      G
      GwadaMan
    • RE: Pair Trading with minutes data

      @backtrader the code is splited. Does it miss something ? I didn't undestand your question.

      cerebro.resampledata(data0,timeframe=tframes[args.timeframe], compression=args.compression)
      cerebro.resampledata(data1,timeframe=tframes[args.timeframe], compression=args.compression)

      parser.add_argument('--timeframe', default='minutes',
      choices=bt.TimeFrame.Names,
      required=False, action='store',
      help='TimeFrame for Resample/Replay')

      parser.add_argument('--compression', default=1, type=int,
      required=False, action='store',
      help='Compression for Resample/Replay')

      posted in Indicators/Strategies/Analyzers
      G
      GwadaMan
    • RE: Pair Trading with minutes data

      :Here a part of the source code with the timeframe/compression setting

      def runstrategy():
          args = parse_args()
      
          # Create a cerebro
          cerebro = bt.Cerebro()
      
          # Get the dates from the args
          fromdate = datetime.datetime(2016, 11, 25) # datetime.datetime.strptime(args.fromdate, '%Y-%m-%d')
          todate = datetime.datetime(2016, 12, 02) # datetime.datetime.strptime(args.todate, '%Y-%m-%d')
      
          # Create the 1st data
          tframes = dict(
              secondes=bt.TimeFrame.Seconds,
              minutes=bt.TimeFrame.Minutes,
              days=bt.TimeFrame.Days,
              weeks=bt.TimeFrame.Weeks,
              months=bt.TimeFrame.Months,
              years=bt.TimeFrame.Years)
      
          # Create the 1st data
          """
          data0 = btfeeds.YahooFinanceCSVData(
              dataname=args.data0,
              fromdate=fromdate,
              todate=todate)
          """
          data0 = btfeeds.GenericCSVData(
              dataname=args.data0,
      
              fromdate=fromdate,
              todate=todate,
      
              nullvalue=0.0,
      
              dtformat=('%Y-%m-%d %H:%M:%S'),
              datetime=0,
              high=2,
              low=3,
              open=1,
              close=4,
              volume=5,
              openinterest=-1,
          )
      
          # Add the 1st data to cerebro
          cerebro.adddata(data0)
      
          # Create the 2nd data
          """
          data1 = btfeeds.YahooFinanceCSVData(
              dataname=args.data1,
              fromdate=fromdate,
              todate=todate)
          """
          data1 = btfeeds.GenericCSVData(
              dataname=args.data1,
      
              fromdate=fromdate,
              todate=todate,
      
              nullvalue=0.0,
      
              dtformat=('%Y-%m-%d %H:%M:%S'),
              datetime=0,
              high=2,
              low=3,
              open=1,
              close=4,
              volume=5,
              openinterest=-1,
          )
      
          # Add the 2nd data to cerebro
          cerebro.adddata(data1)
      
      
          cerebro.resampledata(data0,timeframe=tframes[args.timeframe], compression=args.compression)
          # Create the 2nd data
          # Add the 2nd data to cerebro
          #cerebro.adddata(data1)
          cerebro.resampledata(data1,timeframe=tframes[args.timeframe], compression=args.compression)
      
          # Add the strategy
          cerebro.addstrategy(PairTradingStrategy,
                              period=args.period,
                              stake=args.stake)
      
          # Add the commission - only stocks like a for each operation
          cerebro.broker.setcash(args.cash)
      
          # Add the commission - only stocks like a for each operation
          cerebro.broker.setcommission(commission=args.commperc)
      
          # And run it
          cerebro.run(runonce=not args.runnext,
                      preload=not args.nopreload,
                      oldsync=args.oldsync)
      
          # Plot if requested
          if args.plot:
              cerebro.plot(numfigs=args.numfigs, volume=False, zdown=False)
      
      
      def parse_args():
          parser = argparse.ArgumentParser(description='MultiData Strategy')
      
          parser.add_argument('--data0', '-d0',
                              default='intra-DDD.csv',
                              help='1st data into the system')
      
          parser.add_argument('--data1', '-d1',
                              default='intra-SSYS.csv',
                              help='2nd data into the system')
      
          parser.add_argument('--fromdate', '-f',
                              default='1997-01-01',
                              help='Starting date in YYYY-MM-DD format')
      
          parser.add_argument('--todate', '-t',
                              default='1998-06-01',
                              help='Starting date in YYYY-MM-DD format')
      
          group = parser.add_mutually_exclusive_group()
          group.add_argument('--tframe', default='years', required=False,
                             choices=['days', 'weeks', 'months', 'years'],
                             help='TimeFrame for the returns/Sharpe calculations')
      
          group.add_argument('--legacyannual', action='store_true',
                             help='Use legacy annual return analyzer')
      
      
          pgroup = parser.add_mutually_exclusive_group(required=False)
      
          pgroup.add_argument('--replay',
                              required=False, action='store_true',
                              help='replay to chosen timeframe')
      
          pgroup.add_argument('--resample', default = True,
                              required=False, action='store_true',
                              help='resample to chosen timeframe')
      
          parser.add_argument('--timeframe', default='minutes',
                              choices=bt.TimeFrame.Names,
                              required=False, action='store',
                              help='TimeFrame for Resample/Replay')
      
          parser.add_argument('--compression', default=1, type=int,
                              required=False, action='store',
                              help='Compression for Resample/Replay')
      
          parser.add_argument('--timeframe1', default=True,
                              choices=bt.TimeFrame.Names,
                              required=False, action='store',
                              help='TimeFrame for Resample/Replay - Data1')
      
          parser.add_argument('--compression1', default=None, type=int,
                              required=False, action='store',
                              help='Compression for Resample/Replay - Data1')
      
          parser.add_argument('--period', default=10, type=int,
                              help='Period to apply to the Simple Moving Average')
      
          parser.add_argument('--cash', default=100000, type=int,
                              help='Starting Cash')
      
          parser.add_argument('--runnext', action='store_true',
                              help='Use next by next instead of runonce')
      
          parser.add_argument('--nopreload', action='store_true',
                              help='Do not preload the data')
      
          parser.add_argument('--oldsync', action='store_true',
                              help='Use old data synchronization method')
      
          parser.add_argument('--commperc', default=0.005, type=float,
                              help='Percentage commission (0.005 is 0.5%%')
      
          parser.add_argument('--stake', default=10, type=int,
                              help='Stake to apply in each operation')
      
          parser.add_argument('--plot', '-p', default=True, action='store_true',
                              help='Plot the read data')
      
          parser.add_argument('--numfigs', '-n', default=1,
                              help='Plot using numfigs figures')
      
          return parser.parse_args()
      
      
      if __name__ == '__main__':
          runstrategy()
      
      posted in Indicators/Strategies/Analyzers
      G
      GwadaMan