2016-08-24 17:43:11 -04:00
|
|
|
from unittest import TestCase
|
|
|
|
from datetime import datetime
|
|
|
|
from pandas_datareader.data import get_data_yahoo
|
|
|
|
from numpy.testing import assert_allclose
|
|
|
|
import pytest
|
2016-08-24 17:52:52 -04:00
|
|
|
from six.moves import map
|
2016-08-24 17:43:11 -04:00
|
|
|
|
|
|
|
from metrik.tasks.tradeking import Tradeking1mTimesales
|
|
|
|
from metrik.trading_days import TradingDay
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('ticker', [
|
|
|
|
'AAPL', 'GOOG', 'SPY', 'REGN', 'SWHC', 'BAC', 'NVCR'
|
|
|
|
])
|
|
|
|
def test_returns_verifiable(ticker):
|
|
|
|
# Test that the quotes line up with data off of Yahoo
|
|
|
|
now = datetime.now()
|
|
|
|
prior_day = now - TradingDay(1)
|
|
|
|
|
|
|
|
quotes = Tradeking1mTimesales.retrieve_data(prior_day, ticker)
|
|
|
|
|
2016-08-24 17:52:52 -04:00
|
|
|
yahoo_ohlc = list(map(tuple, get_data_yahoo(ticker, prior_day, prior_day)[
|
2016-08-24 17:43:11 -04:00
|
|
|
['Open', 'High', 'Low', 'Close']
|
2016-08-24 17:52:52 -04:00
|
|
|
].values))[0]
|
2016-08-24 17:43:11 -04:00
|
|
|
|
|
|
|
open = high = close = 0
|
|
|
|
low = 999999
|
|
|
|
for index, quote in enumerate(quotes['quotes']):
|
|
|
|
if index == 0:
|
|
|
|
open = quote['opn']
|
|
|
|
if index == len(quotes['quotes']) - 1:
|
|
|
|
close = quote['last']
|
|
|
|
high = max(high, quote['hi'])
|
|
|
|
low = min(low, quote['lo'])
|
|
|
|
|
|
|
|
tradeking_ohlc = (open, high, low, close)
|
|
|
|
|
|
|
|
assert_allclose(tradeking_ohlc, yahoo_ohlc, rtol=1e-3)
|