Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    1. Home
    2. Brad Lloyd
    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 1
    • Posts 12
    • Best 1
    • Groups 0

    Brad Lloyd

    @Brad Lloyd

    1
    Reputation
    872
    Profile views
    12
    Posts
    0
    Followers
    0
    Following
    Joined Last Online
    Website www.linkedin.com/in/jbradleylloyd Location Munich Area, Germany

    Brad Lloyd Unfollow Follow

    Best posts made by Brad Lloyd

    • RE: Reach _trades list

      you could write them to csv, or if you are using pycharm you can have the console output to csv
      did you look at the backtrader.analyzers.Transactions?

      posted in General Code/Help
      Brad Lloyd
      Brad Lloyd

    Latest posts made by Brad Lloyd

    • RE: Check the order status of Multiple Stocks

      I was just saying I did the loop different using 'for' instead of enumerate
      but I do something like this

      params = ('portfolio', ['AAPL', 'GOOG', 'SPY', 'IWM', 'EEM'])    
      
      def next(self):
          for symbol in self.p.portfolio:
      
              d = self.getdatabyname(symbol)
              if self.order[symbol]:
                  continue
             
             if self.signal:
                  self.order[symbol] = self.buy(d, size=self.trade_size[symbol])
      
      posted in General Code/Help
      Brad Lloyd
      Brad Lloyd
    • RE: Check the order status of Multiple Stocks

      @cwse
      I create the self.order dict in init and don't have a problem
      you would have to run it in debug and figure out what key it fails on

      the only thing I could see is that my loop is different as I pass all my symbols as param called portfolio and then just do loop that is

      for symbol in self.p.portfolio:
      
      posted in General Code/Help
      Brad Lloyd
      Brad Lloyd
    • RE: Check the order status of Multiple Stocks

      @cwse
      I use the following for multiple symbols

      in your init where you define self.order = None, make it a dict , self.order = {}

      def __init__(self):
          self.order = {}
          for i, d in enumerate(d for d in self.datas if len(d)):
             self.order[d._name] = None
      
      def notify(self, order):
      # standard code for notification 
          self.order[order.data._name] = None
      
      def next(self):
         for i, d in enumerate(d for d in self.datas if len(d)):
             if not self.order[d._name]:
                continue
      
      posted in General Code/Help
      Brad Lloyd
      Brad Lloyd
    • RE: create a CSV of the result of optstrategy

      try this:
      cerebro.addwriter(bt.WriterFile, csv = True, out='your_strategy_results')

      posted in Indicators/Strategies/Analyzers
      Brad Lloyd
      Brad Lloyd
    • RE: Reach _trades list

      if you are using IB, you should be able to put each system in a sub account and manage the positions this way.

      you can also access the IB transaction log and I think you can retrieve things by order id, but I know this was somewhat of an issue for us, IB was not all that helpful. on a daily basis you should probably reconcile what your system thinks your position is vs what the broker has, the brokers make mistakes more often than you would think

      we had a similar issue with needing persistent state variables for live trading and ended up having to store them in a database, but I would think you could do the same in a single csv file and just read the last lines in at startup.

      posted in General Code/Help
      Brad Lloyd
      Brad Lloyd
    • RE: resampling Pandas dataframe

      note we solved it by creating a new cerebro class that lets us do the following

      cerebro.add_feeds(startdate, enddate, portfolio_symbols, conflations)
      
      posted in General Code/Help
      Brad Lloyd
      Brad Lloyd
    • RE: resampling Pandas dataframe

      not sure how to get the formatted code to paste

      startdate = datetime.datetime(2012, 1, 1)
      enddate = datetime.datetime(2013, 1, 3)
      def get_mstar_data(sym, startdate, enddate):
          s = startdate.year
          e = enddate.year
          df = None
          for i in range(s, e + 1):
              for filename in glob.glob("%s/%d/%s*_1min.gz" % (m_star_cbot_path, i, sym)):
                  filedf = _create_df(filename)
                  filedf = filedf.ix[startdate:enddate]
                  print (len(filedf.index))
                  df = filedf if df is None else df.append(filedf)
      
      
      
          return mstar(
              fromdate=startdate,
              todate=enddate,
              dataname=df,
              name=sym,
              datetime=None
      
          )
      
      
      data = get_mstar_data('ZC0Y', startdate, enddate):
      
      cerebro.adddata(data)
      cerebro.resampledata(data, name=ZC0Y15m, timeframe=bt.Timeframe.Minutes, compression=15)
      
      posted in General Code/Help
      Brad Lloyd
      Brad Lloyd
    • resampling Pandas dataframe

      not sure if anyone else has had trouble with loading data from a pandas dataframe and then using cerebro.resample, but we did. The dataframe for minute data loads find and then when I go to pass the dataframte to cerebro.resample I get nan values. if I use a csv it loads and resamples with no problems

      so we ended up using pandas own resample feature which works just fine

      posted in General Code/Help
      Brad Lloyd
      Brad Lloyd
    • RE: Problem with resampling of intraday data

      your daily resampled data will have the previous days price because you don't know todays values
      you might want to try and replay the data if you are wanting the daily values to update through out the day

      posted in General Code/Help
      Brad Lloyd
      Brad Lloyd
    • RE: Submit order 30 minutes before market close

      @Ed-Bartosh
      the bulk of the time you have 16:00 as you close, 16:15 for some of the index ETFs,
      you can download the exchange calendars and then put the holidays in where you early close

      if you have some timezone issues then try using pytz to manage that, I think there is some functionality in backtrader for it

      another option would be to count minutes from the first trade of the day, but you still have to manage the holidays

      posted in General Discussion
      Brad Lloyd
      Brad Lloyd