forked from willcruse/hackathonEG
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstatisticalMethods.py
69 lines (47 loc) · 1.44 KB
/
statisticalMethods.py
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import pandas as pd
import requests
from sklearn.impute import SimpleImputer
def simpMovingAverage(df, n):
df = df.transpose()
df = df.rolling(n).mean()
my_imputer=SimpleImputer()
df = my_imputer.fit_transform(df)
df = pd.DataFrame(df)
return df
def expWeightFuncs(df, n):
df = df.transpose()
df = df.ewm(halflife = n).mean()
my_imputer = SimpleImputer()
df = my_imputer.fit_transform(df)
df = pd.DataFrame(df)
return df
def prevReturn(df):
df.transpose()
def industryMovingAvg(df, n):
hot_encoded = pd.get_dummies(df)
instList = []
epoch_res = requests.get('http://egchallenge.tech/instruments').json()
for md in epoch_res:
instList.append({
'instrument_id': md['instrument_id'],
'industry': md['industry'],
'simpMovingAverage': simpMovingAverage(df, n)
})
instList.sort(key=lambda x: x[1])
industry = instList[0][1]
industryMovingSum = 0
i=0
totalIndustryAvgList = []
for x in range(len(instList)):
if instList[x][1] == industry:
industryMovingSum += instList[x][2]
i+=1
else:
totalIndustryAvgList.append({
'industry': md['industry'],
'totalIndustryAvg': industryMovingSum/i
})
industry = instList[x][i]
i=1
industryMovingSum += instList[x][2]
return totalIndustryAvgList