Commit Graph

2313 Commits

Author SHA1 Message Date
Joe Jevnik f8f7f2fc4c ENH: Allows history to be dynamic and grow the container at runtime.
Previously, all specs had to be pre-allocated by using the 'add_history'
function. This is now no longer required and instead serves as a hint to
the HistoryContainer to pre-allocate the space for the given spec.

History can grow by increasing the length for a frequency, adding a
frequency, or adding a field. It can grow with any combination of
these.

HistoryContainer now is aware of the data_frequency of the algorithm,
and no longer uses the daily_at_midnight flag; instead, this is the
default behavior.
2014-11-03 15:57:44 -05:00
Delaney Granizo-Mackenzie 1c08f60f7c MAINT: Updated the naming scheme from reconstruct to set_state 2014-10-29 14:30:26 -04:00
Delaney Granizo-Mackenzie 589c014f73 ENH: Updated naming scheme of serialization methods. 2014-10-29 14:15:04 -04:00
Brian Fink 677f5ecde0 BUG: Hide account methods from repr 2014-10-29 13:41:15 -04:00
Brian Fink 287023498e BUG: Fix flake8 2014-10-28 22:10:28 -04:00
Brian Fink 93296d7ef5 ENH: Add serialization to account 2014-10-28 21:54:14 -04:00
Scott Sanderson affeb2afbc DEV: Add tz kwarg to get_datetime. 2014-10-23 00:59:50 -04:00
Thomas Wiecki 820115f7be MAINT: Replace iterkv with iteritems.
iterkv is being deprecated as of pandas 0.14.
2014-10-22 17:25:37 +02:00
Thomas Wiecki 18ad02f6a4 MAINT: Make len check for ffillable explicit. 2014-10-22 17:25:37 +02:00
Joe Jevnik c6e85d08f0 ENH: Does value checking for time offsets for market_open and market_close 2014-10-20 17:17:34 -04:00
Joe Jevnik 69124cb6ab BUG: Fixed a bug with offsets in week_start and week_end 2014-10-20 17:17:34 -04:00
Joe Jevnik 615228b272 ENH: Changes the default time_rule for schedule_function to market_open() 2014-10-20 17:17:34 -04:00
Joe Jevnik ad25f29b7b ENH: Provides aliases for the (Date|Time)RuleFactory classes for better Quantopian/Zipline interoperability 2014-10-20 17:17:34 -04:00
Joe Jevnik d360b9d9bd ENH: Provides a more descriptive error if market_open or market_close are provided a non-keyword argument that is not a datetime.timedelta 2014-10-20 17:17:34 -04:00
Scott Sanderson 76c32f2940 PERF: Use np.empty instead of np.ones.
No reason to use ones when we multiply everything by NaN immediately.
2014-10-18 16:49:27 -04:00
Scott Sanderson 7104725e3c DEV: Cleanup from PR comments.
Flip axes of numpy array in frame_from_bardata.
Add default=None to SidData.get.
2014-10-17 11:55:30 -04:00
Scott Sanderson 30c4a1a1dc PERF: Optimized rewrite of HistoryContainer.update.
Uses a numpy array instead of a dict of dicts when initializing history
container.

In testing this reduced the total time spent in HistoryContainer.update
by 66%.

BEFORE COMMIT:
Thu Oct 16 22:30:46 2014    results/cprofile/unoptimized

         185223320 function calls (182210491 primitive calls) in 401.351
         seconds

   Ordered by: cumulative time
   List reduced from 2398 to 27 due to restriction <'update'>

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
     8580    0.461    0.000  160.571    0.019
     qexec/zipline/history/history_container.py:388(update)

AFTER COMMIT:
Thu Oct 16 22:12:28 2014    results/cprofile/optimized

         143177181 function calls (140164352 primitive calls) in 272.403
         seconds

   Ordered by: cumulative time
   List reduced from 2395 to 27 due to restriction <'update'>

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
     8580    0.086    0.000   47.294    0.006 qexec/zipline/history/history_container.py:388(update)
2014-10-16 22:32:43 -04:00
Brian Fink 50c5b73a7b add account object to context 2014-10-10 17:10:45 -04:00
Joe Jevnik df234f516c BUG: Fixes various bugs with the event manager:
- NotHalfDay only worked at midnight
- week_(start|end) were actually month_(start|end)
- Removes check_args from api.
- Default offset of 30mins for market_(open|close)
2014-10-09 14:01:56 -04:00
Jonathan Kamens 1d3a8759bc MAINT: Remove use of deprecated getchildren method on xml element
Rather than calling getchildren on xml.etree.ElementTree elements,
we're now supposed to just itegrate over the elements.
2014-10-08 11:39:48 -04:00
Joe Jevnik d6e997e96c BUG: Stops the TradingEnvironment from being created at import time when
zipline.utils.events is imported.

Changes the class level attribute `env` on EventRule to a property so
that the environment is only looked up at when needed.
2014-10-07 12:30:28 -04:00
Joe Jevnik 3c37704a5b ENH: Adds a new api method schedule_function.
schedule_function takes a date rule, a time rule, and a function and
will call the function, passing context and data only when the two rules
fire. This allows for code that is conditional to the datetime of the
algo.

This is implemented internally with `Event` objects which are pairings
of `EventRule`s and callbacks.

