Commit Graph

601 Commits

Author SHA1 Message Date
Scott Sanderson b89fc0c028 BUG: Fix error from RequiredWindowLengthMixin.
WindowLengthNotSpecified expects an argument.
2015-08-04 01:41:03 -04:00
Scott Sanderson 7bb20eb297 MAINT: Check dates before computing factor_matrix.
In SimpleFFCEngine.factor_matrix barf with a useful error if end_date <=
start_date.
2015-08-03 12:06:24 -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
jfkirk 67c56f768b ENH: Adds auto-closing feature and implements for Futures 2015-07-31 10:38:44 -04:00
Scott Sanderson f13e9fd125 TEST: Add test asserting dynamic api_methods. 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
jfkirk 8d5bfd3c91 BUG: Aligns performance packet generation between minute and daily modes 2015-07-21 13:25:39 -04:00
Eddie Hebert ace2b5c9e9 PERF: Improve risk metrics update speed.
Remove the DataFrame of headline risk metrics, in favor of a numpy array
for each metric, like the underlying vectors.
2015-07-15 15:36:35 -04:00
Eddie Hebert 27ab36deb2 MAINT: Remove references to minute risk.
The minutely calculation of risk metrics had been removed with a
previous patch, remove vestigial references.

Remove a test which tested the behavior of updating the second minute of
a day.

Remove the logic that changed the datetime index of the risk metrics
depending on emission rate, now only trading_days are needed.

Remove `returns_frequency` parameter since both minute and daily
data frequency always use daily returns.
2015-07-15 15:36:35 -04:00
Eddie Hebert 36319122cc PERF: Change asset finder to be backed by sqlite3.
Attack the startup bottleneck of creating the asset finders caches for a
large universe, which was between 1-2 seconds on development and
production machines.

Instead, allow the AssetFinder to be passed a sqlite3 file that has
already been populated and then hydrate asset objects only when an
equity is referenced for the first time.

To create aforementioned sqlite3, create an AssetFinder with an db_path
and `create_table` set to True. If `create_table` is set to False, the
prepopulated data in the sqlite file found at db_path will be used.

Default behavior is to use an in memory database.

Behavior that changes:

- Fuzzy lookup now only works on one character, that character needs to be
specified at write/metadata consumption time, since the fuzzy lookup key
is created by dropping the character from each symbol.

- Overwriting partially written metadata is no longer
  supported. i.e. some unit tests allowed for inserting just the identifier,
  and then later updating the symbol, end_date, etc.

  Instead of building an upsert behavior at this time, this patch
  changes the unit tests so that the data for each asset is only
  inserted once.

Other notes:

- populate_cache is now removed, since there is no longer a two step
  process of inserting metadata and then realizing that metadata into
  assets. _spawn_asset is rolled into insert_metadata, so that a call to
  insert_metadata both converts the metadata and makes it available in
  the data store.
2015-07-14 09:54:38 -04:00
Andrew Daniels 2ab9f8a63c ENH: Futures API 2015-07-13 09:50:36 -04:00
Eddie Hebert ad4126bf58 STY: Remove unused import.
Mea culpa.
2015-07-10 17:03:44 -04:00
Eddie Hebert 2616a12551 TST: Remove test for lookup of future contract by symbol.
The lookup of future contract by individual symbol is a constraint on
incoming changes of changing how the asset finder stores data.

(i.e. the asset finder is changing so that there are separate tables for
both futures and equities.)

