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})
def test_savitzky_golay(self): input_data = np.array( [11.20, 12.29, 13.35, 13.95, 14.16, 14.82, 15.09, 15.39, 15.71, 15.78, 16.12, 16.31, 16.44, 16.57, 16.69, 16.77, 16.72, 16.92, 16.91, 16.85, 16.96, 16.95, 16.89, 17.01, 17.01, 16.96, 16.91]) expected_data = np.array( [11.20, 12.14, 13.05, 13.79, 14.38, 14.80, 15.12, 15.39, 15.66, 15.91, 16.09, 16.29, 16.43, 16.56, 16.69, 16.75, 16.81, 16.86, 16.88, 16.90, 16.93, 16.96, 16.95, 16.96, 16.97, 16.97, 16.98]) processed_data = smooth.savitzky_golay( input_data, window_size=11, order=3) self.assertTrue((np.round(processed_data, 2) == expected_data).all())