Commit Graph

31 Commits

Author SHA1 Message Date
fawce 1a85781170 updated run method to use sim_params. 2013-02-18 10:24:32 -05:00
fawce 2c7355a0dc Refactoring of TradingEnvironment to isolate the global state: index symbol and exchange timezone. Parameters that define the simulation (start, end, and capital base) were put in a new class, SimulationParameters.
Global state for the financial simulation environment is accessed through the
zipline.finance.trading module, which now contains a module variable:
environment.

Parameters are passed into an algorithm as a keyword argument, sim_params.
SimulationParameters creates a trading day index for the test period that
can be used to find trading days, calculate distance between trading days,
and other common operations. The sim params index is just selected from the
global state.

================

Details:

    - adding delorean to the requirements.
    - made index symbol a parameter for loading the benchmark data. changed
    messagepack storage to be symbol specific.
    - ported risk, performance, algorithm, transforms, batch transforms
    and associated tests to use simulation parameters and global environment
    - factory and sim factory use global state and sim params
    - factory method parameter names now reflect the class expected
2013-02-18 10:24:32 -05:00
Richard Frank f914c53790 Added parameter type validation to record_variables 2013-02-11 18:07:05 -05:00
Richard Frank 59d76ce378 Don't let record_variables be used after initialize. 2013-02-11 14:44:46 -05:00
Eddie Hebert 81337d1306 Adds the ability to record variables.
Takes the value set for a variable on handle_data and records it,
e.g.:
```
    def initialize(self):
        self.incr = 0
        self.record_variables(['incr'])

    def handle_data(self, data):
        self.incr += 1
```

Would record a variable of `incr`.

Emits the recorded variables as part of the daily performance.

This batch combins work from:
Thomas Wiecki <thomas.wiecki@gmail.com> (@twiecki)
fawce <fawce@quantopian.com> (@fawce)
2013-01-31 08:16:54 -05:00
Eddie Hebert 7443b0c602 Pulls alias_dt wrapper out of sequential_transforms.
So that stepping through/cProfile output are a little clearer.
2013-01-30 16:20:58 -05:00
Thomas Wiecki fccc5e8006 ENH: Added constants.py which contains financial constants. 2012-12-30 12:02:38 -05:00
Thomas Wiecki 4615b29713 REF: Renamed granularity to data_frequency. 2012-12-30 11:50:46 -05:00
Thomas Wiecki 8346155f0e MIN: Override annualizer if set. New handling of granularity (no default arg anymore). Renamed minutely to minute. 2012-12-24 12:55:52 -05:00
Thomas Wiecki 3ca8029766 MIN: Replaced annualizer with a dictionary. Added set_granularity method. 2012-12-20 14:27:40 -05:00
Thomas Wiecki daf29c2d39 ENH: Add granularity and annualizer arguments to TradingAlgorithm. Accompanying doc string and unittest. 2012-12-20 12:49:24 -05:00
Thomas Wiecki 775c564ea1 ENH: Added DataPanelSource. 2012-12-13 12:55:05 -05:00
Eddie Hebert 3ff3a6964e Allows the capital base of an algorithm to be more easily modified.
By having run() use a capital_base member of the algorithm to
create the trading environment, the capital base should now be
configurable in the instantiation of the algorithm.

e.g.:

```
algo = LowCapitalBaseAlgorithm(capital_base=1000.0):
```
2012-12-04 10:42:58 -05:00
Richard Frank 4d41070585 Fix for slippage time getting out of sync with algo.
Moved grouping by date earlier in the pipeline of generators,
prior to any date-dependent state getting involved.  Grouping
pulls from the pipeline until the start of the next group,
which is in the next day.  The effect of grouping after
slippage but before handle_data is that slippage and the algo
are out of sync by a transaction.
2012-11-27 13:38:50 -05:00
Eddie Hebert 0617e53d69 Upgrades flake8 from 1.5 -> 1.6
Also, removes flake8 ignores, since the warnings that were
at odds with eachother now work.
2012-11-19 12:49:09 -05:00
Eddie Hebert 086c12ddf8 Locks down the ability to easily override the algo's portfolio.
Starting down the path of making the portfolio completely read-only
with respect to the handle_data in algo.

