PART XV · Chapter 120 · 660 / 660

Lesson 660. Quant and backtesting terms

Chapter 120. Portfolio, Asset Allocation, Derivatives & Quant Validation Terms

This lesson gathers the terms used when trading rules or allocation rules are tested on past data, and the traps that make those results look better than they really are. It only explains what the terms mean and does not present any particular trading rule or signal. The rules and numbers in the examples are all hypothetical.

This lesson is general information that explains what investment terms mean. The numbers in the examples are assumptions made for illustration.

Backtest

Definition: Applying a trading rule or allocation rule set in advance to past data to calculate what the result would have been if it had been followed exactly at the time.

In plain words: It helps to check an idea, but the result of the calculation is not a return actually earned by trading at the time. The result changes a lot with which data were included or left out, whether information unknown at the time was used, and how costs were put in. Asset allocation backtests have few trades and long periods, so one interest-rate era or one rebalancing assumption decides a large part of the result (Lesson 445).

Example: Suppose you see a result such as "investing this way over the past few years would have made a lot of money". First ask whether the calculation included the companies that failed at the time. Then ask whether the time the signal was seen and the price at which the order was placed come in the right order.

Often confused with: The typical traps that inflate a backtest are survivorship bias, look-ahead bias, overfitting and a missing transaction cost assumption. Looking again with a period not used when building the rule, before trusting the result, is the out-of-sample test.

Related lessons:

Testable rule

Definition: A trading rule that writes down its universe, data, signal time, orders, costs and version completely, so that anyone calculating it gets the same list of trades.

In plain words: A single sentence such as "buy when the price passes its high" is read differently by different people, so even testing the same period can give different numbers of trades. Lesson 305 writes the rule as a six-box specification and holds that two people's fill lists match only when even whether to round or to round down is written. A sentence missing numbers, times or the type of price, such as "buy at a reasonable price", is not yet a rule.

Example: Assumptions: if the close on the signal day is $51.80 and the next day's limit-price cap is set 1% above the close, the cap is 51.80 × 1.01 = $52.318, which is $52.31 when cents are rounded down. Someone who rounds instead writes $52.32, and the two trade lists can come apart.

Often confused with: A rule being testable means it can be recalculated, not that its performance is good. Whether the performance holds up is looked at separately with the out-of-sample test.

Related lessons:

Out-of-sample test

Definition: Applying an unchanged rule to data from a period not looked at while building and choosing the rule, to check whether the result holds up.

In plain words: Lesson 476 splits data into a training period for building the rule, a validation period for choosing among candidates and a final test period kept until the end. The final test data are commonly called out-of-sample data. If you changed conditions after seeing the validation result, that period is no longer new data. If you change the rule after seeing the final test result, record it as a new version, and do not call a rerun on the same period a new out-of-sample test.

Example: Assumptions: a rule that turned $1,000 into $1,400 in the training period is applied unchanged to the final test period, and $1,000 becomes $950. The returns of the two periods are 40% and (950 − 1,000) ÷ 1,000 × 100 = −5%. The periods differ in length, so the two numbers are not compared directly, but it is an example of a rule whose results while being built did not appear afterward.

Often confused with: Lesson 306 splits development, selection and final test periods with the same idea and also counts the number of settings tried. The method that repeats this by moving the periods forward one step at a time is the walk-forward test.

Related lessons:

Overfitting

Definition: The problem of fitting a rule so closely to past data that it captures that period's chance features and then does not work well in a new period.

In plain words: If you test many values for the period of a buy criterion and announce only the best one, the failures of the other values you tried are hidden. So the better the result, the more you ask how many conditions were changed while producing it. Still, good past results alone do not prove overfitting, and later weakness can come from a change in the market environment.

Example: Assumptions: combining five high-breakout periods, three exit periods and two market filters gives 5 × 3 × 2 = 30 combinations, and adding three ideas dropped along the way means 33 attempts were made. If the best of them is evaluated again on the same period, luck is mixed into that number.

