Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    1. Home
    2. Roman Semko
    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 2
    • Posts 7
    • Best 0
    • Groups 0

    Roman Semko

    @Roman Semko

    0
    Reputation
    402
    Profile views
    7
    Posts
    0
    Followers
    0
    Following
    Joined Last Online

    Roman Semko Unfollow Follow

    Latest posts made by Roman Semko

    • RE: Backtesting oanda/forex

      Warning: one more newbie question about sizing: I want to trade with oanda and have a USD account. If I use order_target_percent to calulate the sizing, in the end the backtrader has to pass "units" parameter to the Oanda API. The end price varies depending on what units you are buying.

      • If I buy one lot of USD/ZAR the units will be 100.000 and the price before leverage is also 100.000 USD.
      • If I buy one lot of EUR/USD the units will be 100.000, but the "price" paid before the leverage is 100.000/eur_usd_exhange_rate.

      I guess my question is whether the size calculation takes into the account that the price/margin needed for one unit of a currency pair depends on the currency pair being traded.

      Hence, order_target_percent should render different sizes depending on the pair traded and the currency used, right?

      posted in General Code/Help
      Roman Semko
      Roman Semko
    • RE: Backtesting oanda/forex

      @backtrader Thanks for your informative replies. I will take a look at the blog post!
      Have a wonderful day. ^^

      posted in General Code/Help
      Roman Semko
      Roman Semko
    • RE: Backtesting oanda/forex
      classMySizer(bt.Sizer):
          params = (
              ('leverage', 50)
          )
      
          def _getsizing(self, comminfo, cash, data, isbuy):
              return math.floor(cash * self.p.leverage / data[0])
      
      ...setcommission(leverage=50)
      ...addSizer(MySizer)
      

      would that be correct?

      posted in General Code/Help
      Roman Semko
      Roman Semko
    • RE: Backtesting oanda/forex

      Understood. What about sizing and leverage?
      If I had a leverage of 1:50 in my practice account, how do I simulate those? What do I put in my sizer to buy as much currency as possible with the current leverage, ofr example?

      posted in General Code/Help
      Roman Semko
      Roman Semko
    • Backtesting oanda/forex

      Hi guys,

      I am trying to create a small forex strategy for later use in oanda. Does anybody have a sample script for me how to:

      • Setup the commission with leverage.
      • Sizing (taking into the account the used leverage).
      • Buying selling currency pairs.

      So that it emulates the oanda commissions/leverage properly. I am having hard time figuring out how to use backtrader in that case.

      I have found an old thread regarding commissions, but only with sample for Eurostoxx and it does not use the leverage property:

      https://community.backtrader.com/topic/333/accurate-commissions-for-ib-and-oanda/3

      Any help appreciated!

      posted in General Code/Help
      Roman Semko
      Roman Semko
    • RE: isbuy in SIzer is always True. Why?

      Wow. That was quick! Thank you! ^^

      posted in General Code/Help
      Roman Semko
      Roman Semko
    • isbuy in SIzer is always True. Why?

      Hi guys, I am struggling with a simple example. Maybe someone else had a similar issue. I am creating a simple sizer. My problem is that it always passes True for isbuy, even for sell. Here a dead-simple example to showcase the problem:

      import os
      import datetime
      from core.yahoo import getf  # My own function, returns path to a file of ticker data.
      import backtrader as bt
      from random import randint
      
      class Sizer(bt.Sizer):
          def _getsizing(self, comminfo, cash, data, isbuy):
              print '     ISBUY?', isbuy
              return 1
          
      class Strategy(bt.Strategy):
          def next(self):
              if randint(0, 1):
                  print 'BUY'
                  self.buy()
              else:
                  print 'SELL'
                  self.sell()
      
      # getf is a function that returns a path to the file, where yahoo data has been downloaded into.
      datapath = os.path.join(os.getcwd(), getf('VGT'))  
      data = bt.feeds.YahooFinanceCSVData(
          dataname=datapath,
          fromdate=datetime.datetime(2007, 1, 1),
          todate=datetime.datetime(2012, 12, 31),
          reverse=True)
      
      cerebro = bt.Cerebro()
      cerebro.addstrategy(Strategy)
      cerebro.addsizer(Sizer)
      cerebro.adddata(data)
      cerebro.broker.setcash(5000.0)
      cerebro.run()
      

      The result? isbuy is always true!

      BUY
           ISBUY? True
      BUY
           ISBUY? True
      SELL
           ISBUY? True
      BUY
           ISBUY? True
      SELL
           ISBUY? True
      SELL
           ISBUY? True
      SELL
           ISBUY? True
      BUY
           ISBUY? True
      

      Am I doing something wrong?

      Thanks for any help!

      posted in General Code/Help
      Roman Semko
      Roman Semko