Пример #1
0
def get_volatility_surface():
    data = structures.volatility_surface("SPX", get_db_date()).values()
    for expiration in xrange(min(3, len(data))):
        keys, values = zip(*data[expiration])
        values = np.round(smooth.savitzky_golay(np.array(values), window_size=11, order=3), 2)
        data[expiration] = zip(keys, values)
    return jsonify({"root": data})
Пример #2
0
 def test_volatility_surface(self):
     stocks.fetch_historical('SPX', TEST_DB_NAME)
     surface1 = structures.volatility_surface(
         'SPX', self.test_timestamp.date(), 50, TEST_DB_NAME)
     surface2 = OrderedDict([
         (date(2016, 1, 15), [
             (1985.0, 21.43), (1990.0, 21.19), (1995.0, 20.81),
             (2000.0, 20.67), (2005.0, 20.12), (2010.0, 19.76),
             (2015.0, 19.41), (2020.0, 19.06), (2025.0, 18.75),
             (2030.0, 18.39),
         ]),
         (date(2016, 2, 19), [
             (1985.0, 19.14), (1990.0, 18.95), (1995.0, 18.74),
             (2000.0, 18.51), (2005.0, 18.33), (2010.0, 18.12),
             (2015.0, 17.93), (2020.0, 17.71), (2025.0, 17.51),
             (2030.0, 17.31),
         ]),
         (date(2016, 3, 18), [
             (1985.0, 18.55), (1990.0, 18.41), (1995.0, 18.23),
             (2000.0, 18.06), (2005.0, 17.91), (2010.0, 17.74),
             (2015.0, 17.58), (2020.0, 17.41), (2025.0, 17.25),
             (2030.0, 17.1),
         ]),
         (date(2016, 4, 15), [(2000.0, 17.88), (2025.0, 17.17)]),
         (date(2016, 6, 17), [(2000.0, 17.31), (2025.0, 16.86)]),
         (date(2016, 9, 16), [(2000.0, 16.95), (2025.0, 16.6)]),
         (date(2016, 12, 16), [(2000.0, 16.66), (2025.0, 16.36)]),
         (date(2017, 1, 20), [(2000.0, 16.71), (2025.0, 16.48)]),
         (date(2017, 6, 16), [(2000.0, 16.58), (2025.0, 16.36)]),
         (date(2017, 12, 15), [(2000.0, 16.39), (2025.0, 16.24)]),
     ])
     self.assertEqual(surface1, surface2)