Commit Graph

4752 Commits

Author SHA1 Message Date
Eddie Hebert 6f33bdcfd3 Merge pull request #1604 from quantopian/use-linked-list-for-contracts
MAINT: Use a doubly linked list for contract chain.
2016-11-30 06:54:28 -05:00
Eddie Hebert d147397983 MAINT: Use a doubly linked list for contract chain.
Instead of requiring the roll finder to juggle the indices into the ordered
contracts, use a doubly linked list where the nodes element is the contract
with members pointing to the previous and next contracts in the chain.

Besides improving legibility in the roll finder code, this change is on the path
to adding a predicate to exclude contracts from the chain, e.g. contracts in ED
which are not in the roll schedule.

Change test results for primary chain, since new implementaton does not stop at
contract in which has not yet started when constructing the chain.
2016-11-30 06:01:59 -05:00
Scott Sanderson 74df429057 Merge pull request #1588 from quantopian/randc-built-in-factors
ENH: Add MACD, MA, and AnnVol as built in factors
2016-11-28 16:18:58 -05:00
Scott Sanderson 37f58264cd Merge pull request #1603 from quantopian/randc-built-in-factors-twekas
Randc built in factors twekas
2016-11-28 15:30:40 -05:00
Scott Sanderson ee230c807f DOC: Docstring updates. 2016-11-28 15:29:36 -05:00
Scott Sanderson 4210a2f80f MAINT: Tweaks/cleanups in technical.py.
- Use `expect_bounded` to check inputs.
- Add tests for expected failures from `MACDSignal`.
- Use `float64` instead of `float` in a few places.  This prevents
  diverging behavior on 32-bit systems.
- Docstring edits.
2016-11-28 13:02:40 -05:00
Scott Sanderson d140d585c2 MAINT: Put exponential_weights where it's used.
`math_utils` is mostly a shim around bottleneck imports.  If we need
this somewhere else, it probably belongs in `numpy_utils`.
2016-11-28 13:02:40 -05:00
Scott Sanderson c05635333e STY: Put whitespace between operators. 2016-11-28 12:57:03 -05:00
Scott Sanderson 52958a0340 TEST: Use parameter_space for randomized tests.
- Use a RandomState with a seed so that we have repeatible results.
- Use `randint` instead of `random_integers.` `random_integers` is
  deprecated.
