Commit Graph

1709 Commits

Author SHA1 Message Date
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
Eddie Hebert cdc3886e91 Merge fixes for intraday perfomance.
Contains bugs and protocol compatibility changes.
2013-05-07 19:48:40 -04:00
fawce ede8471663 BUG: Fix next trading calculation.
If we are in a day beyond the historical data use the last close,
instead. Relevant for trading current data.
2013-05-07 19:26:24 -04:00
fawce 3d8674ffb6 MAINT: Cleaned up to_dict highlighting daily and minutely difference.
Make the difference between the two emission rates more exact.
2013-05-07 19:24:47 -04:00
fawce 2d850d0970 BUG: Fix calculation of cumulative risk stats.
- Use current dt instead of market_close.
- Handle intraday close
- Remove zeroing out of sharpe etc.
2013-05-07 19:21:20 -04:00
Eddie Hebert 32835b87f3 MAINT: Rename perfomances intraday_perf to minute_perf.
minute_perf is more precise than intraday_perf as a naming scheme
for the performance packet type.
2013-05-07 19:21:20 -04:00
fawce b53da8d4b3 MAINT: Refactor check_entry method to also look at np.inf
Also, make the method a module function.
2013-05-07 19:20:49 -04:00
Eddie Hebert 5c883659b5 BUG: Fix missing values from supplemental data in batch transform.
Adapt the supplemental data fill so that it works with the new
shape of the batch transform that was switched to with the rolling
panel optimizations.
2013-05-07 18:17:08 -04:00
Eddie Hebert d3ade5050c MAINT: Tune logging of StateTransform start/end to debug.
These log lines are useful for debugging, but a bit spurious
on every algorithm run.
2013-05-07 17:27:06 -04:00
Eddie Hebert 3e1ac4f19a TST: Add tests to verify risk calcualtions from streamed events.
So that we can verify the risk metrics as they are calculated.
Work towards being able to hand verify risk calculations.
2013-05-07 17:21:56 -04:00
Eddie Hebert 91e5abbc44 MAINT: Use a for loop for main algorithm run loop instead of list
So that stepping through a debugger is a little easier, with
respect to having easy access to the algorithm object, and seeing
which step in `self.gen` the interpreter is currently at.
2013-05-07 17:19:38 -04:00
Eddie Hebert aa54d0ae0e MAINT: Allow the algorithm benchmark returns to be overrideable.
So that test data can be well defined with a short list of benchmarks.

This could also lead to having more customizable benchmarks for
backtests.
2013-05-07 16:09:58 -04:00
fawce e6c156c50b ENH: Add intraday risk and performance for minute emission.
Both risk and performance now calculate performance since inception
(cumulative) and since the open. Both periods are updated intraday
and both are reported.

Batch risk for periods starting after the end of the treasury curve
history now use most recent curve.
2013-05-06 22:01:41 -04:00
Eddie Hebert 6afc85c17d BUG: Fix missing and delayed transaction last_sale_price's.
Critical that trade events be last, so that the perf tracker's
position information be updated with both the transaction and
the trade for last_sale.

Without, the first transaction would be recorded with a last_sale
of 0.

With @fawce
2013-05-06 16:28:47 -04:00
fawce 1752f78447 ENH: Allow algorithm to run past end of trading.environment history.
Work towards running an algorithm against 'live' data, which can't
be bound to the available benchmarks and treasuries, since the
benchmarks and treasury curves for that day won't be published
until that night.
2013-05-06 15:09:56 -04:00
Eddie Hebert d686fac02d MAINT: Use property for tradesimulation perf_key. 2013-05-05 11:32:33 -04:00