Commit Graph

51 Commits

Author SHA1 Message Date
Scott Sanderson 6e8a4b8144 ENH: Improvements to rank().
- Add an `ascending=True` keyword to `rank()`.

- Add `top(N)` and `bottom(N)` methods to Factor.  These return Filters
  that pass the top and bottom N elements each day.

- Add a slightly faster path for rank(method='ordinal').  I had
  originally thought the fast path was 2-3x faster because I had my
  benchmark data axes flipped.  The actual speedup is only 5-10%, which
  means it probably wasn't worth the effort to Cythonize...but we have a
  slightly faster version now so we might as well use it.

- Refactor test_filter and test_factor to make it easier to implement
  and test transformations on factors.  These tests now subclass
  BaseFFCTestCase, which provides facilities for passing a dict of terms
  and an "initial_workspace", the values for which are used by
  SimpleFFCEngine rather than needing to manually manage the inputs and
  outputs of each term.
2015-08-31 00:32:33 -04:00
Scott Sanderson e0bd25cb18 MAINT: Remove temporary nullctx alias. 2015-08-05 18:36:37 -04:00
Scott Sanderson 5da03d2df5 BUG: Make NumExprFilter return ndarray.
- Previously it was returning a DataFrame because of how we applied an &
  with a DataFrame mask.  The error was masked by the fact that
  `np.assert_array_equal` coerces inputs to arrays before comparing.

- Added `zp.utils.test_utils.check_arrays`, which checks type equality
  before calling `np.assert_array_equal`.
2015-08-03 11:59:11 -04:00
Scott Sanderson 01c03d2267 MAINT: Add nullctx back to test_utils.
Temporary upstream compat for Quantopian code.

To be removed at the earliest possible convenience.
2015-07-29 12:30:46 -04:00
Scott Sanderson ef4f642e62 ENH: Compute engine architecture for FFC API.
This patch lays the groundwork for a compute engine designed to
facilitate construction of factor-based universe screening and portfolio
allocation.  It contains:

A new module, `zipline.modelling`, containing entities that can be used
to express computations as dependency graphs.  Each node in such a graph
is an instance of the base `Term` class, defined in
`zipline.modelling.term`.  Dependency graphs are executed by instances
of `FFCEngine`, defined in `zipline.modelling.engine`.

A new module, `zipline.data.ffc`, containing loaders and dataset
definitions for inputs to the modelling API.

New `TradingAlgorithm` api methods: `add_factor`, and `add_filter`.
These methods can only be called from `initialize`, and are used to
inform the algorithm that each day it should compute the given terms.
Computed factor results are made available through a new attribute of
the `data` object in `before_trading_start` and `handle_data`.  Computed
filter results control which assets are available in the factor matrix
on each day.
2015-07-29 12:30:46 -04:00
Jonathan Kamens ca0f906b11 TST: Don't modify master security lists directory during tests
Rather than drop files temporarily into the master security lists
directory during unit tests, create temporary directories for the
tests. This avoids issues when the tests are being run at the same
time as other code that uses the real security lists data.
2015-04-29 21:41:32 -04:00
Eddie Hebert 314b22656f MAINT: Remove left over simple transform code.
Remove pieces that are no longer used now that the simple transforms are
wrappers around history via the SIDData object.

Move window length related pieces into batch_transform, since the rest
of the utils module is no longer used.
2015-03-30 14:18:39 -04:00
fawce 1ab082102a first edition of leveraged etf list 2015-02-05 13:57:28 -05:00
Scott Sanderson 6e92b40ed9 MAINT/TEST: Move to_utc from history_cases.py to test_utils.py. 2014-06-09 17:40:06 -04:00
Scott Sanderson 644486e6da ENH: Add trading controls to zipline API.
Adds four new methods to the Zipline API that can be used as circuit-breakers
to interrupt the execution of an algorithm.  The API methods are:

`set_max_position_size`
`set_max_order_size`
`set_max_order_count`
`set_long_only`

