Sine Weighted Moving Average

The Sine Weighted Moving Average (SINWMA) weights the prices of the window with the first half of a sine wave, so the prices in the middle of the window weigh the most.

The formula for the Sine Weighted Moving Average first sets the weight \(w_{i}\) of the i-th price of the window of n periods, from \(i = 1\) for the oldest to \(i = n\) for the latest, on the sine wave:

\[w_{i} = \sin\left(\frac{i \cdot \pi}{n + 1}\right)\]

The average weights each closing price \(\text{Close}_{i}\) with its own weight:

\[\text{SINWMA} = \frac{\sum_{i=1}^{n} w_{i} \cdot \text{Close}_{i}}{\sum_{i=1}^{n} w_{i}}\]

Its weights rise and fall smoothly instead of linearly, so it is a smoother version of the Triangular Moving Average, with a similar lag of about half the window.

A moving average smooths the price by averaging it over the last n periods, so that the trend shows through the noise of single periods. It is the oldest and most widely used trend indicator: the direction of the average shows the direction of the trend, the price above (below) it an uptrend (downtrend), and other indicators, from the MACD to the Bollinger Bands, are built on it. Every moving average trades smoothness against lag: the more periods it averages, the smoother it is and the later it turns after the price. The averages differ in how they weight the prices within the window and whether they adapt their speed to the market, each a different answer to that trade-off.

Also known as: SINWMA, sine weighted MA.

In the Finance Toolkit this is get_moving_average with method="sine", the same function as Moving Average.

Example · ^GSPC · 2021 to 2025

Install the Finance Toolkit with pip install financetoolkit -U, then call get_moving_average:

from financetoolkit import Toolkit

toolkit = Toolkit(
    tickers=["^GSPC"],
    api_key="FINANCIAL_MODELING_PREP_KEY",
    start_date="2021-01-01",
    end_date="2025-12-31",
)

toolkit.technicals.get_moving_average(method="sine", window=50)

Which returns:

References

  • Paper Everget (2018). “Sine Weighted Moving Average.” TradingView script.
  • Library Referenced against pandas-ta-classic’s sinwma (Sine Weighted Moving Average)
Share