Logarithm
The Log node computes the logarithm of each value in the specified base (default: Math.E for natural log). Input values must be strictly positive; non-positive or null inputs yield null. Log transforms compress skewed price distributions, convert multiplicative returns to additive log-returns, linearize exponential growth curves, and are essential for any entropy or information-theoretic computation.
Algorithm
- ▸output[i] = Math.log(input[i]) / Math.log(b)
- ▸b defaults to Math.E (natural logarithm)
- ▸input ≤ 0 or b ≤ 0 or b === 1 → null (guards for undefined log)
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| b | number | Math.E (≈ 2.718) | Logarithm base. Use 10 for common log, 2 for binary, or e for natural log-returns. |
Inputs & Outputs
| Port | Type | Description |
|---|---|---|
| Inputs | ||
| input | number[] | Source numeric array |
| Outputs | ||
| values | number | null | Computed value at each bar; null before the warmup period completes |
| timestamps | number[] | Bar timestamps (UNIX ms), aligned 1-to-1 with values |
Use Cases
Log Returns
Apply natural log to closing prices, then subtract the previous bar with the Subtract node, to produce continuous log-returns: ln(close[i]) - ln(close[i-1]).
Log Scale Oscillators
Log-transform a volume series before feeding it into Average and Stddev to prevent large volume spikes from dominating the mean.
Exponential Growth Linearization
Take the log of an exponentially growing equity curve to linearize it, making trend-following nodes like Slope and R-Squared meaningful.