Commit Graph

5611 Commits

Author SHA1 Message Date
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
Eddie Hebert afdb6c99af MAINT: Return orders alongside transactions from slippage simulate.
So that blotter.process_trade doesn't need to reindex the dictionary of
open orders, yield a tuple of (order, transaction) from simulate.

Also, update corresponding unit tests now that the method returns
a generator instead of a list.
2013-06-19 16:35:05 -04:00
Eddie Hebert 2aa038c2a7 MAINT: Make usage of absolute`value more clear in slippage.
Instead of using copysign with a param of 1, use `abs` to make the
code more clear between when slippage is using the absolute value,
and when it is creating an amount that uses the order direction.
2013-06-18 11:22:35 -04:00
Eddie Hebert b1234adee6 BUG: Protect against transactions with an amount less than 1.
If the amount is less than 1, then many more transactions than are
needed are created and then ignored by both the slippage and blotter
code.
2013-06-18 11:14:52 -04:00
Ben McCann eaa9880203 DOC: Reference example in quickstart to keep it up-to-date.
Fix the quickstart docs by including the example so that it's
always up-to-date.
2013-06-14 15:58:45 -04:00
Ben McCann eb027833b3 DEV: Make the other example charts larger as well 2013-06-14 15:47:44 -04:00
Eddie Hebert 972eb1707d Merge fixes to docstring for TradingAlgorithm. 2013-06-14 15:44:12 -04:00
Matti Hanninen 43d3757004 DOC: Fix docstring for TradingAlgorithm
Get the amount from the algorithm object instead of referring to
a (undefined) global.
2013-06-14 15:43:51 -04:00
Matti Hanninen d475766c63 DOC: Fix docstring for TradingAlgorithm
Fix the example given in the class docstring as the original didn't work
on REPL.
2013-06-14 15:43:40 -04:00
Matti Hanninen 8e27cc053c DEV: Don't invoke hardwired Python
Instead use /urs/bin/env to detect the Python interpreter. This way the
scripts work better with the possible virtual environment.
2013-06-14 15:38:45 -04:00
Eddie Hebert d41aff9a99 ENH: Provide a process_order method to override for custom slippage.
To make implementing a custom slippage model more straightforward,
provide a simulate method that will setup the calling of
`process_order`, which individual slippage models override to
do the unique slippage handling, where the simulate method handles
the boilerplate of checking order triggers, etc.
2013-06-13 19:01:00 -04:00
Eddie Hebert e727bfbd03 MAINT: Factor out order processing from slippage models.
Step towards having a shared simulate method in the base SlippageModel,
which would call a process_order method in each model.
2013-06-13 17:49:18 -04:00
Eddie Hebert 7f669c4391 MAINT: Separate volume and direction while calculating volume share.
In the volume share slippgae, the current amount had the direction,
i.e. buy/sell was baked into the value of `cur_amount` which then
needed to have the direction multiplied out when parts of the slippage
model needed to take in just the magnitude/amount into account.

So calculate the current volume, use that in calculations and then
apply at the order direction at order time.

Also, when applying the direction to the magnitude of the sell,
use copysign to make the code more explicit about taking the direction
of the order, instead of it possibly having some scalar impact.

As well as remove direction from volume_share calculation since that
calculation and subsequent calculations only care about the magnitude,
so make the disregard for direction more explicit by removing it.
2013-06-13 15:24:53 -04:00
Eddie Hebert 0ae41f4d01 MAINT: Remove check in slippage model which is always true.
Since `cur_amount` before it's changed by the direction, is always
a positive value, multiplying it back by the direction should also
always be positive.
2013-06-13 12:42:26 -04:00
Richard Frank 88b9881145 TST: Include the label in the failure message of isinstance asserts 2013-06-12 14:18:09 -04:00
Eddie Hebert dc14f0e9ff MAINT: Remove _period_trading_days member from TradingEnvironment.
Now that the period_trading_days method is removed, the internal
member that cached the value, is also no longer needed.
2013-06-12 13:26:31 -04:00
Eddie Hebert 59edea66f1 MAINT: Remove unused method from TradingEnvironment.
period_trading_days is no longer referenced elsewhere.
2013-06-12 13:25:11 -04:00
Eddie Hebert 692da712b8 MAINT: Removed unused member from risk class.
`runonce` is only ever written to, but never used.
2013-06-12 12:31:25 -04:00
Eddie Hebert fd60d775d5 BUG: Fix early exit from fixed slippage when a order amount is zero.
The order loop should continue, effectively dropping/skipping the zero
amount order, not return early and erroneously skip possible valid
orders.
2013-06-12 10:43:09 -04:00
Eddie Hebert d1968429f1 ENH: Add a convenience property for open amount of a blotter.Order
Found that when implementing different slippage model, needed the
open amount in several places/functions, having the open amount
as a property of an order should help reduce the need for passing that
around and maintaining the value separately.
2013-06-12 10:43:09 -04:00
Richard Frank e24f581dcd BUG: Extend trading environment's trading days with extra_dates
instead of just limiting it with max_date.  This allows for an
additional "live" day appended to the end, fixing various uses
of the trading_day_map, and replacing the isolated check in
get_next_close.
2013-06-11 10:43:24 -04:00
Eddie Hebert 2b5b670493 MAINT: Change signature of create_transaction.
- Change the expected type for order information from the string
  of the order id to an `Order` object, so that it matches the same
  abstraction level as passing in an event.
- Change the order (not to be confused with the parameter named `order`)
  of the parameters so that they go from left to right in order of
  static -> dynamic, i.e. the parameters most likely to change within
  each invoration are the amount and price, with amount more likely
  to change than price.
2013-06-10 17:10:48 -04:00
Eddie Hebert 7d26168359 MAINT: Reduce number of parameters for create_transaction.
create_transaction accepted both sid and order, which in all cases
was derived from the current event, so remove `sid` and `order`,
replacing them with event

If there is a scenario where sid and order need to be set independently
of each other, then the underlying Transaction object can be called
directly.

Looking towards making writing custom slippage models slightly easier
by removing the redundancy.
2013-06-10 15:36:58 -04:00
Eddie Hebert 4bde1e4c11 MAINT: Change slippage guard to check for slippage model base type.
Now that VolumeShareSlippage and FixedSlippage inherit from the same
class, check for `SlippageModel` instead of the inividual classes.
2013-06-10 10:27:16 -04:00
Eddie Hebert 5727080b21 MAINT: Provide a callable base class for slippage models.
Work towards a set_slippage method accepts a function that takes
event and orders as the argument, instead of being tightly bound
to using classes like FixedSlippage etc., in that scenario the
instances of SlippageModel will be used via `__call__`, so that
backwards compatiblity is maintained.
2013-06-07 18:24:50 -04:00