Commit Graph
242 Commits
Author SHA1 Message Date
fawceandEddie Hebert beecebc7d8 ENH: Support multi-day minutely emission.
Change the event loop so that minute emission has rollovers
between days.
2013-04-30 17:19:22 -04:00
fawceandEddie Hebert 28df9ec423 MAINT: Refactor performance tracker as part of algorithm.
Instead of having the performance tracker as part of the
tradesimulation class, hold on to it inside of the algorithm
object, so that the perf_tracker is more easily accessed for
reset behavior, etc.
2013-04-30 17:19:01 -04:00
fawce de37a08c23 MAINT: flake8 error 2013-04-26 19:57:45 -04:00
fawce 9062b9636a MAINT: refactoring for orders api
- moved Order and Blotter to zipline.finance.blotter
- moved order method from AlgoSimulator to Blotter
- eliminated the set_order method in algorithm
- moved blotter to the algorithm
2013-04-26 19:45:59 -04:00
Eddie Hebert b3efb5eb69 MAINT: Remove ndict class.
Now that ndict is no longer used in any part of the system during
a backtest, remove all remaining references in tests, etc.
2013-04-26 16:03:01 -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
fawceandEddie Hebert 24dfcaffc8 MAINT: Remove TradeSimulationClient class layer.
In favor of directly using the AlgorithmSimulator class.
2013-04-25 18:03:44 -04:00
fawceandEddie Hebert 427ea8d4ca ENH: Change simulation loop to use benchmarks as simulation 'clock'.
Refactor PerformanceTracker, Blotter, and AlgorithmSimulator to
work with handling the end of a bar at the AlgorithmSimulator level
instead of within PerformanceTracker.

- PerforamnceTracker and Blotter are longer generators,
  both provide functions to process events instead.
- AlgorithmSimulator calls each from within the loop running
  over the data generator.
- Change test_perf_tracker utility to be compatible with change
  away from PerformanceTracker as a generator.

Has the effect of:
- Fixing the timing of order emission.
- Allow minutely emission of benchmarks, which was prevented
  by the extra grouping previously caused by Blotter.

Minutely emission also depends on work for streaming benchmarks
through performance and risk at a minute granularity.
2013-04-25 17:16:35 -04:00
fawceandEddie Hebert 3811df78b9 BUG: Fix grouping of events streamed through blotter.
To fix the grouping of events so that (dt, events) ordering
is preserved, the tracking of order states needs to change
in the following way.

Change how order keeps track of dates:
- Change order's dt field to reflect modified date.
- Add a created field.

Change how performance keeps track of orders by:
- Map dt to transactions
- Map dt to orders
- Map order ids to keep track of updated orders.
2013-04-22 16:46:28 -04:00
Eddie Hebert a1e3222456 STY: Tweak whitespace in comment. 2013-04-22 15:56:03 -04:00
Eddie Hebert 32d57ef955 STY: Add space after comma in order docstring. 2013-04-22 15:33:13 -04:00
fawceandEddie Hebert ca0bce1680 TST: Refactor so tests can exercise internal methods in blotter. 2013-04-18 16:09:24 -04:00
fawceandEddie Hebert bc95c3a62e BUG: Fix emission of order updates.
The emission of order updates from the blotter were incorrect,
and subsequently, performance.

Previously, only the first action of the order was emitted,
fix so that all status updates are emitted.
2013-04-18 16:08:44 -04:00
Eddie Hebert bf1fc42acc BUG: Fix time spent checking equality of floating point numbers.
The use of np.allclose introduced a severe performance penalty,
caused by the creation of two `np.array`s for each check.

Instead create and use a similar check which maintains tolerance
to floating point rounding, but operates only on scalars.
2013-04-16 13:09:26 -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
Eddie Hebert 6a3c35c0fd BUG: Ensure that correct dates are emitted during entire minute rate.
Also, fix double emission of performance results with the last minute.

