Systemicalpha

Sine

systemic:core-sinMathfunction1 cr

Inputs

NameTypeDescription
DatafloatarrayA list of numerical values representing **angles in radians** to compute the sine of.

Outputs

NameTypeDescription
Sinfloatarray- **Description**; The sine value is the result of applying the sine function to the phase angle. It represents the cyclical position in the market based on the phase angle derived from the price and time series data.

The Sine module computes the trigonometric sine of each value in the input series. This fundamental mathematical function maps angles (in radians) to their vertical projection on the unit circle, producing smoothly oscillating values bounded between −1 and +1.

sin⁡(θ):R→[−1,1]\sin(\theta) : \mathbb{R} \rightarrow [-1, 1]

How It Works

flowchart TD
    subgraph Input["Input Data"]
        A["Angles in radians:<br/>θ₁, θ₂, θ₃, ... θₙ"]
    end
    
    subgraph Processing["NumPy Sine Calculation"]
        NP["np.sin(array)"]
        NAN["Missing or ±∞ → null"]
    end
    
    subgraph Output["Result"]
        S["sin(θ₁), sin(θ₂), ... sin(θₙ)"]
        B["All values bounded: [-1, +1]"]
    end
    
    A --> NP --> NAN --> S --> B

The Unit Circle and Sine

The sine function traces the y-coordinate of a point rotating around the unit circle:

flowchart LR
    subgraph Cycle["One Complete Rotation (0 to 2π)"]
        P0["θ = 0<br/>sin = 0"]
        P1["θ = π/2<br/>sin = +1"]
        P2["θ = π<br/>sin = 0"]
        P3["θ = 3π/2<br/>sin = -1"]
        P4["θ = 2π<br/>sin = 0"]
    end
    
    P0 -->|"Rising"| P1 -->|"Falling"| P2 -->|"Falling"| P3 -->|"Rising"| P4
Angle (radians)Angle (degrees)sin(θ)Position on Cycle
00°0Start (right)
π/630°0.5Rising
π/445°0.707Rising
π/290°+1Peak (top)
π180°0Zero crossing (left)
3π/2270°−1Trough (bottom)
2π360°0Complete cycle

Key Mathematical Properties

PropertyDescriptionFormula
Bounded RangeOutput always between −1 and +1−1≤sin⁡(θ)≤1-1 \leq \sin(\theta) \leq 1
PeriodicityRepeats every 2π radianssin⁡(θ+2π)=sin⁡(θ)\sin(\theta + 2\pi) = \sin(\theta)
Odd SymmetryNegating input negates outputsin⁡(−θ)=−sin⁡(θ)\sin(-\theta) = -\sin(\theta)
Phase RelationshipCosine is shifted sinecos⁡(θ)=sin⁡(θ+π2)\cos(\theta) = \sin(\theta + \frac{\pi}{2})

Angle Units: Radians Required

⚠️ Critical: This module expects angles in radians, not degrees.

Conversion formula:

radians=degrees×π180\text{radians} = \text{degrees} \times \frac{\pi}{180}
Common DegreesRadianssin(θ)
0°00
30°π/6 ≈ 0.5240.5
45°π/4 ≈ 0.7850.707
60°π/3 ≈ 1.0470.866
90°π/2 ≈ 1.5711.0
180°π ≈ 3.1420

Financial Applications

1. Cyclical Time Encoding

Markets exhibit cyclical patterns: daily trading sessions, weekly patterns, monthly options expiry, and seasonal trends. The sine function encodes these cycles as smooth, continuous features without discontinuities.

flowchart TD
    subgraph TimeData["Raw Time Data"]
        H["Hour of day: 0-23"]
        D["Day of week: 1-7"]
        M["Month: 1-12"]
    end
    
    subgraph Convert["Convert to Angles"]
        HA["θ = hour × 2π / 24"]
        DA["θ = day × 2π / 7"]
        MA["θ = month × 2π / 12"]
    end
    
    subgraph Encode["Cyclical Encoding"]
        SIN["SIN module"]
        COS["COS module"]
    end
    
    subgraph Features["Smooth Features"]
        F1["Hour: sin, cos"]
        F2["Day: sin, cos"]
        F3["Month: sin, cos"]
    end
    
    H --> HA --> SIN & COS --> F1
    D --> DA --> SIN & COS --> F2
    M --> MA --> SIN & COS --> F3

