With all of the recent options discussion and inspiration from the recent financial hacker blogs I have decided I need to learn more about options and backtesting them.
https://financial-hacker.com/algorithmic-options-trading/


I am trying to test some theories which led me to trying to calculate a CONTRACT on the fly. I have tried this similar to the first series of jcl's blog posts that describe how to load a dataSet with artificial option data from historic prices and contractVal().

Thinking that the CONTRACT needs to stay in memory I have just created a dataSet in INITRUN with some number larger then the number of contracts I plan on trading. Then I add sequentially to the dataSet with the last line in the below code. The contractPrint appears to be loading the struct correctly.

I am getting an error "Error 111: Crash in TMF at Bar ###". It happens on the following bar. Any thoughts on why this is happening? Any suggestions on a different method to calculate options in runtime?

Code
if(is(INITRUN))
{
    c = (CONTRACT*)dataNew(1,num,9);
}


then inside run() i use something similar to

Code

	vol = VolatilityOV(20);
	Price = series(price());
	barDate = ymd(wdate(0));
	//printf("\n BarDate=%i",barDate);
	
	printf("\n\n Entering option barDate=%i   BarNum=%i",barDate,Bar);
	
	c->time = dmy(barDate);
	c->fUnl = Price[0];
	c->fStrike = Price[0] +10;
	c->Type = CALL;
	c->Expiry = ymd(c->time+6*7);
	c->fBid = contractVal(c,Price[0],vol,Dividend,Interest);
	c->fAsk = (1.+BidAskSpread/100)*c->fBid + BidAskSpreadMin;
	contractPrint(c,TO_WINDOW);

	var prem = c->fBid*Lots*Multiplier;
	Commission = 0.65/Multiplier;
	MarginCost = contractMargin(c,2); //2==INDEX
	printf("\n contractMargin=%.2f",contractMargin(c,2));
	printf("\n ContractPrice=%.2f",contractPrice(c));
	printf("\n ContractIntrinsic=%.2f",contractIntrinsic(c,c->fUnl));
	printf("\n Contract=%i",c);
	printf("\nMarginCost=%.2f",MarginCost*100);

	enterShort(c);
	c++;
	



Last edited by jbhunter; 04/12/20 03:54.