Commit Graph

48 Commits

Author SHA1 Message Date
fawce 24dfcaffc8 MAINT: Remove TradeSimulationClient class layer.
In favor of directly using the AlgorithmSimulator class.
2013-04-25 18:03:44 -04:00
Eddie Hebert 2b0a91e568 BUG: Fix examples with regards to simulation parameters.
Fix bug where algorithms that lack sim_params do not pass the source
derived created sim_params through the generator creation logic.
2013-04-25 12:57:56 -04:00
Eddie Hebert 9099d301f3 ENH: Stream benchmark returns as events.
Instead of creating a list of benchmarks in the risk module,
stream benchmarks through the system as events, starting from the
algorithm generator.

Works towards more easily setting arbritrary pricing data as
a a benchmark, as well as working towards live minutely benchmarks.
2013-04-15 11:43:13 -04:00
Eddie Hebert 35f57ada3e ENH: Send transactions and orders as standalone events.
- Add transaction and order types
- Move TransactionSimulator from trading.py to tradesimulation.py
  (only used by other members of the tradesimulation module)
- Make Transaction an independent event, like dividend
- Add Blotter class.
- Flatten the transaction events to be independent of trade bar events
- Make orders into events that reach performance (need to add
handling)
- Issue IDs to orders and tracking each transaction's order id.
- Make volume share slippage fill orders independently, rather than
  aggregating them into a single transaction.
- Perf tracker holds orders, serializes them with transactions.
- Order state defined and maintained by order class.
- Minutely emission of orders based on last_modified date.
2013-04-14 18:59:57 -04:00
Richard Frank 5a7702c22d MAINT: Factored out _create_data_generator helper method 2013-04-03 16:04:33 -04:00
fawce 241a43bb13 ENH: Adds an optional filter to the algorithm's date_sorted_sources
So that a filter function can filter out sids on a 'static' source,
when the universe of sids changes.

e.g. when using fetch_csv with a changing universe of stocks.
2013-03-26 16:48:34 -04:00
Eddie Hebert 3707c7b225 MAINT: Changes name of grouping of by dt in generator chain.
Changes name to `grouped_by_dt` instead of `grouped_by_date` to
clarify that the grouping is by dt, which can be by minute, instead
of grouping by calendar date.
2013-03-20 12:12:33 -04:00
Eddie Hebert 0169251c89 MAINT: Removes unused init method from algorithm.
The init method had been copied to method called initialize,
to avoid confusion with __init__
2013-03-19 22:59:38 -04:00
Eddie Hebert d2bdfc931d BUG: Fixes error added while rearticulating sim_params.
Previous attempt to make sim_parms logic clearer had clobbered the
override logic when sim_params is passed to the run function.

Added a few comments as well as restructuring how the sim_params
that are passed to run overrides the default values or not.

This also makes the passing of sim_params to run to no longer have
the side-effect of overwriting the default sim_params.
2013-03-19 22:46:04 -04:00
Eddie Hebert ccef17dec6 MAINT: Fixes comment about perf type. 2013-03-19 21:35:01 -04:00
Eddie Hebert a645b2a86e MAINT: Fixes comment about returned performance types.
The simulator had been changed to return dictionary objects instead
of ndicts.
2013-03-19 20:56:56 -04:00
Eddie Hebert 50e0334b3d STY: Uses if/else for setting sim_params in algorithm.
Instead of checking 'if' and then 'if not', uses an if/else.
2013-03-19 20:53:44 -04:00
Eddie Hebert 1909a0576f MAINT: Removes unused frame_count member from algorithm class.
frame_count is only over incremented, but never read or otherwise
used.
2013-03-19 20:36:53 -04:00
Eddie Hebert 0b6e4650d9 MAINT: Removes unused flag from algorithm class.
The `self.done` member of TradingAlgorithm is never used.
2013-03-19 19:50:40 -04:00
Eddie Hebert 3e65980bda MAINT: Updates copyright of algorithm module to current year. 2013-03-19 19:06:54 -04:00
fawce 890762bde7 MAINT: added typed errors module
- added exceptions in place of asserts for expected fields for rolling
transforms.
- removed assertions with Messages in favor of typed exceptions.
2013-03-19 11:39:23 -04:00
Eddie Hebert e901e06f39 Changes the API for recording variables.
Uses a method called 'record' that provides a key value,
instead of providing keys to extract from context.

The variables are stored internally to the algorithm in a dictionary,
and not just stared as a property of the algorithm.

Main intent behind this change is to make the API more user friendly,
since the previous recorded_variables relies on the value to be set
in the algorithms context/self, the hope is that only having to use
the `record` method means less moving pieces and a more understandable
API.

i.e., instead of:

```
def initialize(self):
    recorded_variables('foo', bar')

def handle_data(self, data):
    self.foo = 1
    self.bar = 2
```

The API is now:

```
def initialize(self):
    pass

def handle_data(self, data):
    self.record(foo=1, bar=2)
```
2013-03-02 18:28:35 -05:00
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