Sine
systemic:core-sinMathfunction1 crInputs
| Name | Type | Description |
|---|---|---|
| Data | floatarray | A list of numerical values representing **angles in radians** to compute the sine of. |
Outputs
| Name | Type | Description |
|---|---|---|
| Sin | floatarray | - **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.
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 |
|---|---|---|---|
| 0 | 0° | 0 | Start (right) |
| π/6 | 30° | 0.5 | Rising |
| π/4 | 45° | 0.707 | Rising |
| π/2 | 90° | +1 | Peak (top) |
| π | 180° | 0 | Zero crossing (left) |
| 3π/2 | 270° | −1 | Trough (bottom) |
| 2π | 360° | 0 | Complete cycle |
Key Mathematical Properties
| Property | Description | Formula |
|---|---|---|
| Bounded Range | Output always between −1 and +1 | |
| Periodicity | Repeats every 2π radians | |
| Odd Symmetry | Negating input negates output | |
| Phase Relationship | Cosine is shifted sine |
Angle Units: Radians Required
⚠️ Critical: This module expects angles in radians, not degrees.
Conversion formula:
| Common Degrees | Radians | sin(θ) |
|---|---|---|
| 0° | 0 | 0 |
| 30° | π/6 ≈ 0.524 | 0.5 |
| 45° | π/4 ≈ 0.785 | 0.707 |
| 60° | π/3 ≈ 1.047 | 0.866 |
| 90° | π/2 ≈ 1.571 | 1.0 |
| 180° | π ≈ 3.142 | 0 |
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) | 0 | 0 | Session start |
| 11:00 | π/4 | 0.71 | Morning session |
| 12:45 (Midday) | π/2 | 1.0 | Peak of session |
| 14:30 | 3π/4 | 0.71 | Afternoon session |
| 16:00 (Close) | π | 0 | Session end |
3. Seasonality Features
| Cycle | Angle Formula | Application |
|---|---|---|
| Hour of Day | θ = hour × 2π / 24 | Intraday patterns |
| Day of Week | θ = day × 2π / 7 | Weekly seasonality |
| Day of Month | θ = day × 2π / 30 | Monthly patterns |
| Month of Year | θ = month × 2π / 12 | Seasonal effects |
| Quarter | θ = quarter × 2π / 4 | Quarterly 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 Range | sin(θ) | 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 ).
Edge Cases
| Situation | Behavior | Notes |
|---|---|---|
| Empty input | Rejected with an error | Minimum length of 1 is enforced |
| Missing (null) values | null at the same position | Gaps are preserved, never filled |
| NaN values | null | Treated as missing data |
| Very large angles | Correctly wraps via periodicity | sin(100π) = 0 |
| Negative angles | Works correctly (odd symmetry) | sin(−π/2) = −1 |
| Inf values | null | Sine is undefined for an infinite angle |
Related Modules
| Module | Relationship |
|---|---|
| COS | Cosine — pair with SIN for complete circular encoding |
| TAN | Tangent — sin/cos ratio, unbounded |
| ARCSIN | Inverse 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 |
|---|---|---|
| 0 | 0 | Starting point |
| π/2 | +1 | Maximum (peak) |
| π | 0 | Midpoint crossing |
| 3π/2 | -1 | Minimum (trough) |
| 2π | 0 | Cycle complete |
Key Properties
- Bounded output: Always between −1 and +1
- Periodic: Repeats every 2π radians
- Smooth: Continuous with no jumps
- Odd symmetry:
Angle Units
⚠️ Important: Angles must be in radians, not degrees.
| Degrees | Radians | sin(θ) |
|---|---|---|
| 0° | 0 | 0 |
| 30° | π/6 | 0.5 |
| 45° | π/4 | ≈ 0.707 |
| 90° | π/2 | 1 |
| 180° | π | 0 |
Conversion formula:
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
| Situation | Outcome / Note |
|---|---|
| Empty input | Rejected — minimum length of 1 is enforced. |
| Very large angles | Conceptually wrap every 2π (periodic). |
| Negative angles | Output sign flips (odd symmetry). |
| Angles near multiples of π | Result close to 0; tiny rounding differences possible. |
| Missing (null) / NaN | null at the same output position — gaps pass through, never filled. |
| ±Infinity | null — 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:
| Combination | Interpretation |
|---|---|
| sin > 0, cos > 0 | First quadrant (0 to π/2) |
| sin > 0, cos < 0 | Second quadrant (π/2 to π) |
| sin < 0, cos < 0 | Third quadrant (π to 3π/2) |
| sin < 0, cos > 0 | Fourth 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.