mirror of
https://github.com/wassname/catalyst.git
synced 2026-07-08 06:24:49 +08:00
MAINT: Remove references to minute risk.
The minutely calculation of risk metrics had been removed with a previous patch, remove vestigial references. Remove a test which tested the behavior of updating the second minute of a day. Remove the logic that changed the datetime index of the risk metrics depending on emission rate, now only trading_days are needed. Remove `returns_frequency` parameter since both minute and daily data frequency always use daily returns.
This commit is contained in:
@@ -1,58 +0,0 @@
|
||||
#
|
||||
# Copyright 2013 Quantopian, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import unittest
|
||||
import datetime
|
||||
import pytz
|
||||
|
||||
from zipline.finance.trading import SimulationParameters
|
||||
from zipline.finance import risk
|
||||
|
||||
|
||||
class TestMinuteRisk(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
|
||||
start_date = datetime.datetime(
|
||||
year=2006,
|
||||
month=1,
|
||||
day=3,
|
||||
hour=0,
|
||||
minute=0,
|
||||
tzinfo=pytz.utc)
|
||||
end_date = datetime.datetime(
|
||||
year=2006, month=1, day=3, tzinfo=pytz.utc)
|
||||
|
||||
self.sim_params = SimulationParameters(
|
||||
period_start=start_date,
|
||||
period_end=end_date
|
||||
)
|
||||
self.sim_params.emission_rate = 'minute'
|
||||
|
||||
def test_minute_risk(self):
|
||||
|
||||
risk_metrics = risk.RiskMetricsCumulative(self.sim_params)
|
||||
|
||||
first_dt = self.sim_params.first_open
|
||||
second_dt = self.sim_params.first_open + datetime.timedelta(minutes=1)
|
||||
account = {'leverage': 0.0}
|
||||
|
||||
risk_metrics.update(first_dt, 1.0, 2.0, account)
|
||||
|
||||
self.assertEquals(1, len(risk_metrics.metrics.alpha.valid()))
|
||||
|
||||
risk_metrics.update(second_dt, 3.0, 4.0, account)
|
||||
|
||||
self.assertEquals(2, len(risk_metrics.metrics.alpha.valid()))
|
||||
@@ -125,7 +125,6 @@ class PerformanceTracker(object):
|
||||
|
||||
self.cumulative_risk_metrics = \
|
||||
risk.RiskMetricsCumulative(self.sim_params,
|
||||
returns_frequency='daily',
|
||||
create_first_day_stats=True)
|
||||
|
||||
self.minute_performance = PerformancePeriod(
|
||||
|
||||
@@ -92,15 +92,8 @@ class RiskMetricsCumulative(object):
|
||||
)
|
||||
|
||||
def __init__(self, sim_params,
|
||||
returns_frequency=None,
|
||||
create_first_day_stats=False,
|
||||
account=None):
|
||||
"""
|
||||
- @returns_frequency allows for configuration of the whether
|
||||
the benchmark and algorithm returns are in units of minutes or days,
|
||||
if `None` defaults to the `emission_rate` in `sim_params`.
|
||||
"""
|
||||
|
||||
self.treasury_curves = trading.environment.treasury_curves
|
||||
self.start_date = sim_params.period_start.replace(
|
||||
hour=0, minute=0, second=0, microsecond=0
|
||||
@@ -130,15 +123,7 @@ class RiskMetricsCumulative(object):
|
||||
|
||||
self.create_first_day_stats = create_first_day_stats
|
||||
|
||||
if returns_frequency is None:
|
||||
returns_frequency = self.sim_params.emission_rate
|
||||
|
||||
self.returns_frequency = returns_frequency
|
||||
|
||||
if returns_frequency == 'daily':
|
||||
cont_index = self.get_daily_index()
|
||||
elif returns_frequency == 'minute':
|
||||
cont_index = self.get_minute_index(sim_params)
|
||||
cont_index = self.trading_days
|
||||
|
||||
self.cont_index = cont_index
|
||||
self.cont_len = len(self.cont_index)
|
||||
@@ -185,24 +170,6 @@ class RiskMetricsCumulative(object):
|
||||
|
||||
self.num_trading_days = 0
|
||||
|
||||
def get_minute_index(self, sim_params):
|
||||
"""
|
||||
Stitches together multiple days worth of business minutes into
|
||||
one continous index.
|
||||
"""
|
||||
trading_minutes = None
|
||||
for day in self.trading_days:
|
||||
minutes_for_day = trading.environment.market_minutes_for_day(day)
|
||||
if trading_minutes is None:
|
||||
# Create container for all minutes on first iteration
|
||||
trading_minutes = minutes_for_day
|
||||
else:
|
||||
trading_minutes = trading_minutes.union(minutes_for_day)
|
||||
return trading_minutes
|
||||
|
||||
def get_daily_index(self):
|
||||
return self.trading_days
|
||||
|
||||
def update(self, dt, algorithm_returns, benchmark_returns, account):
|
||||
# Keep track of latest dt for use in to_dict and other methods
|
||||
# that report current state.
|
||||
|
||||
Reference in New Issue
Block a user