Hacktoberfest 2026:維護者為十月標記出來的 issue,仍然開放、適合新手。 瀏覽 Hacktoberfest issue

exponential_moving_average returns an incorrect second value when window_size=1

未關閉 適合新手
#15,449 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
2/5
預估耗時
1-3 小時
新手友好度
88/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
python
領域
fintech-quant

研究方向

從 financial/exponential_moving_average.py 開始,使用 window_size=1 執行已回報的重現。檢查 i <= window_size 附近的初始化分支,並查看現有的 doctest 以了解上下文。完成的標準是:對於該輸入,exponential_moving_average 回傳 [10.0, 20.0, 30.0],同時保留現有的 window_size=3 行為。

由索引模型根據 Issue 內容生成。

描述

bug
Repository commit

7f81fcd68c195ce71534de09d1b69d2b61665902

Python version (python --version)

Python 3.14.7

Dependencies version (pip freeze)

No third-party dependencies are required for this reproduction; the function uses only the Python standard library.

Expected behavior

For window_size=1, the documented smoothing factor is:

alpha = 2 / (1 + window_size) = 1

Therefore, the documented recurrence should return each input value unchanged.

For input [10.0, 20.0, 30.0], the expected output is:

[10.0, 20.0, 30.0]

Actual behavior

The function returns [10.0, 15.0, 30.0], so the second value is incorrect.

Reproduction from the repository root:

from financial.exponential_moving_average import exponential_moving_average

actual = list(
    exponential_moving_average(iter([10.0, 20.0, 30.0]), window_size=1)
)
print(actual)
# [10.0, 15.0, 30.0]

assert actual == [10.0, 20.0, 30.0]
# AssertionError

The initialization branch uses if i <= window_size. At i=1 and window_size=1, it calculates (moving_average + stock_price) * 0.5, producing 15.0 instead of applying alpha=1.

The existing doctest uses window_size=3 and passes, but does not cover this case.

The unmodified source file at the reported commit was tested with Python 3.14.7.

主要語言
Python
星號
225k
分支
51.1k
平均合併
16 小時 12 分鐘
30 天內合併 PR
180

環境準備

在 Codespaces 中開啟

在瀏覽器裡用你自己的 GitHub 帳號啟動這個專案的開發容器。

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

TheAlgorithms/Python 的其他 Issue

查看 TheAlgorithms/Python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。