Lesson 477 showed that spreads and slippage cut into real results, and Lesson 025 showed that the fill price can differ from the order price. Lesson 447 and Lesson 613 computed the cost of rebalancing for a whole account. This lesson turns those costs into a calculation model inside a backtest.
The model is one line. The cost taken out in each period is the one-way cost multiplied by that period's turnover. With this formula we compute, on synthetic data, the before-cost and after-cost results and the breakeven cost of three hypothetical teaching rules with different turnover. Every cost number is an assumption, not a real broker's commission schedule or quote data.
1. One-way cost: the cost of buying or selling the whole account once
The one-way cost is the cost of buying the whole account once or selling it once, written as a share of the account value. It has three parts: the commission, half of the spread (the gap between the bid and the ask), and the market impact, which arises when your own order pushes the price.
Market impact grows with the size of the order. A common approximation is that impact is proportional to the square root of the participation rate. Tóth and others explain this square-root approximation and its empirical support in a 2011 paper. Its title is "Anomalous price impact and the critical nature of liquidity in financial markets." The participation rate is your order size divided by the volume traded in that period. When the participation rate is four times larger, impact is twice as large, and the proportionality factor has to be estimated separately for each stock and period.
Assumptions: commission 0.02%, half-spread 0.03%, and impact of 1.00% at a participation rate of 100%. An order at a participation rate of 1% has impact of 1.00 × √0.01 = 0.10%, and the one-way cost is 0.02 + 0.03 + 0.10 = 0.15%. In the same stock, an order at a participation rate of 4% has impact of 0.20% and a one-way cost of 0.25%. This means the same rule has different costs as the account grows (fill assumptions are in Lesson 586).
2. Turnover and the order in which costs are taken out
Turnover is the sum of the absolute sizes of the weight changes in each period. A holding weight that changes from 0 to 1 is turnover 1, and one that falls from 1 to 0.5 is 0.5. The sum over one year is called annual turnover. The period cost is the one-way cost × that period's turnover, so the cost taken out each year is roughly annual turnover × one-way cost.
Counting costs by the number of trades is wrong. Assumptions: a rule that cut its weight from 1 to 0.5 and then raised it back to 1 traded twice, but its turnover is 0.5 + 0.5 = 1. Taking a whole-account one-way cost for every trade counts the cost twice, and leaving out trades that change only part of the weight counts the cost as 0.
Costs are taken out in the period in which the fill happens. If you decide on the close of period t and fill in period t + 1 (shifting by one period, Lesson 583), the cost is also taken out of the return of period t + 1. If the fill price already includes the spread, do not take the spread out of the costs again. Assumptions: if the fill price was recorded as worse than the mid price by the half-spread of 0.03%, the only cost left to take out is the commission of 0.02%. Taking out 0.05% again would subtract the 0.03% twice.
3. Synthetic data and three rules
Unlike the other lessons, the synthetic data in this lesson was built so that trend rules come out positive before costs. It is synthetic data made with a fixed seed, in which each period's return continues slightly in the same direction as the previous period's. The formula is period return = 0.02% + 0.10 × (previous period return − 0.02%) + a random shock. The shock is drawn from a normal distribution with a mean of 0 and sized so that the standard deviation of period returns is 1% (autocorrelation coefficient 0.10, period mean 0.02%). This setting is for showing the effect of costs and does not mean that real market returns behave this way. There are 2,520 periods (about ten years if daily).
The rule is a hypothetical teaching rule, "if the close is above the n-period moving average, hold for the next period; otherwise cash," with n set to 5, 20 and 100. The cash return is assumed to be 0. The three are only numbers chosen to compare turnover.
The result of one path swings with luck, so the same calculation was run on 20 paths, seeds 20261105 to 20261124, fixed before writing. The turnover and breakeven cost in the table are the medians and ranges of the values computed for each path, and the last column is the value for the first path (seed 20261105), drawn in figure 2.
| Rule (synthetic data, 20 paths) | Median annual turnover | Median breakeven one-way cost | Range of breakeven one-way cost | Breakeven cost, first path |
|---|---|---|---|---|
| 5 periods | 61.6 | 0.16% | 0.04 to 0.29% | 0.29% |
| 20 periods | 27.5 | 0.25% | −0.04 to 0.67% | 0.41% |
| 100 periods | 12.2 | 0.30% | −0.17 to 1.16% | 0.76% |
An annual turnover of 61.6 means that the weight changes over one year add up to buying or selling the whole account 61.6 times. The shorter the moving average, the more often the close crosses it, so turnover is higher. Turnover changed little from path to path (5 periods: 58.3-66.4).
The breakeven cost is the one-way cost that brings the average excess return to 0. It is the average period return (the difference from the cash return of 0) divided by the average period turnover. The 5-period rule has much higher turnover, so its median breakeven cost is the lowest.

