I was trying to simulate option trading using Amibroker. For my Index, I have imported the near month and far month option data as follows:
A ticker symbol IND_2000_CE_ 1, means a call option expiring in the near month with a strike price of 2000. IND_2000_CE_ 2 would mean an option expiring a month after the current month.
Now, I want to implement a calendar spread as follows. First, I will identify the closest expiry price on the 13th of each month. Then, I will short the far month (eg IND_2000_CE_ 2) and buy the near month series (IND_2000_CE_ 1). On the option expiry day, I will cover the Far month series and sell the near month series. My code looks something like this.
SetTradeDelays( 0,0,0,0);
SetOption("PriceBoundChecking",False);
y = Year();
m = Month();
d = Day();
w = DayOfWeek();
IndexC = Close;
Buy=Sell=0;
DayBuy = 13; //Optimize("Day",0,1,23,1);
for(i=0; i <
BarCount; i++){
if(d[i] == DayBuy){
Buy[i] = 1;
//Short[i] = 1;
NP = int(IndexC[i] /100)*100; //Find the closest series
TickerNear = "NIFTY_"+NP+"_PE_1";
TickerFar = "NIFTY_"+NP+"_PE_2";
ShortArray = Foreign(TickerNear,"Close");
BuyArray = Foreign(TickerFar,"Close");
BuyPrice[i] = BuyArray[i]- ShortArray[ i];
//ShortPrice[ i] = ShortArray[i] ;
}
if(ExpiryDay( y[i],m[i] ,d[i],w[i] )){
Sell[i] =
1;
//Cover[i] = 1;
SellArray = Foreign(TickerFar,"Close");
CoverArray = Foreign(TickerNear,"Close");
SellPrice[i] = SellArray[i] -CoverArray[ i];
//CoverPrice[ i] = CoverArray[i] ;
}
}
Buy=ExRem(Buy, Sell);
Sell=ExRem(Sell, Buy);
Currently, I am facing two problems:
1. Though I am able to use the price of options when buying selling (using Foreign), when I do a Buy and Short on the same day, Amibroker automatically interprets it either as a Buy or Sell depending on backtester settings (instead of a Buy and Short which will be later followed with a Sell and Cover). Is there any way to force
Amibroker to accept a buy and short for the same day?
2. Though the code above gives correct results, I am not able to exploit the complete power of Backtester because the drawdown figures are meaningless (It assumes, it is deriving the price from the index -- where as it is working on a different ticker (for the options). Any fix to this problem?
Thanks,
Zee