Number of contracts in futures mode

Hi,
I am trying to do a backtest with futures of VIX and I do not understand the number of contracts that Amibroker takes, so I dont know what i am doing wrong.
I have Amibroker 6.39.1
I read this:
https://www.amibroker.com/guide/h_futbacktest.html

As far as I know, 1 Contract = 1000 "shares" so if the entry price is 16.58 I should get 6 contracts with an equity of 100K but Amibroker takes 99 and I do not know what I am doing wrong.

Other than activate futures mode with an initial equity of 100K, I set:
PositionSize = -100;
MarginDeposit =1000;
RoundLotSize = 1;

The example in the link I posted is pretty straight-forward:
Initial Equity = 50K
PositionSize = -20; // use 20% of equity
MarginDeposit = 675; // this you can set also in the Symbol-Information page
RoundLotSize = 1; // this you can set also in the Settings page

50,000*0.2/675 = (integer)14.8148 = 14 contracts

Thanks,
Regards

If you want to specify the number of contracts in your backtest directly you should use

SetPositionShares( 6, spsShares ); // buy 6 contracts

If you are in Futures mode and you specify MarginDeposit > 0 (i.e. constant deposit expressed in dollars), instrument price does not matter when it comes to calculation how many contracts you can buy. You are opening position using MarginDeposit, not price itself (unless margin is expressed in percentage of price).

As to your example, AmiBroker would do the following calculation:
100% of Equity (100000) / 1000 (MarginDeposit per contract) = 100 contracts (without commission). Actually you get only 99 because of commission.

Hi Tomasz,
I do not want to buy always the same number of contracts. I would like to buy as many contracts as the equity in that moment allowes me to.

I also tried a trick with the Equity() function (not in futures mode) but it looks like it buys up to 100K and not up to the portfolio equity that I have accumulated before starting the trade:

SetPositionSize(1000Floor(Equity(0,0)/(C1000)),spsShares);

I tried out a combination the parameters inside Equity() but I never see that the Position Value goes above 100K.

Do you know if I am doing something wrong with the Equity Function as well?

Thanks

SetPositionSize( 100, spsPercentOfEquity );

Hi pmxgs
That does not work in this case

Please re-read my ENTIRE response, not just first line. It explains calculation and it just WORKS perfectly fine. 99 contracts that you get is CORRECT NUMBER. Just re-read my post.

You do NOT use Equity() the way that you displayed here (for Equity call you have to set position sizing FIRST). @pmxgs response is CORRECT.

Hi Tomasz
I read your post and now again but the fact is this:
If I buy a contract at 16.58 USD and one contract consist of 1000 "shares", I invest 16.58K in 1 contract.
With 100K, I can buy 6 contracts (maybe 5 after commisions, i don't know, but it does not matter), which is what I would like to see, not 99. I would just like to adjust whatever parameters in Amibroker to see that.

The answer of pmxgs does not work in this case, I will be continue seeing a number of contracts that I dont expect and if not in futures mode I am going to see 6031 shares at 16.58USD, which is not a multiple of 1000.

I hope, what I would like to do is a bit clearer.

It is not important to me, if I do the backtest with shares and I buy 6000 shares instead of 6 contracts, 3000 shares instead of 3 contracts and so on but I have to make sure that the shares boiught are always a multiple of 1000 and that I buy as many contracts or (multiple of 1000) shares as the current (not the initial) equity allowes me to.

This is something I tried with Equity() and maybe it is not even possible, I do not know.

@Drenik you are not using any margin in that calculation. Futures trading usually enable you to use 10-20 times leverage. Your calculation is purchasing $100k worth of the full contract value with your $100k of equity. In reality, depending upon the contract/exchange/broker etc you can probably purchase much more.

Also I think you are incorrect when you wrote in your first post

A quick look at the CBOE web site will show that the margin requirement is probably not $1,000. I don't trade futures so I may be mistaken.

image

Hi portfoliobuilder,
I do not want to use margin. I am just looking to buy as many contracts as I can with the equtity in my account.
I am sure I am doing something wrong and something is missing but I do not find how to do what i want to do.
I do not trade Futures either, this is something i am trying to test out with one instrument.
In the moment, only one thing is clear to me: if I try to buy one contract of VIX, I will be investing: PRICEx1000.
With 100K, without margin, i can buy Floor(100K/(PRICEx1000)) contracts.

If in the real world, I couldn't use up the 100K and I can only use 60% or whatever is ok.
I would just size down.

From what I understand you don't want to buy as many contracts as possible but instead the goal is to have 100% equity exposure.

In that case the easiest way would be to use the line below and turn off Futures Mode. (in this case you would be buying around 6.000 "shares"

SetPositionSize( 100, spsPercentOfEquity ); 

If you still want to use futures mode then you can use:

SetPositionSize( (100*MarginDeposit)/(C*PointValue), spsPercentOfEquity ); // futures mode

and this should give you 6 contracts. (assuming price of 16,58 and point value of 1000)

note: I did not check the code in AB

1 Like

In futures, the word "margin" does not mean margin loan like in stocks. Margin is the minimum net liquidity you must have to trade one contract. Make sure you read this page: https://www.cmegroup.com/education/courses/introduction-to-futures/margin-know-what-is-needed.html

Although the exchange's margin on the June VX contract is $8,195 right now, at IB the margin deposit is $18,005:
image

The required margin deposit can change more than once every day and it is set by your broker, so you should ignore the exchange's published margin. When the market is volatile, your broker will raise the margin far above the exchange's requirement.

Therefore, you should be careful about using a static value for margin deposit in your backtest, because it changes over time.

As documented in the manual: Back testing systems for futures contracts
MarginDeposit in AmiBroker can be expressed as FRACTION (percentage) of contract price. For example if you write

MarginDeposit = -10; // use 10% of contract price for margin deposit

You need to be aware that typically, margin deposit does not influence calculated profits directly because profit is calculated from prices (entry and exit) and number of contracts. Margin deposit is not directly involved in profit calculation, other than just limiting your buying power to certain number of contracts. So as far as backtest goes (in terms of profit calculation), whenever you use exact margin deposit as published by the broker or not, it is not as important as other might suggest.

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.