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.

Engineering Returns With Multi Asset Universes

Before the engineering starts: Only four months ago, the pageview counter passed the 100,000 milestone. In all likelihood the 200,000 mark will be hit today. Thank you very much for your interest.

The series about Harvesting Momentum (see part I, part II and part III) largely covered pairwise strategies. Now it is time to investigate the performance of more diversified universes to generate returns.


A recent post on CSSA presented Momentum Score Matrices as a tool for predicting the profitability of a given asset universe. Assuming a random walk, the momentum profitability depends on the degree in dispersion of mean returns between the assets in a portfolio. David Varadi states: "A heterogeneous universe of assets such as one containing diverse asset classes will have different sources of returns- and hence greater dispersion- than a homogeneous universe such as sectors within a stock index."

Following a similar, but simplified approach to the cross-sectional dispersion of mean returns, the pairwise momentum score can be calculated as the population average of the squared difference between the momentum values of asset ABC against asset XYZ. Or in "R":

Dispersion (D) for $IEF - $TIP based on 3 month returns during 2001 - 2014. Average = 8

For an asset collection consisting of 14 assets, this approach results in the below matrix. The calculations can be performed using "R", Excel or AmiBroker. Examples of each are available on the Google Drive connected to this post. AmiBroker has the benefit of exporting the momentum matrix as html-file, which then can be imported into Excel for analysis (and prettifying).

Dispersion matix based on 3 month returns using synthetic $ETF's

Value Investing By Proxy

By many Benjamin Graham is considered to be the father of "value investing" and with his book "The Intelligent Investor", Mr. Graham brought value investing to the individual investor.


Mr. Graham advised the investor to always hold bonds in his investment portfolio:
"We recommend that the investor divide his holdings between high-grade bonds and leading common stocks; that the proportion held in bonds be never less than 25% or more than 75% with the converse being necessarily true for the common-stock component."
Combining Mr. Graham's recommendation with the concept of paired switching previously discussed, leads to the following long only application:
  • Intermittently rebalance a basket of VTI (stocks) and TLT (bonds) and allocate 75% of capital to the best performing EFT and the remaining 25% to the other ETF.
  • The rebalancing frequency may be set for example to quarterly or monthly.
  • Performance is measured using total return over the prior quarter or prior three months.
Building such a "Value Investing By Proxy" model in Excel is fairly easy using monthly adjusted closes available from Yahoo! Finance (VTI, TLT).

Composing Synthetic Prices For Extended Historical ETF Data

Backtesting of strategies is best done with at least 10+ years of historical price data, preferably even more. However, ETF's with such prolonged historical data are rare. The obvious escape would be to replace ETF's with look-a-likes from mutual fund companies like Vanguard or Fidelity. Can't we have both ways at the same time?


Actually we can, thanks to Michael Kapler's excellent Systematic Investor Toolbox for R: SIT. Some time ago Michael added a special function to his SIT: getSymbols.extra. Using "R", the language for statistical computing and graphics (get it here), the code composes 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. With a minor addition to Michael's code, in one and the same run for each ETF the newly created synthetic prices can be saved to CSV-file. Next, with its Import Wizard, these CSV-files can be imported into AmiBroker's database quite easy. Alternatively, pulling the CSV-data into Excel is another achievable option.

CSV-data after import in Excel

The chart below shows the extended price history of $VWO. First the data of EEM is added and calibrated to fit and extend VWO. Next the same is done with the addition of VEIEX' data. Finally the data of FEMKX is added, thus prolongating VWO's history from 2005 back into 1990 adding almost 15 years of backtestable data.

$VWO: VWO extended with EEM extended with VEIEX extended with FEMKX

Harvesting Momentum: Let's Kick Tires With AmiBroker [ Part III - Final ]

The previous posts in this series covered a basic Tactical Asset Allocation approach with with signals taken from the daily and the weekly time frames. This final post will be dedicated to portfolio rotation based on monthly and quarterly time frame. Only two asset class universes will be covered. Multi asset class universes are going to be the subject of a future post.


Taking the monthly time frame into consideration basically means rotation decisions are made once a month, after the close of the month. For the quarterly time frames this comes to only 4 re-balancing opportunities per year: at the end of each quarter. However, usually the re-balancing frequency is way lower.

For backtesting once again the source code provided in the opening post will be used, basically allowing the DIY retail investor to engineer his own alpha. Even if you don't have access to thinkorswim or Amibroker, the strategy at hand can be fairly easy implemented using Excel, since momentum is the only metric taken into consideration for re-balancing decisions.

Monthly Periodicity