Since this lookup is not yet fully supported, we can add it back in on
top of the new asset finder.
2015-07-10 14:59:33 -04:00
jfkirk efa6d8dbce ENH: Adds a perf tracker method to handle SIDs leaving the universe 2015-07-09 17:03:21 -04:00
Andrew Daniels 7cde3939bf BUG: Determine valid future contracts with notice date
Since most brokers will cease accepting trades by the notice date, contracts should not be considered valid after the notice date. This commit adjusts the lookup_future_chain method to consider all contracts with notice dates on or following the current date invalid.
2015-07-09 15:23:29 -04:00
Eddie Hebert 9688989eba MAINT: Use symbol lookup directly from algorithm.
Instead of using the generic lookup, use the asset finder symbol method
directly when `symbol` is used in an algorithm.
2015-07-08 14:41:02 -04:00
Eddie Hebert f46fef1755 TST: Remove asset finder test for NASDAQ collisions.
The asset finder retrieved from the test environment is empty, so the
test does not end up testing anything, since the test cases loop over
the empty list of sids in the asset finder.

Remove to possibly be added back in and re-implemented after a larger
refactoring of the module.
2015-07-06 10:52:36 -04:00
Andrew Daniels 977c6cfcde MAINT: Consolidates and improves future lookup methods
Removes unused future lookup methods and consolidates everything into lookup_future_chain. Since the FutureChain object will have to hold a root symbol and dates, it should be responsible for cleaning the user input, so this is removed from the lookup method.

Adds knowledge date to future lookups. This makes our definition of valid contracts more flexible. We know about a contract if it starts trading by the knowledge date, and a contract is expired if it expires by the as_of_date.

Also fixes a bug with computing future chains, where contracts were not included in the chain on their expiration date.
2015-07-02 10:34:32 -04:00
jfkirk 1ec70b2a26 ENH: Removes use of lookup_generic in DataFrame index mapping 2015-07-01 13:43:31 -04:00
jfkirk 2421753509 TST: Fixes broken tests for DataFrameSource 2015-07-01 13:43:31 -04:00
jfkirk 258b5ea2ca API: DataFrame/Panel sources expect integer sids, not identifiers
This commit modifies the DataFrameSource and DataPanelSource to accept only Int64Indexes on the incoming data and moves the burden of mapping user identifiers to TradingAlgorithm.run().
2015-07-01 13:43:31 -04:00
jfkirk a4ce9712b8 DEP: Removes sids field from SimulationParameters 2015-07-01 13:43:31 -04:00
jfkirk 31f24a238a DEP: Removes unnecessary identifier_cache from asset_finder
The identifier cache's usage was nearly identical to using lookup_generic, so this commit removes identifier-keyed caching and modifies anything that uses it.
2015-07-01 13:43:31 -04:00
Eddie Hebert 7a1a6ddb37 PERF: Reduce time spent indexing in risk cumulative update.
Instead of using the pandas.Series datetime index for every single
vector, get the index at the beginning of the update loop based on the
dt and then use that index to set the values.

Also, since the dt lookup is no longer needed, store the values as numpy
arrays, which are more lightweight.

