Backtrader Community

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

    franklili

    @franklili

    0
    Reputation
    17
    Profile views
    4
    Posts
    0
    Followers
    0
    Following
    Joined Last Online

    franklili Unfollow Follow

    Latest posts made by franklili

    • RE: What is the format of datetime in btcsvData?

      Thank you very much.

      posted in General Code/Help
      F
      franklili
    • RE: What is the format of datetime in btcsvData?

      My script is:

       btrun --csvformat btcsv \
             --data bitfinex_BTCUSD_min_20160601_20160803_2.csv \
              --cash 10000 \
              --commission 0.0035 \
              --margin 10000 \
              --cerebro  \
              --strategy ema_mean_reversion_strategy.py:TestStrategy:printlog=True,emaperiod=747,upper=31,lower=-28,trailpercent=12 \
               --fromdate 2016-06-01T00:01:00 \
               --todate 2016-08-03T02:02:00 \
               --analyzer :SharpeRatio \
               --writer csv=True > ~/Python-for-Finance1/automate_backtest_result.csv \
               --timeframe minutes \
               --compression 1
      
      

      My csv file is:

      Datetime,Open,High,Low,Close,Volume,openinterest
      2016-06-01T00:01:00,530.68,530.69,530.68,530.69,5.16764001,7.7e-05
      
      

      the result is the same.
      I understanded the reason. the datetime column should be split to date and time columns. the datetime in result is correct.

      posted in General Code/Help
      F
      franklili
    • What is the format of datetime in btcsvData?

      @backtrader I am running btrun. The format of datetime is "%YYYY-%mm-%dd %HH:%MM:%SS" or "%YYYY-%mm-%ddT%HH:%MM:%SS", I used minutes level data, the datetime of first line is "2016-06-01T00:01:00", but the stanstat result display the datetime is "%YYYY-%mm-%dd 23:59:59.999989".

      Id,bitfinex_BTCUSD_min_20160601_20160803_2,len,datetime,open,high,low,close,volume,openinterest,TestStrategy,len,datetime,Broker,len,cash,value,BuyS
      ell,len,buy,sell,Trades - Net Profit/Loss,len,pnlplus,pnlminus
      1,bitfinex_BTCUSD_min_20160601_20160803_2,1,2016-06-01 23:59:59.999989,530.68,530.69,530.68,530.69,5.16764001,7.7e-05,TestStrategy,1,736116.99999999
      99,Broker,1,10000.0,10000.0,BuySell,1,,,Trades - Net Profit/Loss,1,,
      
      code_text
      

      What is the format of datetime in btcsvData?

      posted in General Code/Help
      F
      franklili
    • multiprocessing.pool.MaybeEncodingError

      In Linux, when I added optstrategy, there was a error:
      Traceback (most recent call last):
      File "ema_mean_reversion.py", line 355, in <module>
      results = cerebro.run()
      File "/home/ubuntu/anaconda3/lib/python3.7/site-packages/backtrader/cerebro.py", line 1143, in run
      for r in pool.imap(self, iterstrats):
      File "/home/ubuntu/anaconda3/lib/python3.7/multiprocessing/pool.py", line 748, in next
      raise value
      multiprocessing.pool.MaybeEncodingError: Error sending result: '[<main.EmaMeanReversionStrategy object at 0x7f4ab7de6b38>]'. Reason: 'PicklingError("Can't pickle <class'main.EmaMeanReversionStrategy'>: it's not the same object as__main__.EmaMeanReversionStrategy")'
      this is my codes:

      class EmaMeanReversionStrategy(bt.Strategy):
          params = (
              ('emaperiod', 750),
              ('printlog', False),
              ('upper', 3.0),
              ('lower', - 2.7)
          )
          def __init__(self):
              self.dataclose = self.datas[0].close
              self.ema = bt.indicators.ExponentialMovingAverage(
                      self.datas[0], period=self.params.emaperiod)
              self.dpce = (self.dataclose / self.ema - 1) * 100
              
              .....
      if __name__ == '__main__':
          cerebro = bt.Cerebro(optreturn=False)
          cerebro.optstrategy(EmaMeanReversionStrategy, upper = np.arange(2.0, 4.0, 0.2))
          cerebro.addobserver(bt.observers.DrawDown)
          cerebro.addsizer(bt.sizers.PercentSizer, percents = 95)
          dataframe = pd.read_csv('bitfinex_BTCUSD_min_20180601_20190531.csv', index_col=0, parse_dates=True)
          dataframe['openinterest'] = 0
          fromdate = datetime.datetime(2018, 12, 1, 0, 1)
          fromdate_str = fromdate.strftime('%Y/%m/%d')
          todate = datetime.datetime(2019, 5, 31, 23, 59)
          todate_str = todate.strftime('%Y/%m/%d')
          data = bt.feeds.PandasData(dataname=dataframe,
              fromdate = fromdate,
              todate = todate,
              timeframe = bt.TimeFrame.Minutes
              )
          # Add the Data Feed to Cerebro
          cerebro.adddata(data, name = 'BTCUSD')
          # Set our desired cash start
          cerebro.broker.setcash(100000.0)
          # Set the commission
          cerebro.broker.setcommission(commission=0.0035)
          results = cerebro.run()
      
      
      posted in Indicators/Strategies/Analyzers
      F
      franklili