Commit Graph

2149 Commits

Author SHA1 Message Date
Jonathan Kamens 96d8ebec3d BLD: List patsy before statsmodels in requirements.txt 2014-05-21 05:25:05 -04:00
Jonathan Kamens 03e40fd057 BLD: statsmodels requires patsy
Since statsmodels requires patsy, and statsmodels is now in
requirements.txt instead of requirements_dev.txt, patsy also needs to
be in requirements.txt instead of requirements_dev.txt.
2014-05-21 05:15:56 -04:00
Scott Sanderson fd0d0a84d8 DOC: More generic PostInit error messages.
Make the error messages for {DoBadThing}PostInit no longer reference "the
simulation", since the algorithm may not actually be running as a simulation.
2014-05-20 14:52:34 -04:00
Tony Lambiris 32a29088fe BLD: Move statsmodels from dev requirements into main requirements.
Pandas website states statsmodels is needed for parts of pandas.stats.
Also, update statsmodels to 0.5.0.

Upgrade of version is to both keep up to date, and to improve
performance on lazy imports, as fixed by
https://github.com/statsmodels/statsmodels/issues/573
2014-05-20 12:56:57 -04:00
Scott Sanderson 2be999e277 DOC: Update release notes for all_api_methods helper. 2014-05-14 11:34:09 -04:00
Scott Sanderson c3075f0ece ENH: Add a classmethod to TradingAlgorithm to get all API methods. 2014-05-14 11:24:33 -04:00
David Edwards c045f3a868 MAINT: deleted duplicate attribute in Portfolio
Deleted duplicate of Portfolio.portfolio_value in zipline.protocol. It
was defined on line 75 and line 82.
2014-05-13 10:17:50 -04:00
Scott Sanderson 2976a0dc5f DOC: Update release notes for trading controls. 2014-05-12 18:11:48 -04:00
Scott Sanderson 644486e6da ENH: Add trading controls to zipline API.
Adds four new methods to the Zipline API that can be used as circuit-breakers
to interrupt the execution of an algorithm.  The API methods are:

`set_max_position_size`
`set_max_order_size`
`set_max_order_count`
`set_long_only`

Internally, these methods are implemented by each registering a TradingControl
callback object with the TradingAlgorithm.  During
TradingAlgorithm.__validate_order_params (and thus before any side-effects of
the order call occur), each callback's `validate` method is called with
information about the order to be placed and the algorithm's current state,
raising an exception if the callback detects that an error condition has been breached.
2014-05-12 17:51:09 -04:00
Eddie Hebert 9953c7ea28 DOC: Update release notes. 2014-05-12 14:34:46 -04:00
Pankaj Garg 6e9dc6e552 BUG: Use env_trading_calender for open and closes data
TradingEnvironment class uses env_trading_calendar for trading days,
but the default trading calendar for open_and_close data, which causes
errors later, because of misalignment of trading days.

The issue can be resolved by using env_trading_calendar for
open_and_closes as well
2014-05-12 14:29:21 -04:00
twiecki c44458790a DOC: Add release notes for 0.6.2. 2014-05-07 15:34:46 -04:00
twiecki 8422006165 DOC: Fix typo in release announcement. 2014-05-07 15:34:46 -04:00
twiecki 12b651d9f0 DOC: Update README on conda installation, CLI and new example algo. 2014-05-07 15:34:46 -04:00
twiecki 59f8dfd94c DOC: Add note on installation to setting up dev env. 2014-05-07 15:34:46 -04:00
twiecki c9a75c7b42 STY: Rename run_algo to run_pipeline. 2014-05-07 15:34:42 -04:00
twiecki 2bfc2f9d93 DOC: Add doc strings. 2014-05-07 15:34:41 -04:00
twiecki f5086e4b0e ENH: Add IPython cell magic.
When zipline is imported it checks whether
it runs in the IPython notebook. If it does,
it registers a %%zipline magic that takes the
same arguments as the CLI with the addition of
a -o for specifying the output variable to store
the performance frame in.

The algo code in the cell is, as of yet, executed
in its own environment rather than that of the
IPython NB which is probably what we want.

Also adds cli option to save the perf dataframe
to a pickle file.

Also adds an IPython notebook buyapple example.
2014-05-07 15:34:41 -04:00
twiecki 5b45c46502 TST: Add tests for parse_args(). 2014-05-07 15:34:41 -04:00
twiecki f9fded97ac ENH: Implement CLI.
Add a CLI that reads in an algorithm, loads data,
run the algorithm, and output performance metrics.

The examples are adapted to the new zipline API and
analyses are split into separate files.

