Two smaller tools
This page covers two small tools. One finds close substitutes for a stock, for use in tax-loss harvesting, and the other tests whether the monthly MACD crossover has worked on a given stock. Only the substitutes finder is public.
Correlated substitutes finder
The finder takes one stock and finds the three liquid US stocks whose returns have behaved most like that stock's. I built it as research support for tax-loss harvesting in direct-indexed accounts, where a name that has been sold needs a close stand-in.
- 1Candidates come from a built-in list of 151 large US stocks, or from a text file of tickers. Each needs a 90-day median daily volume of at least $25m and 250k shares. ETFs, ADRs, preferreds and closed-end funds are excluded.
- 2The finder works on daily log returns computed from adjusted closes. By default it uses two years of returns, which is 504 trading days, or fewer when a name has a shorter history.
- 3A composite score ranks the candidates, with the raw correlation shown beside it. I set its weights by judgement and didn't fit them to any outcome. The top three are kept, each with a one-line rationale assembled by rule.
- 4The output is the results in JSON, together with a copy of a fixed dashboard in which only the data block has been replaced. The layout is the same for every run.
Correlation labels run from Very High (0.90 and above) to Poor (below 0.40), and a collapse in rolling correlation is flagged. The tool makes no wash-sale determination.
The sliders only reproduce the score formula. A real run computes the inputs from two years of prices for about 150 candidates and keeps the top three.
Backtesting monthly MACD crossovers on one stock
The script asks whether the monthly MACD (12, 26, 9) crossover has been worth acting on for one stock. It scores every crossover in the last five years on the forward return over the next 3, 6 and 12 months.
- 1Four statistics. The number of signals, the 3-month hit rate, the expectancy (average 3-month return, sign flipped for bear signals) and the false-signal rate, where a reversal within two months counts as false.
- 2One result. Fixed thresholds, the same every run, turn those four into Reliable, Mixed or Inaccurate. Eight to fifteen signals is a small sample, so the result describes those five years on that stock and is not a recommendation.
- 3A fixed dashboard. Only the data block changes between runs. It shows the result, the statistics behind it and the stock's momentum against its 10-month moving average.
| Result | Rule, applied from the top |
|---|---|
| Reliable | N ≥ 8, 3-month hit rate ≥ 60%, expectancy ≥ 3% on bull or bear signals, false signals ≤ 25% |
| Mixed | fewer than 8 signals in the five-year window (low sample) |
| Inaccurate | N ≥ 8, 3-month hit rate < 40% and false signals ≥ 35% |
| Mixed | anything else, reported as Mixed or inconclusive with the reasons given |