mirror of
https://github.com/bspeice/metrik
synced 2024-11-04 22:48:11 -05:00
Remove the LIBOR stuff
Focus on data I can't retrieve historically - LIBOR rates I can get in the future.
This commit is contained in:
parent
d8f32d8128
commit
5e6bc68a33
@ -8,12 +8,10 @@ from subprocess import check_output
|
||||
from os import path
|
||||
|
||||
from metrik.conf import get_config
|
||||
from metrik.flows.rates_flow import LiborFlow
|
||||
from metrik.flows.equities_flow import EquitiesFlow
|
||||
from metrik import __version__
|
||||
|
||||
flows = {
|
||||
'LiborFlow': LiborFlow,
|
||||
'EquitiesFlow': EquitiesFlow
|
||||
}
|
||||
|
||||
|
@ -1,14 +0,0 @@
|
||||
from metrik.flows.base import Flow, WeekdayMidnight
|
||||
from metrik.tasks.ice import LiborRateTask
|
||||
|
||||
|
||||
class LiborFlow(Flow):
|
||||
|
||||
@staticmethod
|
||||
def get_schedule():
|
||||
return WeekdayMidnight()
|
||||
|
||||
def _requires(self):
|
||||
currencies = ['USD']
|
||||
return [LiborRateTask(self.present, currency)
|
||||
for currency in currencies]
|
@ -1,92 +0,0 @@
|
||||
from __future__ import print_function
|
||||
|
||||
import csv
|
||||
import requests
|
||||
from collections import namedtuple
|
||||
from dateutil.parser import parse
|
||||
from io import StringIO
|
||||
from pytz import timezone
|
||||
|
||||
from luigi.parameter import DateParameter, Parameter
|
||||
from six.moves.urllib.parse import quote_plus
|
||||
|
||||
from metrik.tasks.base import MongoCreateTask
|
||||
from metrik.trading_days import TradingDay
|
||||
|
||||
LiborRate = namedtuple('LiborRate', [
|
||||
'publication', 'overnight', 'one_week', 'one_month', 'two_month',
|
||||
'three_month', 'six_month', 'one_year', 'currency'
|
||||
])
|
||||
|
||||
|
||||
class LiborRateTask(MongoCreateTask):
|
||||
|
||||
date = DateParameter()
|
||||
currency = Parameter()
|
||||
|
||||
def get_collection_name(self):
|
||||
return 'libor'
|
||||
|
||||
@staticmethod
|
||||
def retrieve_historical_libor(date, currency):
|
||||
url = ('https://www.theice.com/marketdata/reports/icebenchmarkadmin/'
|
||||
'ICELiborHistoricalRates.shtml?excelExport='
|
||||
'&criteria.reportDate={}&criteria.currencyCode={}').format(
|
||||
quote_plus(date.strftime('%m/%d/%y')),
|
||||
currency
|
||||
)
|
||||
|
||||
fields = ['tenor', 'publication', 'usd_ice_libor']
|
||||
text = requests.get(url).text
|
||||
f = StringIO(text)
|
||||
next(f) # Skip the header
|
||||
|
||||
# TODO: Messing with globals() is probably a terrible idea, is there
|
||||
# a better way to write the below code?
|
||||
for row in csv.DictReader(f, fieldnames=fields):
|
||||
mapping = {
|
||||
'Overnight': 'overnight',
|
||||
'1 Week': 'one_week',
|
||||
'1 Month': 'one_month',
|
||||
'2 Month': 'two_month',
|
||||
'3 Month': 'three_month',
|
||||
'6 Month': 'six_month',
|
||||
'1 Year': 'one_year'
|
||||
}
|
||||
if row['usd_ice_libor']:
|
||||
globals()[mapping[row['tenor']]] = float(row['usd_ice_libor'])
|
||||
|
||||
if row['publication']:
|
||||
# Weird things happen with the publication field. For whatever reason,
|
||||
# the *time* is correct, but very often the date gets screwed up.
|
||||
# When I download the CSV with Firefox I only see the times - when I
|
||||
# download with `requests`, I see both date (often incorrect) and time.
|
||||
dt = parse(row['publication'])
|
||||
dt = dt.replace(year=date.year, month=date.month, day=date.day)
|
||||
if dt.tzinfo is None:
|
||||
dt = timezone('America/New_York').localize(dt)
|
||||
globals()['publication'] = dt
|
||||
|
||||
# Because of the shenanigans I did earlier with globals(), ignore
|
||||
# unresolved references. Probably a better way to do this.
|
||||
# noinspection PyUnresolvedReferences
|
||||
return {
|
||||
'currency': currency,
|
||||
'publication': publication,
|
||||
'overnight': overnight,
|
||||
'one_week': one_week,
|
||||
'one_month': one_month,
|
||||
'two_month': two_month,
|
||||
'three_month': three_month,
|
||||
'six_month': six_month,
|
||||
'one_year': one_year
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
def retrieve_data(date, currency):
|
||||
# ICE publish data a day late, so we actually need to retrieve data
|
||||
# for the trading day prior to this.
|
||||
return LiborRateTask.retrieve_historical_libor(
|
||||
date - TradingDay(1),
|
||||
currency
|
||||
)
|
@ -1,65 +0,0 @@
|
||||
from unittest import TestCase
|
||||
from datetime import datetime
|
||||
import pytz
|
||||
import logging
|
||||
|
||||
from metrik.tasks.ice import LiborRateTask
|
||||
|
||||
|
||||
# noinspection PyUnresolvedReferences
|
||||
class TestICE(TestCase):
|
||||
def test_correct_libor_Aug8_2016(self):
|
||||
# Validate with:
|
||||
# https://www.theice.com/marketdata/reports/icebenchmarkadmin/ICELiborHistoricalRates.shtml?excelExport=&criteria.reportDate=8%2F8%2F16&criteria.currencyCode=USD
|
||||
aug8_libor = LiborRateTask.retrieve_historical_libor(
|
||||
datetime(2016, 8, 8), 'USD')
|
||||
|
||||
assert aug8_libor['overnight'] == .4189
|
||||
assert aug8_libor['one_week'] == .4431
|
||||
assert aug8_libor['one_month'] == .5119
|
||||
assert aug8_libor['two_month'] == .6268
|
||||
assert aug8_libor['three_month'] == .8065
|
||||
assert aug8_libor['six_month'] == 1.1852
|
||||
assert aug8_libor['one_year'] == 1.5081
|
||||
|
||||
london_tz = pytz.timezone('Europe/London')
|
||||
actual = london_tz.localize(datetime(2016, 8, 8, 11, 45, 6))
|
||||
logging.info('Publication date in London time: {}'.format(
|
||||
aug8_libor['publication'].astimezone(london_tz)))
|
||||
assert aug8_libor['publication'] == actual
|
||||
|
||||
def test_correct_libor_Aug9_2010(self):
|
||||
# Validate with:
|
||||
# https://www.theice.com/marketdata/reports/icebenchmarkadmin/ICELiborHistoricalRates.shtml?excelExport=&criteria.reportDate=8%2F9%2F10&criteria.currencyCode=USD
|
||||
aug9_libor = LiborRateTask.retrieve_historical_libor(
|
||||
datetime(2010, 8, 9), 'USD')
|
||||
|
||||
assert aug9_libor['overnight'] == .23656
|
||||
assert aug9_libor['one_week'] == .27725
|
||||
assert aug9_libor['one_month'] == .29
|
||||
assert aug9_libor['two_month'] == .3375
|
||||
assert aug9_libor['three_month'] == .40438
|
||||
assert aug9_libor['six_month'] == .6275
|
||||
assert aug9_libor['one_year'] == .995
|
||||
|
||||
london_tz = pytz.timezone('Europe/London')
|
||||
actual = london_tz.localize(datetime(2010, 8, 9, 15, 49, 12))
|
||||
logging.info('Publication date in London time: {}'.format(
|
||||
aug9_libor['publication'].astimezone(london_tz)))
|
||||
assert aug9_libor['publication'] == actual
|
||||
|
||||
def test_correct_date_reasoning(self):
|
||||
# Make sure I document how to handle datetime issues in the future
|
||||
london_tz = pytz.timezone('Europe/London')
|
||||
ny_tz = pytz.timezone('America/New_York')
|
||||
|
||||
# DON'T YOU DARE SET TZINFO, SHENANIGANS HAPPEN
|
||||
assert (datetime(2016, 8, 8, 15, 0, 0, tzinfo=london_tz) <
|
||||
datetime(2016, 8, 8, 15, 0, 0, tzinfo=ny_tz))
|
||||
|
||||
assert (datetime(2016, 8, 8, 15, 0, 0, tzinfo=london_tz) >
|
||||
datetime(2016, 8, 8, 10, 0, 0, tzinfo=ny_tz))
|
||||
|
||||
# ALWAYS USE timezone.localize()
|
||||
assert (london_tz.localize(datetime(2016, 8, 8, 15)) ==
|
||||
ny_tz.localize(datetime(2016, 8, 8, 10)))
|
Loading…
Reference in New Issue
Block a user