Navigation

    Backtrader Community

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

    JohnShiu

    @JohnShiu

    0
    Reputation
    399
    Profile views
    2
    Posts
    0
    Followers
    0
    Following
    Joined Last Online

    JohnShiu Unfollow Follow

    Latest posts made by JohnShiu

    • Extracting variables defined in strategy

      Hi,
      There are usually a bunch of variables defined in a strategy. For example, what I would like to do is:

      class MyStrategy(Strategy):
          def __init__(self):
              self.sstc = indicators.Stochastic(data, ....)
              self.sma = indicators.SimpleMovingAverage(data, ...)
      
              self.indicators_log = {"sstc": self.sstc, "sma": self.sma}
      

      To extract the variables in the strategy, e.g. indicators_log, I tried to add analyzer:

      class MyAnalyzer(Analyzer):
          def get_analysis(self):
              indicators_log = self.indicators_log
              ... do something ...
              return indicators_log
      

      But obviously it doesn't work
      So my question is..
      (1) Is it possible to extract the variables defined in the strategy, e.g. indicator_log, in analyzer?
      (2) If not, are there any recommendations to get the variables? (better including their name, for me to do further analysis in some later time)

      Thanks

      posted in Indicators/Strategies/Analyzers
      J
      JohnShiu
    • line info lost during resampling

      Hi,
      I start using backtrader recently and have nice experience with it. This is the best package I found so far for doing backtest.
      However, I have got a problem when using the Cerebro.resampledata

      First of all, I wrote a customized pandasdata class, in which I added a field "code", to fit the data format in my database:

      class PandasData_Customize(feeds.PandasData):
          params = (("code", "code"), )
          lines = ("code", )
          datafields = [............., "code"]
      
      

      The "code" would be something like ES, DX, etc.... It is supposed to be unique for an asset, i.e. data.code is unique for each data in self.datas

      It has been working well (daily data) with Cerebro.adddata(PandasData_Customize(dataname=df))
      The data.code from the output = Cerebro.run() are correct.

      Recently, I am trying to backtest using monthly time frame, with:
      Cerebro.resampledata(PandasData_Customize(dataname=df), timeframe=TimeFrame.Months)
      But the data.code is always NaN

      I tried to find hints from the "Resampling" session in the doc, but it seems the case for customized datafeeds is not mentioned yet.
      I also read some source codes from the cerebro.py and resamplerfilter.py, but still not sure which part I should modify to get a correct resampling of the custom line I added.
      Any hints/idea?

      Thanks

      posted in General Discussion
      J
      JohnShiu