Skip to content

Commit

Permalink
modified utils.py
Browse files Browse the repository at this point in the history
  • Loading branch information
jjakimoto committed Jan 6, 2017
1 parent 4815b73 commit 81d0b8d
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions utils.py
Expand Up @@ -4,13 +4,9 @@
from collections import deque
# data scraping packages
from bs4 import BeautifulSoup
# use different package depending on python version
# satisfy compatilibty between python2 and python3
from six.moves.urllib.request import urlopen
version = int(sys.version[0])
if version == 3:
from urllib.request import urlopen, Request
else:
from urllib2 import urlopen, Request

# the symbols of S&P500 and S&P 100 are ^GSPC and ^OEX
def get_sap_symbols(name='sap500'):
"""Get ticker symbols constituting S&P
Expand All @@ -25,7 +21,6 @@ def get_sap_symbols(name='sap500'):
else:
raise NameError('invalid input: name should be "sap500" or "sap100"')
# fetch data from yahoo finance
req = Request(site)
page = urlopen(site)
soup = BeautifulSoup(page, 'html.parser')
table = soup.find('table', {'class': 'wikitable sortable'})
Expand Down Expand Up @@ -125,4 +120,7 @@ def get_data_list_key(symbols, st, end, key='Open'):
if len(fail_symbols) > 0:
print('we cound not fetch data from the following companies')
print(fail_symbols)
return pd.DataFrame(np.array(values).T, index = date, columns=sucess_symbols)
return pd.DataFrame(np.array(values).T, index = date, columns=sucess_symbols)

def testscore(prediction, target):
return np.mean(np.abs(prediction - target) / target)

0 comments on commit 81d0b8d

Please sign in to comment.