6093 Commits

Author SHA1 Message Date
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
Ben McCann cc7969e777 DEV: Make the example chart larger so that it's readable 2013-06-07 10:15:33 -04:00
Eddie Hebert b2895e06ee MAINT: Remove logging processer from transaction stub.
Now that the tradesimulation transform calls the blotter/slippage
within, instead of being wrapped in a slippage generator, the logging
for slippage can rely on the processor set within the tradesimulation
loop, instead of maintaining its own.
2013-06-06 17:43:39 -04:00
Eddie Hebert f978d4807e MAINT: Simplify current date logic in tradesimulation loop.
Now that the tradesimulation loop has changed to use benchmarks
as a 'clock', the logic for setting the current time can be grouped
together at the beginning of each iteration instead of the date
and snapshot grouping.

Also, can remove the snapshot_dt and use simulation_dt instead
of having two variables that were keeping track of the same value.

Also, it is no longer needed to peek into the data to get the first
simulation_dt now that simulation_dt is set at the beginning of each
loop iteration.
2013-06-06 17:43:18 -04:00
Ben McCann 99676067d7 DOC: Add some more installation instructions 2013-06-06 10:07:35 -04:00
Eddie Hebert fa13a98aa2 MAINT: Update TA-Lib to latest release. 2013-06-05 13:30:11 -04:00
Jonathan Kamens 9ee0d5e3a3 Upgrade Logbook to 0.4.2 2013-06-04 13:30:42 -04:00
Jonathan Kamens efadc6cf68 MAINT: blotter shouldn't allow orders of more than 1e+11 shares 2013-05-30 11:24:29 -04:00
Jonathan Kamens f9580316c9 MAINT: Reformat comment to make flake8 happy 2013-05-30 10:06:23 -04:00
Jonathan Kamens 3390c017bb MAINT: Upgrade dependent package versions, add pip-tools
pandas==0.11.0, Cython==0.19.1, TA-Lib==0.4.6, requests==1.2.3,
delorean==0.2.1, nose-parameterized==0.3, pyflakes==0.7.2

Also add pip-tools==0.3.4 to requirements_dev.txt.
2013-05-30 09:38:28 -04:00
Jonathan Kamens 48a7ce5310 BUG: Improve check for orders for zero shares
The check to filter out orders for zero shares wasn't truncated the
number of shares to an integer before checking, so if a fractional
amount less than 1 was being passed in, it wasn't being filtered out
even though it should have been. This is now fixed.
2013-05-29 12:46:24 -04:00
Eddie Hebert 6c6b45659b BUG: Fix bar data contains check when override is used.
The override should be used to filter out symbols not in the universe,
however it was returning false positives.

To remove the false positives, after the contains check passes,
ensure that the key exists in the _data member.
2013-05-23 11:37:12 -04:00
Eddie Hebert 25d6f3afd1 BUG: Fix contains logic when override is not used.
The internal _data should be checked, not the __dict__
2013-05-23 11:31:58 -04:00
Eddie Hebert 0ef428c8e0 BUG: Fix exception when using capital_base as a kwarg to an algorithm.
Need to pop of the kwarg, since `initialize` does not use it as a
parameter.
2013-05-21 17:51:51 -04:00
Richard Frank 8be617c4bf MAINT: Allow overriding of order id creation 2013-05-16 15:01:14 -04:00
Richard Frank fa4b5a7ea4 MAINT: Importing zipline protocol as zp 2013-05-16 15:01:14 -04:00
Thomas Wiecki 3ea8ac8da2 BUG: Fix updating of trading_days_total in minute.
In the batch_transform we were incrementing the trading_days counter if there
is a new day event. Thus with a window_length of 1 and daily bars you will
update the batch_transform on the first day which is correct. But with minutes
you update with the first minute bar of the day which is not correct.

This is fixed by calculating the market_close explicity and seeing whether the
event.dt is on or past it.

I also added a unittest to test the correct behavior of this.
2013-05-16 14:51:19 -04:00
Thomas Wiecki 4a991c062b BUG: Change trading_days to num_trading_days in repr. Fixes #162. 2013-05-16 09:12:04 -04:00
Eddie Hebert 54541eb24c BUG: Fix short circuit in StateTransform loop.
A missing `continue` statement was causing the short circuit on
event type to not have the intended effect of skipping the update
portion of the loop.
2013-05-15 16:57:09 -04:00