Commit Graph

2071 Commits

Author SHA1 Message Date
Eddie Hebert 803b58c8aa MAINT: More precise extraction of returns from returns container.
Use slice to date, `[:dt]` instead of `pd.Series.valid` to extract
from returns containers.

Using `valid` lead to some confusion when debugging tests, because
it papers over missing data.

The use of `.valid` was based on the assumption that all values
from the zeroth date to the current algo date are populated,
with no trailing values.
`[:dt]` extracts the same data, but in a hopefully more precise
and explicit fashion.
2014-03-21 17:22:10 -04:00
Eddie Hebert 7ce971fa17 MAINT: Use more clearly named cumulative risk returns containers.
Change `_period_returns` to `_cumulative_returns`, so that there
is less mental overhead/confusion when reading through the risk
module.
2014-03-20 16:00:34 -04:00
Richard Frank 54ad18e2ff MAINT: Simplified event stream creation for tests 2014-03-11 19:08:22 -04:00
Richard Frank 7a3f73cf1d BUG: Update perf period state when positions are changed by splits
Otherwise, self._position_amounts will be out of sync with position.amount, etc.
That value is used to calculate pnl and returns, so test for them.
2014-03-11 19:08:22 -04:00
Eddie Hebert 4860a966b3 REL: Update copyright year on all files changed since the new year. 2014-03-07 22:31:41 -05:00
Eddie Hebert a203f69635 PERF: Remove alias_dt transform in favor of property on SIDData.
Adding a copy of the Event's dt field as datetime via the
`alias_dt` generator, so that the API was forgiving and allowed
both datetime and dt on a SIDData object, was creating noticeable
overhead, even on an noop algorithms.

Instead of incurring the cost of copying the datetime value and
assigning it to the Event object on every event that is passed
through the system, add a property to SIDData which acts as an
alias `datetime` to `dt`.

Eventually support for `data['foo'].datetime` may be removed,
and could be considered deprecated.
2014-03-07 10:55:59 -05:00
twiecki 778da20468 BUG: Fix floating point error in order(). 2014-03-06 12:32:19 -05:00
twiecki eccaf8d53d ENH: Add symbol api function
A symbol() lookup feature was added to Quantopian.
By adding the same API function to zipline we can
make copy&pasting of a zipline algo to Quantopian
easier.
2014-03-05 17:15:44 -05:00
Richard Frank 5020c36f8d BUG: Fix cost basis calculation
Cost basis calculation now takes direction of txn into account.

Closing a long position or covering a short shouldn't affect the cost basis.
2014-03-05 14:48:58 -05:00
Richard Frank e459c2729c MAINT: Refactored unit tests to remove duplication
of arguments to factory.create methods.

Also added checking of the perf period cost basis results after each txn.
2014-03-05 14:48:42 -05:00
Richard Frank e7ec629510 MAINT: Cleaned up sid checks and exception types
Removed unnecessary parens

Keeping NameError reserved for when locals or globals are not found.
Exception is what we use for the other sid checks, so now they are consistent.
2014-03-05 14:40:05 -05:00
twiecki 63f1c791da DOC: Changed conda install channel. 2014-03-05 13:13:07 -05:00
Richard Frank 76b11e8b84 MAINT: Removed unnecessary floating point checks in slippage
Cleaned up some other expressions in slippage as well

Fixes #277
2014-03-04 18:36:29 -05:00
Eddie Hebert 6cdd5ddb10 BUG: Fix max drawdown calculation.
The input into max drawdown was incorrect, causing the bad results.
i.e. the `compounded_log_returns` were not values representative of
the algorithms total return at a given time, though
`calculate_max_drawdown` was treating the values as if they were.
Instead, use the `algorithm_period_returns` series, which does provide
the total return.

Update risk answer key with an Excel calculation of max drawdown
to help corroborate the calculations.

