Commit Graph

343 Commits

Author SHA1 Message Date
Jean Bredeche 8f1d599fc6 fixing some bugs with splits (ratios and empty positions) 2013-07-24 15:26:15 -07:00
Jean Bredeche 6fc077a573 ENH: Add support for splits in zipline.
When a split is encountered, open positions and open orders
are updated accordingly.
2013-07-23 16:22:58 -04:00
Eddie Hebert 9b73373978 BUG: Revert returns cov to use ddof of 1.
Fix the spreadsheet to apply a factor of COUNT / COUNT - 1
to the COVAR value.

Also, go back to using the C[1][1] index instead of calculating
var independently.
2013-07-23 13:17:10 -04:00
Eddie Hebert f451efe483 TST: Read alpha values from answer key.
Corroborate alpha values with Excel answer key.
2013-07-23 12:15:24 -04:00
Eddie Hebert 7c01d39858 BUG: Fix beta calculation.
Use recent change to benchmark variance in the beta calculation,
instead of referring to the 4th quadrant of the covariance.

Also, read answers from answer key for corroboration of beta values.
2013-07-23 12:07:24 -04:00
Eddie Hebert 3164aa9016 BUG: Make covariance match values in answer key.
The np.cov call needs a ddof of 0 to match the answer key, which uses
Excel's VAR.

When switching np.cov to use a ddof of 0, the benchmark variance is
no longer the 4th quadrant of the cov result, so use np.var directly.
2013-07-23 11:30:48 -04:00
Eddie Hebert 2314e8a281 TST: Read benchmark variance from answer key.
Add reference to updated answer key with benchmark variance cells,
and use the new cells as the reference for the benchmark variance
test.

The values changed from the original hardcoded values, due to the
change to close over close benchmarks.
2013-07-19 20:28:12 -04:00
Eddie Hebert 56c7c840fa TST: Fix answer key index converter for values larger than 'AB'
Change logic so that it uses the 26 ^ n as the base for each letters
index value.
2013-07-19 20:26:30 -04:00
Eddie Hebert de608b0b05 TST: Read more sharpe values from the answer key.
Recent conversion of sharpe to reading from the answer key had left
a few tests with hard coded answers.
2013-07-19 12:10:17 -04:00
Eddie Hebert 8c006fc347 TST: Use xlsx format instead of xls.
The xls conversion was corrupting some equations, so switching to
use Excel produced xlsx.
2013-07-19 11:06:37 -04:00
Eddie Hebert 135b872a58 DOC: Fix typo in xslx format name. 2013-07-18 18:36:42 -04:00
Eddie Hebert 575e45ab4e TST: Read more risk expected values from the answer spreadsheet.
Convert test_risk from hardcoded values to reading algorithm
returns, volatility, and sharpe answers from the spreadsheet.
2013-07-18 18:09:49 -04:00
Eddie Hebert d58181db34 TST: Fix case where there is no existing risk answer key.
The download checksum was not being correctly set when no file existed.
Set the checksum to the latest value so that a download is triggered.
2013-07-18 14:47:33 -04:00
Eddie Hebert e5e38a437b TST: Download risk answer key from S3.
So that the answer key does not onerous on the SCM repo size, add a
utility to download the answer key automatically.

Prevent re-download on every test suite run if the local answer key
matches the latest version.
2013-07-18 14:31:08 -04:00
Eddie Hebert 5579e54c6f TST: Read benchmark returns directly from answer key spreadsheet.
The risk tests originally were based on a spread sheet, with the
results of returns etc copy and pasted into the `test_risk` module.

Include the spreadsheet and read the values directly using a Python
Excel spreadsheet library.
2013-07-18 14:31:08 -04:00
Eddie Hebert 87c0f40aa0 TST: Move risk tests to their own module.
Will be adding the Excel spreadsheet answer key, a dedicatetd
directory for risk should help make clear why and where the spreadsheet
is used.
2013-07-18 14:31:08 -04:00
Thomas Wiecki 940ddd22d3 TST: Added testing of order timings and price. 2013-07-17 19:56:55 -04:00
Richard Frank 75dd77ea03 ENH: Added early closes to trading environment
specifically, expected 1 PM closes since 1993
2013-07-16 12:02:34 -04:00
Ben McCann efe50f8494 BUG: Fix get_benchmark_returns.
It should calculate the return off the pervious day's close, instead
of current day's open.
2013-07-15 15:35:09 -04:00
Eddie Hebert eac882b773 ENH: Enable TALib transforms to perform on multiple stocks.
The TALib transform only supported operating on the first value
of a given batch transform panel row.

Instead of returning the one value, even if an panel with multiple
sids was provided, return a dictionary that maps stock to TALib
result.
2013-07-10 14:40:58 -04:00
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 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
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
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
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
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 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
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 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 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
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 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 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
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
Thomas Wiecki b8b21b347f TST: Added unittest that runs all examples. 2013-05-02 16:33:08 -04:00
Eddie Hebert 419c03dedb BUG: Smooth test and compile issues with TALib
So that TALib is still available, but smooth out the ability to
run tests with some issues that bear investigating.

- Ignore MAVP during tests.
- Temporarily use a "regular" member instead of  __doc__ string.
  (TODO: look into using `type` to generate the class)
- During tests wait until a window exists.
2013-04-30 20:19:37 -04:00
Jeremiah Lowin cc39ec3aef ENH: Add support for TALib based transforms.
Provide a subclass of BatchTransforms that are powerd by the ta-lib
library.
2013-04-30 17:35:56 -04:00
Thomas Wiecki 2be7014d51 ENH: Rewrite of batch_transform to use rolling panel.
- Added unittest to test for newly appearing sids.
- Fixed logic bug where window was only full after
  window_length+1 events got passed.
2013-04-29 15:30:40 -04:00
Wes McKinney c5f4d00bf1 ENH: prototype data structure for managing a rolling datapanel
Manage a rolling window collection of collection of panels
for computation purposes.
2013-04-29 15:19:02 -04:00
Eddie Hebert a4ea33218d TST: Move batch transform tests to their own file.
From @twiecki's rolling batch transform work.
2013-04-26 23:56:35 -04:00
fawce 9062b9636a MAINT: refactoring for orders api
- moved Order and Blotter to zipline.finance.blotter
- moved order method from AlgoSimulator to Blotter
- eliminated the set_order method in algorithm
- moved blotter to the algorithm
2013-04-26 19:45:59 -04:00
Eddie Hebert b3efb5eb69 MAINT: Remove ndict class.
Now that ndict is no longer used in any part of the system during
a backtest, remove all remaining references in tests, etc.
2013-04-26 16:03:01 -04:00
Eddie Hebert d4a8878c6e TST: Ensure holiday edge case is covered in dividend performance test.
Add a test suite of dividend performance that ensures a holiday
is covered, needed because tests usually go over a random test range,
so holiday coverage isn't covered in basic test.

From @fawce.
2013-04-26 10:56:54 -04:00