Backtrader Community

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

    abyaby

    @abyaby

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

    abyaby Unfollow Follow

    Latest posts made by abyaby

    • RE: backtrader.linebuffer.LineBuffer object at

      @backtrader Thanks that you mentioned the Limit Order. I thought, it doesnt matter, if I add

      cerebro.broker.setcommission(commission=0.002)
      

      Regarding unkown data
      I have backtest self.data.close and self.data.close[0] again.

      PnL with Limit order are different

      PnL with Market order are the same. What could it mean? I was especting data.close with market order a random number but surprisingly its the same.

      data.close[0] vs. data.close
      order.market -478.3 order.market -478.3
      order.limit -634.26 order.limit 2370.7

      And if some one know why data.close and data.close[0] have defferent limit order PnL ?

      posted in Indicators/Strategies/Analyzers
      A
      abyaby
    • RE: backtrader.linebuffer.LineBuffer object at

      @backtrader Thanks a lot of your fast and brief answer.

      posted in Indicators/Strategies/Analyzers
      A
      abyaby
    • backtrader.linebuffer.LineBuffer object at

      Hi,
      Could anyone help me?
      I dont know which Buy and Sell price I am getting. Wheather on actuel closing bar or next closing price.
      Please take a quick look on my code.

      I have backtested since months with following logic.

          if not self.position:
              # Not yet ... we MIGHT BUY if ...
              if self.bcross == 1.0:
                  # BUY, BUY, BUY!!! (with default parameters)
                  price = self.data.close
                  self.log("BUY CREATE, {}".format(price))
                  # Keep track of the created order to avoid a 2nd order
                  self.order = self.buy(
                      exectype=bt.Order.Limit,
                      price=price)
          else:
              # Already in the market ... we might sell
              if self.scross == -1.0:
                  # SELL, SELL, SELL!!! (with all possible default parameters)
                  price = self.data.close
                  self.log("SELL CREATE, {}".format(price))
                  # Keep track of the created order to avoid a 2nd order
                  self.order = self.sell(
                      exectype=bt.Order.Limit,
                      price=price)
      

      As you can see I used price = self.data.close instead self.data.close[0]

      My log function is this and unfortunatly it was off.

      def log(self, txt, dt=None):
          dt = dt or self.data.datetime[0]
          if debug:
              print("{}, {}".format(bt.num2date(dt), txt))
      

      I got good and bad end results and they all were reproduceable! plotting, sharpratio, vwr, sqn, Analyzer everything was working well.

      my datafeed is

      symbol = 'BTC/USDT'
      # 2018-10-24T14:10:00Z - 2018-10-24T17:50:00Z
      # 2018-10-24T23:00:00Z - 2018-10-25T01:45:00Z
      hist_start_date = datetime.utcnow() - timedelta(days=500)
      hist_stop_date = datetime.utcnow() - timedelta(hours=1)
      data = bt.feeds.CCXT(exchange='binance',
                          symbol=symbol,
                          timeframe=bt.TimeFrame.Minutes,
                          fromdate=hist_start_date,
                          todate=hist_stop_date,
                          compression=60)
      

      Today I debug and came to know that something is going wrong and got these results

      0_1558705832803_0304e80c-6b28-4fd3-b214-5ff2abf8080a-image.png

      @backtrader How could I go live, if I tested my strategies with self.data.close ? Is buy price, "buy at closing price of next bar" ?
      Sell = "selling at closing price of next bar"?
      Or did I backtested something unrealistic and I have to make new strategies with self.data.close[0] ?

      Thanks for helping.

      posted in Indicators/Strategies/Analyzers
      A
      abyaby
    • RE: PnL Net calculation Quote currency Bitcoin

      I have got the solution. It was very simple :-) I just took startcash 1 instead 10000 and the calculations are good.

      posted in General Code/Help
      A
      abyaby
    • PnL Net calculation Quote currency Bitcoin

      Hi,
      I need help. To calculate Sharpe Ratio and VWR I need PnL Net in Dollar.

      My startcash is in $
      startcash = 10000
      cerebro.broker.setcash(startcash)

      cerebro.addsizer(bt.sizers.SizerFix, stake=2)

      symbol = 'ETH/BTC'

      At the moment I am getting PnL Net in BTC and it adds BTC value (for example 0.5 PnL Net) to Initail Porfolio Value. At the end my Final Porfolio Value is 10000.56 $ instead 12500$. I think because of this I am getting Sharpe Ratio -359.41 and VWR: 0.0

      How could I solve this problem? That Cerebro calculate automatically BTC PnL Net value in Dollars.

      With all other Quote Pairs like (BTC-EUR), USD, USDT etc I am getting right Sharpe and VWR.

      posted in General Code/Help
      A
      abyaby