handle_data becomes a special event with a rule that always fires. This
makes the logic for handling events more complete and compact.
2014-10-06 13:42:36 -04:00
Thomas Wiecki 6050b57fa4 Merge pull request #406 from gitter-badger/gitter-badge
DOC Add a Gitter chat badge to README.md
2014-10-05 01:23:25 +02:00
The Gitter Badger 02f5f30fdf Added Gitter badge 2014-10-03 22:46:37 +00:00
Scott Sanderson 490391b9ae TEST: Remove uncessary copy calls from history tests. 2014-10-03 06:07:02 -04:00
Scott Sanderson 028ba719a2 BUG: Fix numpy dtype casting bug that only manifests in pandas 0.14.0. 2014-10-02 18:09:51 -04:00
Scott Sanderson d52dc68b5a PERF: Use numpy functions for concatenation in history. 2014-10-02 16:10:56 -04:00
Scott Sanderson 19d97524da PERF: Don't apply lambdas to large DataFrames. 2014-10-02 11:12:51 -04:00
Scott Sanderson 235954d480 DEV: Overhaul core history logic.
Overhaul the core HistoryContainer logic to be more robust to changing
universes.

Major Changes
-------------
* Remove `return_frame` cache.  The original purpose of using
  return_frames was to avoid having to create new DataFrames on each
  iteration of handle_data, but we ended up having to copy the return
  frames anyway because user code could mutate the frames in place.
  Removing the return_frames reduces unnecessary copying, and reduces
  the logic of `get_history` to just forward-filling and concatenating
  two DataFrames.

* Use a `MultiIndex`ed DataFrame to represent
  `last_known_prior_values`.  This makes lookups faster and greatly
  simplifies the logic of adding and dropping sids.

* HistoryContainer no longer attempts to determine its universe based on
  the contents of its internal buffers.  The TradingAlgorithm
  controlling the container is now responsible for explicitly calling
  `add_sids` or `drop_sids` when securities enter or leave the
  algorithm's universe.  These methods, along with the internal
  `_realign` method, provide a clean interface for changing the universe
  of securities managed by the container.

* Refactor index mutation logic in `RollingPanel` into a
  `MutableIndexRollingPanel` subclass.  Maintenance of the old behavior
  is regrettably necessary to support `BatchTransform`.

* Refactor shared logic from `roll` and `get_history` into a single
  `aggregate_ohlcv_panel` method that's responsible for collapsing an
  OHLCV buffer into a frame.
2014-09-29 14:42:57 -04:00
Scott Sanderson b3c7c26cee MAINT: Remove unused function in test_rolling_panel.py. 2014-09-29 14:40:03 -04:00
Scott Sanderson fcb137e0bb DOC: Clarificatory comments in HistoryContainer. 2014-09-29 14:40:03 -04:00
Scott Sanderson 9152d8da37 DOC: Slightly better comment on Frequency._ffill. 2014-09-29 14:40:03 -04:00
Scott Sanderson c477680ca3 MAINT: Use filter builtin instead of if-statement and continue. 2014-09-29 14:40:02 -04:00
Scott Sanderson 97e4e5e94d MAINT: In _create_generator only overwrite perf_tracker when it's None. 2014-09-29 14:40:02 -04:00
Scott Sanderson 94b53bdcb7 MAINT: Minor tweaks to docstring. 2014-09-29 14:31:57 -04:00
Joe Jevnik 4db4256cfe MAINT: Adds a tests/utils/ directory and renames test_utils.py
to utils/test_factory.py
2014-09-29 12:57:39 -04:00
Scott Sanderson fd71f956c7 DOC: Add more information to IncompatibleHistoryFrequency message. 2014-09-19 23:48:55 -04:00
John Ricklefs 16827e1af4 REV: Revert numpy update (back to 1.8.1)
This reverts commit 0eb12156c8.
2014-09-18 14:10:13 -04:00
John Ricklefs 0eb12156c8 BLD: Update numpy to 1.8.2 2014-09-18 12:23:54 -04:00
Thomas Wiecki 4615b57fc2 MAINT: Add custom exception for incompatible history frequency specification. 2014-09-18 16:20:28 +02:00
Thomas Wiecki 69a66f776e BLD: Trying to fix travis. 2014-09-17 19:21:29 +02:00
Thomas Wiecki cbb8e28f8e TST: Fix history unittest. 2014-09-17 18:17:36 +02:00
Thomas Wiecki 5490349c62 MAINT: Test frequency.unit_str instead of frequency string. 2014-09-17 18:17:11 +02:00
Thomas Wiecki 49b511558d BLD: Remove numpy 1.8.1 requirement from travis. 2014-09-17 16:23:17 +02:00
Thomas Wiecki 011f072fe2 MAINT: Add assertion for incompatible history freq specification. Supplying 1m frequency to history but only providing daily source data resulted in an odd non-descript exception. This adds a specific check and raises a more informative exception. 2014-09-17 15:04:37 +02:00
Eddie Hebert 7eb1d719ed MAINT: Check attributes instead of contains for event fields.
In support of source that emits a subclass of Event which defines some
fields as properties instead of doubling the value in the
`Event.__dict__`

Use hasattr instead of the overridden __contains__ method of the Event
class, so that when non-algorithm facing code checks for field existence,
properties count.

Intentionally not touching the `__contains__` in Event, to avoid
changing, at the moment, any algo behavior that relies on the
`__contains__` behavior's use of `__dict__`
2014-09-08 11:09:41 -04:00
Richard Frank 6a5eaea835 MAINT: Use local variable with same value 2014-09-03 18:07:51 -04:00
Richard Frank 3784ed4ba9 ENH: A TradingAlgorithm method called before each trading day 2014-09-03 18:07:51 -04:00
Scott Sanderson 1b2d79988f BUG: Fix exception when comparing Event to object with no __dict__.
In particular don't throw an exception on comparison to `None`.
2014-09-02 20:42:49 -04:00
Delaney Granizo-Mackenzie 5d5dbb5c3a Merge pull request #385 from quantopian/exception-on-nan-order-value
BUG: StopLimit better bad value exception handling
2014-08-26 14:43:22 -04:00