AmiBroker for Options backtesting?

trash

Well-Known Member
#32
Now please come up with a portrait of your computer screen such that we all get lured for your services and express our wonder at your creativity. But do not share anything factual to help novice beginners. Great MBA skills! Great way to advertise! :D
Portrait? Advertise?
Where have I advertised anything, you "genius"?

All I responded to NJ23 was that AB can be used for what he intends to do and all that is required to store options data is AB database itself (and since this forum section here is called "AmiBroker"). Nothing more nothing less.

If using AB there isn't anything faster than AB's database system. Why would anyone in his/her right mind go down to a slower path voluntarily?
The project I made handles multiple underlying symbols and their portfolio of options (plus thousands of historical data bars) at the same time in realtime (and for BT purpose) and intraday so it needs to be fast and stable but not stalling for minutes and hours and waiting for something to happen (maybe).
 
Last edited:
#33
If using AB there isn't anything faster than AB's database system.
True but not always. Can you use Foreign() in a loop to dynamically form string Symbols (for Option Symbol syntax shown before) to fetch its quotes in order to form an independent Array (like PCR, IV, Prob calc etc..) whose elements are to be used bar-by-bar (or to Plot) using AB? I doubt that otherwise how else you could perform Option BT with continuous datapoints! Rather one could simply go for Python or R or SQL or anything else, do whatever that is needed and then import that back to AB (caveat: only EOD no real-time IEOD). Problem is the expiry date in our option symbols. So anyways whenever we get data from our exchange or from any 3rd party data vendor they provide option symbols that contain string expiry date. Thus, it becomes suitable to use an external source for calc and then cascade the data back to AB. The project that you are bragging about I am certain that you did not had to deal with string expiry date from your data source. Hence you could loop that up solely in AB DB itself.
 
Last edited:

trendtrade

niftytrader12
#34
True but not always. Can you use Foreign() in a loop to dynamically form string Symbols (for Option Symbol syntax shown before) to fetch its quotes in order to form an independent Array (like PCR, IV, Prob calc etc..) whose elements are to be used bar-by-bar (or to Plot) using AB? I doubt that otherwise how else you could perform Option BT with continuous datapoints! Rather one could simply go for Python or R or SQL or anything else, do whatever that is needed and then import that back to AB (caveat: only EOD no real-time IEOD). Problem is the expiry date in our option symbols. So anyways whenever we get data from our exchange or from any 3rd party data vendor they provide option symbols that contain string expiry date. Thus, it becomes suitable to use an external source for calc and then cascade the data back to AB. The project that you are bragging about I am certain that you did not had to deal with string expiry date from your data source. Hence you could loop that up solely in AB DB itself.
@Loss_Lover Very valid points bro.
Seems like trash is not familiar with the issues that we have to face because of the Options Symbol Naming Mechanism being used by most data sources. It is not such plain forward to use these option strike symbols, because of continuous change in their names after every expiry.

For instance NSE option symbols shows up like MARUTI18NOV6800PE with a syntax <SYMBOL><yy><MMM><strike><OptionType>.
And then there is added complexity because of the different naming scheme for BankNifty WEEKLY Expiry symbols as well. That is why it was earlier mentioned by @NJ23 that he had to spent almost a month to figure out this Options Symbols Naming Issue. Since trash does not seem to trade the Indian Markets, so it is understandable why he misses this point.

It would be interesting to know, how @TracerBullet bro managed this issue in Python.

For making trash familiar with this issue, I am posting here the Naming Scheme used by GFDL Data Vendor for the Option Symbols -

MONTHLY Options Example -
NIFTY13AUG10500CE.NFO,
BANKNIFTY30AUG1827000CE.NFO

<underlying>
<expiry year in 2 digits>
<expiry month in 3 characters>
<strike price>
<CE for CALL Option and PE for PUT Option>
.NFO
-------- The BIGGER NAME contains 5 separate blocks as described above.



Weekly Options Example -
BANKNIFTY02AUG1825800CE.NFO,
BANKNIFTY30AUG1825900PE.NFO
<underlying>
<expiry date in 2 digits>
<expiry month in 3 characters>
<expiry year in 2 digits>
<strike price>
<CE for CALL Option and PE for PUT Option>
.NFO
-------- The BIGGER NAME contains 6 separate blocks as described above.
I hope trash will not start a fight in this thread and offend so many knowledgeable trader friends who have tried to positively help in this thread about the issue which is faced by most Indian traders whenever they start to think about doing some kind of backtests on Options Data. This is a very practical problem, which is faced by many of us, at some time or the other. Hopefully because of this collective effort, we will be able to figure out some solution, if not in Amibroker, then maybe in some other tools.

Best Regards to you all.

