Navigation

    Backtrader Community

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

    Bingchen Liu

    @Bingchen Liu

    0
    Reputation
    229
    Profile views
    6
    Posts
    0
    Followers
    0
    Following
    Joined Last Online
    Website www.linkedin.com/in/bingchen-liu-995818149 Location Greater New York City Area

    Bingchen Liu Unfollow Follow

    Latest posts made by Bingchen Liu

    • RE: Save cerebro plot to file

      I'm glad my reply can help and thank you for your sharing !

      Best,
      Bingchen

      posted in General Code/Help
      B
      Bingchen Liu
    • RE: Save cerebro plot to file

      Hi JF,

      You are welcome. I'm glad that my code can give you some ideas. You can see from the code in the source file cerebro.py that although multiple input variables are given for plot function, some of them are not used in the plot function at all ==|||. Thus I guess that the plot function only give you some basic frames on these functions and you have to define by yourself if you want some specific ideas. For more about the plot, you can see doc for matplotlib.pyplot.

      Cheers,
      Bingchen

      posted in General Code/Help
      B
      Bingchen Liu
    • RE: Save cerebro plot to file

      I got the similar problem, I can't change plot size and save picture either. Thus I just rewrite the function in the cerebro.py file. This is my code, I hope this can give you some help.

      def plot(self, plotter=None, numfigs=1, iplot=True, start=None, end=None,
               width=16, height=9, dpi=300, tight=True, use=None,path = None,
               **kwargs):
          '''
          Plots the strategies inside cerebro
      
          If ``plotter`` is None a default ``Plot`` instance is created and
          ``kwargs`` are passed to it during instantiation.
      
          ``numfigs`` split the plot in the indicated number of charts reducing
          chart density if wished
      
          ``iplot``: if ``True`` and running in a ``notebook`` the charts will be
          displayed inline
      
          ``use``: set it to the name of the desired matplotlib backend. It will
          take precedence over ``iplot``
      
          ``start``: An index to the datetime line array of the strategy or a
          ``datetime.date``, ``datetime.datetime`` instance indicating the start
          of the plot
      
          ``end``: An index to the datetime line array of the strategy or a
          ``datetime.date``, ``datetime.datetime`` instance indicating the end
          of the plot
      
          ``width``: in inches of the saved figure
      
          ``height``: in inches of the saved figure
      
          ``dpi``: quality in dots per inches of the saved figure
      
          ``tight``: only save actual content and not the frame of the figure
          '''
          if self._exactbars > 0:
              return
      
          if not plotter:
              from . import plot
              if self.p.oldsync:
                  plotter = plot.Plot_OldSync(**kwargs)
              else:
                  plotter = plot.Plot(**kwargs)
      
          # pfillers = {self.datas[i]: self._plotfillers[i]
          # for i, x in enumerate(self._plotfillers)}
      
          # pfillers2 = {self.datas[i]: self._plotfillers2[i]
          # for i, x in enumerate(self._plotfillers2)}
          import matplotlib.pyplot as plt 
          figs = []
          for stratlist in self.runstrats:
              for si, strat in enumerate(stratlist):
                  rfig = plotter.plot(strat, figid=si * 100,
                                      numfigs=numfigs, iplot=iplot,
                                      start=start, end=end, use=use)
                  # pfillers=pfillers2)
      
                  figs.append(rfig)
              fig = plt.gcf() 
              plotter.show()
          fig.set_size_inches(width, height)
          fig.savefig(path,dpi = dpi) 
          return figs
      
      posted in General Code/Help
      B
      Bingchen Liu
    • RE: How to get the current value for the fund, not just in notify fcn?

      Got it, thank you !

      posted in Indicators/Strategies/Analyzers
      B
      Bingchen Liu
    • RE: How to get the current value for the fund, not just in notify fcn?

      Thank you for your quick reply. cerebro.broker.get_fundvalue() can give me the value. But the problem is that I want to get the value in the next() for Strategy class. Thus get_fundvalue is not available.

      posted in Indicators/Strategies/Analyzers
      B
      Bingchen Liu
    • How to get the current value for the fund, not just in notify fcn?

      In my backtesting program, I wanted to change cash when trading. Thus I added some code in notify_fund() to change cash. The problem is that I want to define a get_value() function which can get the current value of the fund (which is the value variable in the notify_fund() function). However, I don't know where I can find or get the value. Please give me some suggestions and thanks a lot.

      posted in Indicators/Strategies/Analyzers
      B
      Bingchen Liu