Commit Graph

337 Commits

Author SHA1 Message Date
fawce d381865a89 BUG: Ensure that order exists before attempting to cancel. 2013-04-30 17:19:16 -04:00
fawce 34f1dd783a STY: Tweak comments in performance to match rest of file. 2013-04-30 17:19:09 -04:00
fawce f3cfc9623d ENH: new order management methods:
- get_open_orders
- get_order
- cancel
2013-04-26 19:46:00 -04:00
fawce afef4ea34c ENH: added cancel function
- removed vestigial methods
- removed code that drops filled orders from memory
2013-04-26 19:46:00 -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
fawce 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
Eddie Hebert d31303b86c ENH: Add basis for minute rate emission of performance.
- Create different benchmark containers in performance
  depending on emission rate.
- Add a minute close method which updates algorithm and
  benchmark returns, and calculates the risk metrics
  depending on those methods.
- Provide fake 0.0 values for annualized metrics like
  sharpe, sortino, and information, until we figure out
  how they should be treated in the context of minutely
  calculation.

*NOTE* This does not fully work without the changes to the
simulation loop by @fawce
2013-04-25 16:49:38 -04:00
Eddie Hebert 7d615c5af5 MAINT: Improve message for return mismatch by including current dt.
Based on work from @fawce's simulation loop work.
2013-04-25 16:48:19 -04:00
Eddie Hebert fd6c71286d MAINT: Use sim_params for risk metrics init.
Prepare for adding emission_rate in risk metrics logic.
2013-04-25 15:30:34 -04:00
Eddie Hebert d067f13ba8 MAINT: Use a fake progress value for minute performance.
Eventually should to either return None or remove
progress completely, but in the meantime, return a
constant of 1.0 for progress of minute emissions.

Also, factor out the daily calculation into a property
instead of calculating during process.
2013-04-25 14:28:33 -04:00
Eddie Hebert 1183c44fad MAINT: Remove unused last_dt member from risk.RiskMetricsIterative 2013-04-25 00:28:35 -04:00
Eddie Hebert ab1a23526d BUG: Use last trading day for last successful date message.
market_open member does not exist on TradingEnvironment.
2013-04-24 16:17:31 -04:00
Eddie Hebert 8937ac1f41 MAINT: Generate perfomance message only once per bar for minute mode.
Instead of creating a set of perf messages for each event during minute
emission mode, only include the messages on the last event in the bar.

Should cut down on calculations/serialization as well, as work towards
doing more 'end of bar' logic for minute benchmarks.
2013-04-22 17:37:32 -04:00
fawce 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
fawce ca0bce1680 TST: Refactor so tests can exercise internal methods in blotter. 2013-04-18 16:09:24 -04:00
fawce 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 643d556482 MAINT: Add empty values for risk metric calculated components.
eigen vales, covariance, etc. are not calculated until the first
return is passed through, so initialize this values to None, so that
`repr` and its ilk work on a freshly created `RiskMetricsIterative`
object.
2013-04-16 10:45:11 -04:00
Richard Frank d487401989 BUG: Perf tracker should emit perf messages only for TRADE events 2013-04-15 16:57:33 -04:00
Eddie Hebert 4ff49749d7 BUG: Fix environment minute date range start and volume.
The bar timestamps for day start and finish, for NYSE traded stocks,
should be 9:31 AM EST to 4:00 PM EST, for a total of 390 minutes.

Fix starting at 9:30 AM and the creation of 391 bars.
2013-04-15 16:35:41 -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 6210467bec MAINT: Use pd.Series for benchmarks and algorithm returns in risk.
Instead of lists, use pd.Series, so that memory is preallocated.
2013-04-15 11:37:21 -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
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 e03d51f0bc BUG: Fix extra minutely performance period during minute performance.
Prevent an extra performance result with the timestamp of the midnight of
the day from being emitted.

Fix by setting the `saved_dt` value with the dt of the first event,
before entering into the main performance loop, otherwise a performance
result with a midnight timestamp and data from just the first event is
emitted.
2013-04-10 10:51:39 -04:00
Eddie Hebert 5a7039ab93 BUG: Move minutely performance period end time forward in time.
The end time of the performance period during minutely emission
should move forward with the events' dt, not be static.
2013-04-10 10:51:39 -04:00
Eddie Hebert 23ff65ad32 MAINT: Convert per share cost to float during init.
The cost value should always be a float.
The per share calculation shouldn't be changed dramatically by being
a float, (except for potential rounding errors), but change to so
that PerShare and PerTrade are aligned.
 # Please enter the commit message for your changes. Lines starting
2013-04-09 12:04:08 -04:00
Eddie Hebert da9d599afd BUG: Fix floored results in trade commission calculations.
When the cost basis was set to an integer the division in the
calculation would floor down to the nearest integer.
Ensuring that the number is a float during PerTrade's init
will ensure that the calculation doesn't use integer division.

Do the conversion to float in init rather than calculate, so that
calling the builtin `float` is not added to any inner loops.
2013-04-09 11:44:16 -04:00
Eddie Hebert 90fa2a8a4e MAINT: Stop including progess field with minute performance result.
As currently implemented, progress doesn't currently make sense with
minutely results. Dropping the field from the results so should help
reduce some noise.
2013-04-09 11:02:00 -04:00
Eddie Hebert 5422970d13 BUG: Stop intraday performance from emitting all transactions.
The intraday performance results were emitting all transactions
for the entire day up to that point, instead of the desired transaction
list for the current timestamp.

