PyInvesting
← Back to research notes

Methods and evidence

A worked example of a market breadth allocation rule

A market-breadth allocation rule turns an observation about many stocks into a target for a portfolio. To evaluate one, you must define the universe, threshold, observation time, execution time and costs. Here is a deliberately simple hypothetical example with arithmetic you can check. It is not PyInvesting's live allocation strategy and has no claimed investment performance.

Define the rule before looking at outcomes

Assume a fixed universe of ten fictional stocks, each with enough price history to calculate the same moving average. After the final market close of each month, count how many closes are strictly above their average. Let breadth = 100 × qualifying stocks / eligible stocks.

For this example only: if breadth is at least 60%, set a 100% target in a broad-market ETF; otherwise target 100% cash. Do not use the same closing price to execute a decision that is only known after that close. Assume execution at the next available trading session, with actual execution prices and costs to be supplied in a real test.

Hypothetical month-end signals; no market returns are assumed
ObservationAbove averageBreadthNext-session target
Month A7 of 1070%100% ETF
Month B6 of 1060%100% ETF
Month C4 of 1040%100% cash
Month D6 of 1060%100% ETF

The “at least” comparison matters at 60%. Month B keeps the same target as Month A, so a target change alone does not require another complete purchase. Month C sells the ETF; Month D buys it again. A real implementation must also specify fractional shares, rounding, residual cash, distributions and any rebalance tolerance.

Add an explicit cost assumption

Suppose the portfolio value at each illustrative transition is $10,000 and the cost is 0.10% of the amount traded per leg. Selling $10,000 costs $10; buying $10,000 later costs another $10. This simplified $20 example holds trade notionals fixed to isolate the arithmetic. Actual notionals and portfolio values would change with prices, costs and cash flows.

Cash interest, taxes, fund expenses, spreads and slippage are separate assumptions. They are not automatically captured by naming a transaction-cost rate. A frequent threshold crossing can produce turnover and losses even if the final market direction looks favorable.

Decide how missing observations affect the denominator

If one stock lacks enough history, dividing by nine instead of ten changes the meaning of the signal. Excluding it, holding the previous valid signal, or refusing to evaluate are different policies. Choose and record one before testing. Also define how a stock enters or leaves the universe; a list selected from today's survivors can distort historical conclusions.

Compare the rule with an appropriate baseline

Use the same ETF, available dates, currency, price adjustment and cost conventions for the allocation rule and a buy-and-hold comparison. Record time in cash, number of switches, turnover, maximum drawdown and returns. Assess a separate evaluation period without choosing the threshold to maximize that period's result.

The 60% threshold here is an illustration, not an optimized choice. Before interpreting historical results, check whether plausible nearby thresholds materially alter the conclusion and record every variation you tried.

Download the worksheet and inspect the live measure

The four-row calculation worksheet contains the inputs and targets shown above. For actual descriptive observations, use our weekly breadth study and downloadable data. The live Fear & Greed page explains its own measure and allocation history; do not substitute this fictional ten-stock rule for that methodology.

To learn the visual workflow for a separate relative-strength example, read how to backtest without coding. A backtest can test the consequences of assumptions; it cannot establish that a rule will work in the future.