mirror of
https://github.com/wassname/catalyst.git
synced 2026-06-28 11:51:47 +08:00
clarifying the results protocol for the backtest.
This commit is contained in:
@@ -352,10 +352,10 @@ class RiskReport():
|
||||
provided for each period.
|
||||
"""
|
||||
return {
|
||||
'1_month' : [x.to_dict() for x in self.month_periods],
|
||||
'3_month' : [x.to_dict() for x in self.three_month_periods],
|
||||
'6_month' : [x.to_dict() for x in self.six_month_periods],
|
||||
'12_month' : [x.to_dict() for x in self.year_periods]
|
||||
'one_month' : [x.to_dict() for x in self.month_periods],
|
||||
'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]
|
||||
}
|
||||
|
||||
def periodsInRange(self, months_per, start, end):
|
||||
|
||||
+12
-14
@@ -421,20 +421,7 @@ class TransactionSimulator(qmsg.BaseTransform):
|
||||
# we cap the volume share at 25% of a trade
|
||||
if volume_share == .25:
|
||||
break
|
||||
|
||||
if simulated_amount == 0:
|
||||
warning = """
|
||||
Calculated a zero volume transation on trade:
|
||||
{event}
|
||||
for order:
|
||||
{order}
|
||||
"""
|
||||
warning = warning.format(
|
||||
event=str(event),
|
||||
order=str(order)
|
||||
)
|
||||
qutil.LOGGER.warn(warning)
|
||||
|
||||
|
||||
orders = [ x for x in orders if abs(x.amount - x.filled) > 0 and x.dt.day >= event.dt.day]
|
||||
|
||||
self.open_orders[event.sid] = orders
|
||||
@@ -449,6 +436,17 @@ for order:
|
||||
direction
|
||||
)
|
||||
else:
|
||||
warning = """
|
||||
Calculated a zero volume transaction on trade:
|
||||
{event}
|
||||
for order:
|
||||
{order}
|
||||
"""
|
||||
warning = warning.format(
|
||||
event=str(event),
|
||||
order=str(order)
|
||||
)
|
||||
qutil.LOGGER.warn(warning)
|
||||
return None
|
||||
|
||||
|
||||
|
||||
+18
-8
@@ -615,10 +615,8 @@ def PERF_FRAME(perf):
|
||||
"""
|
||||
Frame the performance update created at the end of each simulated trading
|
||||
day. The msgpack is a tuple with the first element statically set to 'PERF'.
|
||||
Frames prepared by this method are sent via the same socket as
|
||||
Frames prepared by RISK_FRAME. So, both methods prefix the payload with
|
||||
a shorthand for their type. That way, all messages received from the socket
|
||||
can be PERF_UNFRAMED(), whether they are risk or perf.
|
||||
Like RISK_FRAME, this method calls BT_UPDATE_FRAME internally, so that
|
||||
clients can call BT_UPDATE_UNFRAME for all messages from the backtest.
|
||||
|
||||
:param perf: the dictionary created by zipline.trade_client.perf
|
||||
:rvalue: a msgpack string
|
||||
@@ -666,7 +664,7 @@ def PERF_FRAME(perf):
|
||||
|
||||
perf['returns'] = returns
|
||||
|
||||
return msgpack.dumps(tuple(['PERF', perf]))
|
||||
return BT_UPDATE_FRAME('PERF', perf)
|
||||
|
||||
def convert_transactions(transactions):
|
||||
results = []
|
||||
@@ -677,10 +675,22 @@ def convert_transactions(transactions):
|
||||
return results
|
||||
|
||||
def RISK_FRAME(risk):
|
||||
return msgpack.dumps(tuple(['RISK', risk]))
|
||||
return BT_UPDATE_FRAME('RISK', risk)
|
||||
|
||||
|
||||
def PERF_UNFRAME(msg):
|
||||
def BT_UPDATE_FRAME(prefix, payload):
|
||||
"""
|
||||
Frames prepared by RISK_FRAME and PERF_FRAME methods are sent via the same
|
||||
socket. This method provides a prefix to allow for muxing the messages
|
||||
onto a single socket.
|
||||
"""
|
||||
return msgpack.dumps(tuple([prefix, payload]))
|
||||
|
||||
def BT_UPDATE_UNFRAME(msg):
|
||||
"""
|
||||
Risk and Perf framing methods prefix the payload with
|
||||
a shorthand for their type. That way, all messages received from the socket
|
||||
can be PERF_FRAMED(), whether they are risk or perf.
|
||||
"""
|
||||
prefix, payload = msgpack.loads(msg, use_list=True)
|
||||
return dict(prefix=prefix, payload=payload)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user