Systemicalpha

Tangent

systemic:core-tanMathfunction1 cr

Inputs

NameTypeDescription
DatafloatarrayA list of angle values in **radians** for which to compute the tangent.

Outputs

NameTypeDescription
TanfloatarrayThe 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.

tan⁡(θ)=sin⁡(θ)cos⁡(θ):R→R\tan(\theta) = \frac{\sin(\theta)}{\cos(\theta)} : \mathbb{R} \rightarrow \mathbb{R}

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:

Angletan(θ)Meaning
0° (0 rad)0Flat, horizontal line
45° (π/4 rad)145° slope, rises 1 unit per 1 unit horizontal
60° (π/3 rad)1.732Steeper slope
89°57.29Near vertical, very steep
90° (π/2 rad)±∞Vertical line — undefined

Key Properties

PropertyDescriptionFormula
UnboundedOutput can be any real number−∞<tan⁡(θ)<+∞-\infty < \tan(\theta) < +\infty
PeriodRepeats every π radians (180°)tan⁡(θ+π)=tan⁡(θ)\tan(\theta + \pi) = \tan(\theta)
Odd SymmetryNegating input negates outputtan⁡(−θ)=−tan⁡(θ)\tan(-\theta) = -\tan(\theta)
AsymptotesUndefined at π/2 + kπtan⁡(π2)=undefined\tan(\frac{\pi}{2}) = \text{undefined}

Reference Values

Angle (radians)Angle (degrees)tan(θ)Notes
00°0Flat
π/630°0.577Gentle slope
π/445°1Equal rise/run
π/360°1.732Steep slope
π/290°±∞Vertical asymptote
2π/3120°−1.732Downward steep
π180°0Flat again

⚠️ Critical: Angle Units

This module expects angles in radians, not degrees.

Conversion formula:

radians=degrees×π180\text{radians} = \text{degrees} \times \frac{\pi}{180}
DegreesRadians
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:

SituationBehavior
Missing (null) or NaN in inputnull at the same output position
Near asymptoteReturns very large finite values
Exactly at asymptoteDepends 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
0Flat, sideways market
0 to 0.5Weak trend
0.5 to 1Moderate trend (27°–45°)
1 to 2Strong trend (45°–63°)
> 2Extreme/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

Propertytansin / cos
RangeUnbounded (−∞ to +∞)Bounded (−1 to +1)
Periodπ2π
AsymptotesYes (at π/2 + kπ)No
Best forSlope/steepnessCyclical encoding
StabilityCan explodeAlways 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

SituationBehavior
Empty inputRejected — at least 1 value is required
Single valueReturns single tangent value
Angle at π/2 + kπVery large (or NaN depending on precision)
Negative anglestan(−θ) = −tan(θ)
Large anglesPeriodic — reduce modulo π if needed
Missing (null) or NaN inputnull at the same position — gaps are never filled
±Infinity inputnull — 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

Rendering diagrams...
© 2026 WanoLabs. All rights reservedAlpha build v0.1.5