Robbie Geary's GTR1 Backtester

This edition of the backtester is no longer updated.

Welcome! Currently, your best source of information on the backtester is the Mechanical Investing message board at, assisted by Mark Willcox's indispensable search tool. Search for posts by user rgearyiii or containing "gtr1". More information is available here, though much of it is obsolete. However, the best way to learn to use this backtester is to ask for examples that test your trading ideas, which users at will gladly provide. Also, if you're not already familiar with Jamie Gritton's Screen Builder, it would probably be a better place to start learning how to build screens.

If you're already proficient with the GTR1 backtester and would like to volunteer to improve the documentation, write tutorials or develop the user interface, send rgearyiii a message from In the meantime, the following brief instructions will hopefully be somewhat helpful:

Steps (Required): This is the only element of the form requiring input. As a simple demonstration, enter the text "aprc top 10" for Step 0 and click "Run Backtester". After a few seconds, you should get results, which are explained below. This screen (which I nickname "Buffet & Friends") picks the 10 common stocks among the entire US market with the highest actual prices on each day in the past.

All steps must reference a field and end in top n, bottom n, top n%, bottom n%, = x, != x, < x, > x, <= x, or >= x. A field reference can be either a specific pre-existing field (like aprc), an expression you build out of functions like ratio, linear, product, etc, or a label for an expression you've defined in the right half of the form. Thousands of field files and functions for combining them or performing technical analysis are available. To see a list of all field files, run the backtester with the text "list:*.*" in the "Miscellaneous Options" box. If you are already familiar with Jamie Gritton's Screen Builder, you'll notice that the names of VL field files are generally the same as Jamie's field codes, plus the extension .v.

Optional Settings

Field Labels/Expressions: This optional section is useful if you use the same expression in more than one step, making it easier to both construct and read your steps. For example, if you're calculating VL P/E ratios with the expression ratio(vprc, ces.v), you can label the expression "PE" on the right and enter as many steps like "PE > 0" or "PE bottom 10%" as you want, instead of entering ratio(vprc, ces.v) > 0, ratio(vprc, ces.v) bottom 10%, etc. The labels you give expressions will show up in the "Translation" section of the results after you run the backtest.

Start date/End date: Enter market dates in yyyymmdd format if you want to limit the calculation of results to specific periods. Note that behind the scenes, the backtest engine always runs backtests over the maximum period supported by the fields you reference; all these settings do is limit what is displayed.

Field File Lag: This sets the number of days field files are lagged. Data sources like VL, AAII, IBD etc usually do not publish their data before the market closes, so a lag of at least one market day should be used in backtests to avoid screening on data that was not actually available to investors before the market close on trading dates. When screening for current stock picks, however, a lag of zero market days is usually desirable. Leave this option blank to apply a lag of 1 when bakctesting and a lag of 0 when screening. This setting can be overridden for specific field files using the notation filename:n, which applies of lag of n market days to the file. For example, tim.v:3 lags tim.v (VL Timeliness) by three market days.

Note: This setting does not affect the "lag" argument in technical analysis functions like tr, rrs, sma, etc.

Holding Period: Enter a number of market days from 1 to 254 if you want to use a holding period other than 20 market days (roughly four weeks). This setting determines how often screening steps are performed for possible sells or buys within a portfolio. It also determines how many non-overlapping trading cycles the backtester runs for the same screen variant. If the holding period is 20 market days, the backtester runs 20 trading cycles, staggered by one market day.

Rebalance every...: This setting determines how frequently the backtester returns portfolios to equal weight by dollar value among all positions. By default, the backtester fully rebalances after each holding period, regardless of whether the screening steps call for any trades. Rebalancing leads to higher turnover and may reduce real-world returns. Set this value as high as you want to reduce the frequency of complete rebalances. E.g., if the holding period is 20 market days, a value of 5 will produce complete rebalances every 100 market days. The backtester always makes purchases in equal dollar amounts.

Rick Interval: Enter a number of market days from 1 to 254 to set the length of periods over which total returns are calculated when the backtester calculates the risk statistics shown in results. For some measurements, like Ulcer Index, daily returns (intervals of 1 market day) might be most appropriate, while for others, like Downside Deviation, longer periods make more sense. The default value is 20 market days, which is what most users prefer for GSD.

Friction: Enter any positive percentage to specify the round-trip trading loss on each position due to commissions, spreads, slippage, etc. Frictional costs are applied to all positions at sale (including sales executed in the course of rebalancing or triggered by stops).

Stop-Loss/Gain Multipliers: Stocks are normally only sold at the end of holding periods, but these settings can be used to trigger earlier sales (but not buys). A Stop-Gain Multiplier of 1.05 triggers a sale at the current day's close for any stock held that has gained 5% or more since the beginning of the current holding period, while a Stop-Loss Multiplier of 0.95 does the same for any stock held that has lost 5%. Stop conditions are only evaluated at market close (with no regard for intra-day highs or lows); if triggered, sales are executed at the same market close.

Shrink: Selecting this option causes the backtester to reduce the number of positions in a portfolio to the number of stocks passing buy or hold conditions when that number is less than the number of stocks called for in the final screening step, thereby ensuring the portfolio is 100% invested in stock. Otherwise, when this setting is not selected, the backtester holds cash in positions that cannot be filled with new stocks passing the screening criteria. If no stocks pass buy or hold conditions, then the portfolio consists entirely of cash, regardless of this setting.

Count: Selecting this option causes the backtester to report the number of stocks passing each step instead of the performance statistics it normally reports. This mode is useful for determining if your steps are behaving as intended, getting a feel for the distribution of a field's values, building market-timing signals and more.

No Cache: Selecting this option stops the backtester from writing to or reading from cache files. This is useful mainly in debugging or verifying that parameterization is working correctly. Note that the blender reads from the backtester's cache files, so if a backtest has not been cached, it cannot be included in blends.

Miscellaneous Options: This box is for options not currently handled elsewhere in the form. For example, entering risk=gdstub before running a backtest causes the results to show the risk measurements GSD, Downside Deviation, Sharpe Ratio, Treynor Index, Ulcer Index and Beta, instead of just GSD by default. Any subset of the letters g, d, s, t, u and b may be placed in any order after risk= to show the corresponding statistics in the same order.

Screen References: Paste the links to any screens you want to reference (if, for example, you are using field functions importf or imports) in these boxes.

  Start date:   Holding Period: mkt days   Friction: %    Shrink
  End date:   Rebalance every: periods   Stop-Gain Multiplier:    Count
  Field File Lag: mkt days   Risk Interval: mkt days   Stop-Loss Multiplier:    No cache
Misc. Options:
Steps: [more] (At least one step is required.) Field Labels : Expressions [more] (Field labels/expressions are optional.)
0:  :
1:  :
2:  :
3:  :
Hold while passing Step and satisfying
Screen References [more]