Commit Graph

662 Commits

Author SHA1 Message Date
Scott Sanderson b766ce6ebd ENH: Add zipline.utils.cache.
Implements a `CachedObject` utility class for wrapping cached results
with an expiration date.
2015-10-01 18:03:53 -04:00
Scott Sanderson 00c413e9d4 ENH: Add zipline.utils.preprocess.
Implements tools for preprocessing the arguments to user-facing
functions.
2015-10-01 18:03:53 -04:00
Scott Sanderson 75138343ba BUG: Use IGNORE_EXCEPTION_DETAIL in test_doctests.
Causes doctest to not care about the module of the raised exception.
This matters because Python3 includes the module in the formatted
exception, but Python3 doesn't, so the doctest will always fail on one
or the other without this flag.
2015-10-01 18:03:53 -04:00
Stewart Douglas 8ba15a6f72 BUG: Correctly test for duplicate symbols 2015-10-01 15:02:23 -04:00
Eddie Hebert 23e7433635 TST: Make params explicit to calc results.
Change calculate_results to take explicit parameters for sim_params, env
and benchmark_events instead of reading those values off of the TestCase
instance.

This prepares for tests setting specific sim_params in each test case,
which is needed for an incoming refactoring of how the test data is set up.
2015-09-29 14:36:45 -04:00
Eddie Hebert 9581afb32a TST: Remove random simulation parameters.
For better predictability/ability to reason and step through the test
cases, use the same start and end for each run of the test suite.
2015-09-29 14:36:45 -04:00
Eddie Hebert cbb3d807b7 TST: Remove instant fill from close position test.
'instant fill' execution may be on the path to deprecation, (the removal
is currently proposed by the branch which removes events in favor of
operating over dts.), so remove instant_fill from the close position
tests so that the input and output is the same between the proposed
branch and here.

(This was one of the few places where instant fill was used that
was not testing instant fill behavior explicitly, so may be better to
align this test with the rest of the suite.)

Also, change test methods to make it more clear on which day the values
the expected and actual results differed.
2015-09-28 14:48:19 -04:00
Eddie Hebert 5d2217b0eb Merge pull request #726 from quantopian/explicit-position-value-calcs
MAINT: Only calc position values once per packet.
2015-09-25 17:33:53 -04:00
Eddie Hebert c88412e3f1 TST: Add coverage for long and short count.
Make basic checks of position stats test all fields, by adding coverage
for `shorts_count` and `longs_count`.
2015-09-25 16:42:25 -04:00
Richard Frank 136eb8aa0d BUG: Running an algo with a df/panel of Assets was raising SidNotFound 2015-09-24 21:49:45 -04:00
Richard Frank 0b6b11a080 MAINT: Removed some unnecessary instance attributes 2015-09-24 21:49:45 -04:00
Eddie Hebert ae97e75388 MAINT: Only calc position values once per packet.
Instead of calculating the position values for each stat result, e.g.
gross_exposure, net_liquidity etc.; get the positions upfront and then
calculate the period and position stats in order, passing each value
explicitly to the ones that follow it in the dependency chain.

e.g. the gross_value depends on the long_value and the short_value,
which called the position_values property for calculating both the
long_value and the short_value.

Removing the repeated calls to position_values (and
position_exposures) removes the need for the caching the last sale
prices and position amounts in separate vectors, since it is inexpensive
enough to read those values off of the positions dictionary held in the
position tracker.

