Commit Graph

2213 Commits

Author SHA1 Message Date
Delaney Granizo-Mackenzie 3a48eb9bc2 Update zipline-0.6.2.md 2014-07-02 11:03:17 -04:00
Delaney Granizo-Mackenzie 6920fec9a3 Update zipline-0.6.2.md
Added a note about record functionality.
2014-07-02 10:57:27 -04:00
Thomas Wiecki d105d615d0 MAINT: Removed undocumented and untested sources for pytables and csv. Closes #267. 2014-07-02 11:32:27 +02:00
Thomas Wiecki 8d09305c36 BUG: Fix constant of trading hours to be 6.5. Fixes #214. 2014-07-02 11:26:35 +02:00
Delaney Granizo-Mackenzie c3169f60cd ENH: Added dynamic name functionality to record() API function.
Added the ability to pass *args before the **kwargs so that positional
arguments of the form name, value can be recorded.
2014-06-30 14:09:09 -04:00
Scott Sanderson 75b415ac48 BUG: Algo no longer crashes after creating new history column.
Fixes an issue that caused a crash if a user assigned a new column into a
returned history DataFrame.  This occurred because we re-use DataFrames between
history() calls, so the new column caused an index-size mismatch on the next
attempted calculation.

Ideally we would fix this by in-place dropping the columns, but that isn't
supported in pandas 0.12.0, so instead we just return a complete copy of the
frame.  We should re-evaluate this implementation when we're on a more modern
pandas version.
2014-06-30 12:09:03 -04:00
Thomas Wiecki f8e84ecd48 MAINT: Remove unused annualizer code. 2014-06-30 17:28:02 +02:00
Thomas Wiecki 10885e1b77 MAINT: One way to set sim_params and data_frequency.
There were sevaral places you could supply sim_params
in TradingAlgorithm (__init__, run). This got confusing
as its not clear who updated what and which one was the
correct one to use at each time.

Then there were to ways to define data_frequency, one in
__init__() and one in the sim_params which also added code
complexity.

This refactor makes it explicit that sim_params are to be
passed to __init__() only. Moreover, data_frequency is
only stored in sim_params. For backwards compatibility,
it can still be supplied separately but will link to
the one in sim_params.

For example, you could create new sim params via:

sim_params = create_simulation_parameters(data_frequency='minute')
algo = MyAlgo(sim_params)
algo.run(data)

In addition, perf_tracker only gets initialized in one place:
_create_generator() which should also make the various ways
of running an algorithm more deterministic.

This also fixes a bug with SimulationParameters where
you could not change the period_start. Unfortunately, the
current implementation still requieres an implicit call to
update the internal variables.
2014-06-30 17:28:02 +02:00
Scott Sanderson 4c9cf1321d PERF: Replace .ix usages with with .loc in TradingEnvironment.
Replace usage of .ix in TradingEnvironment with .loc when we know that we're
using an index key.