Add a `dt` parameter to the `to_dict` method of PerformancePeriod so
that the transactions are limited to a specific datetime.
When the parameter is `None`, a todays_performance object will
function as previously with returning all transactions for the day.
 # Please enter the commit message for your changes. Lines starting
2013-04-05 13:55:04 -04:00
Eddie Hebert a66d6866f5 MAINT: Use searchsorted instead of bisect on treasury curves.
Remove use of .keys() and creation of a new list of the curve
Series's values.
2013-04-04 13:44:22 -04:00
Eddie Hebert bb3e9727dc MAINT: Mask treasury_curves used by risk metrics to period range.
So that calculations that leverage the range of the treasury_curves,
like `pd.Series.searchsorted` will not overshoot the 'end' of the
range we are calculating risk metrics.
2013-04-04 13:44:22 -04:00
Eddie Hebert cf60eeb46b MAINT: Refactors out selection of treasury duration its own function.
Instead of having the duration selection logic in choose_treasury,
break out duration specific logig into another function.
2013-04-04 13:44:22 -04:00
Eddie Hebert 0cc953e00f MAINT: Move choose_treasury method from risk metrics class to module. 2013-04-04 13:44:22 -04:00
Eddie Hebert 2e603fa936 MAINT: Factor out treasury_curve argument from risk choose_benchmark
Move the reference to self.treasury_curve to a parameter, on the path
of making this method a module level function.
2013-04-04 13:44:22 -04:00
Eddie Hebert 39038131db MAINT: Remove saving of treasury duration.
The treasury_duration member in RiskMetrics is never used except
for in unit tests.

Remove the saving of treasury_duration in preparation for the
move of the choose_treasury method out of the RiskMetrics classes.

Down the line, if we do restore the sanving of treasury_duration,
choose_treasury can return a tuple that includes treasury_duration
instead of just returning the rate.
2013-04-04 13:44:22 -04:00
Eddie Hebert 8ea52e0421 MAINT: Factor out start and end date choose_treasury parameters.
Preparing for move of method to a module level function.
2013-04-04 13:44:21 -04:00
Eddie Hebert b461c0d91c MAINT: Move get_treasury_rate to risk module level. 2013-04-04 13:44:21 -04:00
Eddie Hebert 5f86ee72ee MAINT: Move search day distance function to module level. 2013-04-04 13:44:21 -04:00
Eddie Hebert 9627f48963 MAINT: Convert treasury curves data to pd.Series
Instead of using OrderedDict, use a pd.Series so that utilities
like searchsorted, etc. can be used.
2013-04-03 11:59:08 -04:00
Eddie Hebert 39f457ca28 MAINT: Use dateutil module for adding months to a datetime.
Instead of having an advance_by_months function maintained in
Zipline, leverage the relativedelta module provided by dateutil.
2013-04-03 10:41:47 -04:00
Eddie Hebert 0dca5d004a MAINT: Remove unused RiskReport.find_metric_by_end 2013-04-03 10:14:36 -04:00
Eddie Hebert b3c23b0d8b MAINT: Rename risk metric function names to include '_ratio' suffix.
To make the risk metrics being calculated more clear, change the
naming convention that ratios have a '_risk' suffix.

Also, fixes typo in beta docstring.
2013-04-02 11:27:34 -04:00
Eddie Hebert 210a43a306 MAINT: Factor out risk metric logic from risk objects.
Move the risk metric definitions to functions at the module level
with defined parameters.

Both risk implementations call these functions, where the difference
between risk implementations is with which internal data they
send to the various risk metrics.

Metrics moved:
- Sharpe Ratio
- Sortino Ratio
- Information Ration
- Alpha
2013-04-01 12:43:27 -04:00
Eddie Hebert 702e6f00d2 MAINT: Use numpy for risk period returns.
Following the lead of the RiskMetricsBatch conversion to use
more pandas and numpy.
Bringing the iterative and batch versions closer together as we
work towards folding them into one.
2013-03-29 17:06:54 -04:00
Eddie Hebert 147e806bb0 MAINT: Moves exchange to utc conversion inside of environment object.
So that the environments' exchange time is used without having to
specify it independently.

Also, moves uses of Delorean.shift for the exchange conversion inside
of environment to use the exchange_dt_to_utc method.
2013-03-28 12:29:52 -04:00
Eddie Hebert 10825c9a1d MAINT: Updates copyright year on finance module. 2013-03-28 09:24:53 -04:00
Eddie Hebert 7679e5a581 ENH: Wires minutely emission of data from performance tracker.
Wires up performance tracker so that when `emission_rate` is set
to `minute`, the performance packets are sent out every minute,
instead of once per day.

Please note, the performance packets that are generated are not
ready for prime time consumption, this patch is merely a step towards
hooking up the ability to inspect minute data.

Known issues:
- The packets do not currently include risk information.
  Since we need to consider how this affects the denominators
  of the risk calculations.
2013-03-27 16:58:56 -04:00