Skip to content

feat: add exponential moving average to financial#1021

Open
AliAlimohammadi wants to merge 2 commits intoTheAlgorithms:masterfrom
AliAlimohammadi:add-exponential-moving-average
Open

feat: add exponential moving average to financial#1021
AliAlimohammadi wants to merge 2 commits intoTheAlgorithms:masterfrom
AliAlimohammadi:add-exponential-moving-average

Conversation

@AliAlimohammadi
Copy link
Contributor

Description

Adds an implementation of Exponential Moving Average (EMA) calculation to the financial module. EMA is a technique used in financial analysis to smooth time series data, weighting recent prices more heavily than older ones, making it more responsive to price changes than Simple Moving Average (SMA).

The formula used is:

$$s_t = \alpha \cdot x_t + (1 - \alpha) \cdot s_{t-1}$$

where $x_t$ is the stock price at time $t$, $s_{t-1}$ is the previous EMA value, and $\alpha = \frac{2}{1 + w}$ is the smoothing factor derived from the window size $w$. A simple moving average is used to seed the initial values until the window is first filled.

Reference: Exponential Smoothing — Wikipedia

Checklist

  • I ran cargo clippy --all -- -D warnings just before my last commit and fixed any issue that was found.
  • I ran cargo fmt just before my last commit.
  • I ran cargo test just before my last commit and all tests passed.
  • I added my algorithm to the corresponding mod.rs file within its own folder, and in any parent folder(s).
  • I added my algorithm to DIRECTORY.md with the correct link.
  • I checked CONTRIBUTING.md and my code follows its guidelines.

@codecov-commenter
Copy link

codecov-commenter commented Feb 28, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.02%. Comparing base (d14a4e2) to head (ba8de94).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1021      +/-   ##
==========================================
+ Coverage   95.98%   96.02%   +0.04%     
==========================================
  Files         384      385       +1     
  Lines       28890    28950      +60     
==========================================
+ Hits        27729    27799      +70     
+ Misses       1161     1151      -10     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@AliAlimohammadi
Copy link
Contributor Author

@siriak, this is ready to be merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants