Navigation

    Backtrader Community

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

    Posts made by spg_trader

    • How to add datafeed with text field?

      Hello, I am trying to add datafeed with text field. For example a csv file with columns with delivery month info of future contracts, or names of calendar spread. I know I can convert everything into int/float before loading, but want to see if there is an easy way to incorporate text field in datafeed directly. I tried some simple modifications, but it seems like the linebuffer object requires float data. Haven't figured out how to modify it yet (or if possible at all).
      Checked some older posts, seems like the author intends all data to be of float type. Wondering if anyone else has went down a similar path. Thank you.

      posted in General Discussion
      S
      spg_trader
    • RE: Multiple dataseries with misaligned or missing dates?

      I think there are a couple of threads about this situation, as well as the author's blog. You can google it with keywords "backtrader multiple datafeeds synchronization".
      My understanding is that the last available value of the datafeeds with scattered dates will be repeatedly delivered to cerebro as the clock progresses, assuming nothing special is being done. One solution is keep a counter of the length of each datafeed in your next() or prenext() function. When there is missing data, the length of the datafeed will not increase , even if the stale value is delivered again. Something like this:

          def __init__(self):
              # datafeed pointer, keeping track if any datafeeds delivery new data or not
              self.df_pt = dict()     
              for i, d in enumerate(self.datas):
                  self.df_pt[d._name] = 0
          def next(self):
          # check if new data has been delivered for current datafeed
              for i, d in enumerate(self.datas):
      
                  dt, dn = self.datetime.date(), d._name
                  
                  if len(d) <= self.df_pt[dn]:
                      pass # or any other actions you desire
                  else:
                      self.df_pt[dn] = len(d)
      
      posted in General Code/Help
      S
      spg_trader
    • Best way to implement multiple individual contracts for the same instrument?

      Hello,

      I would like to test some carry strategies on commodities, which requires calculation of implied yield on multiple individual contracts of the same instrument, e.g. soybean oil from the front month to 2 years out. So continuously linked contracts based on rollover doesn't seem to be convenient for this purpose. I am wondering what is the best way to implement this? I am sure someone else probably figured this out before. Some thoughts I have:

      • Naively I can add all the datefeeds to cerebro, and have my indicator go through them one by one. Is there a more elegant way, say expand the csvdata class so that the one datafeed object would contain all the contracts of the same instrument, and deliver either front month or back month intelligently? or handle it at the strategy level, instead of datafeed level?
      • Or is it better to pre-process the data, adding the implied yield as a new column to the csv. This way cerebro doesn't need to load multiple individual contracts. The value/momentum strategies only need the front month to operate, only carry needs the extra data along the curve. Maybe this way is more efficient?

      Appreciate any insights the community could provide. Thank you.

      posted in General Discussion
      S
      spg_trader
    • RE: Data question

      Also checkout iqfeed/polygon/CQG/dxfeed for intraday data if you need them.

      posted in General Discussion
      S
      spg_trader
    • RE: Data question

      Don't know the why they are different, maybe something like dividend adjustment? I think free data have their limitations.

      You can check out some payed data vendors. EOD data are relatively cheap. PremiumData/Norgate has <$100 package for 30 years data. PinnacleData is another choice. CSIdata is more expensive, but people say they are of higher quality. If absolute quality is desired, then purchase from the exchanges is probably the best, but very expensive.

      posted in General Discussion
      S
      spg_trader
    • 1 / 1