Sine
systemic:core-sinMathInputs
| Name | Type | Description |
|---|---|---|
| Data | Number series | The series of angles, in radians, whose sine is calculated. |
Outputs
| Name | Type | Description |
|---|---|---|
| Sin | Number series | The sine of each input angle, a value from -1 to 1. |
Cost
0.198 + 0.00569·n credits for n bars, rounded up. The marks are each plan's limit of bars.
The Sine module computes the sine of each value in the input series. The sine maps an angle (in radians) to its vertical position on the unit circle. The result oscillates smoothly between −1 and +1.
How It Works
flowchart TD
subgraph Input["Input Data"]
A["Angles in radians:<br/>θ₁, θ₂, θ₃, ... θₙ"]
end
subgraph Processing["Sine Calculation"]
NP["Sine of each value"]
NAN["Missing or ±∞ → empty"]
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 is the y-coordinate of a point that moves 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
⚠️ Important: 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 have cycles: daily trading sessions, weekly patterns, monthly options expiry and seasonal trends. The sine encodes these cycles as smooth, continuous features with no jumps.
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["Sine module"]
COS["Cosine 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: With raw hour values (0-23), 23:00 and 00:00 look as far apart as possible, but they are next to each other. Sine/cosine encoding keeps them close.
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 | ≈ 0.23π | 0.66 | Morning session |
| 12:45 (Midday) | π/2 | 1.0 | Peak of session |
| 14:30 | ≈ 0.77π | 0.66 | 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
Sine alone is ambiguous (sin(π/4) = sin(3π/4)). Pair it with cosine for an 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 |
Example System: Time-Based Signal
A time-aware system that reacts only during active hours. It needs an input series that holds the hour of each bar:
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 gives buy signals only during active trading hours (when the sine of the hour angle is high) and skips low-liquidity hours.
Missing Data
When an input value is missing (empty), the output on that bar is empty too. This happens, for example, when a stock series has no bar on a weekend or holiday. Gaps are never filled: every output value is the sine of a real input value. The output has the same length as the input, so each value stays on its own bar.
Handling Invalid Inputs
The sine of an infinite angle (±∞) does not exist. This is different from missing data, but both give an empty output:
- Missing input → empty: there was no value to compute from
- ±Infinity input → empty: there was a value, but its sine is undefined
Every finite angle, however large, has a valid sine (the angle wraps every ).
Edge Cases
| Situation | Behavior | Notes |
|---|---|---|
| No input values | Rejected with an error | At least 1 value is required |
| Missing values | Empty on the same bar | Gaps are kept, never filled |
| Very large angles | Wraps correctly (periodic) | sin(100π) ≈ 0, with tiny rounding differences |
| Negative angles | Works correctly (odd symmetry) | sin(−π/2) = −1 |
| Infinite values | Empty | Sine is undefined for an infinite angle |
Related Modules
| Module | Relationship |
|---|---|
| Cosine | Pair with Sine for a complete circular encoding |
| Tangent | The sin/cos ratio, unbounded |
| ArcSine | Inverse sine: converts values back to angles |
Further Reading
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: the angle points mostly “up”.
- Values near −1: the angle points mostly “down”.
- Values near 0: the angle is near horizontal (pointing “right” or “left”).
- Smooth angle changes give smooth sine changes, which suits continuous cycles.
Summary
The Sine module turns angles (in radians) into smoothly oscillating values between −1 and +1. Its main financial use is cyclical time encoding: converting time into continuous features that keep the circular nature of time. Pair it with the Cosine module for a complete encoding. Remember: the input must be in radians, not degrees.