Commit Graph

143 Commits

Author SHA1 Message Date
Scott Sanderson d610ea0a3b DOC: Rename 'guid' to 'id' in dividend tracking logic. 2014-07-18 15:04:20 -04:00
Scott Sanderson 4712891e88 ENH: Remove dividends from the event stream.
Removes support for handling dividends as part of the algorithm
simulation stream, replacing it with an API in `TradingAlgorithm` for
supplying dividends as a DataFrame.
2014-07-18 15:04:20 -04:00
Scott Sanderson cfe00b0c37 ENH/TEST: Enable '1m' history and add tests for the frequency. 2014-06-05 15:25:49 -04:00
Scott Sanderson de3be983ad BUG: BarData.values() no longer causes in an infinite loop on Python 3. 2014-06-05 15:14:26 -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
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
Eddie Hebert b4959e46cf MAINT: Use six for Python 3 compatible names and behavior.
Use the six module to import functions and types that are
consistent between Python 2 and 3, so that one code base can
support both versions.

- Use integer types instead of int and long.
- Use string_types instead of basestring.
- Account for iteritems, itervalues, iterkeys.
- Use six.moves for filter and zip, reduce
- Use compatible bytes for md5 hasher.
- xrange and range
2014-01-07 11:33:50 -05:00
Richard Frank 2cc9cab17f MAINT: Initialize Portfolio object with default values for attributes
instead of no attributes at all
2013-12-20 17:11:53 -05:00
Eddie Hebert 457ac2630c BUG: Make BarData iterkeys method match dict iterkeys behavior.
Use a generator, instead of creating a list.
2013-12-20 12:41:51 -05:00
Eddie Hebert f2dc979fbc BUG: Make all iteration related methods fo BarData match __iter__
`for s in data` and methods like `for s in data.keys` were not producing
the same list of active sids

Make the other iteration methods match __iter__ by using the contains
method to check whether or not the sid is active.

For use of data outside of the algoscript context, which needs access
to all data fields use data._data
2013-12-20 00:05:53 -05:00
Thomas Wiecki 5f4d8817e8 ENH: Add len() functionality to BarData. 2013-12-03 16:29:17 -05:00
Eddie Hebert 37c56b9aa4 MAINT: Use Series throughout for daily returns.
Remove the lists of DailyReturn objects in favor of using pd.Series
to store the return values.

Should make it easier to inspect the values when stepping through,
make the windowing of data to a certain range more facile by using,
and have some performance increases due to removing object creation
and member access.
2013-10-19 23:06:18 -04:00
John Ricklefs 191715a148 ENH: Add support for asynchronous commission events. 2013-08-26 14:18:32 -04:00
Eddie Hebert 73eb3f12f5 BUG: Prevent unintended keys from appearing in data bar.
The defaultdict behavior was allowing both algo code and
TradingAlgorithm wrappers to add unintended keys.

Remove use of defaultdict in favor of a dictionary that explicitly
adds the values in tradesimulation, otherwise allow a KeyError
if the bar is indexed with a sid that doesn't exist.

Also, when iterating over the keys in the data bar, only return
those keys that have pricing data.
2013-08-01 22:41:58 -04:00
Eddie Hebert 158988d184 MAINT: Use explicit syntax for relative imports.
Python 3 requires using dot syntax for relative imports,
otherwise the import is treated as an absolute import, i.e.
an import of a module from outside of the project.

By using dot syntax now, imports should be compatible with both
Python 2.7 and Python 3.
2013-07-02 15:54:12 -04:00
Eddie Hebert 6c6b45659b BUG: Fix bar data contains check when override is used.
The override should be used to filter out symbols not in the universe,
however it was returning false positives.

To remove the false positives, after the contains check passes,
ensure that the key exists in the _data member.
2013-05-23 11:37:12 -04:00
Eddie Hebert 25d6f3afd1 BUG: Fix contains logic when override is not used.
The internal _data should be checked, not the __dict__
2013-05-23 11:31:58 -04:00
Eddie Hebert 2e327a4d1e MAINT: Add a has_key method to BarData for compatibility.
BarData should, at least for the time being, be compatible with
existing algorithms that had worked against the prior usage of
an ndict as data, which provided `has_key`.