On the first path, the breakeven cost of all three rules was above the median, and the 5-period value of 0.29% is the highest of the 20 and about 1.8 times the median of 0.16%. Setting the breakeven cost from this one path would have badly misjudged the cost margin. This is why the seeds are fixed in advance and the range and median are reported together.
4. Cost sensitivity table
We assumed four one-way costs and computed the after-cost annual compound return on the 20 paths. The numbers in the table are medians of the annual compound return computed for each path.
| One-way cost (hypothetical) | 5 periods, median | 20 periods, median | 100 periods, median |
|---|---|---|---|
| 0% | 9.8% | 6.3% | 3.0% |
| 0.05% | 6.5% | 4.9% | 2.3% |
| 0.10% | 3.2% | 3.5% | 1.7% |
| 0.20% | −3.0% | 0.8% | 0.6% |
With no cost, the 5-period rule has the highest median, but at a one-way cost of 0.20% it is the lowest of the three. Path by path, too, the 5-period rule was the highest of the three at a cost of 0% on 18 of the 20 paths, and the lowest at a one-way cost of 0.20% on 17. Estimating the yearly cost as annual turnover × one-way cost, at 0.20% one-way the 5-period rule loses 61.6 × 0.20 = about 12.3% and the 100-period rule 12.2 × 0.20 = about 2.4%. This estimate is the amount taken out of the arithmetic mean return, so it is not exactly the gap in annual compound return.

Figure 2 draws the 5-period rule's account on the first path for each cost assumption. On this path the 5-period rule's breakeven cost was the highest of the 20, so the lines end higher than the medians in the table. The after-cost annual compound return on the first path was 18.5% at 0% one-way and 4.9% at 0.20%, far from the medians of 9.8% and −3.0% at the same costs.
Do not read the order in this table as a ranking of the rules. The before-cost returns came from synthetic data built to have an edge, and choosing the three rules was itself one trial. What this table shows is that the higher a rule's turnover, the more its result swings with a single cost assumption.
5. The breakeven cost swings too
Looking again at the ranges in the table in section 3, the breakeven cost swings a lot from path to path even on data with the same settings. For 20 periods it ranged from −0.04% to 0.67%, and for 100 periods from −0.17% to 1.16%. The lower a rule's turnover, the more a small difference in before-cost return moves its breakeven cost.
A path with a negative breakeven cost is one that was already worse than cash before costs. There was 1 such path for 20 periods and there were 3 for 100 periods. Because the breakeven cost swings this much even on data with the same settings, if the gap between a breakeven cost computed from one backtest and the expected cost is small, treat nothing about costs as confirmed.
In the plan, write costs as a table, not as one number. Include the three parts of the one-way cost and the basis for each assumption, the definition of turnover, and the period in which costs are taken out. Also include the result with the one-way cost doubled (the doubled-cost check of Lesson 305, computed through turnover).
The record for this lesson is four lines in the cost box. They are the makeup and assumptions of the one-way cost, the annual turnover, the breakeven cost and its range, and the result with costs doubled.
Try it yourself
- Read the median breakeven one-way costs of the three rules from the table in section 3, and use turnover to explain why the 5-period rule's value is the lowest. Also write what you would have misread if you had looked only at the first path's values.
- From the table in section 4, read how many percentage points the median after-cost annual compound return of the 20-period rule changes when its one-way cost doubles from 0.10% to 0.20%. Compare it with the cost increase estimated from the median annual turnover.
- Assumptions: commission 0.02%, half-spread 0.03%, and impact of 1.00% at a participation rate of 100%. What is the one-way cost of an order at a participation rate of 9%?
- Assumptions: a rule's weight changed 0 → 1 → 0.6 → 0.6 → 0. Find the total turnover and the number of trades, and find the cost taken out at 0.10% one-way, as a % of the account.
Answers
First, the medians are 5 periods 0.16%, 20 periods 0.25%, 100 periods 0.30%. The 5-period rule has a median annual turnover of 61.6, about five times that of the 100-period rule (12.2), so it splits its before-cost return across far more trades. Looking only at the first path's values (0.29%, 0.41%, 0.76%), you would have read a more generous cost margin than the middle of the actual range for all three rules, and the 5-period 0.29% was the highest of the 20.
Second, it falls from 3.5% to 0.8%, by 2.7 percentage points. Multiplying the median annual turnover of 27.5 by the added one-way cost of 0.10% gives about 2.8 percentage points, so the change is close to this estimate.
Third, the impact is 1.00 × √0.09 = 0.30%, and the one-way cost is 0.02 + 0.03 + 0.30 = 0.35%. When the participation rate rose nine times, from 1% to 9%, the impact rose three times.
Fourth, the turnover is 1 + 0.4 + 0 + 0.6 = 2.0, and there are three trades. The cost taken out is 2.0 × 0.10 = 0.20%. Taking a whole-account one-way cost for each of the three trades would have given a wrong 0.30%.
Data: synthetic data made by Havilah Research with a fixed seed. Seed 20261105, 2,520 periods, period return = 0.02% + 0.10 × (previous period return − 0.02%) + a normal shock. The standard deviation of period returns is 1%, a setting built so that trend rules come out positive before costs. The medians and ranges in the tables were computed from 20 paths with seeds fixed in advance, 20 seeds 20261105-20261124, and figure 2 and the last column of the table use the first path (seed 20261105). The one-way costs and the market-impact factor are assumptions.
