Margin Order - why it's triggered?



  • Hi,

    If multiple orders are placed on the same day and the orders are mix of buy and sell (not short, just sell part of existing stocks), will the sell orders get rejected due to margin ?

    I suppose reducing the position should not trigger any margin requirements, however during backtesting, I have seen my orders got rejected due to margin.

    In below case, Order Ref 22 got rejected due to margin, which is to reduce position from 1860 to 1643.

    2017-02-14, CREATE BUY REBALANCE: CH600028, Close: 5.840000, Old Position: 1316 New Position 1516 Oref: 19
    2017-02-14, CREATE BUY: CH600827, Close: 15.520001, Oref: 20
    2017-02-14, CREATE BUY: CH601628, Close: 26.570008, Oref: 21
    2017-02-14, CREATE SELL REBALANCE: CH000630, Close: 3.560000, Old Position: 1860 New Position 1643 Oref: 22
    2017-02-15, Order Margin, Ref: 19, Name: CH600028
    2017-02-15, Order Margin, Ref: 20, Name: CH600827
    2017-02-15, Order Margin, Ref: 21, Name: CH601628
    2017-02-15, Order Margin, Ref: 22, Name: CH000630
    

    I manually skip the buy orders on 2017-2-14 (everything else remain the same), leaving only rebalance orders, now the sell order got accepted.

    2017-02-14, CREATE BUY REBALANCE: CH600028, Close: 5.840000, Old Position: 1316 New Position 1516 Oref: 19
    2017-02-14, CREATE SELL REBALANCE: CH000630, Close: 3.560000, Old Position: 1860 New Position 1643 Oref: 20
    2017-02-15, Order Margin, Ref: 19, Name: CH600028
    2017-02-15, SELL EXECUTED, Ref: 20, Name: CH000630, Price: 3.49, Cost: 720.44, Size: -217.00, Comm 1.51
    

    It seems the order of Order matters.
    I made changes to the code and issue rebalance orders prior to buy orders. Strangely now the sell order got executed.

    2017-02-14, CREATE BUY REBALANCE: CH600028, Close: 5.840000, Old Position: 1316 New Position 1516 Oref: 19
    2017-02-14, CREATE SELL REBALANCE: CH000630, Close: 3.560000, Old Position: 1860 New Position 1643 Oref: 20
    2017-02-14, CREATE BUY: CH600827, Close: 15.520001, Oref: 21
    2017-02-14, CREATE BUY: CH601628, Close: 26.570008, Oref: 22
    2017-02-15, Order Margin, Ref: 19, Name: CH600028
    2017-02-15, Order Margin, Ref: 21, Name: CH600827
    2017-02-15, Order Margin, Ref: 22, Name: CH601628
    2017-02-15, SELL EXECUTED, Ref: 20, Name: CH000630, Price: 3.49, Cost: 720.44, Size: -217.00, Comm 1.51
    
    

    Could you please advise if this is expected behavior of backtrader? how the margin works internally? Thanks.


Log in to reply
 

Looks like your connection to Backtrader Community was lost, please wait while we try to reconnect.