Also, remove `compounded_log_returns`, (which actually had stopped
being the `compounded_log_returns` at some point), since the max
drawdown was the only calculation using the values in that series.
2014-02-27 17:16:35 -05:00
Eddie Hebert e3096e9afc MAINT: Remove unused rounding method.
round_to_nearest is no longer referred elsewhere.
2014-02-26 21:55:14 -05:00
Eddie Hebert 7f724a9696 ENH: Provide all drawdowns and max drawdowns in cumulative risk.
The values are not part of the risk report, but can be useful for
examining the behavior of the drawdown calculations.
2014-02-26 20:46:58 -05:00
Colin Alexander 011ed09dc2 ENH: Extended commission PerShare method to allow a minimum cost per trade.
Also added unit tests (test_perf_tracking.TestCommissionEvents) to test
all commission models.
2014-02-25 14:37:08 -05:00
twiecki ae4a9b7d96 DOC: Added contributors to README.md 2014-02-21 09:05:22 -05:00
Richard Frank 14bae3e15b MAINT: Names were reversed from their actual values 2014-02-20 17:44:51 -05:00
Eddie Hebert 5dab18613b BUG: Prevent crash in vwap transform due to non-existent member.
The WrongDataForTransform was referencing a `self.fields` member,
which did not exist.

Add a self.fields member set to `price` and `volume` and use
it to iterate over during the check.
2014-02-20 17:33:30 -05:00
Eddie Hebert dd61ed4e25 BUG: Check required fields for stdev transform.
Move the assert method to the EventWindow subclass, to be
consistent with other transforms; also, add the check to
`handle_add`.
2014-02-20 17:29:25 -05:00
Eddie Hebert c139afb6a9 STY: Indentation fix in stddev. 2014-02-20 17:23:37 -05:00
Eddie Hebert 57c56351e9 MAINT: Re-enable algorithms which omit initialize method.
Though defining the `initialize` method may end up being explicitly
required, in the meantime prevent existing algorithms from crashing
by providing a noop function when `initialize` is not defined.
2014-02-20 13:50:03 -05:00
twiecki 170fe97631 BLD: Updates to conda build files. Now builds on windows. 2014-02-19 16:19:14 -05:00
twiecki e4caa43128 BLD: Added conda build files. 2014-02-16 11:00:51 -05:00
twiecki d900338e00 BUG: Py3 compatibility changes. 2014-02-16 10:59:29 -05:00
twiecki f0322015bd BUG: Fix pandas indexing in trading calendar. 2014-02-11 15:52:43 -05:00
Eddie Hebert e4d2527eca ENH: Limit handle_data to times with market data.
To prevent cases where custom data types had unaligned timestamps,
only call handle_data when market data passes through.

Custom data that comes before market data will still update
the data bar. But the handling of that data will only be done
when there is actionable market data.
2014-02-10 22:12:38 -05:00
Eddie Hebert 7aeaa69acf BUG: Prevent minute emission from crashing at end of available data.
The next day calculation was causing an error when a minute
emission algorithm reached the end of available data.

Instead of a generic exception when available data is reached,
raise and catch a named exception so that the tradesimulation loop
can skip over, since the next market close is not needed at the end.
2014-02-10 22:09:05 -05:00
Eddie Hebert e1608ad3f3 MAINT: Always defer to the algorithms data frequency.
For compatibility with existing behavior of having the,
data_frequency of the algorithm override the simulation parameters.

We may want to consider throwing an exception if the two do not match.
2014-02-10 15:24:18 -05:00
Eddie Hebert 8a22736f1e MAINT: Allow sim_params to provide data frequency for the algorithm.
In the case that data_frequency of the algorithm is None,
allow the sim_params to provide the data_frequency.

For less redundancy when setting up an algorithm.
2014-02-10 14:53:11 -05:00
Eddie Hebert b294d30af0 BLD: Update TA-Lib to latest version.
Keeping current with TA-Lib release.
Also, TA-Lib 0.4.7 has been removed from PyPI, so 0.4.8
is required for fresh PyPI based installs.
2014-02-07 22:03:06 -05:00
Eddie Hebert 7ecf544d15 BUG: Fix repr for cumulative risk metrics.
The __repr__ for RiskMetricsCumulative was referring to an older
structure of the class, causing an exception when printed.

