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/

    When does the broker update the cash after a trade is closed?

    General Discussion
    1
    1
    34
    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.
    • Nicola Prada
      Nicola Prada last edited by

      I am working on a simple system that uses weekly data and must have a fixed size portfolio of securities: if it sells one security, I expect it to buy another one the next week.

      To size the new position I use the available cash and I make an estimation using the last available close of the cash that will be available once the position I have to close is sold.

      2012-02-03, I have a SELL signal.

      2012-02-10 I start the week with 1074.87 in the account. During market hours, I expected the position to be closed and get new cash for 15410.02. According to the broker the position is sold for 15407.58. I expect to have 1074.87 + 15407.58 in my account.

      Once the 2012-02-10 bar is fully CLOSED, I can compute new signals and, since I sold a security for 15407.58, I have to buy the new one using this amount + the cash I had in the account.

      The size is computed using the last available close and a 5% buffer, like this: (cash * 0.95) / close[0]

      After the signal, when the sizer computes the size, the cash in the broker is still 1074.87!
      No sign of the 15407.58 I got from the security I sold and the new trade is sized using only 1074.87 * 95%!

      Here it is the full log:

      2012-02-03 SELL: 63DU GY Equity
      2012-02-03 SIZING 63DU GY Equity: 326 [CLOSE POSITION]

      2012-02-10 ORDER SUBMITTED: SELL 326 63DU GY Equity @ Market [last: 47.2700 expected: 15410.02]
      2012-02-10 ORDER ACCEPTED: SELL 326 63DU GY Equity @ Market [last: 47.2700 expected: 15410.02]
      2012-02-10 ORDER EXECUTED: SOLD 326 63DU GY Equity @ 47.2625 value: 15407.58 comm: 19.00
      2012-02-10 TRADE CLOSED: 63DU GY Equity gross pnl: -2120.63 comm: 38.00 net pnl: -2158.63

      2012-02-10 BUY: DB1 GY Equity
      2012-02-10 SIZING DB1 GY Equity: 21 [last: 47.7270 cash: 1074.87 expected: 0.00 available: 1021.13]
      2012-02-17 ORDER SUBMITTED: BUY 21 DB1 GY Equity @ Market [last: 47.7270 expected: 1002.27]
      2012-02-17 ORDER ACCEPTED: BUY 21 DB1 GY Equity @ Market [last: 47.7270 expected: 1002.27]
      2012-02-17 ORDER EXECUTED: BOUGHT 21 DB1 GY Equity @ 47.9264 value: 1006.46 comm: 19.00
      2012-02-17 TRADE OPENED: 21 DB1 GY Equity @ 47.9264 - value: 1006.46 comm: 19.00

      Am I missing something?

      1 Reply Last reply Reply Quote 0
      • 1 / 1
      • First post
        Last post
      Copyright © 2016, 2017, 2018 NodeBB Forums | Contributors
      $(document).ready(function () { app.coldLoad(); }); }