Commit Graph

1724 Commits

Author SHA1 Message Date
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
Thomas Wiecki b87d454938 BUG: Add bar kwarg to batch_transform.
Before the change to the RollingPanel, window_length
specified the number of days that should be in a window.

The previous commit broke this if data was minute resolution.

By passing bar='minute' to the batch_transform we internally
multiply the window_length by 60*6.5 to have a full day.

Also adds a (still rudamentary) test for batch_transform
with minute data.
2013-05-13 16:42:58 -04:00
Thomas Wiecki c1c71398d6 ENH: Add example that uses talib transform.
The new example is almost identical to the dual_moving_average one.
However, instead of our in-house mavg transform it uses the new
talib exponential moving average (EMA).
2013-05-13 16:38:40 -04:00
Thomas Wiecki 087d4d2c74 DOC: Add ta transforms to manual. 2013-05-13 11:24:10 -04:00
Thomas Wiecki aa7d5de073 BUG: Fix off-by-one error in TALib wrapper.
When setting timeperiod in the talib function it subtracts by 1. We then used this subtracted value to set the window_length in the batch_transform which was then not passing a big enough panel. Ultimately this caused the talib transforms to always return nans.

This also makes the unittest more stringent by explicitly comparing the output of the wrapped TALib moving average to pandas rolling_mean().

Finally, this also allows passing of window_length instead of timeperiod to allow usage of the same interface as before.
2013-05-11 15:42:27 -04:00
Thomas Wiecki 5cf1b2880d DOC: Removed obsolete docs. 2013-05-11 14:57:52 -04:00
Thomas Wiecki c22b86194f DOC: Add __doc__ string for all talib functions. 2013-05-11 14:41:51 -04:00
Eddie Hebert 2e327a4d1e MAINT: Add a has_key method to BarData for compatibility.
BarData should, at least for the time being, be compatible with
existing algorithms that had worked against the prior usage of
an ndict as data, which provided `has_key`.

Of note, the Python language has deprecated `has_key` in favor
of using `in` and `__contains__`.
2013-05-11 00:07:50 -04:00
Eddie Hebert 4177a2c073 DOC: Add @verdverm to contributors list. 2013-05-10 21:39:24 -04:00
Richard Frank 381df3534d MAINT: Ensure we're not setting the blotter to None. 2013-05-10 12:09:38 -04:00
Eddie Hebert a12e907f55 BUG: Fix datetime when a benchmark is the only datum in a bar.
The datetime was only being set while updating the universe with the
bar's trade events.

Now that benchmarks are used as a clock, it is possible to have
benchmarks without having trade bars during that dt, so the datetime
should be updated via benchmark as well.
2013-05-09 03:50:45 -04:00
Eddie Hebert b33243da63 BUG: Ensure that data_frequency set on algo is set on sim_params.
Set the data_frequency member of an algorithm on the sim_params
configuration object.

Though the extra setting is slightly redundant, it is needed to
ensure that the same data_frequency is used throughout.

Should fix a bug where an algo that was intended to be run in minute
mode was operating as if it were daily in performance.

Possible TODO: Remove data_frequency as a param to TradingAlgorithm,
in favor of only being a property of sim_params.
2013-05-09 03:44:51 -04:00
Eddie Hebert e9d80cc044 BUG: Fix out of order emission of performance with minutely data.
With the benchmark returns marked at midnight, the performance packet
for a day was emitted *before* any events for that day were processed.

Fix by expecting benchmarks marked at the market close, for backtests
that use minute data but emit performance results daily, so that the
benchmark handles at the end of day.

TST: Also, add test that exercises the event loop with minutely data,
(with benchmarks that are marked end of day), since that combination
was previously uncovered.
2013-05-08 21:20:25 -04:00
Eddie Hebert 74e743b8c6 MAINT: Add data frequency to simulation parameters.
Working towards performance and risk logic being aware of
data frequency, as different handling of order of events based
on the data frequency is needed.
2013-05-08 21:11:16 -04:00
Eddie Hebert 24019de573 BUG: Paper over multiple types for algorithm returns.
The Seriess-style indexing causes a crash on the list during unit tests.

TODO: Investigate whether the list type of algorithm returns can
      be removed.
2013-05-08 20:58:28 -04:00
fawce 5a2a51f796 MAINT: Use cumulative benchmark and algo returns in risk report.
So that RiskMetricsBatch can use the same benchmark returns that
are collected cumulatively as events are streamed through the system.
2013-05-08 18:41:37 -04:00
Eddie Hebert c0acbe2bc1 MAINT: Revert slice into returns containers instead of using .valid()
Backing out slice vs. valid(), because of an incompatiblity with
starting a minutely emitted session mid-day, since the midday start
date is not yet wired through SimulationParameters.
2013-05-08 18:29:49 -04:00
Eddie Hebert ad06acd49d MAINT: Slice into returns containers instead of using .valid()
The slicing syntax is more explicit about declaring:
'get all returns up until the current dt'.

Also, protects against NaNs that occur before the current dt
being silently ignored.
i.e. the *_returns_cont series *should* have values from start
to current dt, but the .valid() call was occluding a bug where
it wasn't.
2013-05-08 11:29:35 -04:00
Eddie Hebert 16c488e5bc TST: Fix increment in risk test that drops leading values.
The leading date of the date range was never called with update,
because in the main loop the todays_date variable was
incremented before update was called.

Fix by moving the increment to the next trading day to after the
call to update.
2013-05-08 08:31:08 -04:00
Eddie Hebert 41f1200dbd BLD: Exclude test_examples from Travis-CI, also exclude scipy.
scipy build was getting too heavyweight for the Travis-CI build.

Removes test_examples from Travis-CI run, since the examples
depend on scipy and other compiled libraries.

Please, still run test_examples before submitting patches.
2013-05-07 21:20:55 -04:00