Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    1. Home
    2. Maxim Korobov
    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 14
    • Posts 66
    • Best 6
    • Groups 0

    Maxim Korobov

    @Maxim Korobov

    6
    Reputation
    1744
    Profile views
    66
    Posts
    0
    Followers
    0
    Following
    Joined Last Online

    Maxim Korobov Unfollow Follow

    Best posts made by Maxim Korobov

    • RE: Machine learning + backtrader

      From 101 (csv, pandas) to some ML usage and only for trading + code, not just ML + code or trading theory.
      https://www.udacity.com/course/machine-learning-for-trading--ud501

      posted in General Discussion
      Maxim Korobov
      Maxim Korobov
    • Reach _trades list

      I have to get orders and trades list after strategy stop.

      According to http://backtrader.readthedocs.io/en/stable/strategy.html, they could be reached by _orders and _traders fields of strategy.

      There is no problem with _orders - it's just a list. But _trades is

      collections.defaultdict(AutoDictList)
      

      Standard Google and SO answers didn't help to transfer it into list. How to do that?

      posted in General Code/Help
      Maxim Korobov
      Maxim Korobov
    • RE: Indicator warmup period

      Thank you!

      With this flag it works like a charm. Code:

      import backtrader as bt
      
      
      class WarmupDetector:
      
      	@staticmethod
      	def detect(strategies):
      		greatest_warm_up_period, strategy_name = 0, ""
      
      		runner = bt.Cerebro()
      		for sta in strategies:
      			runner.addstrategy(sta, silent=True)
      		stub_data = bt.DataBase()
      		runner.adddata(stub_data)
      		
      		sis = runner.run(runonce=False)
      
      		for si in sis:
      			period = si.get_warm_up_period()
      			if period > greatest_warm_up_period:
      				greatest_warm_up_period, strategy_name = period, si.__class__.__name__
      
      		return greatest_warm_up_period, strategy_name
      
      	@staticmethod
      	def detect_period(strategies):
      		return WarmupDetector.detect(strategies)[0]
      

      Usage:

      warm_up_period, warm_up_strategy_name = WarmupDetector.detect(strategies_to_add)
      
      posted in General Code/Help
      Maxim Korobov
      Maxim Korobov
    • RE: Add lines to indicator

      In my particular case

      line._plotvalue = False
      

      helps.

      Thanks for flexible solution!

      posted in General Code/Help
      Maxim Korobov
      Maxim Korobov
    • AttributeError: 'NoneType' object has no attribute 'close'

      What's reason that f is None?

      "version": "1.9.47.116"
      backtrader\feed.py

      ...

      def preload(self):
          while self.load():
              pass
      
          self._last()
          self.home()
      
          # preloaded - no need to keep the object around - breaks multip in 3.x
          self.f.close()
          self.f = None
      

      ...

      Traceback (most recent call last):
        File "D:/Projects/trading-bot/main/lab/backtrader/playground.py", line 277, in <module>
      	run()
        File "D:/Projects/trading-bot/main/lab/backtrader/playground.py", line 119, in run
      	strategies = run_strategy(back_trader, run_mode == RunMode.DevelopIdea, from_date, to_date)
        File "D:/Projects/trading-bot/main/lab/backtrader/playground.py", line 218, in run_strategy
      	strategies = back_trader.run()
        File "C:\Users\Home\Anaconda3\lib\site-packages\backtrader\cerebro.py", line 1070, in run
      	runstrat = self.runstrategies(iterstrat)
        File "C:\Users\Home\Anaconda3\lib\site-packages\backtrader\cerebro.py", line 1146, in runstrategies
      	data.preload()
        File "C:\Users\Home\Anaconda3\lib\site-packages\backtrader\feed.py", line 689, in preload
      	self.f.close()
      AttributeError: 'NoneType' object has no attribute 'close'
      
      posted in General Code/Help
      Maxim Korobov
      Maxim Korobov
    • RE: AttributeError: 'NoneType' object has no attribute 'close'

      Possible due to this :)

      https://ichart.yahoo.com/table.csv?s=NFLX&a=0&b=1&c=2016&d=4&e=16&f=2017&g=h&ignore=.csv

      alt text

      posted in General Code/Help
      Maxim Korobov
      Maxim Korobov

    Latest posts made by Maxim Korobov

    • RE: Adding a Quandl Data Feed

      A little patch:

          if self.p.apikey is not None:
              urlargs.append('api_key=%s' % self.p.apikey)
      

      There was a typo previously.

      posted in General Code/Help
      Maxim Korobov
      Maxim Korobov
    • RE: AttributeError: 'NoneType' object has no attribute 'close'

      What about implementing Quandl data source internally.
      One cons is that API key is mandatory.

      posted in General Code/Help
      Maxim Korobov
      Maxim Korobov
    • RE: AttributeError: 'NoneType' object has no attribute 'close'

      Possible due to this :)

      https://ichart.yahoo.com/table.csv?s=NFLX&a=0&b=1&c=2016&d=4&e=16&f=2017&g=h&ignore=.csv

      alt text

      posted in General Code/Help
      Maxim Korobov
      Maxim Korobov
    • RE: Simple channel indicator

      Vote to add indicator into main package! It's great for Forex market.

      posted in Indicators/Strategies/Analyzers
      Maxim Korobov
      Maxim Korobov
    • AttributeError: 'NoneType' object has no attribute 'close'

      What's reason that f is None?

      "version": "1.9.47.116"
      backtrader\feed.py

      ...

      def preload(self):
          while self.load():
              pass
      
          self._last()
          self.home()
      
          # preloaded - no need to keep the object around - breaks multip in 3.x
          self.f.close()
          self.f = None
      

      ...

      Traceback (most recent call last):
        File "D:/Projects/trading-bot/main/lab/backtrader/playground.py", line 277, in <module>
      	run()
        File "D:/Projects/trading-bot/main/lab/backtrader/playground.py", line 119, in run
      	strategies = run_strategy(back_trader, run_mode == RunMode.DevelopIdea, from_date, to_date)
        File "D:/Projects/trading-bot/main/lab/backtrader/playground.py", line 218, in run_strategy
      	strategies = back_trader.run()
        File "C:\Users\Home\Anaconda3\lib\site-packages\backtrader\cerebro.py", line 1070, in run
      	runstrat = self.runstrategies(iterstrat)
        File "C:\Users\Home\Anaconda3\lib\site-packages\backtrader\cerebro.py", line 1146, in runstrategies
      	data.preload()
        File "C:\Users\Home\Anaconda3\lib\site-packages\backtrader\feed.py", line 689, in preload
      	self.f.close()
      AttributeError: 'NoneType' object has no attribute 'close'
      
      posted in General Code/Help
      Maxim Korobov
      Maxim Korobov
    • RE: Possible division by zero in `AnnualReturn`

      Thanks for suggestion, I replace it with:

      back_trader.addanalyzer(TimeReturn, timeframe=bt.TimeFrame.Years, _name='annualreturn')
      

      Looks loke pretty the same for SharpeRatio:

      Traceback (most recent call last):
        File "D:/Projects/trading-bot/main/lab/backtrader/morning_buy.py", line 87, in <module>
      	strategies = back_trader.run(timeframe=bt.TimeFrame.Minutes)
        File "C:\Users\Home\Anaconda3\lib\site-packages\backtrader\cerebro.py", line 794, in run
      	runstrat = self.runstrategies(iterstrat)
        File "C:\Users\Home\Anaconda3\lib\site-packages\backtrader\cerebro.py", line 927, in runstrategies
      	strat._stop()
        File "C:\Users\Home\Anaconda3\lib\site-packages\backtrader\strategy.py", line 421, in _stop
      	analyzer._stop()
        File "C:\Users\Home\Anaconda3\lib\site-packages\backtrader\analyzer.py", line 194, in _stop
      	self.stop()
        File "C:\Users\Home\Anaconda3\lib\site-packages\backtrader\analyzers\sharpe.py", line 173, in stop
      	ret_free_avg = average(ret_free)
        File "C:\Users\Home\Anaconda3\lib\site-packages\backtrader\mathsupport.py", line 38, in average
      	return math.fsum(x) / (len(x) - bessel)
      ZeroDivisionError: float division by zero
      
      posted in General Code/Help
      Maxim Korobov
      Maxim Korobov
    • Possible division by zero in `AnnualReturn`

      I'm optimizing parameters for strategy.
      Sometimes when strategy is full of fear, so perform no action. In suck situations ZeroDivisionError: float division by zero occur.

      Traceback (most recent call last):
        File "D:/Projects/trading-bot/main/lab/backtrader/morning_buy.py", line 86, in <module>
      	strategies = back_trader.run(timeframe=bt.TimeFrame.Minutes)
        File "C:\Users\Home\Anaconda3\lib\site-packages\backtrader\cerebro.py", line 794, in run
      	runstrat = self.runstrategies(iterstrat)
        File "C:\Users\Home\Anaconda3\lib\site-packages\backtrader\cerebro.py", line 927, in runstrategies
      	strat._stop()
        File "C:\Users\Home\Anaconda3\lib\site-packages\backtrader\strategy.py", line 421, in _stop
      	analyzer._stop()
        File "C:\Users\Home\Anaconda3\lib\site-packages\backtrader\analyzer.py", line 194, in _stop
      	self.stop()
        File "C:\Users\Home\Anaconda3\lib\site-packages\backtrader\analyzers\annualreturn.py", line 84, in stop
      	annualret = (value_end / value_start) - 1.0
      ZeroDivisionError: float division by zero
      

      I checked that

      b_trader.broker.setcash(1000.0)
      

      was called earlier.

      posted in General Code/Help
      Maxim Korobov
      Maxim Korobov
    • RE: How to automate the running of backtrader?

      Schedule main loop! I prefer APScheduler as it's flexibily for reports running based on schedule.

      posted in General Discussion
      Maxim Korobov
      Maxim Korobov
    • RE: Add lines to indicator

      In my particular case

      line._plotvalue = False
      

      helps.

      Thanks for flexible solution!

      posted in General Code/Help
      Maxim Korobov
      Maxim Korobov
    • RE: Add lines to indicator

      Am I missing something or there is not option to reach (cancel) this code in Plot_OldSync.plotind()?

              if not math.isnan(lplot[-1]):
                  label += ' %.2f' % lplot[-1]
      
      posted in General Code/Help
      Maxim Korobov
      Maxim Korobov