This patch gives a small gain to ~500 sized portfolios, but the main
intent is to clear the path to not storing last_sale_prices on the
position objects at all. Removing all of the caching layer in this class
makes that change easier to apply. Removing the extra calls to
position_values also made this class easier to step through/reason about
when splicing in the new last sale price access, as well.
2015-09-23 22:26:13 -04:00
Scott Sanderson bd147a084e BUG: Fix crash on .latest for integer-typed columns.
Int columns get coerced to float on load, and we don't currently support
non-float columns from CustomFactors.
2015-09-21 13:20:26 -04:00
John Ricklefs 38ff4cc913 BUG: Normalize dates in AssetDateBounds control checks
Assumes that if a given asset's end_date is
e.g. 9/17/2015 00:00:00 UTC that it means the
asset is still tradeable on 9/17/2015 during
the market day.
2015-09-18 15:19:15 -04:00
jfkirk 082bc4f906 MAINT: Removes default_none from lookup_symbol 2015-09-16 14:55:42 -04:00
jfkirk c446e7f62a ENH: Adds fuzzy symbol look-up and makes it distinct from delimited symbols 2015-09-16 14:34:18 -04:00
jfkirk d84bdefef8 MAINT: Removes lookup_symbol_resolve_multiple method
lookup_symbol_resolve_multiple was identical to lookup_symbol, except that lookup_symbol performed upper-casing of the input string and lookup_symbol would return Nones. Now, lookup_symbol has a kwarg 'default_None=True' and all symbols are upper-cased on insertion and request.
2015-09-16 09:54:37 -04:00
jfkirk 29dce965d5 ENH: Simplifies AssetFinder symbol lookup by making fuzzy lookup the default 2015-09-16 09:54:11 -04:00
Scott Sanderson 26fd6fda8b ENH/BUG: Modeling API enhancements.
- Fixes an error where Modeling API data known as of the close of `day
  N` would be shown to algorithms during `before_trading_start` as of
  the close of the same day.  Algorithms should now only receive data
  during `before_trading_start/handle_data` that was known as of the
  simulation time at which the function would be called.

- All Term instances now have a `mask` attribute that must be a `Filter`
  or an instance of `AssetExists()`.  `mask` can be used to specify that
  a Factor should be computed in a manner that ignores the values that
  were not `True` in the mask.

- Changed the interface for `FFCLoader.load_adjusted_array` and
  `Term._compute` from `(columns, mask)`, with mask as a DataFrame, to
  `(columns, dates, assets, mask)`, where mask is a numpy array.  This
  is primarily to avoid having to reconstruct extra DataFrames when
  using masks produced by non `AssetExists` filters.

- Adds `BoundColumn.latest`, which gives the most-recently-known value
  of a column.
2015-09-16 01:47:11 -04:00
Scott Sanderson 46882bfcb9 TST: Remove unnecessary instance attr assignments. 2015-09-16 01:28:16 -04:00
Scott Sanderson 5730de25a4 DEV: Kill compute_from_{arrays,windows}.
All terms just implement `_compute` now. (We reserve `compute` for the
public API of `CustomFactor`.)

Also removed `TestingTermMixin` and its subclasses in favor of just
using `CustomFactor.`
2015-09-16 01:28:15 -04:00
Scott Sanderson 58ceb7b7bb DEV: Add zipline.utils.memoize.
- Moved zipline.utils.lazyval.
- Added `remember_last` which is just `lru_cache(1)` with simpler logic.
2015-09-16 01:28:15 -04:00
Scott Sanderson ad54eedeea Revert "MAINT: AssetFinder now takes fuzzy characters on look-up, not init"
This reverts commit c16bc9f8db.  This
caused upstream breakage unexpectedly.  Postponing until we can synchronize.
2015-09-15 23:57:25 -04:00
jfkirk c16bc9f8db MAINT: AssetFinder now takes fuzzy characters on look-up, not init 2015-09-15 09:38:17 -04:00
Thomas Wiecki 6f2e1672d7 BUG: Forward initialize args and kwargs to user-defined function.
The initialize method of TradingAlgorithm no longer accepts and
silently ignores args and kwargs, but instead forwards them
to the user-defined function referenced by self._initialize.

To avoid passing unexpected arguments to self._initialize, the
following additional adjustments are made:

 - pop 'namespace' from the kwargs supplied to TradingAlgorithm
   rather than simply get()ing it

 - do not pass an AssetFinder to the TradingAlgorithm in
   test_modelling_algo.py, as this has been deprecated and will
   cause self._initialize to fail
