Tangent
systemic:core-tanMathInputs
| Name | Type | Description |
|---|---|---|
| Data | Number series | The series of angles, in **radians**, to take the tangent of. |
Outputs
| Name | Type | Description |
|---|---|---|
| Tan | Number series | The tangent of each input angle, which is the slope at that angle. |
Cost
0.203 + 0.00568·n credits for n bars, rounded up. The marks are each plan's limit of bars.
Description
Tangent (TAN)
The Tangent module returns the tangent of each value in the input series. Sine and cosine stay between −1 and +1, but tangent is unbounded: it is the slope (rise over run) of an angle.
How It Works
flowchart TD
subgraph Input["Input Data"]
A["Angles in radians:<br/>θ₁, θ₂, θ₃, ... θₙ"]
end
subgraph Processing["Tangent Calculation"]
NP["tan of each value"]
NAN["Empty value → empty"]
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 | Rises 1 unit for each unit across |
| 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 reads 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 grow toward ±∞. The module handles these cases:
| Situation | Behavior |
|---|---|
| Empty input value | Empty at the same bar |
| Near or at an asymptote | Very large finite value, positive or negative |
Practical tip: If extreme spikes cause problems, clip or filter values near asymptotes.
Missing Data
When an input bar is empty (for example, a stock series has no bar on a weekend or holiday), the output at that bar is empty. Gaps are never filled: every output value is the tangent of a real input value. The output has the same length as the input, so every value stays on its own bar.
Handling Invalid Inputs
The tangent of an infinite angle (±∞) does not exist, so the output is empty. This differs from missing data, although both give an empty output:
- Empty input → empty: there was no value to compute from
- ±Infinity input → empty: there was a value, but its tangent is undefined
Every finite angle gives a tangent. Angles very close to an asymptote give very large finite numbers, never an empty value.
Financial Applications
1. Trend Slope Analysis
Convert the angle of a regression line into a slope to measure trend strength:
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
A very large tan(θ) signals near-vertical price action. This helps with:
- Detecting parabolic blow-off tops
- Identifying flash crashes
- Flagging unsustainable price acceleration
3. Angular Feature Engineering
For machine learning models, turn time or cyclical features into angles, 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 spike | Always bounded |
Recommendation: For smooth cyclical encoding, prefer sine/cosine pairs. Use tangent when you need a slope or want to emphasize extreme angles.
Edge Cases
| Situation | Behavior |
|---|---|
| Series with no values | Rejected: at least 1 value is required |
| Single value | Returns a single tangent value |
| Angle at π/2 + kπ | Very large finite value |
| Negative angles | tan(−θ) = −tan(θ) |
| Large angles | Periodic: the result repeats every π |
| Empty input value | Empty at the same bar (gaps are never filled) |
| ±Infinity input | Empty (the tangent of an infinite angle is undefined) |
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