mirror of
https://github.com/bspeice/metrik
synced 2024-11-23 07:38:09 -05:00
Add CBOE Optionable list
This commit is contained in:
parent
a44635c660
commit
80e5a17acf
@ -54,7 +54,7 @@
|
|||||||
<ConfirmationsSetting value="0" id="Add" />
|
<ConfirmationsSetting value="0" id="Add" />
|
||||||
<ConfirmationsSetting value="0" id="Remove" />
|
<ConfirmationsSetting value="0" id="Remove" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_3" default="false" assert-keyword="false" jdk-15="false" project-jdk-name="Python 3.5.1 virtualenv at C:\Users\Bradlee Speice\Development\metrik\metrik-virtual" project-jdk-type="Python SDK">
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_3" default="false" assert-keyword="false" jdk-15="false" project-jdk-name="Python 3.5.1 (C:\Users\Bradlee Speice\Anaconda3\python.exe)" project-jdk-type="Python SDK">
|
||||||
<output url="file://$PROJECT_DIR$/out" />
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
</component>
|
</component>
|
||||||
<component name="PythonCompatibilityInspectionAdvertiser">
|
<component name="PythonCompatibilityInspectionAdvertiser">
|
||||||
|
32
metrik/tasks/cboe.py
Normal file
32
metrik/tasks/cboe.py
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
import requests
|
||||||
|
import pandas as pd
|
||||||
|
from six import StringIO
|
||||||
|
|
||||||
|
from metrik.tasks.base import MongoNoBackCreateTask
|
||||||
|
|
||||||
|
|
||||||
|
class CboeOptionableList(MongoNoBackCreateTask):
|
||||||
|
def get_collection_name(self):
|
||||||
|
return 'cboe_optionable_list'
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def retrieve_data(*args, **kwargs):
|
||||||
|
# Explicitly use requests to make mocking easy
|
||||||
|
csv_bytes = requests.get('http://www.cboe.com/publish/scheduledtask/'
|
||||||
|
'mktdata/cboesymboldir2.csv').content
|
||||||
|
csv_str = csv_bytes.decode('ascii')
|
||||||
|
|
||||||
|
# Because some of the fields include extra commas, we need to
|
||||||
|
# pre-process them out
|
||||||
|
old_sep = ','
|
||||||
|
new_sep = '|'
|
||||||
|
csv_rows = csv_str.split('\r\n')
|
||||||
|
csv_header = csv_rows[1]
|
||||||
|
num_cols = len(csv_header.split(old_sep))
|
||||||
|
csv_content = [r.replace(old_sep, new_sep, num_cols - 1)
|
||||||
|
for r in csv_rows[1:]]
|
||||||
|
content_str = '\n'.join(csv_content)
|
||||||
|
csv_filelike = StringIO(content_str)
|
||||||
|
|
||||||
|
company_csv = pd.read_csv(csv_filelike, sep=new_sep)
|
||||||
|
return {'companies': company_csv.to_dict(orient='records')}
|
12
test/tasks/test_cboe.py
Normal file
12
test/tasks/test_cboe.py
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
from unittest import TestCase
|
||||||
|
|
||||||
|
from metrik.tasks.cboe import CboeOptionableList
|
||||||
|
|
||||||
|
|
||||||
|
class CboeTest(TestCase):
|
||||||
|
|
||||||
|
def test_optionable_list(self):
|
||||||
|
companies = CboeOptionableList.retrieve_data()['companies']
|
||||||
|
assert len(companies) > 2000
|
||||||
|
# TODO: Get lists of companies from ETF holdings and verify that they
|
||||||
|
# can be found here as well - this should be a superset
|
Loading…
Reference in New Issue
Block a user