feat(fees): add computeMovingAverage for fee trend smoothing - #833
Open
woahwhattheheck wants to merge 2 commits into
Open
feat(fees): add computeMovingAverage for fee trend smoothing#833woahwhattheheck wants to merge 2 commits into
woahwhattheheck wants to merge 2 commits into
Conversation
trend.ts exposed raw samples and percentiles but no smoothed series. Adds a pure SMA returning the same length as the input, NaN-padded for the first windowSize - 1 entries so callers can plot it against the samples without re-aligning indices.
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #781.
fees/trend.tsexposed raw samples and percentile estimates but no smoothedseries, so callers had to implement their own smoothing to get a usable
forecasting signal.
Changes
src/fees/trend.ts— adds the exported pure function:it can be plotted directly against the samples without re-aligning indices.
windowSize - 1entries areNaN. A partial average there wouldunderstate early movement and read as real signal.
windowSizemust be an integer>= 1; otherwiseRangeError, naming thevalue received.
Two implementation notes
< 1. A fractionalwindow is undefined for index arithmetic, and
NaNwould otherwise sailthrough every comparison and silently produce an all-
NaNseries. Thismatches the existing
toWindowCapacityin the same file, which alreadyrequires
Number.isInteger.subtract-the-outgoing-value accumulator is the usual O(n) trick, but it
drifts over a long float series. Windows here are small and bounded, so the
exact form costs nothing worth having.
A
NaNsample propagates only through the windows containing it, and theseries recovers afterwards — covered by a test.
Validation
npx vitest run test/feeTrend.movingAverage.test.ts— 16/16 passing.Covers padding width, window of 1, length preservation, window larger than
the series, empty input, input immutability, realistic stroop values,
NaNpropagation, and every rejected
windowSize(0, negatives,2.5,NaN,Infinity).npx tsc --noEmitreports 210 errors on this branch and 210 on unmodifiedmain— identical, with none insrc/fees/trend.ts. That baseline ispre-existing and unrelated to this change.