DataFrame.ix can be used with either integer or key-based indices, and as such
it incurs an overhead for figuring out which you meant.
2014-06-26 17:17:08 -04:00
Scott Sanderson 6a2ee7c417 BUG: History no longer fails on length-1 '1m' price-only HistorySpecs
The bug occurred because there is a special case in the initial window setup
code for handling the case where only a length-1 history is used for a given
frequency.  Previously, the code was incorrectly calculating the period end
using a hard-coded expression for the end of the day (the correct behavior for
a length-1 '1d' history), and then using the frequency object to calculate the
period start for the window.  In the case of length 1 '1m' data, this resulted
in an initial window whose start and end was the last minute of the day rather
than the first minute of the day.  For non-price fields, this error doesn't
matter, because the window is only used for rolling digests (which doesn't
happen when there's only a length-1 history), and for the forward-filling logic
(which only happens on price fields).  For a length-1 '1m' price, however, the
incorrect window causes us to attempt to forward-fill an empty panel, resulting
in an IndexError when we do an iloc[0] on a length-0 axis.
2014-06-25 10:54:45 -04:00
Thomas Wiecki 1b571a53a5 BLD: Second try at coverage integration. 2014-06-18 20:20:59 +02:00
Thomas Wiecki be1ccd169a DOC: Add coverage badge to README. 2014-06-18 20:00:16 +02:00
Thomas Wiecki d4e05090a3 BLD: Add coverage integration. 2014-06-18 19:59:06 +02:00
Thomas Wiecki ff11628cd3 DOC: Wrong link for badges. 2014-06-18 17:46:59 +02:00
Thomas Wiecki d6a392e394 DOC: Add version and download counter to README. 2014-06-18 17:45:33 +02:00
Scott Sanderson fe52254bc2 BUG: Rolling back Logbook version due to incompatibility with Processor/filter
interactions.
2014-06-16 13:52:09 -04:00
Thomas Wiecki 96bdb22db9 BUG: RollingPanel was not behaving correctly in corner cases.
There quite some bugs in certain corner cases. Dropping of obsolete
axes was not working correctly, roll over could cause obsolete axes
to not drop. The tests are much more stringent now as well.
2014-06-14 21:07:02 +02:00
Thomas Wiecki e4c974f4b8 ENH: Add removal of elements in benchmark. 2014-06-11 16:50:53 +02:00
Scott Sanderson 79c91897ba ENH: Add freq_filter argument to HistoryContainer.update_digest_panels.
Adds a new argument, `freq_filter`, to `HistoryContainer.update_digest_panels`,
which can be used to supply a predicate determining which digest panels are
updated by the call.  This is useful for supporting initialization/backfilling
of multi-frequency panels in subclasses.
2014-06-09 17:42:41 -04:00
Scott Sanderson 7995e6ac0d DOC: Tweaks to docstrings in history.py and history_container.py. 2014-06-09 17:40:57 -04: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
Eddie Hebert 36501a462b BLD: Set scipy back to 0.12.0
The internal system used to build and get burn-in on packages was
accidentally using scipy 0.12.0, despite the change in the requirements
file to 0.13.2

Setting back to using scipy 0.12.0 until 0.13.2 is more tested with
internal systems, with the goal of upgrading to >= 0.14.0 as soon as
possible.
2014-06-09 14:45:43 -04:00
Scott Sanderson 49eaeeb6ae BUG: Apply integer truncation to order amounts earlier in the pipeline.
Truncate non-integer order amounts in `TradingAlgorithm.order` instead of
`Blotter.order`.  This fixes an issue where non-integer orders coming out of
order_value can spuriously trigger a `LongOnly` trading guard.

Example:

sid.price == 2.0
order_value(sid, 5) -> order(sid, 2.5) -> truncated to order(sid, 2.0)
order_value(sid, -5) -> order(sid, -2.5) -> LongOnlyViolation b/c 2.0 - 2.5 < 0
2014-06-09 11:42:43 -04:00
Thomas Wiecki 2a73873097 BUG: Remove output arg before calling run_pipeline
The IPython magic still created an output file because
the output argument was only removed after the pipeline
was run. This fix simply removes the argument before
the call to run_pipline() when running the IPython magic.
2014-06-09 17:17:37 +02:00
Scott Sanderson f6cbd5eba8 Merge branch 'one_minute_history_for_realz' 2014-06-05 16:37:38 -04:00
Scott Sanderson fba649dd7a TST: Changed test_mixed_frequencies to use a half day.
Also adds a length-1 HistorySpec to the test.
2014-06-05 15:25:49 -04:00
Scott Sanderson cfe00b0c37 ENH/TEST: Enable '1m' history and add tests for the frequency. 2014-06-05 15:25:49 -04:00
Scott Sanderson 3a1fc1032e ENH: Overhaul logic in HistoryContainer.
Updates `HistoryContainer.roll` to handle cases where no data is present for
the period being rolled.

We now only forward-fill the `price` field when `ffill` is specified.
2014-06-05 15:25:49 -04:00
Scott Sanderson 15f1947652 BUG: Don't return mostly nans from get_history when ffill=False.
Fixes an issue where, if `ffill=False`, `get_history` would return nans for
every entry in the history frame except the last one.
2014-06-05 15:25:49 -04:00
Scott Sanderson bad4c9a439 ENH: Prep work for supporting '1m' history.
Overhauls `HistoryContainer` in prep for support of more than one frequency.

Major changes:

   - Methods/variables referring to "day" have been renamed/generalized.
     - `current_day_panel` became `buffer_panel`, which is now a `RollingPanel`
     - `prior_day_panel` became a dictionary mapping `Frequency` objects to
       "digest panels", which are instances of `RollingPanel`.

   - Hard-coded daily rollover replaced with a notion of a "current window" for
     each unique frequency managed by the panel.

     - When the end of the current window is reached for a given frequency, we
       compute an aggregate bar (code refers to this as a "digest"), which is
       appended to a panel associated with that frequency.

     - Window rollover dates are managed by a pair of dictionaries,
       `cur_window_starts` and `cur_window_closes`.  The `Frequency` class is
       responsible for computing window bounds based on the open/close of the
       previous window.

   - Semantic change to the `open_price` field: `open_price` now always
     contains the price of the first trade occurring in the given window.
     Previously it contained the price of the first minute in the window,
     returning NaN it the security happened not to trade in the first minute.
2014-06-05 15:25:48 -04:00
Scott Sanderson b6e5345893 ENH: Enhancements to TradingEnvironment.
Adds a suite of new functions for querying data from the trading calendar.

These include:
      `previous_trading_day`
      `minutes_for_days_in_range` (minutely version of `days_in_range`)
      `previous_open_and_close` (inverse of `next_open_and_close`)
      `next_market_minute`
      `previous_market_minute`
      `open_close_window` (get a range of opens/closes with slicing semantics)
      `market_minute_window` (get a range of minutes with slicing semantics)

Also refactors `test_finance` to move `TradingEnvironment` tests into their own
TestCase.
2014-06-05 15:25:48 -04:00
Scott Sanderson de3be983ad BUG: BarData.values() no longer causes in an infinite loop on Python 3. 2014-06-05 15:14:26 -04:00
Scott Sanderson 7daf58ec9b ENH: Add a class-level instance method on TradingEnvironment.
Adds a classmethod, `instance` on `TradingEnvironment` that returns
`zipline.finance.trading.environment`, instantiating it if necessary.

This makes it possible to initialize the default environment instance in a
less-roundabout way than creating a `SimulationParameters` object.
2014-06-05 12:02:53 -04:00
Scott Sanderson 5392506d6d DOC: Documentation fixups in history_container.py. 2014-06-05 11:15:50 -04:00
Scott Sanderson 0b37663fed Revert "MAINT: Peg .travis.yml packages to specific versions in line with requirements.txt."
This reverts commit 450dded491.
2014-06-04 14:48:59 -04:00
Thomas Wiecki a372549f6f DOC: Add @humdings to contributors. 2014-06-04 20:08:52 +02:00
David Edwards 7547ef535a MAINT: Removed unused keyword arg
Deleted keyword arg include_open_orders, it was left over from working
on handling open orders.
2014-06-04 20:08:52 +02:00
David Edwards 243c0348f3 MAINT: Refactored target order methods
Refactored the target order methods to separate their logic from the
other order methods.

This makes order_target the only target method that calls order()
directly.

order_target_value is passed to order_target instead of order_value.

order_target_percent is passed to order_target_value rather than
order_value.

This simplified the code and decouples the logic of target orders from
the other order methods. This allows the target order methods to be
developed independently from order_value and order_percent.
2014-06-04 20:08:52 +02:00
Scott Sanderson 450dded491 MAINT: Peg .travis.yml packages to specific versions in line with requirements.txt. 2014-06-04 13:58:03 -04:00
Scott Sanderson 1fb78a34cd MAINT: Bump numpy version in .travis.yml. 2014-06-04 10:54:50 -04:00
Eddie Hebert 744decf9de STY: Normalize styles across installations via .dir-locals.el
For Emacs users, set a .dir-locals.el file to define behavior during
formatting operations like `fill-paragraph`

Set:
- Double spaces after sentences. (Which is the default.)
- Fill column to 79 characters. (To match pep8 script.)
- Docstrings to conform to Django formatting, since that is currently
  most alike to the existing docstrings.
2014-06-04 00:06:58 -04:00
Eddie Hebert 26b2a466cf BLD: Update pytz to latest version.
2014.3 -> 2014.4
2014-06-02 22:15:01 -04:00
Thomas Wiecki 40001f3509 STY: Remove warning when ordering zero shares.
Many algorithms that use the new order methods like order_target()
will legitimately try to order 0 shares many times. The printed
warning at every turn is quite annoying and too verbose. We do not
display it on Quantopian either so I'm removing it here as well.
2014-06-02 15:50:21 +02:00
Eddie Hebert 1705428aa4 BLD: Remove pip-tools dependency.
Instead of `pip-review`, now using `pip list --outdated`
2014-05-31 21:56:10 -04:00
Eddie Hebert d384f63e25 BLD: Update tornado to latest.
Upgrade from 3.2 -> 3.2.1
Used for matplotlib, which is imported during tests to make
sure that examples are working.
2014-05-30 15:48:10 -04:00
Eddie Hebert 45c3fafaae BLD: Update xlrd package to latest.
xrld is used for reading the risk answer key.
Update 0.9.2 -> 0.9.3
2014-05-30 14:58:08 -04:00
Eddie Hebert f481d9e7df BLD: Update Markdown library.
Should be orthogonal to any trading simulation, Markdown is
merely used for packaging and converting the README.
2014-05-30 14:47:37 -04:00
Eddie Hebert 93acee4091 BLD: Keep Travis lint and test packages in sync with requirements file.
Instead of hard-coding the package versions in the Travis config,
grep the version number out of the requirements_dev.txt file,
so that the versions do not drift.
2014-05-30 14:11:44 -04:00
Eddie Hebert 2debde31ba BLD/STY: Upgrade to latest versions of lint checkers.
Upgrade pep8 1.4.6 -> 1.5.7
Upgrade pyflakes 0.7.3 -> 0.8.1

Also, tweak some line indentations which now show up as errors,
because of the fixes/changes to visual indent detection between
pep8 versions.
2014-05-30 12:44:10 -04:00
Eddie Hebert 2c8e019835 BLD: Update nose to latest version.
nose 1.3.0 -> 1.3.3
2014-05-29 23:20:30 -04:00