From bb3e9727dc75339e8d117a5b80f826db98136fe8 Mon Sep 17 00:00:00 2001 From: Eddie Hebert Date: Wed, 3 Apr 2013 15:47:14 -0400 Subject: [PATCH] MAINT: Mask treasury_curves used by risk metrics to period range. So that calculations that leverage the range of the treasury_curves, like `pd.Series.searchsorted` will not overshoot the 'end' of the range we are calculating risk metrics. --- zipline/finance/risk.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/zipline/finance/risk.py b/zipline/finance/risk.py index 4f91abd2..29a54c6d 100644 --- a/zipline/finance/risk.py +++ b/zipline/finance/risk.py @@ -282,7 +282,11 @@ that date doesn't exceed treasury history range." class RiskMetricsBase(object): def __init__(self, start_date, end_date, returns): - self.treasury_curves = trading.environment.treasury_curves + treasury_curves = trading.environment.treasury_curves + mask = ((treasury_curves.index >= start_date) & + (treasury_curves.index <= end_date)) + + self.treasury_curves = treasury_curves[mask] self.start_date = start_date self.end_date = end_date