Locally, this patch cuts out about 60% of the time spent in the update
method.
2015-07-01 10:52:02 -04:00
Andrew Daniels 759f346c93 BUG: Fixes issues with AssetFinder future lookups
Contracts must have been trading at the as_of_date to be considered valid, and a contract's position in the chain is now zero-indexed.
2015-06-29 09:51:50 -04:00
Andrew Daniels cc77a52322 ENH: Adds future chain cache and future lookups to AssetFinder 2015-06-25 10:18:18 -04:00
Andrew Daniels 46e7b06991 ENH: Adds root_symbol attribute to Future class
Also update AssetFinder to handle root_symbol in meta data
2015-06-25 10:18:18 -04:00
Andrew Daniels 1ae6037a81 TST: Correct and clean up mock futures data for clarity 2015-06-25 10:18:18 -04:00
jfkirk 9291a89599 BUG: Prevents payout of dividend on final trading close 2015-06-24 21:45:55 -04:00
Scott Sanderson a2008f644a TEST: Remove unused test class. 2015-06-24 16:11:14 -04:00
Scott Sanderson a0cec5d093 TEST: Clean AssetFinder initialization and tests.
- AssetFinder no longer accepts an unused trading_calendar.
- AssetFinder correctly accepts a DataFrame as input.
- Tests for AssetFinder no longer rely on a global trading environment.
2015-06-24 09:50:09 -04:00
jfkirk aa92922ea8 ENH: Adds security_start_date and _end_date with deprecation warnings 2015-06-16 14:26:05 -04:00
jfkirk bfc992363e TST: Fixes broken test_close_position_event 2015-06-12 17:17:10 -04:00
jfkirk eced4e700d TST: Adds close position tests for both Equity and Future 2015-06-12 10:07:50 -04:00
jfkirk 4ef8df2fca ENH: Adds handling of Assets passed to AssetFinder as identifiers 2015-06-11 16:49:23 -04:00
jfkirk 3ee3a1226b BUG: Fixes handling of CLOSE_POSITION events for Futures 2015-06-11 11:40:54 -04:00
warren-oneill 0d7e23857e TST: add unittest for CLOSE_POSTION event type for futures, add commission to TestAlgorithm 2015-06-11 11:39:10 -04:00
jfkirk a5d1f79a37 TST: Reconciles tests with asset management system 2015-06-11 11:35:49 -04:00
jfkirk 035bfbd514 ENH: Adds AssetFinder and asset metadata management 2015-06-11 11:35:48 -04:00
jfkirk 9da644f767 ENH: Moves calling of TradingAlgorithm.initialize to _create_generator 2015-06-11 10:14:07 -04:00
warren-oneill 3d18a2954f TST:adds algo unittest for ClOSE_POSITON event type, adds commission as parameter to TestAlgorithm 2015-06-11 10:11:01 -04:00
warren-oneill 77fb100ae6 adding type as variable to create_test_panel 2015-06-04 15:50:41 +02:00
warren-oneill 44fbdff4ac added CLOSE_POSITION as source type, added pt.close_position_event(), added process_close_postion(), added close processing to tradesimulation, added unittest for close_position_event 2015-06-04 14:23:46 +02:00
jfkirk 9996502573 DEP: Removes use of 'count'-defined test sources
Test sources are now defined by the sim_params period_start and period_end, rather than by the period_start and a defined 'count' of bars. This allows us to consider the sim_params.period_end as the canonical definition of the end of a simulation.
2015-05-28 12:29:33 -04:00
Jonathan Kamens e32d79807f TEST: Object serialization test requires a trading environment
The object serialization test case requires a trading environment
because risk report generation requires treasury curves.
2015-05-12 15:25:44 -04:00
Eddie Hebert dba0a99a16 PERF: Use specific methods for processing events.
By having both the trade simulation main loop route events to "process"
methods based on event type and the process methods also checking event
type, there was some duplicated effort in doing that comparison many
times.

A particular case where this was noted in profiling was for the
`process_event` function which was checking if the type was not a trade
and returning early, when in a larger universe of stocks the value
returned False 99% of the time.

Instead provide separate process functions specific to each type,
e.g. e.g. `process_trade` and `process_transaction` and route traffic to
those functions in tradesimulation.

For a universe of 160 stocks on both no-op algo and an algo that rebuys
its universe every day, saw about a 10% increase locally.

Also:

- Add process_benchmark to blotter since internal subclass relies on
logic on benchmark, this allows the internal process_trade to be a
`pass`.

- Add warning on unrecoginzed event types.
2015-05-08 12:44:32 -04:00
Eddie Hebert 72ab9e74dd MAINT: Remove unused event_count from tracker.
event_count is not referenced anywhere, so remove extra bit of state
tracking.
2015-05-05 16:31:02 -04:00
Jonathan Kamens fd0530d889 MAINT: Flake8 2015-05-01 11:03:01 -04:00
Jonathan Kamens 557e6a3009 Every setup_logger needs a teardown_logger 2015-05-01 07:38:42 -04:00
Jonathan Kamens 656bd86c17 TST: One more overwrite_sim_params=False needed 2015-04-30 15:38:09 -04:00