Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

exponential_moving_average returns an incorrect second value when window_size=1

Đang mở Phù hợp với người mới
#15,449 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
88/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
fintech-quant

Hướng nghiên cứu

Bắt đầu trong financial/exponential_moving_average.py và chạy bản tái hiện đã được báo cáo với window_size=1. Kiểm tra nhánh khởi tạo quanh i <= window_size và doctest hiện có để hiểu ngữ cảnh. Hoàn tất khi exponential_moving_average trả về [10.0, 20.0, 30.0] cho đầu vào đó, đồng thời giữ nguyên hành vi hiện có của window_size=3.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Python
Star
225k
Fork
51.1k
Merge trung bình
16 giờ 12 phút
Pull request đã merge (30 ngày)
180

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của TheAlgorithms/Python

Tất cả issue của TheAlgorithms/Python

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.