The portfolio should only be changed during the course of running
the algorithm by the simulator.

This doesn't do a 100% protection, i.e. an algo could use _portfolio,
or the set_attr property, but hoping this helps guides algo writing
to treat the portfolio as read-only.
2012-11-05 13:40:23 -05:00
fawce fa427afb16 added algotime get/set to algorithm 2012-10-29 18:54:55 -04:00
Eddie Hebert 7904773d00 Updates flake8 to latest.
The latest flake8 release in now 1.5, which pulls in pep8: 1.3.4a0

The upgrade pep8 has changes to what it picks up as lint.
Making code base compatible, so that new devs can install pep8
from PyPI and not have friction over the version difference.

Currently using these ignores in the config file:

```
[pep8]
ignore = E124,E125,E126
```

Ignoring these since they are difficult to squash while maintaining
an 80 char line length, and appear spurious.
Should address later.

Updates Travis config, README, and pip requirements to reflect change.
2012-10-22 11:57:16 -04:00
Thomas Wiecki 15ac658024 Restructured file hierarchy. Transforms now live in transforms (transform.py is now transforms/utils.py). Sources are in sources.py. VWAP is now MovingVWAP. 2012-10-19 18:10:51 -04:00
Thomas Wiecki 92f1dbef0c Fixes bug that .run() could not be called twice on an algorithm. Added unittest to check. 2012-10-19 11:47:59 -05:00
Thomas Wiecki b976c1252b Provides an iterative version of risk metrics.
I wrote this a little while ago as I noticed that a lot of time is spent
computing risk statistics. This is done over the complete history over
and over again while this could be done just by using the previously
computed value (iteratively).

We didn't go forward back then because for minute trade data the
difference was not significant enough. However, now with zipline
standalone I think most people will use daily (because that's
what's available) and it makes a huge difference
(speed-up of a couple of 100%).

Unfortunately, we can't just replace the existing one with an
iterative as for the final cumulative stats the batch is still
better. So that's not as nice, but the performance increase is
big enough for me to issue this PR (zipline is actually painfully
slow with daily data).

There is a unittest that compares that both produce exactly
the same outputs.

Speed measurements (for 500 trading days, daily source):

with iterative:
real 26.617 user 12.909 sys 6.112 pcpu 71.46

prior:
real 44.176 user 31.030 sys 11.381 pcpu 96.00
2012-10-17 23:41:30 -04:00
fawce 96fed05fc0 support for test fixes in qexec 2012-10-10 16:09:40 -04:00
fawce d9cf193ce0 fixes to unit tests 2012-10-10 16:07:11 -04:00
fawce 16b0d71506 refactoring of algorithm to make it work for both batch style run method, and generator style consumption. removed the portfolio property from the data parameter. added set_slippage and set_commission methods to algorithm. removed timeout tracking. 2012-10-10 16:06:32 -04:00
Eddie Hebert bbf2317c57 Saving point for adding license files. 2012-10-08 17:32:40 -04:00
Eddie Hebert 64363fae31 Applies pep8 and pyflakes recommendations.
White space tweaking.
2012-10-03 11:40:14 -04:00
fawce 7a8697f0e5 updated based on PR feedback. 2012-09-30 22:12:00 -04:00
fawce 1caefbff43 tests are passing for independent commission model 2012-09-28 23:12:41 -04:00
Thomas Wiecki 188a9502b0 Added passing of arguments to algorithm initialize and batch transform. 2012-09-25 11:48:37 -04:00
Thomas Wiecki 4324f95f36 Better unittest coverage. DataFrameSource is now filtering sids. Fixed outstanding issues. 2012-09-21 11:59:46 -04:00
Thomas Wiecki 729a4d9058 Large refactoring and documentation of new algorithm base class and batch transform. 2012-09-19 17:49:39 -04:00