Transform Custom Formula
Last updated
The Transform Function in K3 Labs allows users to manipulate and enrich data within workflows. The Custom Formula feature enables users to apply complex mathematical expressions and logical operations on input data, making it a powerful tool for data transformation.
The Custom Formula function supports a variety of mathematical operations on floating-point numbers:
+ (addition)
- (subtraction)
* (multiplication)
/ (division)
% (remainder/modulus)
^ (power/exponentiation)
+ (positive sign)
- (negation)
The Custom Formula function provides built-in mathematical functions, similar to those found in the Rust standard library:
Basic Functions:
sqrt(x): Square root
abs(x): Absolute value
exp(x): Exponential function (e^x)
ln(x): Natural logarithm
Trigonometric Functions:
sin(x), cos(x), tan(x): Sine, cosine, and tangent
asin(x), acos(x), atan(x), atan2(y, x): Inverse trigonometric functions
sinh(x), cosh(x), tanh(x): Hyperbolic sine, cosine, and tangent
asinh(x), acosh(x), atanh(x): Inverse hyperbolic functions
Rounding Functions:
floor(x): Rounds down to the nearest integer
ceil(x): Rounds up to the nearest integer
round(x): Rounds to the nearest integer
roundto(x, d): Rounds x to d decimal places. Example: roundto(10.55235, 2) returns 10.55
Sign Function:
signum(x): Returns -1, 0, or 1 depending on the sign of x
Time Function:
Now: Returns the current timestamp in UTC as seconds since the Unix epoch. No parentheses are required (e.g., Now).
max(x, ...): Returns the maximum value from one or more numbers
min(x, ...): Returns the minimum value from one or more numbers
pi: Mathematical constant π (3.14159...)
e: Euler's number (2.718...)
The Custom Formula function can be used within a Transform Function node in the K3 Labs workflow builder. Users can define custom variables and apply formulas directly to input data.
Expression:
Usage:
If x = 5 and y = 3, the result will be 16.
Expression:
Usage:
If a = 3 and b = 4, the result will be 5 (Pythagorean theorem).
Expression:
Usage:
If x = 10, the result will be ln(10) ≈ 2.302.
If x = -5, the result will be 0 (avoiding logarithm of a negative number).
Expression:
Usage:
If a = 10, b = 15, and c = 7, the result will be 15.
The Custom Formula function can be used in:
Data Filtering: Modify or filter data before passing it to the next step.
Alert Triggers: Calculate thresholds and trigger alerts based on computed values.
Trading Strategies: Apply mathematical operations on financial data for automated trading.
API Data Processing: Transform API responses before sending them to another service.
Last updated
(x + y) * 2sqrt(a^2 + b^2)if(x > 0, ln(x), 0)max(a, b, c)