Why this matters: If you use raw hour values (0-23), the model sees 23:00 and 00:00 as maximally different, when they're actually adjacent. Sine/cosine encoding preserves the cyclical relationship.

2. Intraday Session Timing

Encode the position within a trading session:

Timeθ (if 9:30-16:00)sin(θ)Interpretation
9:30 (Open)00Session start
11:00π/40.71Morning session
12:45 (Midday)π/21.0Peak of session
14:303π/40.71Afternoon session
16:00 (Close)π0Session end

3. Seasonality Features

CycleAngle FormulaApplication
Hour of Dayθ = hour × 2π / 24Intraday patterns
Day of Weekθ = day × 2π / 7Weekly seasonality
Day of Monthθ = day × 2π / 30Monthly patterns
Month of Yearθ = month × 2π / 12Seasonal effects
Quarterθ = quarter × 2π / 4Quarterly cycles

Sine + Cosine: Complete Circular Encoding

Using sine alone loses directional information (sin(π/4) = sin(3π/4)). Pair with cosine for unambiguous circular encoding:

flowchart LR
    subgraph Quadrants["Circle Quadrants"]
        Q1["Q1: sin > 0, cos > 0<br/>θ ∈ (0, π/2)"]
        Q2["Q2: sin > 0, cos < 0<br/>θ ∈ (π/2, π)"]
        Q3["Q3: sin < 0, cos < 0<br/>θ ∈ (π, 3π/2)"]
        Q4["Q4: sin < 0, cos > 0<br/>θ ∈ (3π/2, 2π)"]
    end
    
    Q1 --> Q2 --> Q3 --> Q4 --> Q1
Angle Rangesin(θ)cos(θ)Quadrant
0 to π/2++1st
π/2 to π+−2nd
π to 3π/2−−3rd
3π/2 to 2π−+4th

Building a Systemic System: Time-Based Strategy

Create a time-aware trading system that adjusts behavior based on session timing:

flowchart TD
    subgraph Input["Market Data"]
        P["Price Data"]
        T["Timestamp"]
    end
    
    subgraph TimeEncode["Time Encoding"]
        HOUR["Extract hour"]
        ANGLE["θ = hour × 2π / 24"]
        SIN["SIN(θ)"]
    end
    
    subgraph Indicator["Momentum"]
        RSI["RSI(14)"]
    end
    
    subgraph Logic["Session-Aware Logic"]
        PEAK["sin > 0.7?<br/>(Active hours)"]
        OVER["RSI < 30?<br/>(Oversold)"]
        AND["AND"]
    end
    
    subgraph Action["Signal"]
        BUY["Buy Signal"]
    end
    
    T --> HOUR --> ANGLE --> SIN --> PEAK
    P --> RSI --> OVER
    PEAK & OVER --> AND --> BUY

This system only triggers buy signals during active trading hours (when sin(hour_angle) is high), avoiding low-liquidity periods.


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 sine 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 zero-crossing 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 sine simply does not exist — the function keeps oscillating 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, however large, produces a valid sine (effectively reduced modulo 2π2\pi).


Edge Cases

SituationBehaviorNotes
Empty inputRejected with an errorMinimum length of 1 is enforced
Missing (null) valuesnull at the same positionGaps are preserved, never filled
NaN valuesnullTreated as missing data
Very large anglesCorrectly wraps via periodicitysin(100π) = 0
Negative anglesWorks correctly (odd symmetry)sin(−π/2) = −1
Inf valuesnullSine is undefined for an infinite angle

ModuleRelationship
COSCosine — pair with SIN for complete circular encoding
TANTangent — sin/cos ratio, unbounded
ARCSINInverse sine — converts values back to angles

Further Reading


