## replace_date('31 December 2014');

### About time, leverage and a few grains of salt (Synthetic Prices Part II)

Just in time to be vintage 2014 I finally managed to write a long overdue blog post. Nevertheless thanks to a loyal crowd of readers this year has seen two, actually three, landmarks in the pageview stats. Once beyond the 100k milestone, the 200k mark was surpassed quite fast. A couple of weeks ago the near silent touch of a fabulous 250k followed: one quarter of a million pageviews! Wow! And right now at the cusp of 2015 the counter is steadily turning its way towards 300k. Thank you for all your interest, the rewarding exchange of ideas and your support during this remarkable year.

Regarding today's posting, it is a sequel to the Composing Synthetic Prices For Extended Historical ETF Data post back in May. Using "R", the language for statistical computing and graphics (get it here), thanks to Michael Kapler's excellent Systematic Investor Toolbox for R: SIT, it is possible to compose synthetic ETF's with extended historical data retrieved from suitable mutual funds on full auto while taking care of a seamless fit along the way.

In this post, I will demonstrate how to perform the same task in AmiBroker with two extra benefits: the application of leverage and the option for inverse data treatment. Of course, an R-savvy coder could probably achieve the same in R, but not me.

The below example shows $TLT as synthetic symbol with data going back to 1986*. The$ETF is based on the price data for TLT (green section) available from Yahoo and extended with VUSTX data (red section) from the same source.

In the next example leverage is applied: using SSO data for the duration of its availability (green section) followed by SPY data (red section) with a leverage setting of 2 it is possible to clone $SSO going back all the way until 1993*. To generate the synthetic prices the following code is used for user input, price calculation and symbol creation in AmiBroker's database. An example should crystallize the concept: notice the code sets about by cloning the actual SSO data, starting at the most recent end of day bar and walks back into time, bar by bar, until SSO's inception date is reached (the green section of the chart). As soon as quotes for SSO are no longer available (remember: we are going back into time!), the code switches to the base fund or index, which needs to be loaded as the current charted symbol (see settings below: for SSO it would be SPY or ^GSPC). From now on (the red section of the chart) the code calculates the synthetic prices by applying the leverage factor to the, if need be inverted, data of the charted symbol. The entire synthesizing procedure is performed by AmiBroker including feeding the data needed by the code to perform the operation. Of course the the necessary prices have to be stored beforehand in AmiBroker's database through AmiQuote or the Import Wizard. I happen to like the$-sign as prefix for synthetic symbols, so that is the prefix the code the Parameter settings window offers by default:

Tip: to generate synthetic prices for ETF's like the UltraShort SDS just use a negative leverage factor, i.e. -2 for SDS while utilizing the same workflow.

After the preparations are done for a particular $ETF, the actual extension by AmiBroker is virtually instantaneous and the synthetic$ETF is immediately stored in the current data base. You only need to perform the task quite meticulously.

Please follow the settings on the above screenshot exactly, so load the correct symbol on the chart, set to Daily, adjust Apply to *Current and Range: All quotes. Finally to create the $ETF, hit Scan and the symbol is created in a blink of an eye. For GLD with prices going back to November 2004 there is not a suitable source on Yahoo. Quandl offers London Bullion Market Association Gold prices dating back to April 1968 for download to csv (thanks SP!), but Quandl's data quality is not always up to par. So for the below extending of the GLD price series the high quality subscription data from Norgate Premium Data is used: XAUUSD with history starting early 1984. BTW: for reasons unknown to me, the code occasionally generates a price stream full of errors, even with all the correct settings dialed in:  Erroneous data stream due to monthly chart setting (intentionally invoked for demonstration purposes) Luckily there is an easy fix: just press Scan again (after checking for the right the charted symbol again): To demonstrate the usage of an external data source as well as applying data inversion, let's synthesize$ZIV. According to the Fund Summary for ZIV on Yahoo "the investment seeks to replicate, net of expenses, the inverse of the daily performance of the S&P 500 VIX Mid-Term Futures index." So for extending ZIV, the VXMT data supplied by the CBOE comes in handy, but this data only allows for extending ZIV from November 2010 back to January 2008. Nevertheless a big part of the 2008 crash is covered with the VXMT data tail, so here it is:

After obtaining the VXMT data from the CBOE website be sure to rename the file into ^VXMT.csv for consistency with Yahoo's naming routine. Next, after reading it thoroughly, delete the disclaimer info from the top of the file for easier reading by AmiBroker's import wizard. Finally apply the below settings and hit OK followed by Scan.

It should also be possible to create a synthetic cash or money market fund using the 13 week T-Bill yield data of ^IRX. Since I am not perfectly comfortable with my current method, I cannot show how to proceed creating a fund like $TBILL. Anyone who is familiar with the right procedure, please let me know and I will update this post with the proper acknowledgment. By just repeating the process you could also perform complexer two fold extensions like this one:$MDY = MDY + FMCSX + FDVLX.

Both the code demonstrated in this post and the used code for charting are available for download on Google Drive. The charting code is to be copied into the Program Files > AmiBroker > Formulas > Custom folder and can then be dragged and dropped on the price chart.

I wish each and every reader a good, healthy and prosperous 2015! Santé!

*Warning: As a matter of due diligence all results based on synthetic data should be taken with caution, since the actual relation between a base fund or index and its 2x/3x leveraged derivatives almost never is exactly 1:2 or 1:3. Hence the grains of salt!