Also add config files that run the example
algorithms with preset settings.
2014-05-07 15:34:36 -04:00
Eddie Hebert fde40192cf WIP: Initial port of qprof run script. 2014-05-07 14:15:40 -04:00
Eddie Hebert 5d9a18c538 REL: Release notes file for 0.6.1 2014-05-05 16:19:18 -04:00
Scott Sanderson f41c37a606 ENH: Add the ability to specify an exchange on an ExecutionStyle.
Adds the exchange property the interface for ExecutionStyle and adds an
exchange parameter to the interface of all the existing ExceutionStyles.
Subclasses wishing to support the ability to specify an exchange should set the
_exchange attribute in __init__.
2014-04-29 17:35:12 -04:00
fawce ebf16720ef BUG: security is no longer an int. 2014-04-25 18:29:49 -04:00
Scott Sanderson 5373b6797c ENH: Treat stop and limit prices differently when rounding.
Stop and limit prices both trigger when a price crosses some threshold, but
they trigger in "opposite directions".  For example, on a buy, a limit price is
triggered when a price falls below a specified value, whereas a stop price
triggers when the price exceeds a specified value.

Our current stop/limit price rounding logic is asymmetric, preferring to "round
to improve" the specified price.  This change makes it so that we interpret
"improvement" in opposite directions for stop vs limit prices.
2014-04-25 12:02:23 -04:00
Richard Frank 17df628171 DOC: Replaced "i.e." with "e.g." where appropriate in module 2014-04-24 14:01:05 -04:00
Richard Frank f21bbe58fc ENH: Allow for stock dividends, and in particular, Google's
recent 2 for 1 stock split, where 1 class C share was distributed
for each share of class A held.

Now a dividend can specify a sid and ratio of stock that will be paid
to owners of the original security.  If the ratio is 2.0, then for every
existing share, two shares will be paid.
2014-04-24 14:00:39 -04:00
Richard Frank 0e4f3f957a BUG: ValueError for 'bars' masked by UnboundLocalError
for 'freq'
2014-04-23 17:57:46 -04:00
Scott Sanderson e3faf10dee MAINT: Add tests for UnsupportedOrderParameters.
Add a test case in test_algorithms to verify that appropriate exceptions are
thrown if an algorithm makes a call to the order api with a stop/limit price
and a style.
2014-04-22 23:22:21 -04:00
Scott Sanderson f1fafc34ce ENH: Add style parameters to order API helper methods.
Add `style` parameter to order_value, order_percent, order_target,
order_target_percent, and order_target_value methods.  The style parameter is
forwarded to the underlying call to `order`.
2014-04-22 23:22:21 -04:00
Scott Sanderson 119a1a4cda ENH: Update ordering API to support new ExecutionStyle class in favor of
existing `limit_price` and `stop_price` parameters.  The goal of this change is
to refactor the existing ordering API to provide a cleaner interface for
defining more complex order types.

Adds a new module, zipline.finance.execution, which defines the ExecutionStyle
abstract base class, along with concrete MarketOrder, LimitOrder, StopOrder,
and StopLimitOrder subclasses.

Adds a new `style` keyword argument to the function signature of the `order`
API method, which accepts an instance of ExecutionStyle.

The existing limit_price and stop_price parameters are still supported at this
time, but are converted into the new ExecutionStyle objects before being passed
to Blotter.order.
2014-04-22 23:22:21 -04:00
Scott Sanderson 353419e9ca BUG: Fix __unicode__ method for Order class in blotter.py
Order's __unicode__ was previously calling unicode(self.__repr__) instead of
actually calling the repr method.
2014-04-22 10:58:30 -04:00
Scott Sanderson eadf9d27e8 BUG: Fix a bug causing us to discard very low limit prices.
Fixes an issue where very low limit prices were being rounded to 0.0 and
effectively resulting in market orders.  Adds an explicit check to test for
this behavior.
2014-04-22 10:12:50 -04:00
Scott Sanderson 574415f434 MAINT: Adding tests for Blotter handling of limit and stop orders.
Adds a test algorithm that tries to buy with very high limit prices/very low
stop prices and tries to sell with very low limit prices/very high stop prices.
2014-04-21 16:34:59 -04:00
Scott Sanderson 6412742799 MAINT: Clean up unused data in test. 2014-04-21 16:32:54 -04:00
Scott Sanderson 47bfc2b536 MAINT: Clean up set_algo_instance usage in TradingAlgorithm.
TradingAlgorithm always uses set_algo_instance in pairs of
set_algo_instance(self) and set_algo_instance(None).  Refactoring this to use a
context manager.
2014-04-17 16:19:37 -04:00
twiecki 316611abd5 BLD: Conda zipline fixes. 2014-04-17 16:02:58 -04:00
twiecki b38bf07a95 Bump version: 0.6.0 → 0.6.1 2014-04-17 15:49:33 -04:00
twiecki 85053f7536 BLD: Wrong version in __init__.py 2014-04-17 15:49:31 -04:00
twiecki a4554a75ef BLD: Add bumpversion config. 2014-04-17 15:48:55 -04:00
Eddie Hebert 73573680f1 MAINT: Remove unneeded parameter to cumulative.calculate_alpha
The method was using a mix of the `dt` parameter and `self.latest_dt`.
Use `self.latest_dt` to conform with the rest of the module.
2014-04-17 11:19:45 -04:00
Eddie Hebert 35b09690a1 STY: Conform indentation to current flake8 recommendation.
The lines will be moved back when flake8, pyflakes, and pep8 are
all upgraded to latest.
2014-04-16 16:49:54 -04:00
Eddie Hebert acd0aeacf0 PERF: Reduce number of times the downside mask is created.
Assign the downside mask, `rets < mar` to a value instead of
calculating the downsides twice.
2014-04-16 16:25:02 -04:00
Eddie Hebert 1406f8e9ba PERF: Remove the drop of 'null return' from cumulative returns.
The check of existence of the null return key, and the drop of said
return on every single bar was adding unneeded CPU time when an
algorithm was run with minute emissions.

