-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_task.py
More file actions
43 lines (31 loc) · 1.12 KB
/
test_task.py
File metadata and controls
43 lines (31 loc) · 1.12 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
from get_data import data
# update data with new ticker price
def box_update(ticker, price):
data[f'{ticker}'].append(price)
return data
# and sigma on all timeline for a ticker
def sigma(query):
ticker = query.split(' ')[0]
#new_price = data[ticker][-1] + (data[ticker][-1] * pr_move_new)
#box_update(ticker, new_price)
price = data[ticker][::-1]
pr_move = []
sigma = 0
# calculate all values of price moving on timeline
for i in range(len(price)-1):
val = (price[i+1] / price[i] - 1) * 100
val = round(val, 2)
pr_move.append(val)
avarage_price_move = round((sum(pr_move) / (len(price)-1)), 2)
# calculate sigma
for i in range(len(pr_move)):
sigma += (pr_move[i] - avarage_price_move)**2
if len(price) <= 30:
sigma = (round(sigma, 2) / (len(price) - 2))**0.5
else:
sigma = (round(sigma, 2) / (len(price) - 1))**0.5
# calculate result
pr_move_new = (float(query.split(' ')[1])) * 100
result = float(round(abs((pr_move_new-avarage_price_move)/sigma), 1))
return result
print(sigma('ADBE 0.0258'))