Change the perf tracker unit tests so that it doesn't rely on an
'extra' event triggering emission.
Unlike daily, minute emission now emits at the end of the bar in
the PerformanceTracker.transform instead of waiting for the next event.
2013-04-11 15:42:07 -04:00
Eddie Hebert d21b500db6 ENH: Emit a rollup of day's performance in minutely emission mode.
During minute emissions, it is still helpful to have a final daily
performance result, analogous to what would be the final packet in
a daily emitted backtest, so that all transactions, etc. are contained
in one place.
2013-04-10 16:20:44 -04:00
Eddie Hebert 58af62f18d REL: Update copyright on all files touched since end of 2012.
s/Copyright 2012/Copyright 2013/
2013-04-05 14:28:15 -04:00
Eddie Hebert eb42d4bfbd BUG: Fix tradesimulation index into perf results when emitting minutely.
The indexing into performance results during the simulation loop fails
when emitting minutely since 'daily_perf' only exists on daily performance
results, not the minutely results.

Fix by making the key used to index into performance results depend
on the emission rate.
2013-04-04 17:16:38 -04:00
Eddie Hebert 736a4babf0 MAINT: Renames parameter to TradeSimulationClient.
Renames from environment -> sim_params to match the type of the
argument passed.

(A refactoring had changed it to SimulationParams.)
2013-03-26 17:09:48 -04:00
Eddie Hebert f2d618b466 MAINT: Moves create_trade out of gens.utils
Slight refactoring of moving create_trade so that it's alongside
other testing/mock data utilities, instead of part of the gens module.
2013-03-25 23:51:25 -04:00
Eddie Hebert 45e28a4b9d MAINT: Updates copyright year on gens.utils module. 2013-03-25 23:51:20 -04:00
Eddie Hebert 33a1ed305f MAINT: Removes alternate function from gens.utils
This function is no longer refrenced elsewhere in the codebase.
2013-03-25 23:51:12 -04:00
Eddie Hebert 5118789e9b MAINT: Removes unused mock data function from gens.utils
This function is unused, and on the general path of moving testing
functions out of gens.utils
 # Please enter the commit message for your changes. Lines starting
2013-03-25 23:50:59 -04:00
Eddie Hebert 279e125ab8 MAINT: Pull initialization of simulation dt out of event loop.
Fakes a 'peek' into the data stream, so that the 'do we have a
simulation_dt?' check isn't called on each leoop iteration.
2013-03-20 14:34:12 -04:00
Tony WormandEddie Hebert 086679c3d6 ENH: Adds new order types.
Adds the following order types:
- market
- limit
- stop
- stop limit
2013-03-19 14:32:11 -04:00
fawceandEddie Hebert 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
Eddie Hebert 632cbf2e62 MAINT: Updates copyright for recently changed files. 2013-03-18 18:04:34 -04:00
Eddie Hebert 77bc821025 MAINT: Defines members of the Order object.
Instead of a loosely defined object for Order, explicitly
defines the parameters and corresponding members.

Clearing the way for adding more members to the Order object.
2013-03-18 17:59:14 -04:00
fawceandEddie Hebert 817ed88e38 Adds dividends to performance tracking.
Algorithm returns and the risk calculations that depend on them now include
cash dividends. This commit does _not_ provide an API for user algorithms to
access dividends.

PerformanceTracker expects the dividend data to arrive as events, similar to
the way that Trades arrive. Dividends are expected to have adjusted payment
amounts that are inline with adjusted trades.

PerformanceTracker maintains state of all the unpaid dividends in the position
objects held in PerformancePeriod. Dividend objects contain all the relevant
dates (declared, ex, payment) as well as net and gross amounts. Dividends are
removed from the list as they are paid. Cash flow is not incremented until the
payment day. This creates the possibility of a dividend being owed but not
paid or realized before the end of a test. For example, a dividend with an
ex_date of today may have a pay date 2 weeks in the future. Right now the
algorithm does not receive any credit for unpaid dividends.