2015-09-14 10:42:20 -04:00
jfkirk a6ce1e5e8d ENH: Adds auto_close_date field to Future objects 2015-09-11 14:08:03 -04:00
jfkirk 4770c5956c TST: Fixes modelling test tearDown 2015-09-10 11:53:29 -04:00
jfkirk 6e6ef447d2 TST: Adds tearDownClass methods to delete TradingEnvironments 2015-09-10 11:53:29 -04:00
jfkirk 65a4c4523e STY: Renames serialization_utils dump and load methods 2015-09-10 11:53:29 -04:00
jfkirk 262f0b7d09 MAINT: Removes mutable default method args
Also removes accidental modifications to Jenkins
2015-09-10 11:53:29 -04:00
jfkirk 608dff245b TST: Updates test for set_symbol_lookup_date 2015-09-10 11:53:29 -04:00
jfkirk 265bffbe01 TST: Updates modelling test base for new TradingEnvironment 2015-09-10 11:53:29 -04:00
jfkirk 3c1eea4ca1 MAINT: Removes references to trading.environment 2015-09-10 11:53:29 -04:00
jfkirk 5320fd0fc5 BUG: Adds missing parens to AssetFinder sids property 2015-09-10 11:53:28 -04:00
jfkirk 2a28d09380 MAINT: Removes exchange_id and root_symbol_id columns from AssetDB 2015-09-10 11:53:28 -04:00
jfkirk 35ed8c28a8 TST: Fixes modelling test to use new TradingEnvironment framework 2015-09-10 11:53:28 -04:00
jfkirk f1f3f9b751 TST: Fixes broken event test 2015-09-10 11:53:28 -04:00
jfkirk dc964a7e7d MAINT: Removes the ability to reference a global TradingEnvironment
This commit removes the ability to reference a shared TradingEnvironment through the zipline.finance.trading module. In place, the classes that require a TradingEnvironment, or its child AssetFinder, contain their own references to those objects.

This commit also adds serialization utilities that allow for the pickling/unpickling of objects without unintentionally their TradingEnvironments or AssetFinders.
2015-09-10 11:53:28 -04:00
Stewart Douglas d3516959a3 MAINT: Don't set string to upper before writing, remove unused libs 2015-09-10 11:53:27 -04:00
Stewart Douglas 7be2cf8652 MAINT: Allow algo.run() to write to db 2015-09-10 11:53:27 -04:00
Stewart Douglas 1ef2274d11 MAINT: Update tests to conform to new reader/writer structure 2015-09-10 11:53:26 -04:00
Stewart Douglas 1c512c5478 TST: Update test_algorithm.py to incorporate TradingEnvironment.write_data 2015-09-10 11:53:25 -04:00
Stewart Douglas 501fd58fdf ENH: Replace update_asset_finder with write_data
The write_data methods invokes the relevant AssetDBWriter subclass
to write data to the database. update_asset_finder is no longer
a relevant method since the AssetFinder is strictly a reader class.
2015-09-10 11:53:24 -04:00
Stewart Douglas 97e980751f MAINT: Integrate asset writer changes into TradingEnvironment 2015-09-10 11:53:23 -04:00
Stewart Douglas abcb6704e8 TST: Modify tests given new AssetFinder behavior 2015-09-10 11:53:22 -04:00
Stewart Douglas 746f70a133 ENH: Create AssetDBWriter class
The AssetDBWriter class and its subclasses will
ultimately be responsible for creating the SQLite
database tables and writing data to these tables.

In the longer term AssetDBWriter and AssetFinder will
be decoupled, sharing only an SQLite connection.
However, for backward compatibility reasons this has
not yet been fully implemented.

Modify tests since AssetFinder no longer has a
metadata_cache attribute.
2015-09-10 11:53:22 -04:00
Stewart Douglas 45adc57267 TST: Simulate running an algo using scripts/run_algo.py
Previously we have not had test coverage of the parse_args() or
run_pipeline() functions invoked when running scripts/run_algo.py.
2015-09-10 11:47:45 -04:00
Stewart Douglas 283c959cc4 MAINT: Move analyze methods into algorithm files 2015-09-10 11:36:14 -04:00
Stewart Douglas e507ee097d TST: Add coverage for set_symbol_lookup_date method 2015-09-08 11:01:04 -04:00
Stewart Douglas 1e31866471 MAINT: FutureChain should only accept Timestamp 2015-09-08 11:01:04 -04:00