Prime Number Oscillator — how far the price sits from the prime
nearest it:
pno = price − nearestPrime(price)
Positive when the price is above the prime nearest it, negative below,
and exactly 0 when the price is an integer prime. Appends one column,
default 'pno'.
The convention, pinned
The published description of this study is "the difference between the
price and the nearest prime number", which fixes the magnitude and leaves
two things open. Both are decided here rather than left to be discovered:
The sign is price − prime, following the phrase's own word order.
The mirror convention (prime − price) is exactly −pno; a caller who
wants it negates the column.
"Nearest" is nearest on either side, not the next prime above.
Where two primes are equidistant — 6 sits one from both 5 and 7 —
the tie goes to the lower, so pno(6) = +1. Arbitrary, and stated
and tested rather than emergent.
No TA-Lib function; the oracle is a pure-Python replication over a sieve
(the generator does not assume sympy is installed).
Edges
No warm-up; row 0 is defined. Length-preserving.
Bounded by half the local prime gap in either direction, so the
reading widens slowly as prices rise — it is roughly ±½·ln(p) at price
p, not a fixed band. A reading that looks bigger at higher prices is
the number line, not the market.
A price below 2 is outside the domain and reads undefined, as do
values past Number.MAX_SAFE_INTEGER — the kernel's rule, shared with
primeNumberBands so the two agree about where the study stops.
Neither scale- nor shift-invariant, and the property tests assert
the absence rather than skipping it. Multiplying every price by k does
not multiply the reading by anything, and adding a constant does not
leave it alone — the primes do not move with the data.
Runs over any column, including another study's output — but mind
the magnitude: a dollar-volume column at 1e12 costs ~8 ms per bar
(the kernel's cost table), so "any column" means any price-like one; the
composition rule is the same as everywhere else, and a source warm-up
simply carries through (NaN in, NaN out).
Cost grows with the price level, steeply: measured at 1M bars,
55 ms at ordinary equity prices and 6.5 s at ~1e7. See
primeNumberBands and the kernel's cost note.
Prime Number Oscillator — how far the price sits from the prime nearest it:
Positive when the price is above the prime nearest it, negative below, and exactly
0when the price is an integer prime. Appends one column, default'pno'.The convention, pinned
The published description of this study is "the difference between the price and the nearest prime number", which fixes the magnitude and leaves two things open. Both are decided here rather than left to be discovered:
price − prime, following the phrase's own word order. The mirror convention (prime − price) is exactly−pno; a caller who wants it negates the column.6sits one from both5and7— the tie goes to the lower, sopno(6) = +1. Arbitrary, and stated and tested rather than emergent.No TA-Lib function; the oracle is a pure-Python replication over a sieve (the generator does not assume
sympyis installed).Edges
±½·ln(p)at pricep, not a fixed band. A reading that looks bigger at higher prices is the number line, not the market.undefined, as do values pastNumber.MAX_SAFE_INTEGER— the kernel's rule, shared with primeNumberBands so the two agree about where the study stops.kdoes not multiply the reading by anything, and adding a constant does not leave it alone — the primes do not move with the data.NaNin,NaNout).