Commit Graph

1785 Commits

Author SHA1 Message Date
Eddie Hebert d58181db34 TST: Fix case where there is no existing risk answer key.
The download checksum was not being correctly set when no file existed.
Set the checksum to the latest value so that a download is triggered.
2013-07-18 14:47:33 -04:00
Eddie Hebert d0118ff6de BLD: Fix typo in pip specification of xlrd 2013-07-18 14:44:08 -04:00
Eddie Hebert b759409525 TST: Add xlrd module to requirements_dev
THe xlrd module is used by the answer_key module to read results
from a spreadsheet.
2013-07-18 14:35:00 -04:00
Eddie Hebert 9a629d8781 Merge reading of risk unit test expected results from a spreadsheet.
To help tentpole the risk results with an alternative implementation.

Also, the spreadsheet provided is what the original answers were based
from, reading from said spreadsheet should help prevent drift.
2013-07-18 14:31:21 -04:00
Eddie Hebert e5e38a437b TST: Download risk answer key from S3.
So that the answer key does not onerous on the SCM repo size, add a
utility to download the answer key automatically.

Prevent re-download on every test suite run if the local answer key
matches the latest version.
2013-07-18 14:31:08 -04:00
Eddie Hebert 5579e54c6f TST: Read benchmark returns directly from answer key spreadsheet.
The risk tests originally were based on a spread sheet, with the
results of returns etc copy and pasted into the `test_risk` module.

Include the spreadsheet and read the values directly using a Python
Excel spreadsheet library.
2013-07-18 14:31:08 -04:00
Eddie Hebert 87c0f40aa0 TST: Move risk tests to their own module.
Will be adding the Excel spreadsheet answer key, a dedicatetd
directory for risk should help make clear why and where the spreadsheet
is used.
2013-07-18 14:31:08 -04:00
Thomas Wiecki 940ddd22d3 TST: Added testing of order timings and price. 2013-07-17 19:56:55 -04:00
Richard Frank 75dd77ea03 ENH: Added early closes to trading environment
specifically, expected 1 PM closes since 1993
2013-07-16 12:02:34 -04:00
Ben McCann efe50f8494 BUG: Fix get_benchmark_returns.
It should calculate the return off the pervious day's close, instead
of current day's open.
2013-07-15 15:35:09 -04:00
Ben McCann b9bd928862 DOC: Fix documentation compilation warnings; improve output formatting
Fix warnings when compiling the docs.
Removes the documentation of the default types, which already gets
included automatically and was wrong because not kept in sync with the
function signature.

Changed, the formatting to the Sphinx formatting.
This looks much better in the compiled documents, but does make the
source a bit harder to read.
2013-07-15 14:18:07 -04:00
Eddie Hebert b7b4d397ba BUG: Revert "Merge ability to specify timing of fills."
This reverts commit e3a9ca27b1, reversing
changes made to 3d8bdeb429.

Conflicts:
	zipline/gens/tradesimulation.py

The aforementioned change needs a revert because it caused a 'doubling'
of orders, since the portfolio is not updated until after handle_data
is called a second time after an order has been processed.

The flexibility of fill_delay is still desired, but remove for now,
favoring reverting back to existing behavior over trying ot fix the
fill_delay logic.
2013-07-15 10:47:55 -04:00
Jonathan Kamens 948846c254 MAINT: Upgrade pep8, pyflakes 2013-07-12 14:20:59 -04:00
Eddie Hebert 0dbdf5b1d3 BUG: Fix duplicated values for multi-stock TALib transform.
A multi-stock TALib transform was returning the same value for
all stocks, specifically the value for the first stock in the panel.

Index into the datapanel using `sid` instead of using the `[0:]`
index which was used when only supporting one sid.
2013-07-11 15:44:38 -04:00
Eddie Hebert fa845cbf03 MAINT: Move batch transform into a dedicated module.
Break the BatchTransform class and decorator function into a
separate module, with hope that it makes it easier to zero in on
batch transform logic.
2013-07-10 17:56:32 -04:00
Eddie Hebert 5758f885c5 TST: Update talib example for compatibility with multiple sids.
To support mulitple sids the TALib transforms now return a dict,
instead of a float. Accordingly, the TALib example script now needs
to index into the transform result.
2013-07-10 15:37:03 -04:00
Eddie Hebert eac882b773 ENH: Enable TALib transforms to perform on multiple stocks.
The TALib transform only supported operating on the first value
of a given batch transform panel row.

Instead of returning the one value, even if an panel with multiple
sids was provided, return a dictionary that maps stock to TALib
result.
2013-07-10 14:40:58 -04:00
Eddie Hebert 37352210c0 MAINT: Make TALib zipline_wrapper a module level function.
Prepare for making the zipline_wrapper operate on multiple sids,
as the needed nested logic will get cramped within the nested function.