Often confused with: It is like a student who memorized the questions and answers of a test: the score on the same questions is high, but whether the student will do well on new questions is unknown. It is also called curve fitting, and the procedures that filter it out are the out-of-sample test and the walk-forward test. The illusion created when you pick the best of many test results is worked out in Lesson 588, and its correction in Lesson 589.

Related lessons:

Look-ahead bias

Definition: The error of using in a past calculation information that was not yet public or not yet final at the time, as if it had been known, which makes the result look better than it was.

In plain words: Lesson 475 also describes the same error as letting future information leak into the test. Common examples are counting a purchase at the day's close on results released after the close, and mistaking the last day of the quarter the results cover for the day the information became public. Using on the same day a value that is fixed only after the next bar, such as a confirmed high, is the same error (Lesson 243).

Example: Assumptions: on a day when good results came out after the close, the close was $100, the next day's open was $120, and the shares were later sold at $126. Counting a purchase at $100, as if the results had been known in advance, gives (126 − 100) ÷ 100 × 100 = 26%. Counting from the next day's open, the price at which you could actually have bought, gives (126 − 120) ÷ 120 × 100 = 5%.

Often confused with: Testing the past with only the stocks that remain today, survivorship bias, also uses a list that was unknown at the time, but it is told apart as a problem of the universe list. The check that matches the time a filing was received with the time an order could be placed is in Lesson 305.

Related lessons:

Survivorship bias

Definition: The problem of looking at the past with only the survivors, leaving out those that failed and dropped off the list, so that results look better than they really were.

In plain words: Testing the past with today's index members drops from the calculation the losses of stocks that were delisted or removed from the index in between. So Lesson 305 uses each date's own universe list and checks whether removed and delisted stocks are included. The loss on a delisted stock is not always total, so the amount actually recovered is checked separately too.

Example: Assumptions: you invested $1,000 in each of three companies, and one failed and dropped off the list. Looking only at the remaining two, you calculate as if $2,000 became $2,600 and record a return of 600 ÷ 2,000 × 100 = 30%. The result calculated on the whole $3,000 at the start is lower than this.

Often confused with: Testing a strategy only on stocks you already know rose sharply also inflates results in the same direction.

Related lessons:

Transaction cost assumption

Definition: The assumptions, set in advance, about the commissions, spreads, slippage, currency conversion costs and taxes to deduct from backtest results.

In plain words: Actual orders do not fill exactly at the price shown on the screen, and every trade has costs, so the smaller the expected return, the more the difference matters. Lesson 305 makes costs one box of the specification and checks whether the same costs were deducted from every trade. Deducting the bid-ask gap again as if it were a commission, when it is already reflected in the fill price, counts the cost twice (Lesson 477).

Example: Assumptions: if the specification sets a one-way cost of 0.15%, a round trip of 0.15 × 2 = 0.30% is deducted from each trade. If an asset allocation report that assumed zero costs sells 10% of the account and buys 10% every year, at 0.30% one way, 20% × 0.30% = 0.06 percentage points come out every year.

Often confused with: The cost assumptions in the leveraged product lessons (Lesson 405, and calculator Lesson 625) mean financing costs and fees inside the product, a different thing from transaction costs in a backtest. The gap between the expected and the actual fill price itself is slippage.

Related lessons:

Win rate

Definition: The share of all trades that ended with a gain.

In plain words: The win rate alone does not tell the result of a rule. If you earn a little when you win and lose a lot when you lose, money can shrink even with a high win rate. So the win rate is read together with the average gain and average loss, that is, the payoff ratio.

Example: Assumptions: in 10 trades, you earned $10 seven times and lost $30 three times. The win rate is 70%, but the overall result is 70 − 90 = −$20.

Often confused with: Under rules with a low win rate, losing streaks are more common than expected, so Lesson 287 sets the stopping standard for losing streaks from the win rate of your own rule. The average result of one trade, combining the win rate with average gains and losses, is the expected value per trade.

Related lessons:

Payoff ratio

Definition: The average gain of winning trades divided by the size of the average loss of losing trades.

In plain words: The minus sign on a loss shows its direction, so the size of the loss is used when finding the ratio. With a low payoff ratio and a high win rate, or a high payoff ratio and a low win rate, the result can go either way, so the two are read together. Compare only records with the same period and the same treatment of costs.

