Esempio n. 1
0
    def _test_get_historical_data(self):
        # product_code = 'ICE/TFM'
        product_code = 'ICE/BPB'
        start = datetime.date(2016, 1, 1)
        end = datetime.date(2017, 12, 1)
        date = start
        step = relativedelta(months=1)
        while date < end:
            year = date.year
            month = date.month
            date = date + step
            print("Date", date)
            # continue

            month_code = quandl_month_codes[month]
            symbol = '{}{}{}'.format(product_code, month_code, year)
            quotes = get_historical_data(service='quandl',
                                         sym=symbol,
                                         start=datetime.datetime(2010, 1, 1),
                                         end=datetime.datetime.now())
            quotes_settle = quotes['Settle']
            num_quotes = len(quotes_settle)
            last_price = pick_last_price(quotes_settle)
            vol = calc_historical_volatility(quotes_settle)
            print(symbol, year, month, num_quotes, last_price, vol)
Esempio n. 2
0
 def _test_get_quandl_data_ttf(self):
     quotes = get_historical_data(service='quandl',
                                  sym='ICE/TFMF2014',
                                  start=datetime.datetime(2013, 1, 1),
                                  col='Settle')
     index = quotes.index
     self.assertIsInstance(index[0], Timestamp)
     self.assertEqual(len(quotes), 60)
Esempio n. 3
0
 def _test_get_quandl_data_goog(self):
     quotes = get_historical_data('quandl',
                                  'GOOG',
                                  col='Close',
                                  end=datetime.date(2017, 10, 26))
     index = quotes.index
     self.assertIsInstance(index[0], Timestamp)
     self.assertTrue(len(quotes), 23)
Esempio n. 4
0
 def _test_get_quandl_data_wti(self):
     quotes = get_historical_data(
         service='quandl',
         sym='ICE/TX2009',
         start=datetime.datetime(2007, 1, 1),
         end=datetime.datetime(2007, 2, 1),
         col='Settle',
     )
     index = quotes.index
     self.assertIsInstance(index[0], Timestamp)
     self.assertEqual(len(quotes), 23)
Esempio n. 5
0
def generate_calibration_params(start,
                                end,
                                markets,
                                get_historical_data=get_historical_data):
    name = 'quantdsl.priceprocess.blackscholes.BlackScholesPriceProcess'
    all_quotes = []
    sigmas = []
    date = start
    all_market_names = []
    # Iterate over all "markets" (e.g. 'GAS').
    all_curves = {}
    for market_name, market_spec in markets.items():
        all_market_names.append(market_name)
        forward_vols = []
        forward_curve = []
        while date <= end:
            forward_year = date.year
            forward_month = date.month
            kwargs = market_spec.copy()
            kwargs['sym'] += quandl_month_codes[forward_month] + str(
                forward_year)

            # Get the data.
            quotes = get_historical_data(**kwargs)

            all_quotes.append(quotes)
            vol = calc_historical_volatility(quotes)
            forward_vols.append(vol)
            last = pick_last_price(quotes)
            forward_curve.append((date, last))

            # Next month.
            date = date + relativedelta(months=1)
        sigma = np.median(forward_vols)
        sigmas.append(sigma)
        all_curves[market_name] = forward_curve
    # Todo: Align dates and drop rows that aren't full.
    rho = calc_correlation(all_quotes)
    return {
        'name': name,
        'market': all_market_names,
        'sigma': sigmas,
        'rho': rho,
        'curve': all_curves,
    }
Esempio n. 6
0
def generate_calibration_params(start, end, markets, get_historical_data=get_historical_data):
    name = 'quantdsl.priceprocess.blackscholes.BlackScholesPriceProcess'
    all_quotes = []
    sigmas = []
    date = start
    all_market_names = []
    # Iterate over all "markets" (e.g. 'GAS').
    all_curves = {}
    for market_name, market_spec in markets.items():
        all_market_names.append(market_name)
        forward_vols = []
        forward_curve = []
        while date <= end:
            forward_year = date.year
            forward_month = date.month
            kwargs = market_spec.copy()
            kwargs['sym'] += quandl_month_codes[forward_month] + str(forward_year)

            # Get the data.
            quotes = get_historical_data(**kwargs)

            all_quotes.append(quotes)
            vol = calc_historical_volatility(quotes)
            forward_vols.append(vol)
            last = pick_last_price(quotes)
            forward_curve.append((date, last))

            # Next month.
            date = date + relativedelta(months=1)
        sigma = np.median(forward_vols)
        sigmas.append(sigma)
        all_curves[market_name] = forward_curve
    # Todo: Align dates and drop rows that aren't full.
    rho = calc_correlation(all_quotes)
    return {
        'name': name,
        'market': all_market_names,
        'sigma': sigmas,
        'rho': rho,
        'curve': all_curves,
    }
Esempio n. 7
0
 def _test_get_google_data_goog(self):
     # NB start and end doesn't seem to be effective with the 'google' service.
     quotes = get_historical_data('google', 'GOOG', col='Close', limit=30)
     index = quotes.index
     self.assertIsInstance(index[0], Timestamp)
     self.assertEqual(len(quotes), 30, str(quotes))