def quote_factory(_, row): """Converts row to quote""" symbol, expiration, date, time, close = row expiration = database.decode_date(expiration) date = database.decode_date(date) time = database.decode_time(time) return FutureQuote(symbol, expiration, date, time, close)
def quote_factory(_, row): """Converts row to quote""" symbol, type_, expiration, strike, date, time, \ bid, ask, stock, iv_bid, iv_ask = row expiration = database.decode_date(expiration) date = database.decode_date(date) time = database.decode_time(time) return OptionQuote(symbol, type_, expiration, strike, date, time, bid, ask, stock, iv_bid, iv_ask)
def test_update_stocks_vol_last(self): structures.update_stocks_vol('SPX', TEST_DB_NAME) with database.connect_db(TEST_DB_NAME) as db: db.execute('SELECT MAX(date) FROM stocks WHERE symbol=?;', ['SPX']) test_date = database.decode_date(db.fetchall()[0][0]) db.execute('SELECT * FROM volatility WHERE symbol=? AND date=?;', ['SPX', test_date]) original_row = db.fetchall()[0][3:] db.execute('UPDATE volatility SET change=?, vol1d=?, vol2d=?, ' \ 'vol3d=?, vol4d=?, vol5d=?, vol6d=?, vol7d=?, vol8d=?, '\ 'vol9d=?, vol1m=?, vol2m=?, vol3m=?, vol6m=?, vol1y=? ' \ 'WHERE symbol=? AND date=?;', [0] * 15 + ['SPX', test_date]) db.execute('SELECT * FROM volatility WHERE symbol=? AND date=?;', ['SPX', test_date]) corrupted_row = db.fetchall()[0][3:] self.assertTrue(all(abs(item) > 1e-5 for item in original_row)) self.assertTrue(all(abs(item) < 1e-5 for item in corrupted_row)) structures.update_stocks_vol_last('SPX', TEST_DB_NAME) with database.connect_db(TEST_DB_NAME) as db: db.execute('SELECT * FROM volatility WHERE symbol=? AND date=?;', ['SPX', test_date]) updated_row = db.fetchall()[0][3:] self.assertTrue(all(abs(item) > 1e-5 for item in updated_row))
def test_date(self): date = datetime.date(2015, 12, 9) self.assertEqual(database.decode_date(database.encode_date(date)), date)