Skip to content

Add IdlePeriod() to PringsSpecialK - #422

Merged
cinar merged 1 commit into
masterfrom
fix/prings-special-k-idleperiod
Aug 21, 2026
Merged

Add IdlePeriod() to PringsSpecialK#422
cinar merged 1 commit into
masterfrom
fix/prings-special-k-idleperiod

Conversation

@cinar

@cinar cinar commented Aug 21, 2026

Copy link
Copy Markdown
Owner

Closes #418.

What was missing

Every other indicator in this library implements IdlePeriod() int (the subject of the consistency sweep in #413) so a caller knows how many leading values to skip before the output channel starts yielding real data. PringsSpecialK didn't, even though ComputeWithContext already computes exactly this value internally:

maxIdle := p.Sma195Roc530.IdlePeriod() + p.Roc530.IdlePeriod()

used to align every other SMA(ROC(...)) branch to the slowest one. Without an exposed IdlePeriod(), a generic caller (e.g. the indicator registry in #416) has no way to know how many leading dates correspond to its warm-up — which, with the default periods, is 724.

Its own test already worked around this by reconstructing an equivalent value from unrelated standalone Sma/Roc instances rather than calling a method on the type itself — a sign the type should expose it.

Fix

// IdlePeriod is the initial period that Pring's Special K won't yield any results.
func (p *PringsSpecialK[T]) IdlePeriod() int {
	return p.Sma195Roc530.IdlePeriod() + p.Roc530.IdlePeriod()
}

TestPringsSpecialKComputeBasicOutput now calls IdlePeriod() on the actual instance instead of hand-reconstructing the number from a throwaway Sma(530)/Roc(195) pair (which happened to total the same value only because (530-1)+195 == 194+530) — it already passed before this change and still does, confirming the new method's value matches what that test independently expected all along. Added TestPringsSpecialKIdlePeriod as a direct check.

Test plan

  • go test -race -cover ./momentum/... — 92.4% coverage
  • go vet, staticcheck, gosec clean on momentum/ (an unrelated pre-existing revive finding in rvi.go, a file this PR doesn't touch, is untouched)
  • go build ./... and the full INDICATOR_BASE test suite (asset, backtest, cmd, helper, momentum, strategy, trend, volatility, volume) pass

🤖 Generated with Claude Code

Every other indicator in this library exposes IdlePeriod() so callers
know how many leading values to skip before the output channel starts
yielding real data. PringsSpecialK never did, even though
ComputeWithContext already computes exactly this value internally as
maxIdle to align its SMA(ROC(...)) branches -- it just never exposed
it. Callers had no way to know how many leading dates correspond to
its (500+ period) warm-up.

Expose that same computation as IdlePeriod(), and update
TestPringsSpecialKComputeBasicOutput to call it instead of
hand-reconstructing an equivalent value from unrelated Sma/Roc
instances, and add a direct IdlePeriod test.

Fixes #418

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.29%. Comparing base (46c719e) to head (f252dbe).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #422      +/-   ##
==========================================
- Coverage   92.31%   92.29%   -0.03%     
==========================================
  Files         229      229              
  Lines        7276     7278       +2     
==========================================
  Hits         6717     6717              
- Misses        472      474       +2     
  Partials       87       87              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@cinar
cinar marked this pull request as ready for review August 21, 2026 05:24
@cinar
cinar merged commit 45e16d4 into master Aug 21, 2026
5 checks passed
@cinar
cinar deleted the fix/prings-special-k-idleperiod branch August 21, 2026 05:25
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 21, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

momentum.PringsSpecialK is missing an IdlePeriod() method

2 participants