- Use `parameter_space` to test multiple period lengths.
2016-11-28 12:57:03 -05:00
Scott Sanderson 84e7c03147 Merge pull request #1599 from quantopian/memory-savings
Memory savings
2016-11-28 10:52:23 -05:00
Eddie Hebert 320f1f64db Merge pull request #1600 from quantopian/use-prev-session-for-volume-roll
BUG: Fix bounds errors in roll finder.
2016-11-26 21:37:21 -05:00
Andrew Daniels 1f176de497 MAINT: Improve minute writer handling of non-trading minutes (#1602)
Previously, if input to the BcolzMinuteBarWriter had the first bar on a
non-trading minute, the next trading session would be considered the
"first day" in the input. Now, we consider the previous trading session
the "first day".

The intention is to correctly associate minutes after official trading
hours on half days with session that closed early, not the following
session (a future improvement here would be to not accept minutes
outside trading hours).
2016-11-26 21:12:12 -05:00
Jonathan Kamens 5ab89ff25d BLD: Use https to download ta-lib source 2016-11-25 12:12:33 -05:00
Ana Ruelas 3363237123 ENH: Add MACDSignal, test with random input 2016-11-23 11:43:29 -05:00
Eddie Hebert 4d434acab7 BUG: Fix bounds errors in roll finder.
Fix common error condition which was triggered whenever the session at the end
of the prefetched history window was a session where the back contract was
active. When the back contract was the active contract, the next contract for
consideration was the front contract at the end of the window, which
definitionally always has an autoclose after the end of the window.
Instead, just start seeking backwards from the end of the window.

Also prevent lookahead bias in volume rolls, which was caused by the using the
volume for a session to determine whether that session had rolled. Information
that would not have been available at the beginning of the session.

This change makes the volume rolls overly conservative, and may be improved by
looking at vectors of the preceding volume and making the roll off of momentum.
2016-11-23 10:35:45 -05:00
Scott Sanderson 9f28b7cede MAINT: Hit more dataframe indexers. 2016-11-22 17:11:04 -05:00
Scott Sanderson 16e78bbccd BUG: sys.exc_clear is py2 only. 2016-11-22 16:34:53 -05:00
Scott Sanderson 7a5f5da6b2 MAINT: Use lazyval instead of two decorators. 2016-11-22 14:26:58 -05:00
Scott Sanderson 8aacac1cb6 PERF: Use searchsorted instead of get_loc.
On pandas < 18, `get_loc` triggers allocation of a large hash table, so
we don't want to call get_loc on minutely `DatetimeIndex`es.
2016-11-22 14:26:58 -05:00
Scott Sanderson 52ed9093eb PERF: Deterministically GC pipeline results.
Any DataFrame that's had `.loc` or `.iloc `called on it participates in
a cycle, which means they're not immediately garbage collected when they
go out of scope.  This matters for pipeline results because they consume
multiple megabytes per column, which means that a pipeline result with
many columns can hold take up over 100MB.  By manually breaking
DataFrame cycles, we can ensure that we never hold multiple pipeline
results in memory at once.
2016-11-22 14:26:58 -05:00
Andrew Daniels 4174a090d0 BUG: Ensure minute OHLC values can safely be converted to uint32 (#1598)
Otherwise, we either raise an exception or filter out all unsafe values.
This addresses an issue where the BcolzMinuteBarWriter would scale up
values to convert to uint32, but the resulting values were too large,
and would be mangled.

Based on the approach we take in the BcolzDailyBarWriter.
2016-11-22 14:11:43 -05:00
Ana Ruelas 435d5acd14 TST: Add test for annualized volatility factor 2016-11-21 14:24:28 -05:00
Ana Ruelas 10f5cc2cbb ENH: Actually use rolling windows for EWMA in MACD 2016-11-21 14:24:28 -05:00
Scott Sanderson 7f762d02bf MAINT: Use fancy default for window_length. 2016-11-21 14:24:28 -05:00
Ana Ruelas 9d68ab6ba7 ENH: Add MACD, MA, and AnnVol as built in factors 2016-11-21 14:24:19 -05:00
Maya Tydykov f3a36fe97f Merge pull request #1557 from quantopian/split_adjust_estimates
Split adjust estimates
2016-11-18 10:21:04 -05:00
Maya Tydykov 757e1c6367 ENH: allow estimates to be split-adjusted.
This modificaiton to the estimates loader allows the caller to pass
in an equity pricing loader which can then be used to get split data
for sids. That split data is then used to do point-in-time adjustments
of estimates data.

TST: add test for multiple estimates columns

TST: add test for multiple datasets requesting different columns

TST: add blaze versions for all next/previous tests
2016-11-18 09:39:54 -05:00
Eddie Hebert 515db18793 Merge pull request #1595 from quantopian/nan-check-transactinos
TMP: Add temporary fix for transactions with nan fill prices.
2016-11-17 13:10:32 -05:00
Eddie Hebert be8326baf2 TMP: Add temporary fix for transactions with nan fill prices.
Protect a case where data is written with a non-zero volume, but a 0/nan for the
OHLC values. The slippage model was relying on a non-zero volume implying that
there was a valid trade price for the corresponding bar. When there was a mismatch,
a transaction with a nan value was created, which would in turn propagate the
nan into portfolio value, which would then cause errors when the portfolio value
was used to size orders during rebalancing.

When data is fixed, can remove.
(Also may want to add behavior to minute bar writer to ensure that 0 volumes
always have corresponding nan ohlc.)
2016-11-17 12:00:28 -05:00
Eddie Hebert 3c94ee7ae3 Merge pull request #1594 from quantopian/fix-after-half-day-nan
BUG: Fix minute bar last traded after half day.
2016-11-15 15:33:42 -05:00
Eddie Hebert 4fcf31730c BUG: Fix minute bar last traded after half day.
When the following conditions occur,

- a `nan` occurred after a half day (e.g. on the Monday after
Thanksgiving, where the Friday would be a half day.)

-data was written to the span between the early close and where the market close
would have been if it were not an early close session

- a `nan` also occured on the last minute of the early market session.

the exisitng implementation would incorrectly return a `nan` when requesting a
forward filled price.

The steps that caused this error were.

1. Request for `'price'` on the market open of the day after the early close.

2. `nan` is found for that minute

3. `get_last_traded_dt` is called, and finds a volume that occurs after the
early close. e.g. `18:47` when the market close was `18:00`.

4. The minute position for `18:47` is used, when calling
`find_positon_of_minute`, since that value is after the `market_close` the
minute is set to the position of `18:00`` due to the delta logic in

5. Since there is also no data in at `18:00`, a `nan` is returned, even though
there were valid minutes earlier in the session. e.g. a non-zero volume at
`16:47` should have been used, but was not.

Fix by checking the current minute against the minute close when searching for
the last traded minute. If the minute is greater than the market close for the
corresponding day, continue the search until the minute position is within the
trading session.

This could also be fixed by enforcing that only zeros can be written between an
early close and the minute where the close would have been, but this fix allows
the reader to work with existing data.
2016-11-15 15:09:19 -05:00
Eddie Hebert de256948db Merge pull request #1592 from quantopian/remove-duplicate-get-rolls
MAINT: Remove duplicate get_rolls in reader.
2016-11-14 15:43:27 -05:00
Richard Frank 104241c00d MAINT: Updated ta-lib source download urls to https 2016-11-14 12:34:19 -05:00
Richard Frank 54487ef054 Merge pull request #1593 from quantopian/nicer-message
ENH: An improved error message when calling zipline api functions
2016-11-11 17:22:06 -05:00
Richard Frank 1d2d6d843f ENH: An improved error message when calling zipline api functions
outside of a running simulation. Previously, an AttributeError was
raised.
2016-11-11 17:00:03 -05:00
Eddie Hebert 8b8b4a8118 Merge pull request #1590 from quantopian/speed-up-history-loader-creation
PERF: Speed up retrieval of HistoryLoader calendar.
2016-11-11 11:37:31 -05:00
Eddie Hebert 138e189cac MAINT: Remove duplicate get_rolls in reader.
The rolls are already calculated and assigned to `rolls_by_asset` earlier in the
`load_raw_arrays` method, so remove the duplication.

The change should not affect results.
2016-11-11 11:09:02 -05:00
Eddie Hebert 229b967c71 PERF: Speed up retrieval of HistoryLoader calendar.
The use of `slice_indexer` on all market minutes was taking about 110ms on my
development machine.

This change to getting the start and end indices changes the entire `_calendar`
method to take 10ms on the same machine.

Noticed while creating a `HistoryLoader` in a notebook context.
2016-11-11 10:54:07 -05:00
Richard Frank da4d6ec582 Merge pull request #1589 from quantopian/rotate-anaconda-token
Rotate anaconda token
2016-11-10 13:45:44 -05:00
Richard Frank 97c3c14db6 SEC: Rotated anaconda token for travis 2016-11-10 12:12:02 -05:00
Richard Frank 7b65cd23db DOC: Added ANACONDA_TOKEN directions 2016-11-10 12:12:02 -05:00
Eddie Hebert b309e3ce1e Merge pull request #1587 from quantopian/fix-bug-for-continuous-future-max-date
BUG: Fix continuous future end dates.
2016-11-09 16:41:57 -05:00
Eddie Hebert e415c0f350 BUG: Fix continuous future end dates.
The end date of the last contract with a sufficient start date was being
used for the continuous future overall end date; however the end date of
that contract (which is the last day for which there is data for the
contract) is not necessarily the greatest end date out of all contracts.
It is possible for the furthest out contract to have some, but very
few, trades before it is more actively traded. Which would give it a
start date within in the range of the simulation, but an end date is
earlier than the other contracts which are active during the simulation.

This bug would result in `nan`s when getting the current price because
of the `end_date` check in `get_spot_value`. When the current simulation
time was greater than the `end_date` of the last contract the condition
which guards against attempting to get data for an instrument past its
end date would return a `nan`, even when the current underlying contract
did have data for that date.

Use max end date of all contracts instead of the last one, to ensure
that the continuous future last date is always great enough to allow
access to all contracts with in the chain.

Also, use min start date to accurately mirror the end date behavior.
2016-11-09 16:19:19 -05:00
Eddie Hebert fa6e4fe8b1 Merge pull request #1586 from quantopian/fix-continuous-future-daily-get-value
BUG: Fix bad attribute lookup on session continuous future reader.
2016-11-08 16:15:05 -05:00
Eddie Hebert 512e62b13e BUG: Fix bad attribute lookup on session continuous future reader.
Use `roll_style` not `roll`.

Also, add test case to cover using the session bar reader `get_value`,
by adding a test which uses `close`, since only `contract` was being
exercised, which does not exercise the session daily bar reader.
2016-11-08 15:48:28 -05:00
Eddie Hebert b5d4df6223 Merge pull request #1585 from quantopian/pricing-data-associable
MAiNT: Add a pricing data shared abc.
2016-11-08 12:26:02 -05:00
Eddie Hebert 5e8faa2fbb MAiNT: Add a pricing data shared abc.
Register equities, futures, and continuous futures to an `abc` which
signifies that the type is associable with data, and thus can be used in
a history context.

May want to use this in `check_parameters` for `BarData` methods, but
work would need to be done to make sure the error message still displays
the registered types.
2016-11-08 11:36:45 -05:00
Eddie Hebert 44b97be712 Merge pull request #1584 from quantopian/allow-single-continuous-future
BUG: Fix `data.history` with a single continuous future.
2016-11-08 11:33:57 -05:00
Eddie Hebert 25eb13ccff Merge pull request #1583 from quantopian/allow-sliding-window-to-reset
ENH: Allow arbitrary history queries.
2016-11-07 22:31:13 -05:00
Eddie Hebert e419e20acf ENH: Allow arbitrary history queries.
In preparation for using `DataPortal` in notebooks, remove restriction on
the `HistoryLoader` to dates that are monotonically increasing. Notebook
usage of the `DataPortal` is more useful when the end of the history
window can be arbitrary dates without having to restart the notebook kernel.

Due to the implementation of the prefetch and caching logic, the end
date of history calls could previously only increase. e.g. `2016-11-01`,
`2016-11-02`, `2016-11-03`. This pattern was sufficient for backtesting
and live simulations, since the current time of the algorithm only ever increases.

With this change, which resets the underlying sliding window when the
last fetched idx is greater than the

Now calls to history in the same process with end dates such
`2016-11-01`, `2016-10-31`, `2015-11-02` should work.
2016-11-07 16:40:51 -05:00