From a66d6866f5a11ebd08df990fe5367db0e4fb6ca4 Mon Sep 17 00:00:00 2001 From: Eddie Hebert Date: Wed, 3 Apr 2013 15:55:04 -0400 Subject: [PATCH] MAINT: Use searchsorted instead of bisect on treasury curves. Remove use of .keys() and creation of a new list of the curve Series's values. --- zipline/finance/risk.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/zipline/finance/risk.py b/zipline/finance/risk.py index 29a54c6d..7059ffd6 100644 --- a/zipline/finance/risk.py +++ b/zipline/finance/risk.py @@ -58,7 +58,6 @@ Risk Report import logbook import datetime import math -import bisect import numpy as np import numpy.linalg as la from dateutil.relativedelta import relativedelta @@ -242,10 +241,10 @@ def choose_treasury(treasury_curves, start_date, end_date): if not search_day: # in case end date is not a trading day or there is no treasury # data, search for the previous day with an interest rate. - search_days = treasury_curves.keys() + search_days = treasury_curves.index # Find rightmost value less than or equal to end_day - i = bisect.bisect_right(search_days, end_day) + i = search_days.searchsorted(end_day) for prev_day in search_days[i - 1::-1]: rate = get_treasury_rate(treasury_curves, treasury_duration,