# Margin modelling to backtest futures investment strategy

Let say that I have access to continuous daily time series for 20+ years of data for E-mini S&P 500 Index Futures. I have a long/short strategy to backtest that places orders either on open or close. The management of the margin has an impact over the performance of the backtest and I am unsure about how to model the margin.

1. How to model margin calls? E.g. is it best practice to use the whole capital to buy as many contract as possible, or buy contracts using half capital and to invest the remaining half in treasury bonds to be used as collateral in case of margin calls?
2. How to model interest rate on margin? E.g. is it best practice to assume no interest rate on margin or to use the 3 month t-bill rate?
3. How to model margin withdrawals? E.g. is it best practice to assume to reinvest the excess on margin in new contracts whenever possible?

A potential solution for points 1 and 3 could be to assume to restore the margin to the initial margin at the end of day and to reinvest the excess liquidity in new contracts or to sell contracts when liquidity is needed to restore the margin.

The answer should target the best practices while not being too much error prone to be implemented in python and fairly representative of the historical performance.

• " to use the whole capital to buy as many contract as possible" ROFL . Don't do this, it is far too dangerous. – noob2 May 19 '17 at 11:50
• Modeling a strategy that employs 15:1 leverage on a direction bet is not well thought out. – amdopt May 19 '17 at 13:15
• as the other commenters are suggesting - stop everything you are doing and think hard about bet sizing. A good start would be to look into the Kelly criterion etc. Forget about margins for now. Just think about simulating a situation where let's say you have a game that pays you even money even though you have a 51%-49% edge. You have a million bucks - how big should your bets be if you want to safely get to two million as safely as possible within a given timeframe. – FinanceGuyThatCantCode May 19 '17 at 13:35
• Famous trader Victor Haghani wrote a paper on bet sizing that may help flesh out what FinanceGuy said papers.ssrn.com/sol3/papers.cfm?abstract_id=2856963 – noob2 May 19 '17 at 13:47
• @noob2 cool paper. I've created a new question here after a couple of days of due diligence reading the literature on Kelly and optimal f: Optimal f (position sizing) without look ahead bias – MLguy May 23 '17 at 11:48

## 1 Answer

The amount of margin required by the exchange per futures contract is not a good guide to position sizing. It is designed to protect the exchange from your failure during a particularly bad day. Using this much leverage is too dangerous especially if your trades last many days; you will usually want to trade less than the maximum allowed number of contracts.

The trade sizing problem in futures trading is: if you have $E$ dollars in your futures trading account at time t, how many contracts should you buy/sell on your next trade.

There are broadly speaking two approaches (with many variants and intermediate cases possible):

The Fixed Fraction position sizing method due to Ralph Vince (1990), is based on risk management considerations only. You must take a position small enough that you could survive N consecutive losses without depleting your account. Vince said you estimate the worst loss per contract $L$ using historical data and then the number of contracts to trade is

$\textbf{contracts} = \frac{1}{N}\frac{E}{|L|}$

Vince recommended that the fraction $f=\frac{1}{N}$ should be set to 0.05 (i.e. $\frac{1}{20}$). Some people recommend 0.10 if you are willing to take a high level of risk. It seems reasonable to estimate $L$ using 95% ValueAtRisk over the relevant trade horizon rather than the biggest loss in your backtest.

A more advanced method of position sizing is based on the Kelly Criterion and its variants. This involves optimizing the long term rate of growth, and requires knowing the distribution of gains and losses (instead of just the biggest loss). It has the desirable property that bigger bets are taken for a trading system that is particularly profitable (and no bets at all for one that just breaks even). See Kelly Criterion. A drawback is that it is difficult to estimate the parameters accurately; in my experience the profitability of a system tends to be overestimated when it is first developed, due to a variety of psychological and statistical biases. For this reason I recommend the risk based methods, at least to start with.

• In the 4th chapter of Vince (1990), the author indicated that the optimal f can be obtained in a convex optimisation problem with respect to the geometric growth of the capital. In chapter 5, the author further discuss that the more risk adverse investor can use the fractional optimal f, that is an arbitrary fraction of the optimal f. Is there any reason for why you are mentioning arbitrary values for the f rather than an optimised one (either optimal f or fractional optimal f)? – MLguy May 22 '17 at 16:10
• Thanks. I am aware of Vince's 'Optimal f'. To me it belongs in the second category of methods, those that arise from the Kelly Criterion. I was trying to divide the methods into two categories: the risk-based ones and those that rely on optimization. (Perhaps I did not do justice to Mr. Vince in doing so. But I think of 'Optimal f' as a very straightforward generalization of Kelly). – Alex C May 22 '17 at 23:50