Esempio n. 1
0
def get_volatility_cone():
    data = structures.volatility_cone("SPX", get_db_date())
    data = [
        [
            {"x": period, "y": value, "name": VOLATILITY_CONE_PERIODS[period]}
            for period, value in izip(VOLATILITY_CONE_PERIODS.keys(), row)
        ]
        for row in data
    ]
    return jsonify({"root": data})
Esempio n. 2
0
 def test_volatility_cone(self):
     stocks.fetch_historical('SPX', TEST_DB_NAME)
     structures.update_stocks_vol('SPX', TEST_DB_NAME)
     cone1 = structures.volatility_cone(
         'SPX', self.test_timestamp.date(), 252, TEST_DB_NAME)
     cone2 = np.array([
         [ 19.84,  16.89,  15.69,  15.88,  18.30,  15.39],
         [  5.82,   8.08,   9.37,   9.64,  10.81,  11.54],
         [  8.85,   9.43,   9.98,  10.50,  11.50,  11.69],
         [  9.83,  10.54,  11.18,  11.01,  12.26,  11.85],
         [ 12.32,  12.41,  11.90,  12.57,  12.94,  12.3 ],
         [ 16.04,  16.64,  18.51,  20.50,  16.94,  15.04],
         [ 21.94,  26.19,  23.62,  21.59,  17.34,  15.3 ],
         [ 43.41,  31.95,  25.45,  22.06,  18.30,  15.54],
     ])
     self.assertTrue(np.array_equal(cone1, cone2))