Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

    Problem with Leverage and Margin

    General Code/Help
    leverage futures
    2
    3
    1385
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • E
      emilpuiu last edited by

      Hi all,

      I have a couple of questions regarding leverage and margin. I am looking mainly at futures and options as an asset class and would like to implement the same leverage/margin principles that is applied to futures.

      As an example, on EURUSD CME futures, the initial margin for speculator is 2310 USD and the contract size is for 125.000 EUR.

      In backtrader, with no leverage, if I set broker.setcash(100.000), I would not be able to buy a single futures due to the contract size, since the buy of 1 contract would be greater than the size of the cash account. In reality, one would have only to post 2310 USD per contract when buying a single futures (and in with a cash size of 100k, I should be able to buy roughly 43 futures for a total notional value of 5.375mio USD)

      I have tried to play with leverage in broker.setcommission(leverage) that was added recently, and using sizers.FixedSizer(10), but my orders are being rejected even if I set broker.setcommission(leverage=50.0), i.e. being levered 50x times which is equivalent to allowing me to trade up to 5mio USD.

      Surely I am missing something on how actually implement the leverage component. Could anyone clarify (perhaps with a snippet code) on how to properly implement a leverage factor?

      Many thanks in advance guys!

      1 Reply Last reply Reply Quote 0
      • A
        ab_trader last edited by

        Set futures type commission scheme and backtrader will treat future contracts correctly.

        • If my answer helped, hit reputation up arrow at lower right corner of the post.
        • Python Debugging With Pdb
        • New to python and bt - check this out
        1 Reply Last reply Reply Quote 0
        • E
          emilpuiu last edited by

          That's it! Thanks very much sir!

          1 Reply Last reply Reply Quote 0
          • 1 / 1
          • First post
            Last post
          Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors