Backtrader Community

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

    Dillonhao

    @Dillonhao

    1
    Reputation
    5
    Profile views
    5
    Posts
    0
    Followers
    0
    Following
    Joined Last Online

    Dillonhao Unfollow Follow

    Best posts made by Dillonhao

    • RE: Out of memory error when running optstrategy

      update。
      looks like the sharp ratio analyzer is the cause. I cancel out the following code and fixed the problem.

      self.addanalyzer(SharpeRatio, timeframe=bt.TimeFrame.Minutes, compression=30)
      
      posted in General Code/Help
      D
      Dillonhao

    Latest posts made by Dillonhao

    • RE: Out of memory error when running optstrategy

      update。
      looks like the sharp ratio analyzer is the cause. I cancel out the following code and fixed the problem.

      self.addanalyzer(SharpeRatio, timeframe=bt.TimeFrame.Minutes, compression=30)
      
      posted in General Code/Help
      D
      Dillonhao
    • RE: Out of memory error when running optstrategy

      @vladisld Sorry. the "cerebro.addstrategy(WLXStrategy)" was commented out in my code. There is a mismatch in the ``` and the markup translated it to a format. my bad. But thank you for the reply.

      posted in General Code/Help
      D
      Dillonhao
    • RE: Out of memory error when running optstrategy

      @run-out Thanks for your help. will give it a try.

      posted in General Code/Help
      D
      Dillonhao
    • Out of memory error when running optstrategy

      New to the Backtrader. I got following error when running the optstrategy in linux server. all the memory and the swap drained then error.

      Traceback (most recent call last):
        File "/home/dillonhao/anaconda3/lib/python3.7/threading.py", line 926, in _bootstrap_inner
          self.run()
        File "/home/dillonhao/anaconda3/lib/python3.7/threading.py", line 870, in run
          self._target(*self._args, **self._kwargs)
        File "/home/dillonhao/anaconda3/lib/python3.7/multiprocessing/pool.py", line 412, in _handle_workers
          pool._maintain_pool()
        File "/home/dillonhao/anaconda3/lib/python3.7/multiprocessing/pool.py", line 248, in _maintain_pool
          self._repopulate_pool()
        File "/home/dillonhao/anaconda3/lib/python3.7/multiprocessing/pool.py", line 241, in _repopulate_pool
          w.start()
        File "/home/dillonhao/anaconda3/lib/python3.7/multiprocessing/process.py", line 112, in start
          self._popen = self._Popen(self)
        File "/home/dillonhao/anaconda3/lib/python3.7/multiprocessing/context.py", line 277, in _Popen
          return Popen(process_obj)
        File "/home/dillonhao/anaconda3/lib/python3.7/multiprocessing/popen_fork.py", line 20, in __init__
          self._launch(process_obj)
        File "/home/dillonhao/anaconda3/lib/python3.7/multiprocessing/popen_fork.py", line 70, in _launch
          self.pid = os.fork()
      OSError: [Errno 12] Cannot allocate memory```
      
      I dig a little bit with tracemalloc and looks like the below multiprocessing consume 50% of the memory.
      ```#1: /home/dillonhao/anaconda3/lib/python3.7/multiprocessing/connection.py:251: 
          return _ForkingPickler.loads(buf.getbuffer())
      

      double check my bt code and have no clue of how to fix it without modify the bt code. Anyone can help? Thanks in advance

      ···
      import sys
      sys.path.append(r'/home/dillonhao/quant/lib/')
      from DataPiple.DataCheck import checkMissingDate
      import pickle
      import logging
      import backtrader as bt
      from backtrader.analyzers import (SQN, AnnualReturn, TimeReturn, SharpeRatio_A, SharpeRatio,
      TradeAnalyzer, drawdown)

      startcash = 1000000

      logging.basicConfig(level=loglevel)

      cerebro = bt.Cerebro()
      cerebro.broker.setcash(startcash)

      cerebro.addstrategy(WLXStrategy)

      cerebro.optstrategy(
      WLXStrategy,
      lmd=np.arange(0.8, 1, 0.01),
      avg = np.arange(1,4),
      dis = np.arange(0,0.02,0.002),

      filename = timeline

      )
      file_location = r'/home/dillonhao/data/history_candle_data'
      file_name = r'BTC-USDT_5m.csv'
      btData = getLocalData(file_location, file_name)
      timedic = timelist = getTimeSlot('2019-06-01', 60, 30, 4)[0]
      data = bt.feeds.PandasData(dataname=btData, fromdate=timedic['stime'], todate=timedic['etime'],
      timeframe=bt.TimeFrame.Minutes)
      cerebro.adddata(data)
      cerebro.addsizer(bt.sizers.PercentSizer, percents=100)
      cerebro.broker.setcommission(commission=0.0005)
      cerebro.addanalyzer(SharpeRatio, timeframe=bt.TimeFrame.Minutes, compression=30)
      cerebro.addanalyzer(SQN)
      cerebro.addanalyzer(AnnualReturn)
      cerebro.addanalyzer(TradeAnalyzer)
      result = cerebro.run(maxcpus=24)
      ···

      posted in General Code/Help
      D
      Dillonhao
    • can broker reject orders under certain condition?

      I'd like to simulate the scenario in which order will be rejected under certain conditions, such as time etc.
      I look through the doc and didn't find anything like subclass or functions. is it possible? thanks in advanced

      posted in General Code/Help
      D
      Dillonhao