Example: Assumptions: if the average gain is $10 and the size of the average loss is $30, the payoff ratio is 10 ÷ 30 = about 0.33. This record had a negative average result per trade even with a 70% win rate.

Often confused with: It is a different number from the target gain divided by the stop distance, set when starting a single trade. The average result calculated from the win rate and the payoff ratio is the expected value per trade.

Related lessons:

Expected value per trade (expectancy)

Definition: The average result of one trade, assuming the same conditions repeat, calculated from the win rate and the average gain and average loss.

In plain words: The formula in Lesson 478 is win rate × average gain − (1 − win rate) × average loss, and its value equals total profit and loss divided by the number of trades. The Advanced Course records results in R and finds the average R per trade with the same formula (Lesson 306). It is only a number that summarizes a past record; it does not mean the same conditions will repeat.

Example: Assumptions: with a win rate of 70%, an average gain of $10 and an average loss of $30, the result is 0.7 × 10 − 0.3 × 30 = −$2. In a record kept in R, with a win rate of 40%, winning trades averaging 2.375R and losses of 1R, it is 0.4 × 2.375 − 0.6 × 1.0 = 0.35R.

Often confused with: An expected value from scenarios with probabilities that have no basis only shows back the probabilities that were chosen, so in that case Lesson 169 uses each scenario's conditional value separately. The average of the results of a few chosen price paths is not an expected value either (Lesson 292).

Related lessons:

Sharpe ratio

Definition: The average excess return, calculated at one interval, divided by the standard deviation of that excess return; it shows the excess return per unit of swing.

In plain words: Each period's excess return is the strategy's return minus that period's risk-free return. When comparing different strategies, use the same period, returns at the same interval and the same risk-free rate. For strategies with rare large losses or lopsided return distributions, this one number cannot show the whole risk, so other measures are read together.

Example: Assumptions: if the arithmetic average of annual returns is 8%, the risk-free return is 2% every year and the standard deviation is 12%, the Sharpe ratio is (8% − 2%) ÷ 12% = 0.5. Here 8% is the arithmetic average, not the annual compound return (CAGR).

Often confused with: There are also measures, such as the Sortino ratio, that look only at the downside swings, but the lessons of this course do not cover them.

Related lessons:

Benchmark

Definition: A comparison set in advance, such as an index or an index ETF, against which investment performance or a stock's moves are compared.

In plain words: The same performance can look good or bad depending on what it is compared with, so set the comparison before looking at results. Lesson 172 puts an individual stock candidate in the same table as an index ETF bought with the same money, and Lesson 245 writes the reference index and end date for calculating relative strength at the top of the record. Active ETFs and rate-based ETFs state their benchmark index in the prospectus (Lesson 431).

Example: Assumptions: if a stock fell 3% over a year while its reference index fell 8% over the same period, it was stronger than the index but still lost money. The performance of a satellite investment also shows what the satellite added only when compared with putting the same money in the core index.

Often confused with: Lessons also write it as the reference index (Lesson 245), the benchmark index (Lesson 431) or the comparison (Lesson 241). Its use differs from the underlying index an ETF is set to follow. The method of comparing a stock with its benchmark is relative strength.

Related lessons:

Walk-forward test

Definition: A method of testing that repeats, in time order, the period for setting the rule and the period for applying it, moving both forward one step at a time.

In plain words: An out-of-sample period split only once may have been a period that happened to be good, so the check is repeated by moving the periods. At each step, the rule's values are chosen by a method set in advance using only the data up to that point, and applied only to the next period. Lesson 306 also writes this check in the test plan in advance and does not use it to change the rule after the final test.

Example: Assumptions: set the rule with data from 2015 to 2019 and apply it to 2020, then set it again with data from 2016 to 2020 and apply it to 2021, moving one year at a time. If the values chosen swing widely from year to year, that itself is a sign that the rule is unstable.

Often confused with: Using only the data up to each rebalancing date when re-estimating weights in asset allocation is the same idea (Lesson 445). A final test split only once is the out-of-sample test.

Related lessons: