Tangent
systemic:core-tanMathfunction1 crInputs
| Name | Type | Description |
|---|---|---|
| Data | floatarray | A list of angle values in **radians** for which to compute the tangent. |
Outputs
| Name | Type | Description |
|---|---|---|
| Tan | floatarray | The tangent value for each input angle—representing the slope at that angle. |
Description
Tangent (TAN)
The Tangent module computes the trigonometric tangent of each value in the input series. Unlike sine and cosine which are bounded, tangent produces unbounded values that represent the slope (rise over run) at any angle on the unit circle.
How It Works
flowchart TD
subgraph Input["Input Data"]
A["Angles in radians:<br/>θ₁, θ₂, θ₃, ... θₙ"]
end
subgraph Processing["NumPy Tangent Calculation"]
NP["np.tan(array)"]
NAN["Missing (null) → null"]
end
subgraph Output["Result"]
T["tan(θ₁), tan(θ₂), ... tan(θₙ)"]
R["Unbounded: can be any real number"]
end
A --> NP --> NAN --> T --> R
Understanding Tangent
The Slope Interpretation
Tangent measures the slope of a line at angle θ from the horizontal:
| Angle | tan(θ) | Meaning |
|---|---|---|
| 0° (0 rad) | 0 | Flat, horizontal line |
| 45° (π/4 rad) | 1 | 45° slope, rises 1 unit per 1 unit horizontal |
| 60° (π/3 rad) | 1.732 | Steeper slope |
| 89° | 57.29 | Near vertical, very steep |
| 90° (π/2 rad) | ±∞ | Vertical line — undefined |
Key Properties
| Property | Description | Formula |
|---|---|---|
| Unbounded | Output can be any real number | |
| Period | Repeats every π radians (180°) | |
| Odd Symmetry | Negating input negates output | |
| Asymptotes | Undefined at π/2 + kπ |
Reference Values
| Angle (radians) | Angle (degrees) | tan(θ) | Notes |
|---|---|---|---|
| 0 | 0° | 0 | Flat |
| π/6 | 30° | 0.577 | Gentle slope |
| π/4 | 45° | 1 | Equal rise/run |
| π/3 | 60° | 1.732 | Steep slope |
| π/2 | 90° | ±∞ | Vertical asymptote |
| 2π/3 | 120° | −1.732 | Downward steep |
| π | 180° | 0 | Flat again |
⚠️ Critical: Angle Units
This module expects angles in radians, not degrees.
Conversion formula:
| Degrees | Radians |
|---|---|
| 45° | π/4 ≈ 0.785 |
| 90° | π/2 ≈ 1.571 |
| 180° | π ≈ 3.142 |
| 360° | 2π ≈ 6.283 |
Handling Asymptotes
Near π/2 + kπ, tangent values explode toward ±∞. The module handles these cases:
| Situation | Behavior |
|---|---|
| Missing (null) or NaN in input | null at the same output position |
| Near asymptote | Returns very large finite values |
| Exactly at asymptote | Depends on floating-point precision |
Practical tip: If extreme spikes cause problems, clip or filter values near asymptotes.
Missing Data
When an input position is missing (null) — for example, a stock series has no bar on a weekend or holiday — the output at that same position is null. Values are never invented to fill a gap: every non-null output is the true tangent of a real datapoint, and the output keeps the same length as the input so every value stays aligned with its timestamp. A fabricated 0.0 would be indistinguishable from a genuine flat-slope reading and silently corrupt downstream signals.
In live mode, the module returns exactly one datapoint — the most recent position — and it may be null when no bar exists at that moment (e.g., a weekend tick on a market-hours series). That gap is correct, not an error.
Handling Invalid Inputs
An infinite input (±∞) is a real datapoint whose tangent simply does not exist — the function keeps oscillating between −∞ and +∞ and never settles as the angle grows without bound. This is distinct from missing data, where no datapoint exists at all. Both surface as null in the output, but they mean different things:
- Missing input → null: there was no bar to compute from
- ±Infinity input → null: there was a bar, but the math is undefined for it
Every finite angle produces a valid tangent — even values extremely close to an asymptote yield very large finite numbers, never null.
Financial Applications
1. Trend Slope Analysis
Convert regression line angles to slope values for trend strength measurement:
flowchart LR
subgraph PRICE["Price Data"]
P["Calculate trend<br/>regression angle"]
end
subgraph TAN["Tangent Module"]
T["angle → slope"]
end
subgraph ANALYSIS["Interpretation"]
S["Slope magnitude =<br/>trend strength"]
end
P --> T --> S
| Slope (tan) | Trend Interpretation |
|---|---|
| 0 | Flat, sideways market |
| 0 to 0.5 | Weak trend |
| 0.5 to 1 | Moderate trend (27°–45°) |
| 1 to 2 | Strong trend (45°–63°) |
| > 2 | Extreme/parabolic move |
2. Parabolic Move Detection
When tan(θ) grows very large, it signals near-vertical price action—useful for:
- Detecting parabolic blow-off tops
- Identifying flash crashes
- Flagging unsustainable price acceleration
3. Angular Feature Engineering
In machine learning systems, transform time or cyclical features into angular space, then apply tangent to create slope-based features.
Tangent vs Sine/Cosine
| Property | tan | sin / cos |
|---|---|---|
| Range | Unbounded (−∞ to +∞) | Bounded (−1 to +1) |
| Period | π | 2π |
| Asymptotes | Yes (at π/2 + kπ) | No |
| Best for | Slope/steepness | Cyclical encoding |
| Stability | Can explode | Always predictable |
Recommendation: For smooth cyclical encoding, prefer sine/cosine pairs. Use tangent specifically when you need slope interpretation or want to emphasize extreme angles.
Edge Cases
| Situation | Behavior |
|---|---|
| Empty input | Rejected — at least 1 value is required |
| Single value | Returns single tangent value |
| Angle at π/2 + kπ | Very large (or NaN depending on precision) |
| Negative angles | tan(−θ) = −tan(θ) |
| Large angles | Periodic — reduce modulo π if needed |
| Missing (null) or NaN input | null at the same position — gaps are never filled |
| ±Infinity input | null — tangent is mathematically undefined for an infinite angle |
Examples
Basic Calculation
Input (radians):
[0, π/6, π/4, π/3]
Output:
[0, 0.577, 1.0, 1.732]
With Negative Angles
Input:
[−π/4, 0, π/4]
Output:
[−1, 0, 1]
Further Reading
- Graph of Tangent - Khan Academy — Visual explanation
- Unit Circle Reference — Geometric foundation
- Radians vs Degrees — Conversion guide