mirror of
https://github.com/wassname/catalyst.git
synced 2026-07-11 05:30:32 +08:00
One test passing, progress!
This commit is contained in:
+2
-2
@@ -1,5 +1,5 @@
|
||||
[loggers]
|
||||
keys=root,simpleExample
|
||||
keys=root
|
||||
|
||||
[handlers]
|
||||
keys=consoleHandler,filesystemHandler
|
||||
@@ -17,7 +17,7 @@ qualname=ZiplineLogger
|
||||
# -------
|
||||
|
||||
[handler_filesystemHandler]
|
||||
class=RotatingFileHandler
|
||||
class=handlers.RotatingFileHandler
|
||||
level=DEBUG
|
||||
formatter=ziplineformat
|
||||
args=("/var/log/zipline/zipline.log",10*1024*1024,5)
|
||||
|
||||
@@ -8,21 +8,21 @@ from collections import defaultdict
|
||||
|
||||
from nose.tools import timed
|
||||
|
||||
import zipline.test.factory as factory
|
||||
import zipline.util as qutil
|
||||
import zipline.utils.factory as factory
|
||||
from zipline.utils import logger
|
||||
import zipline.finance.risk as risk
|
||||
import zipline.protocol as zp
|
||||
import zipline.finance.performance as perf
|
||||
|
||||
from zipline.test.algorithms import TestAlgorithm
|
||||
from zipline.test_algorithms import TestAlgorithm
|
||||
from zipline.sources import SpecificEquityTrades
|
||||
from zipline.finance.trading import TransactionSimulator, \
|
||||
TradeSimulationClient, TradingEnvironment
|
||||
from zipline.simulator import AddressAllocator, Simulator
|
||||
from zipline.monitor import Controller
|
||||
from zipline.core.monitor import Controller
|
||||
from zipline.lines import SimulatedTrading
|
||||
from zipline.finance.performance import PerformanceTracker
|
||||
from zipline.protocol_utils import namedict
|
||||
from zipline.utils.protocol_utils import namedict
|
||||
from zipline.finance.trading import SIMULATION_STYLE
|
||||
|
||||
DEFAULT_TIMEOUT = 15 # seconds
|
||||
@@ -35,7 +35,7 @@ class FinanceTestCase(TestCase):
|
||||
leased_sockets = defaultdict(list)
|
||||
|
||||
def setUp(self):
|
||||
qutil.configure_logging()
|
||||
#qutil.configure_logging()
|
||||
self.zipline_test_config = {
|
||||
'allocator':allocator,
|
||||
'sid':133
|
||||
@@ -511,4 +511,4 @@ class FinanceTestCase(TestCase):
|
||||
self.assertEqual(0, len(order_list))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import uuid
|
||||
import time
|
||||
import socket
|
||||
import gevent
|
||||
import logging
|
||||
import traceback
|
||||
import humanhash
|
||||
|
||||
@@ -22,11 +23,11 @@ import gevent_zeromq
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
import zipline.util as qutil
|
||||
from zipline.gpoll import _Poller as GeventPoller
|
||||
from utils.gpoll import _Poller as GeventPoller
|
||||
from zipline.protocol import CONTROL_PROTOCOL, COMPONENT_STATE, \
|
||||
COMPONENT_FAILURE, BACKTEST_STATE, CONTROL_FRAME
|
||||
|
||||
LOGGER = logging.getLogger('ZiplineLogger')
|
||||
|
||||
class Component(object):
|
||||
"""
|
||||
@@ -314,7 +315,7 @@ class Component(object):
|
||||
)
|
||||
self.control_out.send(exception_frame)
|
||||
|
||||
qutil.LOGGER.exception("Unexpected error in run for {id}.".format(id=self.get_id))
|
||||
LOGGER.exception("Unexpected error in run for {id}.".format(id=self.get_id))
|
||||
|
||||
def signal_done(self):
|
||||
"""
|
||||
@@ -341,7 +342,7 @@ class Component(object):
|
||||
#notify internal work look that we're done
|
||||
self.done = True # TODO: use state flag
|
||||
|
||||
qutil.LOGGER.info("[%s] DONE" % self.get_id)
|
||||
LOGGER.info("[%s] DONE" % self.get_id)
|
||||
|
||||
# -----------
|
||||
# Messaging
|
||||
@@ -461,7 +462,7 @@ class Component(object):
|
||||
DEPRECATED, left in for compatability for now.
|
||||
"""
|
||||
|
||||
qutil.LOGGER.debug("Connecting sync client for {id}".format(id=self.get_id))
|
||||
LOGGER.debug("Connecting sync client for {id}".format(id=self.get_id))
|
||||
|
||||
self.sync_socket = self.context.socket(self.zmq.REQ)
|
||||
self.sync_socket.connect(self.addresses['sync_address'])
|
||||
|
||||
@@ -110,6 +110,8 @@ Performance Period
|
||||
|
||||
|
||||
"""
|
||||
|
||||
import logging
|
||||
import datetime
|
||||
import pytz
|
||||
import msgpack
|
||||
@@ -118,10 +120,11 @@ import math
|
||||
|
||||
import zmq
|
||||
|
||||
import zipline.util as qutil
|
||||
import zipline.protocol as zp
|
||||
import zipline.finance.risk as risk
|
||||
|
||||
LOGGER = logging.getLogger('ZiplineLogger')
|
||||
|
||||
class PerformanceTracker():
|
||||
"""
|
||||
Tracks the performance of the zipline as it is running in
|
||||
@@ -280,8 +283,8 @@ class PerformanceTracker():
|
||||
returns = self.todays_performance.returns
|
||||
max_dd = -1 * self.trading_environment.max_drawdown
|
||||
if returns < max_dd:
|
||||
qutil.LOGGER.info(str(returns) + " broke through " + str(max_dd))
|
||||
qutil.LOGGER.info("Exceeded max drawdown.")
|
||||
LOGGER.info(str(returns) + " broke through " + str(max_dd))
|
||||
LOGGER.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
|
||||
@@ -316,8 +319,8 @@ class PerformanceTracker():
|
||||
"""
|
||||
|
||||
log_msg = "Simulated {n} trading days out of {m}."
|
||||
qutil.LOGGER.info(log_msg.format(n=self.day_count, m=self.total_days))
|
||||
qutil.LOGGER.info("first open: {d}".format(d=self.trading_environment.first_open))
|
||||
LOGGER.info(log_msg.format(n=self.day_count, m=self.total_days))
|
||||
LOGGER.info("first open: {d}".format(d=self.trading_environment.first_open))
|
||||
|
||||
# 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.
|
||||
@@ -332,7 +335,7 @@ class PerformanceTracker():
|
||||
)
|
||||
|
||||
if self.result_stream:
|
||||
qutil.LOGGER.info("about to stream the risk report...")
|
||||
LOGGER.info("about to stream the risk report...")
|
||||
risk_dict = self.risk_report.to_dict()
|
||||
|
||||
msg = zp.RISK_FRAME(risk_dict)
|
||||
|
||||
@@ -42,7 +42,6 @@ import math
|
||||
import pytz
|
||||
import numpy as np
|
||||
import numpy.linalg as la
|
||||
import zipline.util as qutil
|
||||
import zipline.protocol as zp
|
||||
|
||||
LOGGER = logging.getLogger('ZiplineLogger')
|
||||
@@ -245,7 +244,7 @@ class RiskMetrics():
|
||||
cur_return = math.log(1.0 + r) + cur_return
|
||||
#this is a guard for a single day returning -100%
|
||||
except ValueError:
|
||||
qutil.LOGGER.warn("{cur} return, zeroing the returns".format(cur=cur_return))
|
||||
LOGGER.warn("{cur} return, zeroing the returns".format(cur=cur_return))
|
||||
cur_return = 0.0
|
||||
compounded_returns.append(cur_return)
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import logging
|
||||
import datetime
|
||||
import pytz
|
||||
import math
|
||||
@@ -7,14 +8,12 @@ import time
|
||||
from collections import Counter
|
||||
|
||||
# from gevent.select import select
|
||||
from zmq.core.poll import select
|
||||
|
||||
import zipline.messaging as qmsg
|
||||
import zipline.util as qutil
|
||||
import zipline.protocol as zp
|
||||
import zipline.finance.performance as perf
|
||||
|
||||
from zipline.protocol_utils import Enum, namedict
|
||||
from zipline.utils.protocol_utils import Enum, namedict
|
||||
|
||||
# the simulation style enumerates the available transaction simulation
|
||||
# strategies.
|
||||
@@ -25,6 +24,8 @@ SIMULATION_STYLE = Enum(
|
||||
'NOOP'
|
||||
)
|
||||
|
||||
LOGGER = logging.getLogger('ZiplineLogger')
|
||||
|
||||
class TradeSimulationClient(qmsg.Component):
|
||||
|
||||
def __init__(self, trading_environment, sim_style):
|
||||
@@ -94,7 +95,7 @@ class TradeSimulationClient(qmsg.Component):
|
||||
self.finish_simulation()
|
||||
|
||||
def finish_simulation(self):
|
||||
qutil.LOGGER.info("Client is DONE!")
|
||||
LOGGER.info("Client is DONE!")
|
||||
# signal the performance tracker that the simulation has
|
||||
# ended. Perf will internally calculate the full risk report.
|
||||
self.perf.handle_simulation_end()
|
||||
@@ -219,7 +220,7 @@ class TransactionSimulator(object):
|
||||
log = "requested to trade zero shares of {sid}".format(
|
||||
sid=event.sid
|
||||
)
|
||||
qutil.LOGGER.debug(log)
|
||||
LOGGER.debug(log)
|
||||
return
|
||||
|
||||
if(not self.open_orders.has_key(event.sid)):
|
||||
@@ -343,7 +344,7 @@ for orders:
|
||||
event=str(event),
|
||||
orders=str(orders)
|
||||
)
|
||||
qutil.LOGGER.warn(warning)
|
||||
LOGGER.warn(warning)
|
||||
return None
|
||||
|
||||
|
||||
|
||||
+6
-4
@@ -62,6 +62,7 @@ before invoking simulate.
|
||||
|
||||
import mock
|
||||
import pytz
|
||||
import logging
|
||||
|
||||
from datetime import datetime, timedelta
|
||||
from collections import defaultdict
|
||||
@@ -69,19 +70,19 @@ from collections import defaultdict
|
||||
from nose.tools import timed
|
||||
|
||||
import zipline.utils.factory as factory
|
||||
import zipline.util as qutil
|
||||
import zipline.finance.risk as risk
|
||||
import zipline.protocol as zp
|
||||
import zipline.finance.performance as perf
|
||||
import zipline.messaging as zmsg
|
||||
|
||||
from zipline.test.algorithms import TestAlgorithm
|
||||
from zipline.test_algorithms import TestAlgorithm
|
||||
from zipline.sources import SpecificEquityTrades
|
||||
from zipline.finance.trading import TradeSimulationClient
|
||||
from zipline.simulator import AddressAllocator, Simulator
|
||||
from zipline.monitor import Controller
|
||||
from zipline.core.monitor import Controller
|
||||
from zipline.finance.trading import SIMULATION_STYLE
|
||||
|
||||
LOGGER = logging.getLogger('ZiplineLogger')
|
||||
|
||||
class SimulatedTrading(object):
|
||||
"""
|
||||
@@ -141,8 +142,9 @@ class SimulatedTrading(object):
|
||||
self.con = Controller(
|
||||
sockets[6],
|
||||
sockets[7],
|
||||
logging = qutil.LOGGER
|
||||
logging = LOGGER
|
||||
)
|
||||
self.con.cancel_socket = self.allocator.lease(1)[0]
|
||||
|
||||
# TODO: Not freeform
|
||||
self.con.manage(
|
||||
|
||||
@@ -4,14 +4,16 @@ Commonly used messaging components.
|
||||
|
||||
import datetime
|
||||
|
||||
import logging
|
||||
from collections import Counter
|
||||
|
||||
import zipline.util as qutil
|
||||
from zipline.component import Component
|
||||
import zipline.protocol as zp
|
||||
from zipline.protocol import CONTROL_PROTOCOL, COMPONENT_TYPE, \
|
||||
COMPONENT_STATE, CONTROL_FRAME, CONTROL_UNFRAME
|
||||
|
||||
LOGGER = logging.getLogger('ZiplineLogger')
|
||||
|
||||
class ComponentHost(Component):
|
||||
"""
|
||||
Components that can launch multiple sub-components, synchronize their
|
||||
@@ -95,7 +97,7 @@ class ComponentHost(Component):
|
||||
"""
|
||||
Setup the sync socket and poller. ( Bind )
|
||||
"""
|
||||
qutil.LOGGER.debug("Connecting sync server.")
|
||||
LOGGER.debug("Connecting sync server.")
|
||||
|
||||
self.sync_socket = self.context.socket(self.zmq.REP)
|
||||
self.sync_socket.bind(self.addresses['sync_address'])
|
||||
@@ -118,7 +120,7 @@ class ComponentHost(Component):
|
||||
cur_time = datetime.datetime.utcnow()
|
||||
|
||||
if len(self.components) == 0:
|
||||
qutil.LOGGER.info("Component register is empty.")
|
||||
LOGGER.info("Component register is empty.")
|
||||
return False
|
||||
|
||||
return True
|
||||
@@ -140,7 +142,7 @@ class ComponentHost(Component):
|
||||
self.signal_exception(exc)
|
||||
|
||||
if status == str(CONTROL_PROTOCOL.DONE): # TODO: other way around
|
||||
#qutil.LOGGER.debug("{id} is DONE".format(id=sync_id))
|
||||
LOGGER.debug("{id} is DONE".format(id=sync_id))
|
||||
self.unregister_component(sync_id)
|
||||
self.state_flag = COMPONENT_STATE.DONE
|
||||
else:
|
||||
@@ -243,7 +245,7 @@ class Feed(Component):
|
||||
|
||||
if len(self.data_buffer) == self.ds_finished_counter:
|
||||
#drain any remaining messages in the buffer
|
||||
qutil.LOGGER.debug("draining feed")
|
||||
LOGGER.debug("draining feed")
|
||||
self.drain()
|
||||
self.signal_done()
|
||||
else:
|
||||
|
||||
@@ -5,9 +5,8 @@ Simulator hosts all the components necessary to execute a simluation. See :py:me
|
||||
import threading
|
||||
import mock
|
||||
from collections import defaultdict
|
||||
from zipline.monitor import Controller
|
||||
from zipline.core.monitor import Controller
|
||||
from zipline.messaging import ComponentHost
|
||||
import zipline.util as qutil
|
||||
|
||||
class AddressAllocator(object):
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ from zipline.sources import SpecificEquityTrades, RandomEquityTrades
|
||||
from zipline.finance.trading import TradingEnvironment
|
||||
|
||||
def load_market_data():
|
||||
fp_bm = open("./zipline/test/benchmark.msgpack", "rb")
|
||||
fp_bm = open("./tests/benchmark.msgpack", "rb")
|
||||
bm_list = msgpack.loads(fp_bm.read())
|
||||
bm_returns = []
|
||||
for packed_date, returns in bm_list:
|
||||
@@ -27,7 +27,7 @@ def load_market_data():
|
||||
daily_return = risk.DailyReturn(date=event_dt, returns=returns)
|
||||
bm_returns.append(daily_return)
|
||||
bm_returns = sorted(bm_returns, key=lambda(x): x.date)
|
||||
fp_tr = open("./zipline/test/treasury_curves.msgpack", "rb")
|
||||
fp_tr = open(".//tests/treasury_curves.msgpack", "rb")
|
||||
tr_list = msgpack.loads(fp_tr.read())
|
||||
tr_curves = {}
|
||||
for packed_date, curve in tr_list:
|
||||
|
||||
@@ -6,4 +6,4 @@ and other common operations.
|
||||
import logging
|
||||
import logging.config
|
||||
|
||||
logging.config.fileConfig('logging.conf')
|
||||
logging.config.fileConfig('logging.cfg')
|
||||
Reference in New Issue
Block a user