Commit Graph

1698 Commits

Author SHA1 Message Date
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
Eddie Hebert a04ece1840 MAINT: Use up-to-date field names in test_source
TRANSACTION member of Event had been removed.
close_price and open_price, are preferred to to close and open
2013-05-05 11:09:59 -04:00
Eddie Hebert 4b7afb43d2 MAINT: Change repr's so that they are both human and machine readable.
For printability in the repr when debugging algo config and state,
change the repr of TradingAlgorithm and the objects it contains
so that the more closely adhere to the repr interface of being
able to recreate an object instance.
2013-05-04 22:26:28 -04:00
Eddie Hebert 5ae1aab2af TST: Add nose-ignore-docstring plugin to requirements and setup.cfg
So that docstrings can be added for test documentation, but suppress
those docstrings in test output by default.
2013-05-04 12:52:38 -04:00
Eddie Hebert e3c783e163 BLD: Add scipy to test requirements.
For example scripts. Though compiling scipy for TravisCI may be the
straw that breaks the camel's back as far as total suite run time.
2013-05-03 13:32:30 -04:00
Eddie Hebert 727f7bef19 BLD: Use statsmodels 0.4.3 for test scripts.
0.5.0 is unavailable via the pep syntax, an incongruity
between the results of `pip install` and `pip freeze`
2013-05-03 09:40:27 -04:00
Eddie Hebert 42ad791f39 BLD: Add libraries needed for running examples.
Add statsmodels and patsy, since they are used by example scripts
and example scripts are now run as part of the unit test suite.
2013-05-03 09:17:17 -04:00
Eddie Hebert c3cbe4e6b1 Merge addition of unit tests that exercise examples.
Also, multiple fixes to examples that the unit tests uncovered.
2013-05-02 17:05:06 -04:00
Eddie Hebert 7bc20639da BLD: Add matplotlib to test requirements.
Example scripts use matplotlib, so add to requirements_dev.txt
so that CI will include matplotlib.
2013-05-02 16:54:57 -04:00
Thomas Wiecki b748ba62e0 MAINT: Shortened time frame over which examples are run to speed up tests.
Minor fix pairtrade to now use record.
2013-05-02 16:54:57 -04:00
Thomas Wiecki f5a8d76a91 BUG: Do not update last price if price is nan. 2013-05-02 16:54:57 -04:00
Thomas Wiecki d56f1b73f8 BUG: Removed SlippageModel from olmar example.
Fix crash due to 'delay' was no longer supported.
But removing SlippageModel override, since current configs
should be functionally equivalent to FixedSlippage.
2013-05-02 16:54:08 -04:00