PS: I am not a programmer and I do not have knowledge about coding. Maybe some real good coding expert can solve above mentioned issues in a jiffy, but I find it quite complex.
 
#35
Hopefully because of this collective effort, we will be able to figure out some solution, if not in Amibroker, then maybe in some other tools.
The solution that works for me is on Daily timeframe. Day-trading is not my cup of tea and cannot handle instant gratification. So love Swinging! Using AHK, I scrap NSE Bhavcopies and form Option Symbols in the format <Symbol><Expiry date in yyyymmdd><Option type CE or PE><Strike>. Then simply ASCII import that to AB. Notice in the symbol format, Symbol and Option types are the only strings which are constants and user-specified. Now in AFL one could easily store the required Expiry Dates (for BT) in DateNum format for a contract and then use StrExtract to compare that to the current bar's DateNum in order to know the most recent or far or farthest Expiry Date(s). So you are done with one huddle. Now how do you dynamically get Strike levels? For that you need a trick. It's a one time thingy which need no Refresh and must be figured out before getting into the AFL. Here I use R to process the previously stored Bhavcopy CSVs in order to get the Step Difference between two Option Strikes (although NSE provides it here (Individual Securities Options->Strike Price Parameters) but I do not use that; reason being the Step difference will change when Corporate Actions results Split or Bonus issue of Shares). Back to AFL, since now we have the Step Difference we now need to figure out the ever-changing ATM strike for each bar.
Code:
fract = C / StpDiff;
quot = RoundDec( fract, 0 );
StrkATM = quot * StpDiff;
Viola! So now you have an array called StrkATM which stores ATM Strikes independent of any other factor. BTW StpDiff is the Step Difference between two Option strikes. Notice, you have got ATM strike for a candle and you know the Step-Difference. So add-up or subtract-down to figure out the rest of the strikes both towards ITM or OTM as your heart wishes.

Then using a For loop and VarSet/VarGet which would loop through these option symbols dynamically using the attributes discussed above in order to get the desired array which can be plotted alongside your Stock price chart continuously.

One drawback is that when Companies Split or issue Bonus shares. Still everything remains same but the Strike levels now ought to reflect the change. In order to counter this, from Moneycontrol I maintain a CSV that stores all the Split or Bonus Ratios along side its Date. Remember in the beginning I mentioned that I use AHK to prepare the CSVs that are to be imported into AB. This is where the AHK sorts it out and makes the required adjustments in the Strike levels if a company decides to Split or issue Bonus.

Having this said, we can do this on real-time IEOD too using @TracerBullet's RTD.
 
Last edited:

trendtrade

niftytrader12
#36
Thank you so much for sharing the details @Loss_Lover . You have not just solved the Naming Issue, but have also figured out the labeling of OTM,ATM and ITM Options. Wow !

I was about to make a post regarding this, because it looks quite hard to figure out the ATM strike on a daily basis, as it will be different every day.

Best Regards

PS: Now trash would realize, that he is not the only expert coder here. We have other great expert guys in traderji community, who don't just show off, but actually really contribute to the discussion in finding the solutions. ;)
 
#37
Now trash would realize, that he is not the only expert coder here.
Please do not compare me with @trash - he is the Grandfather and Tomasz being the Great Grandfather. I am just their Great Great Grandchild. Ha ha ha :D I just wanted him to taste his own soup that he throws every now and then, here and there to show-off. And he tasted it good. Ha ha ha :banghead::D
Portrait? Advertise?
Where have I advertised anything, you "genius"?

All I responded to NJ23 was that AB can be used for what he intends to do and all that is required to store options data is AB database itself (and since this forum section here is called "AmiBroker"). Nothing more nothing less.

If using AB there isn't anything faster than AB's database system. Why would anyone in his/her right mind go down to a slower path voluntarily?
The project I made handles multiple underlying symbols and their portfolio of options (plus thousands of historical data bars) at the same time in realtime (and for BT purpose) and intraday so it needs to be fast and stable but not stalling for minutes and hours and waiting for something to happen (maybe).
I might pull his leg but I respect him. ;)
 

trendtrade

niftytrader12
#38
Please do not compare me with @trash - he is the Grandfather and Tomasz being the Great Grandfather. I am just their Great Great Grandchild. Ha ha ha :D I just wanted him to taste his own soup that he throws every now and then, here and there to show-off. And he tasted it good. Ha ha ha :banghead::D

I might pull his leg but I respect him. ;)
Sorry brother, I did not mean to offend anyone. I just wanted to say that trash is not the only expert and knowledgeable coder guy in the whole of traderji forum, and there are many other traders here who know a few things about coding like you, @TracerBullet, @NJ23, @UberMachine @travi @bpr @rmike @vagar11 @Happy_Singh @mastermind007 and many many more.

Best Regards
 
#40
.
 
Last edited:

Similar threads