[EDIT] Portfolio123 has changed their database and formulas. This post is now outdated, BUT it is still very similar.
How to Backtest – What is Backtesting?
One part of Old School Value that has really improved behind the scenes are the value stock screeners which includes backtest information.
Previously it was a jumbled mess of spreadsheets, databases, data files and hacks which miraculously worked. But several months ago, I threw it all away and have moved exclusively to a service with reasonable pricing that offers advanced backtesting and screening capabilities from Portfolio123.
Click the button below to download the printable PDF version of this post.
Due to the number of people asking me how to backtest themselves like I did for the stock screeners, the purpose of this post is to show you how easy it is to set up and perform your own backtest using portfolio123 for your own stock strategies.
This way, you can start finding winning value investment strategies and backtest super powerful custom screens to find your own special ideas.
I will go through a quick intro, a tutorial on how to backtest and create your own screens using portfolio123 followed by additional backtesting website reviews.
To backtest means to test how an investment strategy performed over a historical period.
It is a way to simulate what happened in the past based on certain investment criteria with the obvious benefit being that you do not have to wait for years to see how a strategy performs.
This way, your backtesting will be useful in testing hypotheses and to find winning strategies.
How to Backtest with Portfolio123
Here is a breakdown of how the backtest tutorial is organized and I will go through how I created the NCAV stock screen.
- Create Custom Formulas First
- Creating Powerful Screens with Custom Formulas
- Backtesting the Screen
- Getting Screen Results
1. Create Custom Formulas First
To really get the most out of a backtesting system, you need to create custom formulas.
This is the section that you really have to nail down to be able to create awesome custom formulas. (To do this, log into your account, go to the “MY 123” page, select “custom formulas” and select New)
Since I am recreating the NCAV screen here for you, the custom formula I would need to create is NCAV.
NCAV = Current Asset – Total Liability
but for the screen, since Portfolio123 offers a lot of control, I have subtracted preferred shares from the equation. The NCAV formula is now
NCAV = Current Asset – Total Liability – Preferred shares
The formula that Portfolio123 understands looks like this
CurAstQ – LiabTotQ – (EqTotQ – BV$Q)
Now instead of having to write out CurAstQ – LiabTotQ – (EqTotQ – BV$Q) every time you want to get NCAV, you can simply enter $NCAV as a shortcut to the custom formula.
For NCAV, I am only interested in getting the latest quarterly figures from the balance sheet which is why I chose the simple formulas.
But if you wanted to use numbers from previous quarters or years, it is very easy. A detailed guide is available and you can find the detailed description for each of the names used in the formula.
On their website, a spreadsheet with the name for each line item can be found at the help page.
But before that, please click on the image below to download the best free investment checklist that will organize your thoughts and save you time.
As an example of how this works, let’s say you wanted to perform a backtest for whether Total Assets was growing over the past 3 years.
In words, it would be something like
Check Total Assets of 2012 is greater than 2011 Total Assets, and 2011 Total Assets is greater than 2010 Total Assets
Based on the documentation, the formula version would be
AstTot(0,ANN) > AstTot(1,ANN) AND AstTot(1,ANN) > AstTot(2,ANN)
You get the idea of how it works right?
There is a name for each line item and you can choose whether you want quarterly, annual or TTM numbers. Then you take it one step further by using a number that offsets from the latest value.
So a zero is the most current value, 1 is the prior year, 2 is the value for two years back, 3 is the value for three years back and so on. Keep that in mind for when you create your own criteria.
2. Creating Powerful Screens with Custom Formulas
Now that you know how to create custom formulas, let’s apply it to a screen.
Go create a new screen and you will see the following screen.
This is where all the magic happens.
Portfolio123 is so easy to use because if you do not want to mess around with formulas and complicated math functions, it is all there for you. You just point and click to add.
But I like to customize and add more value to my screens so here is what I added in my criteria with an explanation to each rule from the NCAV screen.
- country(“CHN”)=false //remove Chinese companies, but cannot detect reverse merger Chinese stocks
- Sector!=FINANC and Universe($ADR)=false //remove all stocks in the financial industry and ADR’s
- Universe(nootc) //no OTC stocks. I create realistic backtests which can be duplicated by humans
- Vol10DAvg>0.03 //10 day average volume of more than 30,000. Unit is in 100k.
- $NCAV/MktCap>1 //using my custom formula. NCAV is greater than the market cap.
- close(0)>0.5 //closing price must be greater than $0.50
3. Backtesting the Stock Screen
The magic happened in the above section, so now we get to have fun with it now.
On the backtest section, click settings to bring up additional features.
- Universe: the universe of stocks you want to backtest against. You can choose something like mid caps only, S&P500 stocks only or Dow Jones Industrial Average.
- Benchmark: I just stick to either the S&P500 or Russell2000. You can use the raw index, but I like the ETF version so that the comparison is realistic.
- Method: Choose long, short, long/short and hedged. I do not know how to use the long/short or hedged method yet.
- Ranking: This is a great part of Portfolio123. The stocks that make it into the backtest are ranked based on a predefined ranking system. For the NCAV, I rank stocks based on Graham which further filters the list to the best Graham type stocks.
- Price: at what time will the stock enter the backtest? Choose the open, close or average of open and close price.
- Rank Tolerance: You can set whether the portfolio holdings turnover easily
- Slippage: Bid and ask prices are real. The stock price may have gone up already, and slippage adds that simulation into the backtest.
- Carry Cost: The percentage it costs you to rebalance the portfolio. Trading fees, commissions etc.
- Long weight: If you are long only, then it will be 100%. If you are long and short stocks, then a short weight % will also appear and you can adjusted the ratio.
4. Getting Screen Results
Once you have selected all the inputs, run the backtest to get something like below.
Clicking the download link will download an excel file with the data so that you can recreate the graphs yourself.
At the bottom of the results, you can see how the backtesting strategy performed compared to your benchmark.
Clicking the dates will bring up a list of stocks that were included in the backtest during that specific period and will let you see the details of how each performed.
Easy huh? 🙂
More Backtesting Websites
Here are some more backtesting websites that will interest you.
Portfolio123 (subscription required)
- Backtest data from 1999
- No hindsight bias
- Easy learning curve
- Can create complex formulas easily using financial statement data
- Built in pre-defined screens for those just starting out or not comfortable diving into the custom formulas
- Has a stock ranking system for the screeners
- Has industry data, market data information and other useful tools
- Pricey but worth the value.
- Can only download results for 10 screens in a 24 hour timeframe.
- Weak for looking up stock data. Stick to Yahoo Finance.
If you want to program your own backtests, then this is for you. It provides you with a platform on which you can code your own backtests. The design is very easy and intuitive.
- Powerful and Flexible
- Easy to use platform
- Growing community of fellow quant programmers
- Full programming required
- Big learning curve
A startup website I haven’t validated yet. Focusing on click and drag style backtesting. Looks like the interface is easy to use and clean which is great for their target audience.
This backtest came about from an investor from the Motley Fool Mechanical Investing board. The board is still active so you may want to browse through the forums to get ideas on how to build your own screens and backtest.
- Uses Value Line data
- Community support
- Lots of documentations (but difficult to understand for non programmers)
- Fast output and results. It does what it is designed to do.
- Steep learning curve
- No UI. Mostly all text interface.
Created much like Jamie Gritton’s MI Backtester with data coming from the AAII Stock Investor Pro service.
- Stock Investor Pro data is pretty good. Always a 1 month delay, but no hindrance for backtesting.
- Easy to look up past screens and backtests run by other people
- All the results and data is public. You cannot keep your screen to yourself. Easy to find.
- There is a queue to have your screen run. Each screen takes 15min to run so if there is a long queue, you will be waiting for a long time.
Backtesting strategies is a great way to apply what you learn and to come up with your own ideas and hypotheses. By coming up with your own strategies, you have access to a constant flow of ideas.