-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWeek1_1003_Spring2022.py
124 lines (97 loc) · 3.1 KB
/
Week1_1003_Spring2022.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import yfinance as yf
import os
import pandas as pd
import numpy as np
# #################### Import Tesla Stock Info ############################
tsla = yf.Ticker("TSLA")
# get historical market data
hist = tsla.history(start="2022-01-24", end="2022-01-29")
print(hist['Close'])
ave = round(hist['Close'].mean(), 2)
high = round(hist['Close'].max(), 2)
low = round(hist['Close'].min(), 2)
print('Average: {0:}, High: {1:}, Low: {2:}'.format(ave, high, low))
# #################### Read and Clean Data ################################
path = '/Users/mau/Dropbox/Mac/Documents/Econ 103/Spring 2022/Forecast Game/Section 1003'
os.chdir(path)
Generaldata = pd.read_csv('Week 1_1003.csv', header=0)
data = Generaldata[['QID1_6', 'Q4', 'Q5', 'Q6']]
data = data.drop([0, 1])
data = data.dropna()
print(data.info())
data['Q4'] = data['Q4'].str.replace(r"[a-zA-Z$,]",'')
data['Q4'] = data['Q4'].astype(float)
data['Q5'] = data['Q5'].str.replace(r"[a-zA-Z$,]",'')
data['Q5'] = data['Q5'].astype(float)
data['Q6'] = data['Q6'].str.replace(r"[a-zA-Z$,]",'')
data['Q6'] = data['Q6'].astype(float)
data.rename(columns={"QID1_6": "Username", "Q4": "Average", "Q5":"High", "Q6":"Low"}, inplace=True)
# #################### Assign Points ####################################
minave = ave-(ave*.05)
maxave = ave+(ave*.05)
minhigh = high-(high*.05)
maxhigh = high+(high*.05)
minlow = low-(low*.05)
maxlow = low+(low*.05)
# print(minave)
# print(maxave)
#
#
# print(minhigh)
# print(maxhigh)
#
#
# print(minlow)
# print(maxlow)
list = []
for value in data['Average']:
if minave <= value <= maxave:
# print(value, 'ave prediction is present in the range.')
list.append(3)
else:
# print(value, 'ave prediction is not present in the range.')
list.append(0)
list1 = []
for value in data['High']:
if minhigh <= value <= maxhigh:
# print(value, 'high prediction is present in the range.')
list1.append(2)
else:
# print(value, 'high prediction is not present in the range.')
list1.append(0)
list2 = []
for value in data['Low']:
if minlow <= value <= maxlow:
# print(value, 'low prediction is present in the range.')
list2.append(2)
else:
# print(value, 'low prediction is not present in the range.')
list2.append(0)
lt = []
for value in data['Average']:
diffa = round(value-ave, 0)
lt.append(diffa)
lt1 = []
for value in data['High']:
diffh = round(value-high, 0)
lt1.append(diffh)
lt2 = []
for value in data['Low']:
diffl = round(value-low, 0)
lt2.append(diffl)
#
# print(len(lt))
print(len(list))
data['Ave Score'] = list
data['High Score'] = list1
data['Low Score'] = list2
data['Total'] = data['Ave Score']+data['High Score']+data['Low Score']
data['Ave Accuracy'] = lt
data['High Accuracy'] = lt1
data['Low Accuracy'] = lt2
data['Overall Accuracy'] = data['Ave Accuracy']+data['High Accuracy']+data['Low Accuracy']
data['Absolute Value'] = abs(data['Overall Accuracy'])
data['Week'] = 'Week 1'
sorteddata = data.sort_values(by='Total', ascending=False)
print(sorteddata)
sorteddata.to_csv('Results_Week1.csv', index=False)