Internally, these methods are implemented by each registering a TradingControl
callback object with the TradingAlgorithm.  During
TradingAlgorithm.__validate_order_params (and thus before any side-effects of
the order call occur), each callback's `validate` method is called with
information about the order to be placed and the algorithm's current state,
raising an exception if the callback detects that an error condition has been breached.
2014-05-12 17:51:09 -04:00
Eddie Hebert 9326a732a4 MAINT: Make exception handling tests compatible between Python 2 and 3
Python 3 removes the `.message` attribute, so use `str` instead.

Also, the divide by zero message has changed slightly between versions,
so just check for the exception type, instead of also checking the message.
2014-01-07 11:57:49 -05:00
Eddie Hebert b4959e46cf MAINT: Use six for Python 3 compatible names and behavior.
Use the six module to import functions and types that are
consistent between Python 2 and 3, so that one code base can
support both versions.

- Use integer types instead of int and long.
- Use string_types instead of basestring.
- Account for iteritems, itervalues, iterkeys.
- Use six.moves for filter and zip, reduce
- Use compatible bytes for md5 hasher.
- xrange and range
2014-01-07 11:33:50 -05:00
Eddie Hebert bbad5b386a MAINT: Removed unused test_utils.check functions.
The test_utils were the only references to the blist package,
removing so that blist can be removed as a dependency.
2013-12-02 13:19:00 -05:00
Eddie Hebert 6bbc131bbf MAINT: Compare datetime in test utils instead of integer.
Reduce dependency on date_utils, and improve legibility on failing
test.
2013-09-30 23:01:49 -04:00
Richard Frank 88b9881145 TST: Include the label in the failure message of isinstance asserts 2013-06-12 14:18:09 -04:00
fawce 4ed0250424 added a fake window_length to be compatible
with transform protocol
2013-05-01 22:42:17 -04:00
Jonathan Kamens 16e75a31d4 TST: Fix check() test utility function to detect all list differences
The check() function in zipline.utils.test_utils was only comparing
lists up to the length of the shortest list. This fix uses
izip_longest instead of izip so it compares up to the length of the
longest list, which among other things means that it will now
correctly report when one list is empty and the other is not.
2013-04-30 21:13:18 -04:00
fawce 9062b9636a MAINT: refactoring for orders api
- moved Order and Blotter to zipline.finance.blotter
- moved order method from AlgoSimulator to Blotter
- eliminated the set_order method in algorithm
- moved blotter to the algorithm
2013-04-26 19:45:59 -04:00
Richard Frank e8f6b43f2b TST: When comparing dicts, ensure they have the same keys.
dict 'b' might have more keys.
2013-04-15 16:57:44 -04:00
Eddie Hebert 35f57ada3e ENH: Send transactions and orders as standalone events.
- Add transaction and order types
- Move TransactionSimulator from trading.py to tradesimulation.py
  (only used by other members of the tradesimulation module)
- Make Transaction an independent event, like dividend
- Add Blotter class.
- Flatten the transaction events to be independent of trade bar events
- Make orders into events that reach performance (need to add
handling)
- Issue IDs to orders and tracking each transaction's order id.
- Make volume share slippage fill orders independently, rather than
  aggregating them into a single transaction.
- Perf tracker holds orders, serializes them with transactions.
- Order state defined and maintained by order class.
- Minutely emission of orders based on last_modified date.
2013-04-14 18:59:57 -04:00
fawce 2c7355a0dc Refactoring of TradingEnvironment to isolate the global state: index symbol and exchange timezone. Parameters that define the simulation (start, end, and capital base) were put in a new class, SimulationParameters.
Global state for the financial simulation environment is accessed through the
zipline.finance.trading module, which now contains a module variable:
environment.

Parameters are passed into an algorithm as a keyword argument, sim_params.
SimulationParameters creates a trading day index for the test period that
can be used to find trading days, calculate distance between trading days,
and other common operations. The sim params index is just selected from the
global state.

================

