-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForcastAlgorithm.py
More file actions
31 lines (28 loc) · 834 Bytes
/
ForcastAlgorithm.py
File metadata and controls
31 lines (28 loc) · 834 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
def forcast_algorithm(data: list[list[int, float]]) -> float:
'''
This function is an algorithm which predicts next value of the data
Precondition: len(data) >= 2
'''
stock_val = None
forcast = None
prev_forcast = None
smoothing_val = 0.57
for i in data:
stock_val = i[1]
if prev_forcast is None:
prev_forcast = stock_val
forcast = stock_val
temp_forcast = forcast
forcast = forcast + smoothing_val * (stock_val - prev_forcast)
prev_forcast = temp_forcast
return forcast
def test_forcast_algorithm():
data = [[1, 39],
[2, 44],
[3, 40],
[4, 45],
[5, 38],
[6, 43],
[7, 39]]
print(forcast_algorithm(data))
assert 40.54 == forcast_algorithm(data)