Skip to content

derivative

Input Stack:
expr: TimeSeriesExpr
Output Stack:
TimeSeriesExpr

Compute the rate of change (derivative) of a time series, showing how much the value changes per step interval. This is the inverse operation of :integral and is useful for converting cumulative values back to rates or identifying trends in the data.

Parameters

  • expr: The time series expression to compute the derivative of

Behavior

Each output value represents the difference between consecutive datapoints:

  • derivative[i] = input[i] - input[i-1]
  • The first datapoint will typically be NaN since there's no previous value
  • Missing values (NaN) are handled as 0 for the calculation

Examples

Comparing integral and derivative operations:

DerivativeIntegralIntegral Then Derivative
1,:derivative
1,:integral
1,:integral,
:derivative

Relationship with Integral

:derivative and :integral have an asymmetric relationship:

  • Applying :integral then :derivative approximates the original signal
  • Applying :derivative then :integral does NOT restore the original signal

The derivative operation loses information that cannot be recovered with integral. For example, with a constant input like 1:

  • 1,:derivative produces 0 (derivative of constant is zero)
  • 0,:integral produces 0 (integral of zero stays zero)
  • The original constant value 1 is permanently lost
  • :integral - Cumulative sum (inverse operation)
  • :per-step - Convert rates to step-based counts
  • :sub - Manual difference calculation between time series
  • :rolling-sum - Rolling accumulation (related to cumulative operations)