mirror of
https://github.com/wassname/catalyst.git
synced 2026-06-30 01:38:30 +08:00
Merge pull request #119 from quantopian/ditch_maxdd
dropping max drawdown, adding pytz to whitelist.
This commit is contained in:
@@ -7,7 +7,7 @@ numpy>=1.6.1
|
||||
pandas==0.8.0
|
||||
scipy>=0.10.0
|
||||
|
||||
matplotlib==1.1.0
|
||||
#matplotlib==1.1.0
|
||||
#http://sourceforge.net/projects/matplotlib/files/matplotlib/matplotlib-1.1.0/matplotlib-1.1.0.tar.gz
|
||||
|
||||
numexpr==2.0.1
|
||||
|
||||
@@ -66,7 +66,6 @@ class FinanceTestCase(TestCase):
|
||||
period_start = datetime(2008, 1, 1, tzinfo = pytz.utc),
|
||||
period_end = datetime(2008, 12, 31, tzinfo = pytz.utc),
|
||||
capital_base = 100000,
|
||||
max_drawdown = 0.50
|
||||
)
|
||||
#holidays taken from: http://www.nyse.com/press/1191407641943.html
|
||||
new_years = datetime(2008, 1, 1, tzinfo = pytz.utc)
|
||||
|
||||
@@ -41,10 +41,6 @@ Performance Tracking
|
||||
| | For details look at the comments for |
|
||||
| | :py:meth:`zipline.finance.risk.RiskMetrics.to_dict`|
|
||||
+-----------------+----------------------------------------------------+
|
||||
| exceeded_max_ | True if the simulation was stopped because single |
|
||||
| loss | day losses exceeded the max_drawdown stipulated in |
|
||||
| | trading_environment. |
|
||||
+-----------------+----------------------------------------------------+
|
||||
|
||||
Position Tracking
|
||||
=================
|
||||
@@ -131,7 +127,7 @@ import zipline.finance.risk as risk
|
||||
log = logbook.Logger('Performance')
|
||||
|
||||
class PerformanceTracker(object):
|
||||
|
||||
|
||||
"""
|
||||
Tracks the performance of the zipline as it is running in
|
||||
the simulator, relays this out to the Deluge broker and then
|
||||
@@ -163,7 +159,6 @@ class PerformanceTracker(object):
|
||||
self.txn_count = 0
|
||||
self.event_count = 0
|
||||
self.last_dict = None
|
||||
self.exceeded_max_loss = False
|
||||
|
||||
# this performance period will span the entire simulation.
|
||||
self.cumulative_performance = PerformancePeriod(
|
||||
@@ -196,7 +191,7 @@ class PerformanceTracker(object):
|
||||
for sid in sid_list:
|
||||
self.cumulative_performance.positions[sid] = Position(sid)
|
||||
self.todays_performance.positions[sid] = Position(sid)
|
||||
|
||||
|
||||
def transform(self, stream_in):
|
||||
"""
|
||||
Main generator work loop.
|
||||
@@ -206,15 +201,6 @@ class PerformanceTracker(object):
|
||||
event.perf_message = self.handle_simulation_end()
|
||||
del event['TRANSACTION']
|
||||
yield event
|
||||
elif self.exceeded_max_loss:
|
||||
# in case of max_loss, signal to downstream
|
||||
# generators that we are done.
|
||||
event.dt = "DONE"
|
||||
event.perf_message = self.handle_simulation_end()
|
||||
del event['TRANSACTION']
|
||||
yield event
|
||||
# Cut off the rest of the stream.
|
||||
raise StopIteration()
|
||||
else:
|
||||
event.perf_message = self.process_event(event)
|
||||
event.portfolio = self.get_portfolio()
|
||||
@@ -245,9 +231,6 @@ class PerformanceTracker(object):
|
||||
|
||||
message = None
|
||||
|
||||
if self.exceeded_max_loss:
|
||||
return message
|
||||
|
||||
assert isinstance(event, zp.ndict)
|
||||
self.event_count += 1
|
||||
|
||||
@@ -296,19 +279,6 @@ class PerformanceTracker(object):
|
||||
# browser.
|
||||
daily_update = self.to_dict()
|
||||
|
||||
if self.trading_environment.max_drawdown:
|
||||
returns = self.todays_performance.returns
|
||||
max_dd = -1 * self.trading_environment.max_drawdown
|
||||
if returns < max_dd:
|
||||
log.info(str(returns) + " broke through " + str(max_dd))
|
||||
log.info("Exceeded max drawdown.")
|
||||
# mark the perf period with max loss flag,
|
||||
# so it shows up in the update, but don't end the test
|
||||
# here. Let the update go out before stopping
|
||||
self.exceeded_max_loss = True
|
||||
return daily_update
|
||||
|
||||
|
||||
#move the market day markers forward
|
||||
self.market_open = self.market_open + self.calendar_day
|
||||
|
||||
@@ -343,14 +313,11 @@ class PerformanceTracker(object):
|
||||
|
||||
# the stream will end on the last trading day, but will not trigger
|
||||
# an end of day, so we trigger the final market close here.
|
||||
# In the case of max drawdown, we needn't close again.
|
||||
if not self.exceeded_max_loss:
|
||||
self.handle_market_close()
|
||||
self.handle_market_close()
|
||||
|
||||
self.risk_report = risk.RiskReport(
|
||||
self.returns,
|
||||
self.trading_environment,
|
||||
exceeded_max_loss = self.exceeded_max_loss
|
||||
self.trading_environment
|
||||
)
|
||||
|
||||
risk_dict = self.risk_report.to_dict()
|
||||
|
||||
@@ -332,7 +332,7 @@ class RiskReport():
|
||||
self,
|
||||
algorithm_returns,
|
||||
trading_environment,
|
||||
exceeded_max_loss=False):
|
||||
):
|
||||
"""
|
||||
algorithm_returns needs to be a list of daily_return objects
|
||||
sorted in date ascending order
|
||||
@@ -340,7 +340,6 @@ class RiskReport():
|
||||
|
||||
self.algorithm_returns = algorithm_returns
|
||||
self.trading_environment = trading_environment
|
||||
self.exceeded_max_loss = exceeded_max_loss
|
||||
self.created = epoch_now()
|
||||
|
||||
if len(self.algorithm_returns) == 0:
|
||||
@@ -375,7 +374,6 @@ class RiskReport():
|
||||
'three_month' : [x.to_dict() for x in self.three_month_periods],
|
||||
'six_month' : [x.to_dict() for x in self.six_month_periods],
|
||||
'twelve_month' : [x.to_dict() for x in self.year_periods],
|
||||
'exceeded_max_loss' : self.exceeded_max_loss,
|
||||
'created' : self.created
|
||||
}
|
||||
|
||||
|
||||
@@ -49,8 +49,7 @@ class TradingEnvironment(object):
|
||||
treasury_curves,
|
||||
period_start = None,
|
||||
period_end = None,
|
||||
capital_base = None,
|
||||
max_drawdown = None
|
||||
capital_base = None
|
||||
):
|
||||
|
||||
self.trading_days = []
|
||||
@@ -61,7 +60,6 @@ class TradingEnvironment(object):
|
||||
self.period_end = period_end
|
||||
self.capital_base = capital_base
|
||||
self.period_trading_days = None
|
||||
self.max_drawdown = max_drawdown
|
||||
|
||||
assert self.period_start <= self.period_end, \
|
||||
"Period start falls after period end."
|
||||
|
||||
Reference in New Issue
Block a user