Summary

The Sine module transforms angles (in radians) into smoothly oscillating values bounded between −1 and +1. Its primary financial application is cyclical time encoding — converting timestamps into continuous features that preserve the circular nature of time. Always pair with the Cosine module for complete positional encoding. Remember: input must be in radians, not degrees.


The Sine Wave Cycle

flowchart LR
    subgraph Cycle["One Complete Cycle (0 to 2π)"]
        P0["0<br/>sin = 0"]
        P1["π/2<br/>sin = +1"]
        P2["π<br/>sin = 0"]
        P3["3π/2<br/>sin = -1"]
        P4["2π<br/>sin = 0"]
    end
    
    P0 --> P1 --> P2 --> P3 --> P4
Angle (radians)sin(θ)Description
00Starting point
π/2+1Maximum (peak)
π0Midpoint crossing
3π/2-1Minimum (trough)
2π0Cycle complete

Key Properties

  • Bounded output: Always between −1 and +1
  • Periodic: Repeats every 2π radians
  • Smooth: Continuous with no jumps
  • Odd symmetry: sin⁡(−x)=−sin⁡(x)\sin(-x) = -\sin(x)

Angle Units

⚠️ Important: Angles must be in radians, not degrees.

DegreesRadianssin(θ)
0°00
30°π/60.5
45°π/4≈ 0.707
90°π/21
180°π0

Conversion formula: radians=degrees×π180\text{radians} = \text{degrees} \times \frac{\pi}{180}


Financial Applications

1. Encoding Cyclical Time Features

Markets exhibit daily, weekly, and seasonal cycles. Sine encoding converts time into smooth, continuous features:

flowchart TD
    subgraph Time["Time of Day"]
        H["Hour (0-23)"]
    end
    
    subgraph Convert["Convert to Angle"]
        R["θ = hour × 2π / 24"]
    end
    
    subgraph Encode["Cyclical Encoding"]
        SIN["sin(θ)"]
        COS["cos(θ)"]
    end
    
    subgraph Result["Smooth Cycle"]
        F["No discontinuity at midnight"]
    end
    
    H --> R --> SIN & COS --> F

2. Seasonal Pattern Detection

Examples

Input angles (radians):

[0, 0.5π, π, 1.5π, 2π]

Step values:

sin(0)      = 0
sin(0.5π)   = 1
sin(π)      = 0
sin(1.5π)   = -1
sin(2π)     = 0

Output:

[0, 1, 0, -1, 0]

Another example:

Input : [0, π/6, π/4, π/3]
Output: [0, 0.5, ≈0.7071, ≈0.8660]

Interpreting the Output

  • Values near +1: angle points mostly “up”.
  • Values near −1: angle points mostly “down”.
  • Values near 0: angle is near horizontal (pointing “right” or “left”).
  • Smooth angle changes produce smooth sine transitions—good for encoding continuous cycles.

Special / Edge Cases

SituationOutcome / Note
Empty inputRejected — minimum length of 1 is enforced.
Very large anglesConceptually wrap every 2π (periodic).
Negative anglesOutput sign flips (odd symmetry).
Angles near multiples of πResult close to 0; tiny rounding differences possible.
Missing (null) / NaNnull at the same output position — gaps pass through, never filled.
±Infinitynull — sine is mathematically undefined for an infinite angle.
Degree inputs (unconverted)Will not match expected values unless converted to radians first.

Practical Tips

  • For circular features, use both sine and cosine together to preserve full directional information.

3. Pairs with Cosine

For complete circular encoding, use both sine and cosine together:

CombinationInterpretation
sin > 0, cos > 0First quadrant (0 to π/2)
sin > 0, cos < 0Second quadrant (π/2 to π)
sin < 0, cos < 0Third quadrant (π to 3π/2)
sin < 0, cos > 0Fourth quadrant (3π/2 to 2π)

Summary

The Sine module transforms angles into bounded values (−1 to +1) that encode cyclical position. Pair with Cosine for complete circular feature encoding—essential for time-series analysis with periodic patterns.

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