Also, should help clearly define the inputs of the zipline_wrapper
function that are needed before it is passed to the BatchTransform
constructor.
2013-07-10 14:38:57 -04:00
Eddie Hebert 15323a8179 BUG: Enable return values on first day using minute TALib functions.
Set the `compute_only_full` to False so that the 'is window full' logic
is delegated to the TALib's lookback function.
If the window is not full to the `timeperiod` or other lookback setting,
then TALib returns a `np.nan`.

Also, fix the bars/data_frequency not being passed to the BatchTransform
init.
This further shows need to create a minute test for TALib transforms.
2013-07-09 14:54:38 -04:00
Eddie Hebert 3dfe4e9c83 STY: Remove extra lines between statements. 2013-07-09 14:54:09 -04:00
Eddie Hebert e3a9ca27b1 Merge ability to specify timing of fills.
From PR #186
2013-07-09 13:20:16 -04:00
Eddie Hebert d901a12e93 BUG: Prevent algorithm init failure due to missing fill_delay.
Provide a default value for data_frequency, choosing 'daily',
so that the fill_delay is set even when a data_frequency value
is not in kwargs.

This does open up a place for disjointedness if the sim_params that
is passed to run does not match the data_frequency set during initialize.
2013-07-09 12:45:56 -04:00
Thomas Wiecki 5a58ade0fc ENH: Add flag fill_delay kwarg to TradingAlgorithm. 2013-07-09 11:38:09 -04:00
Thomas Wiecki 8e39af906f ENH: Move blotter call to after handle_data() and add fill_delay option. 2013-07-09 11:38:09 -04:00
Eddie Hebert 3d8bdeb429 ENH: Enable minute bar data with TALib transform.
Add a `bars` keyword arg, as is used with BatchTransform.

Also, instead of overwriting the window_length kwarg with timeperiod,
always use the lookback value from the created TALib function,
as timeperiod will be an input into that value if it exists.

Calculate `window_length` in minute mode so that there are enough
days to cover the minutes in the timeperiod.
2013-07-09 11:26:26 -04:00
Eddie Hebert 5fb837bf37 MAINT: Use numpy testing method instead of assertTrue.
So that when the test fails, the comparison is in a more readable
format.
2013-07-08 17:30:48 -04:00
Eddie Hebert ab0d07d8d0 API: Conform timeperiad to TALib interface instead of BatchTransform's.
For the creation of a TALib transform use timeperiod intsead of
window_length, to be more in the style of TALib usage, since all
TALib functions may not ending up using BatchTransform, so start
the practice of adhering to TALib conventions to make porting and
explanation easier.
2013-07-03 13:46:32 -04:00
Eddie Hebert a968b5827c MAINT: Use print function instead of print statement.
The loader module printed some warning messages, these could
be changed to use a logger, but for now convert to use the print
function for compatibility with Python 3.
2013-07-02 21:33:40 -04:00
Eddie Hebert 4f5b2d6298 MAINT: Change relative library imports to use dot syntax.
Testing with a Python 3 virtualenv uncovered more relative imports
that did not explicitly use the dot syntax.
2013-07-02 21:31:59 -04:00
Eddie Hebert 4c42e5a6d7 MAINT: Use Python 3 compatible uuid hex property.
Instead of `uuid`'s `get_hex()` use `hex` which is available in
both Python 2.7 and Python 3.

From: @chinux23, Chen Huang <chen_huang@apple.com>
2013-07-02 16:07:07 -04:00
Eddie Hebert 158988d184 MAINT: Use explicit syntax for relative imports.
Python 3 requires using dot syntax for relative imports,
otherwise the import is treated as an absolute import, i.e.
an import of a module from outside of the project.

By using dot syntax now, imports should be compatible with both
Python 2.7 and Python 3.
2013-07-02 15:54:12 -04:00
Eddie Hebert b77780c783 MAINT: Use DatetimeIndex instead of OrderedDict for trading days.
Looking forwards to Python 3 capability, maintaing code that uses
iterkeys would require some overhead of checking what Python version
is available etc., instead use a DatetimeIndex so there is no need
to use key iterators, reverse, etc. on an OrderedDict, as the
DatetimeIndex allows 0 and -1 index, as well as the needed fast `in`
functionality.
2013-07-02 15:27:38 -04:00
John Ricklefs d9b7578eae Add a VirtualBox-based Vagrant config file.
This VagrantFile will, on "vagrant up"...

