compute_spread

Summary: Computes the spread between two input arrays using a logarithmic transformation. The function calculates: log(array_ai) - k * log(array_bi) for each element.

double[]
compute_spread
(
double[] array_a
,
double[] array_b
,
double k
)

Parameters

array_a double[]

First input array containing numerical values.

array_b double[]

Second input array containing numerical values.

k double

Scaling factor applied to the logarithm of array_b.

Return Value

Type: double[]

result: Returns an array containing the computed spread values.

Notes: - Both input arrays must be of equal length. - The logarithm function is undefined for zero or negative numbers. This function should only be used if all elements in array_a and array_b are positive. If negative values or zeros are possible, consider modifying the function to use: log(abs(x) + epsilon) * sign(x) where epsilon is a small positive constant (e.g., 1e-9). - Be mindful of floating-point precision issues when working with very small numbers. - If working with financial or market data, consider whether a percentage spread or a relative difference might be a more stable measure than logs.