Tests cover buying/selling around the ex_date and payment_date, and checking
that the performance calculated is as expected.
2013-02-06 16:39:39 -05:00
fawceandEddie Hebert 372a714eb8 deleting the portfolio object from every event. 2013-02-06 16:35:24 -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 a6ce57ef4f Removes code branching on sequential/merged flags in StatefulTransform.
So that the unit tests exercise the same transform logic as what
is executed a TradingAlgorithm object.
2013-01-30 16:23:40 -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
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 6f6434cf51 Converts slippage orders to use a simple object.
Reducing the number of ndicts that are created, so that profiling
has less noise.
2013-01-23 09:21:59 -05:00
Eddie Hebert ee02ff6445 Adds _ prefix to decorate_source to imply internal usage. 2013-01-07 13:03:12 -05:00
Eddie Hebert fc03e80cdf Removes done message.
Instead of checking for 'DONE' on each call uses generators
builtin StopIteration for signalling the end of input.
2013-01-07 12:06:31 -05:00
Eddie Hebert e7a31c0661 Removes sort module.
Sort module is now unneeded with use of heapq.merge

Also adapts test_perf_tracking so that it uses date_sorted_sources.
2013-01-07 12:06:10 -05:00
Eddie Hebert 13a2b1c637 Changes date_sort to use heapq module.
Uses heapq.merge to sort input from mulitple sources instead of
our own sort module.

From profiling heapq.merge is more efficient than our own efforts.
2013-01-07 12:03:50 -05:00
Eddie Hebert 0d841503a7 Uses dictionary update instead of iterating through keys.
update_universe is a bottleneck on large data sets.

A large portion of that bottleneck is the call to getitem while
looping over the keys, so using update while passing along the internal
__dict__

Seeing about a 40% improvement.
2013-01-06 17:31:03 -05:00
Eddie Hebert 7b1b9887ba Removes timeout handling from simulator's simulate_snapshot.
The delta was ensuring that the backtester wouldn't exceed the
delta of a bar if it were being run against live data.

However, this extra overhead of getting the current time on each
side of the handle_data adds a penalty in pure backtest mode.

Also, it makes the backtest results potentially non-repeatable,
since it is sensitive to current conditions on a box for processing
time.

Favoring having the timeout handled by whatever is running the
zipline algorithm.
2012-12-31 18:02:11 -05:00
Eddie Hebert f7e4f57425 Enables performance messages on days that have no trades.
Previously, on days that were trading days, but there with no
event data to process for that day, performance metrics were
not emitted, since the handling was based on having an event
trigger the daily performance metric.

Handled by grouping together performance messages, on market open,
for all days since the last market close.

Also, changes perf_tracker unit test to simulate missing data.

Taken from @richafrank's branch handling the same case.
2012-12-28 11:43:31 -05:00
Eddie Hebert 403a8e9064 Removes assert of sort protocol in inner loop.
Since this was invoked as an function, the invocation of the method
was not dropped by -O.
Also, moving towards only having postconditional asserts.
2012-12-21 21:46:46 -05:00
Eddie Hebert 8c2c36755e Removes assert of message confirming to protocol.
Two reasons for removal:
- On the path of removing most non-postconditional asserts.
  Since the asserts on every message is incurring a
  non-insignificant penalty on large datasets.
- Since the assert was invoked as a function, the 'right side'
  of the assert statement, i.e. the error message was being invoked
  as a function, discovered since the __repr__ of the message was
  high on the bottleneck list.
2012-12-21 21:36:32 -05:00
Eddie Hebert 21da812c10 Optimizes checking ready state of sources during sorting.
The main bottle neck here was using `len`.
A boolean check is a sufficient test for more items in the queue.

Also, uses all instead of several functions.
2012-12-21 16:46:16 -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
Richard Frank 095f2dd65b Date bookkeeping fixes in perf and risk
Issues appeared when we were close to the end of our
historical data.

Yielding DONE event with both perf and risk messages now
2012-12-12 15:23:26 -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
Richard Frank c81d6a30d1 Fix to inject log dates from slippage methods. 2012-11-27 12:41:07 -05:00