Instead, add the 0.0 return with an index of the trading day before
the start date.

The removal of the `null return` was mainly in place so that the
period calculation was not crashing on a non-date index value;
with the index as a date, the period return can also approximate
volatility (even though the that volatility has high noise-to-signal
strength because it uses only two values as an input.)
2014-04-16 15:48:13 -04:00
Eddie Hebert ea7d988721 DOC: Update link to latest risk answer key. 2014-04-15 16:17:39 -04:00
Eddie Hebert 101baad0f8 BUG: Fix change of type of period.sharpe
The factoring out of the Sharpe calculation changed behavior
so that both period and cumulative return nans when there is
no volatility; however before that change period returned 0.0.

This breaks existing consumers which expected a non-nan value
for period results.

Smooth out that change by checking the value after the sharpe
has been calculated and reset nan's to 0.0
2014-04-14 18:45:33 -04:00
Eddie Hebert 7cc24cec1f BUG: Fix numerous cumulative and period risk calculations.
The calculations that are expected to change are:
- cumulative.beta
- cumulative.alpha
- cumulative.information
- cumulative.sharpe
- period.sortino

* Explanation of how risk calculations are changing

** Risk Fixes for Both Period and Cumulative

*** Downside Risk

   Use sample instead of population for standard deviation.

   Add a rounding factor, so that if the two values are close for a given
   dt, that they do not count as a downside value, which would throw off
   the denominator of the standard deviation of the downside diffs.

*** Standard Deviation Type

    Across the board the standard deviation has been standardized to using
    a 'sample' calculation, whereas before cumulative risk was monstly using
    'population'. Using `ddof=1` with `np.std` calculates as if the values
    are a sample.

** Cumulative Risk Fixes

*** Beta

   Use the daily algorithm returns and benchmarks instead of annualized
   mean returns.

*** Volatility

   Use sample instead of population with standard deviation.

   The volatility is an input to other calculations so this change affects
   Sharpe and Information ratio calculations.

*** Information Ratio

   The benchmark returns input is changed from annualized benchmark returns
   to the annualized mean returns.

*** Alpha

   The benchmark returns input is changed from annualized benchmark returns
   to the annualized mean returns.

** Period Risk Fixes

*** Sortino

    Use the downside risk of the daily return vs. the mean algorithm returns
    for the minimum acceptable return instead of the treasury return.

    The above required adding the calculation of the mean algorithm returns
    for period risk.

    Also, use algorithm_period_returns and tresaury_period_return as the
    cumulative Sortino does, instead of using algorithm returns for both
    inputs into the Sortino calculation.

* Other Supporting Changes

** answer_key

   Add new mappings for downside risk and Sortino as well as
   re-address the index mappings because of changes to the answer key
   spread sheet.

** test_risk_cumulative

   Change the decimal precision to expect higher precision.
   The calculations are now more aligned with the answer key, so we can
   expect higher precision. In particular now that the standard deviation
   type matches everywhere in both the Python implementation and the answer
   sheet, the precision of the first value no longer has to be glossed over.

** test_events_through_risk

  Change the results which are used as a canary for risk changes,
  since we do expect Sharpe to change with this change..
2014-04-14 16:44:28 -04:00
Eddie Hebert 12f6b95982 TST: Standardize order of test assert params.
So that the np.assert_almost_equals messages have the correct
ACTUAL and DESIRED values in all messages.
2014-04-14 16:00:38 -04:00
Eddie Hebert 76e4334d64 TST: Change cumulative risk test to use some style as rest of suite.
Change the algorithm volatility test to use the same iterkv style
as the rest of the suite, as it was useful to be able to zero in
on the offending date when debugging changes to the risk module.
2014-04-14 15:57:21 -04:00
twiecki 63e3aa4c1e BLD: Remove duplicate six entry. 2014-04-14 09:04:02 -04:00