Understanding efficiency of native price arrays and static variables

I've enjoyed Amibroker's regular innovations. Sometimes however, I become confused about what performance enhancements supercede others. For me, this seems inevitable given Amibroker's stellar continuous quality improvement and my inability to absorb all the many improvements required to stay absolutely current. I would welcome some clarification.

My understanding is that Amibroker native price arrays are the gold standard in efficiency and memory management. Towards maintaining that efficiency, I've been using this approach:

My use case:

I mostly trade options. I use Amibroker to backtest potential option spreads. Up to this point I have been analyzing the potential market setups and possible option combinations in other software platforms (MATLAB and C++) and then importing the resulting data into Amibroker for backtesting confirmation. I would like to now move the initial potential setup and combination analysis into Amibroker and simplify my data management. I know that Amibroker has the power to do everything I require so long as this backyard programmer can harness it!

Currently, I am using ASCII import to retrieve the option data from a vendor supplied end-of-day option chain. For each option I import: Symbol, Date, O, H, L, C, V, OI, AUX1(bid), AUX2(ask).

I then import the preprocessed results from my trade analysis/setup into three synthetic tickers (using all six available price variables in each synthetic ticker): Name() + _extra; Name() + _IVcoefficients; and, Name() + _greeks.

Each backtest has a specific start bar and a specific end bar for analysis. I compute a spread price at each bar. I am currently using SetForeign() to assign option leg prices to variables and then summing the prices of the legs for the option spread price, greeks, etc. I am not doing any charting.

I have read various posts in this forum about static variables, synthetic tickers, as well as the guide for SetForeign(), StaticVarSet(), StaticVarGet(), etc.

My confusion revolves around the comparative efficiency (memory usage and speed) of three differing approaches to accessing/manipulating data: Amibroker native price arrays, static variables, and the various uses of SetForeign() and Foreign() and also AddToComposite.

For example, this document indicates that a single SetForeign() that allows access to the native price array data in one call is 6x faster than the equivalent number of individual Foreign() calls, taking about the same time as a single Foreign().

And, here, it is stated that using read once/save once, static variables offer the same speed as regular variables (no speed penalty).

Are static variables used in this way always as efficient as a variable created by adding price data from several instances of SetForeign() (such in my case above)?

From what I have read and understand, if I am evaluating data in a bar by bar manner, then native price arrays are to be preferred. However, I don't want to make any assumptions so I am asking for clarification. Is using native price arrays in this way more efficient than static variables or any other approach within Amibroker? When would I prefer static variables to variables holding native price array data if the computations can be achieved using either?

Any explanations or references would be enthusiastically appreciated!

In short static variables are always many times faster than SetForeign. So as long as you don't run out of RAM, they are always better.

1 Like

Thank you Tomasz! That cut through the fog quickly!

Hey @tentmakers , unrelated but since you trade options and use Amibroker for backtesting them, what is your opinion of softwares like CMLViz Trade Machine and OptionNET Explorer? Do you use them at all or is Amibroker enough? Also, what is your opinion on the SteadyOptions education service? A guy looking to get into trading options is asking :slight_smile:

Hi @gambleditall, I'm not familiar with CMLViz. OptionNET Explorer and OptionVue are similar products. I tried OptionNET Explorer's 30day free trial but ultimately chose OptionVue and used it for several years. Both platforms provide a lot of features. But, for me, I wanted to be able to use my own calculations for implied volatility and a nonlinear discounting of time. Amibroker gives me the flexibility to use my own calculations not only in charting; but, also in scans, backtests, and optimizations.

I don't have any experience with SteadyOptions eduction service. But, IMHO, wrapping your head around implied volatility, the asymmetrical nature of the underlying price / implied volatility slope, and the impact of nonlinear time decay which also accounts for "market" time vs. calendar time, will give you an edge that is not supplied out-of-the box by the vendors you mentioned. Options are a lot more like flying a military helicopter than a passenger airplane.

Long-term, the only consistent edge I have found (without having an opinion on market movement) is the volatility risk premium that might be harvested in selling options.

With a handle like gambleditall, you might want to reconsider! :wink:

2 Likes

Thanks for the comprehensive reply.

If the only consistent edge is selling premium then why don't you just sell VIX? From my limited knowledge, selling options is a very difficult game from what I understand especially if you are retail. It's profitable until it isn't and a lot of experts say it's akin to picking pennies in front of a steamroller due to the tail risk. Any comments?

Since you are knowledgeable about this market, what is your view on using options when you DO have a view on the market? With the flexibility they provide, is it better to use them vs just trading the underlying?

Right now I only trade direction using edges I have found over time but if options provide a better structure to exploit that edge more asymmetrically I would love to use them. It's just that the learning curve is quite high so I haven't got into it yet, hence the curiosity.

Selling premium is a strategy for harvesting the volatility risk premium (generally the difference between implied volatility and realized volatility) if there is one. VRP is characteristic of index options and not usually a lasting presence in options on individual stocks. Investors who desire to hedge often use index options (e.g., SPX options); they are willing to pay a premium for this hedge just as one might pay a premium for life insurance. Sellers of options generally expect a certain premium level or they might not choose to write the option. I also will buy a hedge against the options I write (create a credit spread). Whatever my strategy might be, it is the volatility profile on which I am concentrating. Both the vertical skew (think strike price) and the horizontal skew (think time to expiry) are critical aspects of implied volatility. Just like an insurance company, you expect a different premium based on how long you think the person might live and how close they are to that time.

There are multiple reasons someone might purchase an option rather than a stock when they have an opinion of the market. Some people use options in place of the underlying simply to leverage their position or to define their risk. If you are in a liquid underlying market and trade stocks, your stops might work in a rapid decline. But, what if the underlying gaps drastically, runs your stop and you lost 20% more than you expected on the open? An option as a surrogate for the stock purchase will have a maximum defined risk (known at the time of purchase).

I undertake option income strategies that sell premium within a defined risk. I don't trade volatility as an asset class (VIX, VXX, SVXY, VIX futures, etc.). I analyze the volatility (implied and realized) and seek to understand how it moves in relation to the movement of the underlying (price/volatility slope in index markets). Each instrument has its own personality if you will.

Like any trader, I want to keep my losses small compared to my gains so that I have a positive expectancy over time. IMHO, the key to making money is to have consistent (even small) profits and use a position sizing algo that takes advantage of the price / probability metrics of your trading strategy and your market. Most of my return is a result of my position sizing strategy. My options income strategies are fairly conservatve (RRR) so that I sleep well at night.

For me, options are the quintessential instrument for personalizing a trading strategy to your unique risk tolerance levels.

Enjoy your adventure!

3 Likes

I take it from this that as a strategy you are selling ITM options and buying OTM options (as a hedge against your sale)? Of course, I am sure there is a lot more to it but essentially that is what you are doing right?

With regards to buying options to play directional moves. Yes, you are right, if you are playing an instrument directionally then you can buy an option to avoid gap risk. However, that is priced into the option and you are paying a premium to avoid that gap risk versus just buying or selling the underlying, correct?