Details:

    - adding delorean to the requirements.
    - made index symbol a parameter for loading the benchmark data. changed
    messagepack storage to be symbol specific.
    - ported risk, performance, algorithm, transforms, batch transforms
    and associated tests to use simulation parameters and global environment
    - factory and sim factory use global state and sim params
    - factory method parameter names now reflect the class expected
2013-02-18 10:24:32 -05:00
Richard Frank f4be285dd7 Removed quarter utilities unused by zipline 2012-11-20 13:46:48 -05:00
Eddie Hebert 0c96915404 Removes requirement of existence /var/log/zipline.log
Instead log to test.log in working directory when running tests.

Also, removes config file for logging module, that is no longer
used since we are now using LogBook.
2012-10-12 11:27:42 -04:00
fawce 0bb0df525a pluggable slippage. 2012-09-14 12:33:10 -04:00
fawce 57a1834c5a refactored so that slippage is implemented as pluggable classes. 2012-09-13 21:22:01 -04:00
fawce c45c44b5c8 fixes per code review 2012-09-12 13:29:05 -04:00
fawce 1f55e8a033 added exception handling tests back. updates to support integration. 2012-09-10 23:06:13 -04:00
fawce b046518c45 tests passing with new lines.py. Still some zmq references left. 2012-09-08 22:44:22 -04:00
Eddie Hebert d90c531679 Removes core.monitor module.
The Monitor class that it provided was an artifact of a version
that depended on ZeroMQ as a communication layer instead of the
current generator bassed model.

Also, removes tests that were exercising the Monitor.
2012-09-05 15:24:30 -04:00
Eddie Hebert 72e64776b9 Applies PEP-8 recommendations to test_utils.
Whitespace wrangling.
2012-08-25 04:10:38 -04:00
Jonathan Kamens ad980e6485 Close test log handler at end of test to fix file descriptor leak 2012-08-21 22:29:51 -04:00
Jonathan Kamens 88e0afc7a0 Require zipline tests to end with a DONE packet 2012-08-21 16:16:34 -04:00
fawce c911dca4d2 added a kwarg to run in blocking 2012-08-16 13:01:22 -04:00
fawce 7f41a9435e new tests and support for logging primitives (bugfix) 2012-08-14 22:46:58 -04:00
fawce 7e86652a75 removed bson dep 2012-08-08 22:33:32 -04:00
fawce 9f98178a47 Merge branch 'new_world_order' of github.com:quantopian/zipline into new_world_order 2012-08-08 21:40:41 -04:00
fawce aec76868f9 exception handling 2012-08-08 21:40:33 -04:00
scottsanderson c64175e2e5 added tests for exception messages in datasources and transforms 2012-08-08 18:44:45 -04:00
fawce 427cfd53ec working on logging 2012-08-08 14:00:36 -04:00
fawce d2d9ef1359 removed a few debug calls 2012-08-07 17:55:27 -04:00
fawce e8f17083f7 merge 2012-08-07 17:49:56 -04:00
fawce aeb50da170 fixes for unit tests, back to 50/51 passing. 2012-08-07 14:42:43 -04:00
fawce 804bcb4e0c exceptions tests passing 2012-08-07 13:16:42 -04:00
fawce dd1056bf30 generator backed component, and a starter test for a source. 2012-08-01 23:41:44 -04:00
fawce 318065125f refactored component to use a generator 2012-08-01 21:43:15 -04:00
fawce 9deaefe6e6 fixes for tests 2012-07-30 13:52:38 -04:00
fawce abf9c8efa5 exception handling code revised. gevent, pypy, and threadsim vestiges removed.
devel flag removed.
2012-07-26 16:22:13 -04:00
fawce dd8c84b0db added stack trace to exception message, wrapped it in BT UPDATE FRAME 2012-07-25 14:40:14 -04:00
fawce c02d15016a added timeouts for component when waiting to hear from the monitor. proof of concept exception relay for algorithm's initialize method. 2012-07-24 23:43:40 -04:00
fawce d950973f0d added a proc join to ensure we block on the simulation fully exiting all processes. 2012-07-24 17:43:49 -04:00