- Create a simple, minimal Precise Pangolin (12.04) Ubuntu 64 bit VM
- Customize the VM with 2 virtual CPU's and 2048MB of RAM
- Configure SSH for passwordless access (from the command-line)
- Add the required packages from the Ubuntu repo to support zipline
- Add (and compile) ta-lib
- Add the required Pip packages

When Vagrant is done, you can start hacking on zipline with:

vagrant ssh
cd /vagrant
python {some python script that uses zipline}
In the spirit of making this a disposable dev environment install
everything in site-packages.

"nosetests" and "examples/dual_moving_average.py" both succeed
after the configuration finishes.
2013-07-02 10:53:04 -04:00
Eddie Hebert 4510c56142 MAINT: Use TALib abstract function names value when creating transforms.
Instead of using reading the __all__ value and filtering out Function,
use the abstract internal variable that lists all functions.
2013-06-28 16:22:22 -04:00
Eddie Hebert c7c55399be BUG: Fix TALib example due to parameter changes.
Remove use of `sid` parameter, which was recently removed.
2013-06-27 21:10:09 -04:00
Eddie Hebert 5d76c0b8a4 ENH: Remove need to pass sid to TALib transform constructor.
Now that BatchTransforms use RollingPanels under the hood, passing
an sid is no longer needed, passing the data will to handle_data
will suffice.
2013-06-27 19:12:01 -04:00
Eddie Hebert 832a39706e STY: Remove unused import from transform tests. 2013-06-27 19:11:15 -04:00
Thomas Wiecki 84e6050c65 BUG: Fix randomly failing talib unittest that relied on dict order. 2013-06-27 17:50:35 -04:00
Thomas Wiecki 9931812745 BUG: Buy/sell triggers not correct in example. Thanks @FerMartin. 2013-06-27 13:23:48 -04:00
Jonathan Kamens d833503e50 BUG: Use context in lieu of "use_environment" decorator
The "use_environment" decorator is too side-effectful (e.g.,
connecting to Yahoo! Finance or another data source) to be used as a
decorator to a function that gets evaluated during module load. This
causes problems, e.g., if Zipline is being used in a gevent
environment, when the trading environment created by the decorator
argument tries to use greenlets when gevent hasn't been fully
initialized.

Since the decorator is nothing more than a context-manager wrapper,
this commit removes the decorator and replaces its use with contexts,
i.e., "with" statements.
2013-06-24 17:13:14 -04:00
Eddie Hebert 61f22f0b0d Merge changes to RollingPanel that allow new sids to be added mid-run. 2013-06-21 10:43:48 -04:00
Thomas Wiecki a7818f853a DOC: Add note about performance issue when updating. 2013-06-20 19:36:36 -04:00
Thomas Wiecki 102cddb4cb ENH: Use smarter matching for updating RollingPanel. 2013-06-20 19:36:36 -04:00
Thomas Wiecki 236fe92a53 ENH: Make RollingPanel update itself if new fields arrive.
Before we preinitialized the BT's fields and sids.
Thus, no new ones could be added after initialization.
This should be fixed now.
2013-06-20 19:36:22 -04:00
Thomas Wiecki 33c23af503 BUG: Do not try to set non-existent items. 2013-06-20 18:32:05 -04:00
Eddie Hebert aca338c9e5 MAINT: Remove unused NaiveRollingPanel from rolling panel module. 2013-06-20 18:00:13 -04:00
Eddie Hebert d6abe172a2 ENH: Add check to ensure transactions and orders are aligned.
Raise exceptions when the slippage model returns transactions
that are non-sensical, i.e. those with zero volume, buy transactions
when the order is a sell (and vice-versa), and transactions that are
for a larger amount than the corresponding order.

TODO: After adding a unit test suite that covers just the blotter,
add tests that exercise this logic to that suite.
2013-06-20 13:23:01 -04:00
Eddie Hebert c36fe01637 STY: Use return instead of StopIteration to short circuit blotter gen.
Using `return` is a little more readable alongside the rest of the logic
compared to exposing iterator internals.
2013-06-20 13:01:09 -04:00
Eddie Hebert ebe00b83f7 MAINT: Pass order emitted from slippage up to tradesimulation.
Instead of searching through the open orders to find the ones
that match the current transactions, now that simulate returns
the pair of transaction and order for which that transaction
was created for, that order can be used where we previously
searched for a modified order.

This should be a runtime improvement since, but not yet verified
via thorough profiling.
2013-06-20 12:36:49 -04:00
Eddie Hebert e160f9afd8 TST: Skip TALib related tests.
The TALib related tests randomly fail, skip for now, as it causes
noise when developing against the latest versions of the codebase.

Should remove skips when TALib is closer to being fully supported.
2013-06-20 00:13:06 -04:00