Convert to printing the last values in the metrics DataFrame.
2014-02-07 21:34:01 -05:00
twiecki d91c18b1c2 BUG: Python 3 fix. 2014-01-30 18:48:46 -05:00
Michael Schatzow 59bcd097d5 ENH: Add hdf5 and csv source.
This creates a data source for csv and hdf5 files, a generator to create a sample csv, and a pytables generator to go from a list of dated gzipped csv's in a directory to a pytables data source.

This does not add a unittest yet which we should write for the future.
2014-01-30 16:47:27 -05:00
twiecki 07e25ae018 Merge branch to adjust benchmark times in minute mode. 2014-01-30 16:35:59 -05:00
twiecki 734abb2800 BUG: NoopAlgorithm requires initialize(). 2014-01-30 16:33:49 -05:00
Jamie Kirkpatrick 147242339d BUG: ensure perf stats are generated for all days
When running with minutely emissions the simulator would report to the
user that it simulated 'n - 1' days (where n is the number of days
specified in the simulation params).  Now the correct number of trading
days are reported as being simulated.
2014-01-30 16:04:29 -05:00
Jamie Kirkpatrick 45844bac31 BUG: adjust benchmark events to match market hours
Previously benchmark events were emitted at 0:00 on the day the
benchmark related to: in 'minute' emission mode this meant that
the benchmarks were emitted before any intra-day trades were
processed.

See: https://github.com/quantopian/zipline/issues/241
2014-01-30 16:01:58 -05:00
Eddie Hebert 9feed61748 MAINT: Use more exact boolean checks for pandas structures.
To prepare for being compatible with pandas==0.13.0, which is stricter
on boolean checks.
2014-01-29 17:13:13 -05:00
Eddie Hebert ff965060ff BUG: Fix typo in requirements file.
Fix incorrect number of '='
2014-01-21 10:51:53 -05:00
Eddie Hebert 47954755fa BLD: Add mock to requirements file.
mock was recently added as part of the testing of port of the script
API for algorithms.
2014-01-21 10:28:01 -05:00
Eddie Hebert 9573e28002 BLD: Update to latest tornado release.
Used by IPython notebook, update version from 3.1.1 to 3.2
2014-01-20 20:07:36 -05:00
Eddie Hebert aa4c67cd4d BLD: Update to latest Cython release.
0.19.2 -> 0.20
2014-01-20 20:05:02 -05:00
Moises Trovo 64b28d15f8 ENH: Add Brazilian calendar for BMF&Bovespa stock market
Add Brazilian Bovespa Stock Market calendar
2014-01-16 12:53:11 -05:00
Thomas Wiecki b69590a2f7 ENH: Factor out API methods. Add support for algo scripts.
This is a step towards the goal of uniting Quantopian scripts
and zipline.

To make the syntax of zipline identical to Quantopian
we break out the API methods (like order) and turn them into
functions. To access the algo object we add a thread local reference
to the current algorithm that is accessed in the API functions.

TradingAlgorithm now takes either a string or two functions
(initialize and handle_data) that it executes.

Use api method decorator for methods available in algoscript.

Ported appropriate algorithm tests from internal code.
2014-01-16 12:07:33 -05:00
Eddie Hebert adcae79da3 BUG: Make itervalues in empty position test Python 3 compatible.
Use `six.itervalues` so that the call works in both Python 2 and 3.
2014-01-10 15:47:09 -05:00
Eddie Hebert 51e8b3244e ENH: Filter out empty positions from portfolio container.
To help prevent algorithms from operating on positions that are
not in the existing universe of stocks.

Formerly, iterating over positions would return positions for stocks
which had zero shares held. (Where an explicit check in algorithm
code for `pos.amount != 0` could prevent from using a non-existent
position.)
2014-01-10 14:30:29 -05:00
Richard Frank 15dd1f9c0e ENH: Always process new orders
Allows for updating of new_orders even when handle_data isn't called
2014-01-10 13:19:02 -05:00
Richard Frank dadf867cf4 MAINT: Updated requests requirement to 2.2.0 2014-01-10 10:01:42 -05:00