MOM
Momentum — the raw price change over a fixed lookback,
price_t − price_{t−period}, in absolute price units.
Quick reference
| Field | Value |
|---|---|
| Family | Momentum Oscillators |
| Input type | f64 (single close) |
| Output type | f64 |
| Output range | unbounded around zero (price-difference scale) |
| Default parameters | period = 10 (Python) |
| Warmup period | period + 1 |
| Interpretation | Sign and size of the move over the last period bars. |
Formula
MOM_t = price_t − price_{t−period}The simplest momentum primitive. Positive output means price is higher than it was period bars ago, negative means lower, and the magnitude is the change in raw price units. Roc is the same idea expressed as a percentage of the old price.
Parameters
| Name | Type | Default | Valid range | Description |
|---|---|---|---|---|
period | usize | 10 (Python) | >= 1 | Lookback distance in bars. period = 0 errors with Error::PeriodZero. |
The Python binding defaults period to 10 via #[pyo3(signature = (period=10))].
Inputs / Outputs
From crates/wickra-core/src/indicators/mom.rs:
use wickra::{Indicator, Mom};
// Mom: Input = f64, Output = f64
const _: fn(&mut Mom, f64) -> Option<f64> = <Mom as Indicator>::update;A single f64 close in, an Option<f64> out. Python maps this to float | None / numpy.ndarray (NaN warmup); Node to number | null / Array<number> (NaN warmup).
Warmup
Mom::new(period).warmup_period() == period + 1. The output needs both the current price and the price period bars back, so the window must hold period + 1 values — the first non-None output lands on input period + 1.
Edge cases
- Constant series. A flat series yields
0.0from inputperiod + 1onward (constant_series_yields_zeropins this). - NaN / infinity inputs. Non-finite inputs are silently dropped: the rolling window is not advanced and the previous value is returned. The next finite input still references the correct historical price.
- Reset.
mom.reset()clears the window and restarts the warmup.
Examples
Rust
use wickra::{BatchExt, Indicator, Mom};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut mom = Mom::new(3)?;
let out: Vec<Option<f64>> = mom.batch(&[1.0, 2.0, 3.0, 4.0, 7.0]);
println!("{:?}", out);
Ok(())
}Output:
[None, None, None, Some(3.0), Some(5.0)]MOM(3) first emits on input 4: 4 − 1 = 3. The fifth input gives 7 − 2 = 5. This matches the reference_values test in crates/wickra-core/src/indicators/mom.rs.
Python
import numpy as np
import wickra as ta
mom = ta.MOM(3)
print(mom.batch(np.array([1.0, 2.0, 3.0, 4.0, 7.0])))Output:
[nan nan nan 3. 5.]Node
const ta = require('wickra');
const mom = new ta.MOM(3);
console.log(mom.batch([1, 2, 3, 4, 7]));Output:
[ NaN, NaN, NaN, 3, 5 ]Interpretation
Mom is a zero-centred oscillator. The textbook reads are the zero-line cross (momentum flipping sign) and divergence (price making a new high while Mom makes a lower high — a stalling trend). Because the output is in price units, Mom values are not comparable across instruments at different price levels; use Roc when you need a scale-free percentage instead.
Common pitfalls
- Comparing
Momacross instruments. AMomof5means very different things on a $10 stock and a $5000 index. Normalise withRocfor cross-asset work. - Forgetting the
+1warmup.warmup_period()isperiod + 1, notperiod.
References
Momentum is one of the oldest technical studies; the implementation here is the standard price − price[period] difference, matching TA-Lib's MOM.
See also
- Indicator-Roc — the percentage-scaled counterpart.
- Indicator-Cmo — bounded momentum from summed changes.
- Indicators-Overview — the full taxonomy.