Of note, the Python language has deprecated `has_key` in favor
of using `in` and `__contains__`.
2013-05-11 00:07:50 -04:00
fawce f3cfc9623d ENH: new order management methods:
- get_open_orders
- get_order
- cancel
2013-04-26 19:46:00 -04:00
Eddie Hebert 89ea97ec52 MAINT: Use a distinct object for minute/day data instead of ndict.
Continue removing ndict usage, instead use a BarData object.
2013-04-26 15:26:01 -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
Richard Frank 2dbafd5162 BUG: Zero out the microsecond attribute of datetimes
wherever we zero out the second attribute.  Otherwise, we can be
off by some microseconds from midnight, etc.
2013-04-15 10:44:44 -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
fawce dba86153d2 ENH: added a CUSTOM datasource type for custom data.
- perf modified to let non-performance related events flow through.
- changes to support streaming non-trading data through batch transforms
and for mixing in sids with just custom data.
- allowing CUSTOM events to flow through to transforms.
- Added logic to maintain pre-specified sid filter.
2013-03-19 11:39:23 -04:00
Richard Frank ebdb5429aa MAINT: Moved DailyReturn to protocol module to break circular references
and removed code that solved that same problem with conditional imports.
2013-03-01 16:05:39 -05:00
Eddie Hebert 88070a0f12 Fixes dictionary-style lookup on Position and Portfolio.
Typo on method name, /__getattr__/__getitem__
2013-01-27 22:49:20 -05:00
Eddie Hebert 2352c1e576 Adds dictionary style access to Portfolio object. 2013-01-27 21:21:01 -05:00
Eddie Hebert 480ca65f56 Adds dictionary style access to Position object. 2013-01-27 21:19:59 -05:00
Eddie Hebert a49bd4af4b Adds a contains method to SIDData to support in statement. 2013-01-23 17:17:35 -05:00
Eddie Hebert 87f99331e8 Uses an object for sid data to be passed to handle data.
Moving another datatype off of ndict, to make it easier to inspect
objects in memory when debugging.
2013-01-23 13:41:57 -05:00
Eddie Hebert a3235bb1a5 Recycles objects for positions.
Instead of creating a new ndict for each position on every event,
we change the values in the object that held the previous position.

The creation of new objects on each event was incurring too much
overhead.

Changes the position type returned by performance module.

For improved speed, changes from ndict to a simple Python object,
since the cost of setting ndict values is too expensive for the
number of times that positions are returned.

Also, changes the containing type of the positions to be dictionary
with the __missing__ overloaded, instead of the ndict that had that
behavior, to reduce the penalty of using ndicts.
2013-01-16 10:30:38 -05:00
Eddie Hebert 48dba943db Uses a Portfolio object instead of an ndict.
Gains some performance by using a 'regular' object instead of
an ndict.

Also, directly sets up the values that we return, instead of going in
between with __core_dict and then removing values.

In it's entirety performanc.as_portfolio is the current
highest bottleneck, working on reducing time spent in that function.
2013-01-16 10:30:38 -05:00
Eddie Hebert 799a357d98 Changes test factory to use Event instead of ndict.
As more sources are moving off of ndict,
changing the factory to use Event, so that when testing we are
exercising use of Event.
2013-01-06 17:13:07 -05:00
Eddie Hebert d1784b26c3 Adds an init to protocol.Event to enable setting of initial values.
So that an Event can use an initial dict to set all values,
instead of needing to set initial values one by one.

i.e. enables:

```
foo = Event({'bar': 1, 'baz': 2})
```

in favor of:

```
foo = Event()
foo.bar = 1
foo.baz = 2
```
2013-01-02 14:58:12 -05:00
Eddie Hebert 8f6ff20e6a Adds a __repr__ method for Event. 2012-12-21 17:07:56 -05:00
Eddie Hebert f54881cd08 Changes tests from using an ndict for trades to an Event object.
When run over large amounts of data the use of ndict's gets and sets
become a large bottleneck, around 1/5th of the CPU time is spent
in ndict's __setattr__, __getattr__, etc.

By switching to an object for an event,
we reduce the penalty significantly.

Removes asserts that check for event being an ndict, as well as those
that assume a certain behavior of the __contains__ method for events.
2012-12-21 14:31:40 -05:00
Eddie Hebert 95ce2d90cf Removes unused constant and redirection of imports.
Removes TRANSFORM_TYPE from protocol, since it is unused.

Also, removes use of ndict as a member of protocol, since it's
import there was for the TRANSFORM_TYPE. Changed to
utils.protocol_utils instead.
2012-10-15 22:57:06 -04:00
Eddie Hebert 25ce71651f Removes unused namelookup function.
Cutting out function whose only use was an unused constant.
2012-10-15 14:02:26 -04:00
Eddie Hebert 9500163ed8 Adds Apache 2.0 license header to source files. 2012-10-08 17:32:41 -04:00
Eddie Hebert 77af1ca632 Applies PEP-8 and pyflakes style to tests and zipline.
Mostly whitespace, line width and other spacing changes.
Also, removes use of deprecated has_key in favor of `in`

Going forward new patches should pass running `flake8` before
submission.
2012-10-05 12:14:09 -04:00
fawce 57a1834c5a refactored so that slippage is implemented as pluggable classes. 2012-09-13 21:22:01 -04:00
fawce 81718011df cut most of protocol, cut most of log_utils. 2012-09-08 23:20:38 -04:00
fawce 7f41a9435e new tests and support for logging primitives (bugfix) 2012-08-14 22:46:58 -04:00
scottsanderson b5054293da change protocol to match new datasources 2012-08-14 12:24:57 -04:00
scottsanderson 4bfbaa8c26 minor protocol change 2012-08-10 01:18:55 -04:00
scottsanderson 7bb4e754b0 added logs 2012-08-09 16:21:49 -04:00
fawce aec76868f9 exception handling 2012-08-08 21:40:33 -04:00
fawce 35e0433a6e added LOG as valid prefix. 2012-08-08 00:46:19 -04:00
fawce aeb50da170 fixes for unit tests, back to 50/51 passing. 2012-08-07 14:42:43 -04:00
fawce 08cce15ef9 added name and message to exception message 2012-07-31 16:02:28 -04:00