The typical US stock market year has 252 trading days (= 12 months with 21 days on average). So for the previously used 85 days/17 weeks lookback period, momentum calculated over a 4 month period (= 4 x 21 days) is suitable. Applied to the base pair (SPY-TLT) this 4 month lookback period renders the following results.

Portfolio Equity SPY - TLT (4 months), drawdown periods in red

A fabulous landmark: 100,000 pageviews


During todays early hours, the pageview counter quietly turned past the memorable 100,000 figure. Reaching 10,000 pageviews was a big surprise already, so the 100k number is something I never even imagined I would achieve when I started this blog.

Actually, getting here by spending countless hours of free time learning and writing code, running aground, discovering new ways and pushing forward again, wasn't always easy. However, I've had lots of fun and learned so incredibly much along the way. Meeting fantastic people too, truly is a great privilege. Many of them sharing their knowledge, really helping me out and putting me on track again.

100k! For real, I could not have done without you. So thank you for your interest, thank you for your support, thank you for the occasional donation and thank you for sharing.

What now then? Focused on portfolio strategies, there are quite a few idea's floating in my head. Stay tuned and do keep sharing so we all benefit!

Harvesting Momentum: Let's Kick Tires With AmiBroker [ Part II ]

In Part I of this series the frame work for a basic Tactical Asset Allocation strategy was discussed using two ETF's representing stocks (first SPY, later MDY) and bonds (TLT). Following on the daily signals of the first post, the continuation of this series will be all about the higher time frames, starting with weekly signals.


Engaging a strategy based on weekly signals might be the way to go for anybody who does not want to be in synch with the crowd, since everyone and his uncle is doing momentum on monthly basis these days. And as it happens, the AFL-code provided in the previous post is just as suitable for weekend traders too.

Weekly Periodicity

As a starting point, the weekly equivalent of 85 days for the momentum calculation is used: 17 weeks without any smoothing.

Portfolio Equity SPY - TLT (17 weeks), draw down periods in red
Profit table SPY - TLT (17 weeks)
SPY-TLT (17w)    2004 - 2013
Total Profit   211     %
CAR   12.05%
MDD (trades)   -16.16%
MDD (system)   -16.16%
Calmar (0%)   0.75
Sharpe (0%)   0.76
Trades   43     
Winners   58.14     %

Harvesting Momentum: Let's Kick Tires With AmiBroker [ Part I ]

Developing indicators and strategies is great, putting them to a stress test by mr. Market is better. But how? As we speak, thinkDesktop does not have the nuts and bolts to perform proper backtesting. After much consideration I decided to invest nearly $500 by buying the AmiBroker Professional suite at the turn of the year. Next I found myself back in primary school, learning to write again ...


Over the last couple of weeks I have been studying AmiBroker’s Formula Language (AFL) like there is no tomorrow. Luckily the "Introduction to AmiBroker" by Howard Bandy (free download) is a great read and AFL has a huge and generous user base, gathered in the AmiBroker User’s List on Yahoo. Last but not least there is Tomasz Janeczko’s extensive UsersGuide with an overwhelming amount of examples.

So this post is all about backtesting. Actually it probably will be the first in a series for presenting some of the backtesting possibilities AmiBroker has to offer. And while we are discovering the AmiBroker Backtester, chances are we might come across some pretty neat portfolio strategies along the way. Stay tuned!

Harvesting Momentum

As stated in previous posts, the "momentum anomaly" is known for centuries. The gist of the momentum anomaly is that assets often continue their price momentum, defined as the change in price over a given lookback period. Momentum works well across asset classes as well as within them. So harvesting momentum really is all about follow the money.

On Seeking Alpha contributor Marc Cohn has published various strategies involving momentum based trading. One of them, "Return Like A Stock, Risk Like A Bond: 15.5% CAGR With 17% Drawdown" utilizes so called "Paired Switching" (see here for SSRN paper) between two exchange traded funds: SPY and TLT. Marc's comprehensive system actually is a TAA strategy in its simplest appearance.


AAA Made Easy For Retail Investors

During 2013 several asset allocation strategies have been presented on this blog. However, all these studies are tailor made for the specific parameters required by the strategy involved. To accommodate the exploration of similar strategies for DIY retail investors a flexible framework would come in handy. And so we have arrived at the rationale of the "All-In-One" Adaptive Asset Allocation suite.


The AAA suite is intended for backtesting numerous asset allocation strategies like TAA, GMR, FAA but also GMRE or BRS (published by Frank Grossmann on Seeking Alpha). The suite consists of two studies:
- AAA_Allocation: for showing historical and present asset allocation (required for "live" trading).
- AAA_Equity: for getting an impression* of portfolio wise performance (non essential).
The suite supports portfolio sizes with up to 12 assets next to a cash proxy.
Rebalancing of capital between the TopX assets is equal weighted.