The Investable Universe
September 22, 2022
How to invest money wisely
January 23, 2023
Show all

Why do quantitative investment?

Quantitative investment is quite a mouthful – seven syllables. Why is it even worth caring about? We’re going to break it down into manageable pieces.

Why do we invest?

Investment is the art of forgoing current pleasure to gain something more tomorrow – at least in theory. Squirrels invest: they bury nuts for the winter. Humans invest all the time – even for as trivial a thing as standing in line to buy Starbucks. Nobody particularly enjoys the standing in line part of the process: it is all about the coffee at the end. We’ll use this coffee metaphor throughout, as we talk about investing. We’ve all has the experience of going to a coffee shop, waiting 20 minutes in line, and then fuming at the terrible cup of coffee that resulted in the end. Some coffee is just better than other coffee.

How do we invest?

Most people invest the same way they buy coffee: they simply go to the nearest (or most convenient) coffee shop and throw down $4 for a latte. They are likely to keep buying coffees from that shop, day after day.

A single ticker investment

Investment wise, this is like deciding they want to invest in stocks, and then just going and buying one. We can model this via our Single Letter portfolio.

Here we have just invested in shares of Agilent Technologies. Why Agilent? Because it is the stock that has the ticker A, and A is the first letter of the alphabet. We made some money at this: every dollar put in January 1st, 2000 returned 150%, turning into $2.50. Why did we pick such an arbitrary choice? For the same reason most people go to the nearest coffee shop, and order a latte: it is easy. We’re modeling a typical investor. Perhaps they work at Agilent. Or they heard something nice about it. Or Cramer pitched it. As far as this article is concerned, we don’t really know or care. With just one stock, none of the results tabs are going to tell us much about our pick. That said, that is a lot of Agilent. 22 years worth. That would be like going to decide, once and for all, what drink we were going to use as our morning cup of Joe for the rest of our lives. Perhaps we should look at it over a smaller time span, and treat each year as a separate investment.

A single ticker investment for a single year

Now we take just one year of Agilent, from 2000 to 2001.

Wow, that is a lot of red. Our dollar turned into $0.76. Maybe we do better next year?

Nope, same story, but even worse! We lost 42% in that year. Maybe the next year will be better. If this were a coffee shop (or an investment advisor), it would surely be out of business by now.

It is even worse!!! Why, oh why did we pick this stock. Oh yeah, because it has the ticker A. You are probably wondering how to get the total performance from 2000 to 2003. You could just pull out a calculator, but Equities Lab can cough up that number in a trice, with hardly any effort on your part. Give it a try now, if you have Equities Lab open. Our dog, London, will wait patiently.

Spanning multiple years

It turns out, it is as simple as adjusting the “bought on” date back to 2000, while leaving the “returned on” date at 1/1/2003.

If we look at the red number in the bottom next to Medical Diagnostics and Research, we see that they lost almost three quarters of their value over the period. Simply brilliant. We could also get that information (and more) by clicking on the giant red box.

Seeing performance through time

This is informative, yet oddly tedious. It would be super nice if we could just get the performance each year in one place, rather than having to adjust all those dates. To do this, let us imagine we have (had) a portfolio of $100,000 in 2000. We set that by creating a tab (use the button or Ctrl T) to create a tab named “initial_cash” and setting the value to 100000. That done, we need to specify the time interval want to use (in our case, yearly, starting in January). We’ll do this with the tab (middle left of the screen). The backtest trading rules section has a rebalance frequency. Rebalance 01/01 means rebalance every January first. That all done, we can see what happened through time by backtesting (use the button in the upper right corner. This will create a dialog box, which confirms the yearly rebalance, and no stop losses, etc. It also gives us a date range, which we need to adjust, so it starts in 2000 . Having adjusted it we can click on “Run”. Once it runs, we’ll get a very useful screen packed with information, which we’ll get back to. For now, click on the Positions tab ( in the lower right).

Happiness is … a collection of single year studies, gathered here for easy viewing. We can see that Agilent has a terrible first few years. After that things settled into mostly years of good performance, with a few stark exceptions. Hovering over the boxes will reveal which ones are the exceptions. It should be no surprise that 2008 was awful: -55%.

What is Backtesting?

Having backtested, the very next question is what happened, behind the covers? We’ll definite it inductively. Imagine a portfolio, at some point in time. To figure out what happens next, do this:

  1. Take the money, and invest it evenly (for now), in all the stocks that match the screen at that point in time.
  2. Store values for all plotted values, so these values show up in the positions table and the portfolio average shows up in a plotted line.
  3. Update the positions with the new trades. If initial_cash is not defined, entries are added when positions are created and closed. If initial_cash is defined, then entries are added for each stock, for each rebalance.
  4. For each day between that point in time, and the next one:
    1. Compute the change in portfolio value, and store that change (so the line is plotted)
    2. Handle dividends. Adjust the shares upwards by the percentage dividend paid (modeling reinvesting all dividends). Splits are handled by the price series being adjusted
    3. Handle stop losses and stop gains. Sell affected stocks, and leave the cash in the account
    4. Handle delisted stocks. If it matches the delist_bankrupt criteria, deduct 99% to handle bankruptcy. Otherwise, assume buyout
    5. Check to see if the new day is a rebalance day. If so, sell all stocks, and go to step 1
    6. Check to see if there is no new day in the backtest. If so, sell all stocks, and finish

In essence,  according to desky.ca the computer is doing the heavy lifting of buying and selling each stock each quarter (or year or month, or whatever), and keeping the equity curve, and doing all the bookkeeping. One can view the screener as defining an index (that changes over time based on the rules set forth), and the backtest as a sample ETF or fund that follows the index.

Does backtesting handle multiple stocks?

Our first backtest was very simple. Just invest in A. It underperformed the SPY index fund, but not by a lot.

If we just invest in B, we get a similar stock, that outperforms in different times:

And when we combine them both, we get this:

Which underscores why a tools can be so helpful. One would assume that two stocks that both got about 250% returns, combined, would get 250% returns. Apparently not. Notice that B was late in coming to the party. That line is flat until 2005. Agilent could be 100% of the portfolio until then. And, as we saw, it got to be 100% awful during that time period. Then B comes along to dilute Agilent’s remarkable recovery.

Do rebalance periods change the results when backtesting?

Clearly they do. Even if we aren’t using any actual algorithm (beyond buy A and B), the timing of rebalancing matters. If we are willing to make more trades, we can rebalance monthly. This gives better performance.

Of course, we could rebalance weekly. Would that be better?

It is. Probably not enough better to justify all those trades, but it is better.

henry
henry
Henry Crutcher is an avid family guy, board gamer (think Settlers of Catan, Puerto Rico, etc), computer nut, and all around geek. Hailing from Louisville, KY, he has noticed that the weather in Louisville is remarkably similar to the weather in Atlanta, GA despite the 407 miles that separate them. He has two daughters, one cat, and lots of trees. He loves the Miles Vorkosigan series from Lois McMaster Bujold, for its mix of SF, comedy and insight into how people work. He also comsumes more than his fair share of cheesy business/economics books, such as The Ascent of Money by Niall Ferguson, or Farewell to Alms, by Gregory Clark.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

gdpr-image
This website uses cookies to improve your experience. By using this website you agree to our Data Protection Policy.
Read more