def get_futures(): date = get_db_date() quotes = futures.query_historical("VX", date) vix_quote = stocks.query_historical(["VIX"], date).get("VIX", 10) if vix_quote is None: return jsonify() data1 = [ { "x": dates.business_dates_diff(date, quote.expiration), "y": quote.close, "name": quote.expiration.strftime("%b'%y"), "suffix": "%+.2f, %+.0f %%, " % (quote.close - vix_quote.close, (quote.close / vix_quote.close - 1) * 100), } for quote in quotes ] if len(data1) > 0: first_point = data1[0] first_point.update({"marker": {"enabled": "false"}}) data2 = [{"x": 0, "y": vix_quote.close, "name": "VIX"}, first_point] else: data2 = [] return jsonify({"part1": data1, "part2": data2})
def get_term_structure(): date = get_db_date() data = structures.atm_term_structure("SPX", date) data = [ {"x": dates.business_dates_diff(date, expiration), "y": iv, "name": expiration.strftime("%b'%y")} for expiration, iv in data ] return jsonify({"root": data})
def get_dates(): date = request.args.get("date", None, type=str) current_date = dates.get_current_timestamp().date() if date is not None: try: date = datetime.strptime(date, "%Y-%m-%d").date() date = min(date, current_date) except ValueError: date = current_date data = {"date": date.strftime("%d.%m.%Y")} for name, lst in EXPIRATIONS.items(): pos = bisect.bisect_left(lst, date) if pos != len(lst): days_left = dates.business_dates_diff(date, lst[pos]) if days_left == 0: data[name] = "<strong>today</strong>" elif days_left == 1: data[name] = "<strong>tomorrow</strong>" else: data[name] = "in <strong>%d</strong> days" % days_left else: data[name] = "" return jsonify(data)
def test_friday_to_friday_backwards(self): self.assertEqual(dates.business_dates_diff( date(2015, 12, 11), date(2015, 12, 4)), -5)
def test_friday_to_friday(self): self.assertEqual(dates.business_dates_diff( date(2015, 12, 4), date(2015, 12, 11)), 5)
def test_sunday_to_monday(self): self.assertEqual(dates.business_dates_diff( date(2015, 12, 6), date(2015, 12, 7)), 1)
def test_same_day_holiday(self): self.assertEqual(dates.business_dates_diff( date(2015, 12, 12), date(2015, 12, 12)), 0)
def test_same_day_business(self): self.assertEqual(dates.business_dates_diff( date(2015, 12, 9), date(2015, 12, 9)), 0)