Applies PEP-8 recommendations, mostly whitespace cleanup.

Also, changes has_key to use `in`
This commit is contained in:
Eddie Hebert
2012-08-23 14:48:05 -04:00
parent b0252e8e64
commit 4337a429ff
+23 -19
View File
@@ -87,6 +87,7 @@ class CancelSignal(Exception):
def __init__(self):
pass
class SimulatedTrading(object):
def __init__(self,
@@ -102,7 +103,8 @@ class SimulatedTrading(object):
self.date_sorted = date_sorted_sources(*sources)
self.transforms = transforms
# Formerly merged_transforms.
self.with_tnfms = sequential_transforms(self.date_sorted, *self.transforms)
self.with_tnfms = sequential_transforms(self.date_sorted,
*self.transforms)
self.trading_client = tsc(algorithm, environment, style)
self.gen = self.trading_client.simulate(self.with_tnfms)
self.results_uri = results_socket_uri
@@ -149,7 +151,7 @@ class SimulatedTrading(object):
"Results socket must exist to stream results"
try:
for event in self.gen:
if event.has_key('daily_perf'):
if 'daily_perf' in event:
msg = zp.PERF_FRAME(event)
else:
msg = zp.RISK_FRAME(event)
@@ -180,7 +182,7 @@ class SimulatedTrading(object):
else:
log.warning("Sending SIGINT")
os.kill(ppid, SIGINT)
def handle_exception(self, exc):
if isinstance(exc, CancelSignal):
# signal from monitor of an orderly shutdown,
@@ -207,7 +209,7 @@ class SimulatedTrading(object):
exc_type.__name__,
exc_value.message
)
self.results_socket.send(msg)
except:
log.exception("Exception while reporting simulation exception.")
@@ -228,8 +230,8 @@ class SimulatedTrading(object):
# bubbled. Since we do not want user logs in our system
# logs, we set bubble to False.
self.zmq_out = ZeroMQLogHandler(
socket = self.results_socket,
filter = lambda r, h: r.channel in ['Print', 'AlgoLog'],
socket=self.results_socket,
filter=lambda r, h: r.channel in ['Print', 'AlgoLog'],
bubble=False
)
@@ -263,7 +265,8 @@ class SimulatedTrading(object):
is the source, with daily frequency in trades.
- simulation_style: optional parameter that configures the
:py:class:`zipline.finance.trading.TransactionSimulator`. Expects
a SIMULATION_STYLE as defined in :py:mod:`zipline.finance.trading`
a SIMULATION_STYLE as defined in
:py:mod:`zipline.finance.trading`
- transforms: optional parameter that provides a list
of StatefulTransform objects.
"""
@@ -278,22 +281,22 @@ class SimulatedTrading(object):
#--------------------
# Trading Environment
#--------------------
if config.has_key('environment'):
if 'environment' in config:
trading_environment = config['environment']
else:
trading_environment = factory.create_trading_environment()
if config.has_key('order_count'):
if 'order_count' in config:
order_count = config['order_count']
else:
order_count = 100
if config.has_key('order_amount'):
if 'order_amount' in config:
order_amount = config['order_amount']
else:
order_amount = 100
if config.has_key('trade_count'):
if 'trade_count' in config:
trade_count = config['trade_count']
else:
# to ensure all orders are filled, we provide one more
@@ -304,14 +307,14 @@ class SimulatedTrading(object):
if not simulation_style:
simulation_style = SIMULATION_STYLE.FIXED_SLIPPAGE
zmq_context = config.get('zmq_context', None)
simulation_id = config.get('simulation_id', 'test_simulation')
results_socket_uri = config.get('results_socket_uri', None)
zmq_context = config.get('zmq_context', None)
simulation_id = config.get('simulation_id', 'test_simulation')
results_socket_uri = config.get('results_socket_uri', None)
#-------------------
# Trade Source
#-------------------
if config.has_key('trade_source'):
if 'trade_source' in config:
trade_source = config['trade_source']
else:
trade_source = factory.create_daily_trade_source(
@@ -321,7 +324,6 @@ class SimulatedTrading(object):
concurrent=concurrent_trades
)
#-------------------
# Transforms
#-------------------
@@ -330,7 +332,7 @@ class SimulatedTrading(object):
#-------------------
# Create the Algo
#-------------------
if config.has_key('algorithm'):
if 'algorithm' in config:
test_algo = config['algorithm']
else:
test_algo = TestAlgorithm(
@@ -356,6 +358,7 @@ class SimulatedTrading(object):
return sim
class SimulatedTradingLite(object):
"""
SimulatedTrading without multiprocess and without zmq.
@@ -372,9 +375,10 @@ class SimulatedTradingLite(object):
self.date_sorted = date_sorted_sources(*sources)
self.transforms = transforms
# Formerly merged_transforms.
self.with_tnfms = sequential_transforms(self.date_sorted, *self.transforms)
self.with_tnfms = sequential_transforms(self.date_sorted,
*self.transforms)
self.trading_client = tsc(algorithm, environment, style)
self.gen = self.trading_client.simulate(self.with_tnfms)
def get_results(self):
return self.gen