Hi, I'm working on a backtester now. I'm trying to make it work as closely as possible to how real orders fill. After much research, I can't find a clear explanation of precisely how to handle margining and PnL for futures contracts. For example: - Contract X has intraday initial margin of 2k, maintenance margin of 1k. Each whole number point is worth $100. - Account starts with 100k USD cash. - System buys 10 contracts of X at 100.00 - Take 20k from cash, move 20k to margin account. Add +10 X contracts. Now.. here's where I am losing it. Suppose price drops to 99.00 and I mark-to-market. I subtract 1k from the margin account -> cash 80k, margin 19k. Then the system sells 2 of the 10 contracts. How much do I move back from the margin account to cash to reflect the sale? My ideas: - $2k each (the initial margin per contract) -> $16k - $1k each (the maintenance margin per contract) -> $18k - a pro rata division of the aggregate loss for all 10 contracts so far: (1k / 10) * 2 contracts, or $200 -> $19,800 Can someone please tell me how this is actually done, and whether the other stuff I've written is correct? Many thanks, R
I'm going to answer my own question, for the benefit of future searchers: The necessary calculations are explained at http://individuals.interactivebrokers.com/php/webhelp/webhelp.htm#Screens/Account_Information.htm and http://individuals.interactivebrokers.com/en/trading/marginRequirements/margin.php?ib_entity=llc . Cheers. R