Commit Graph

1612 Commits

Author SHA1 Message Date
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 2cc6764b90 TST: Factor out the running events through a test performance tracker.
Based on @fawce's work for changing the simulate loop.
2013-04-25 16:33:01 -04:00
Eddie Hebert d0651706ac TST: Prevent dividend test from using non-trading day.
Use the next events' datetime for the transaction instead of
incrementing by a calendar day.
2013-04-25 15:41:26 -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 4b33d6ea4b TST: Ensure that create_trade_history uses midnight for daily trades.
Prepare for implementation of backtest loop that depends on daily
trades being grouped by midnight.
2013-04-25 13:25:50 -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 fed0a9a998 TST: Ensure that test bars and events use midnight for daily data.
Daily data should be using midnight as the timestamp,
ensure that test data created by data_gen use midnight, so that
upcoming implementations that rely on the timestamp will be compatible.
2013-04-25 11:30:57 -04:00
Eddie Hebert c6cbc9f8e2 TST: Explicitly define the data frequency of record incr test. 2013-04-25 01:12:58 -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
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
Eddie Hebert 097c225c6b BUG: Fix treasury loading.
Make adjustments for using Python built-in ElementTree instead of lxml
based lxml.

lxml was edited out during pulling in of memory friendly loading of
treasury curves, however some of the use of ETree was lxml specific.

Mea culpa.
2013-04-22 14:03:25 -04:00
Richard Frank 4ba35d7d46 ENH: Stream benchmark and treasury data when downloading
Instead of loading entire csv or xml into memory.
2013-04-22 12:35:17 -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
Ben McCann fc4d563a02 DOC: Fix documentation compilation 2013-04-17 11:15:38 -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 9f0500aa33 TST: Use 9:31 AM EST for first minute of minute performance tests. 2013-04-16 12:23:09 -04:00
Eddie Hebert e7d64fa2e5 STY: Move import in test to top of file. 2013-04-16 12:23:06 -04:00
Eddie Hebert 5a73ec7de3 TST: Prevent random integer during unit test from exceeding bounds. 2013-04-16 10:49:17 -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 e8f6b43f2b TST: When comparing dicts, ensure they have the same keys.
dict 'b' might have more keys.
2013-04-15 16:57:44 -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 cc322af498 TST: Removes unused members in set up from TestPerformanceTracker. 2013-04-15 10:31:19 -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 cfbbbe2f1c TEST: Ensure that test_transforms's algos are passed sim_params. 2013-04-12 12:54:11 -04:00
Eddie Hebert 48a691e9a7 TST: Group test trades for transaction simulator by date.
Group by date to prepare for other values to be added per dt.
2013-04-12 11:13:23 -04:00
Eddie Hebert 3883f79ece TST: Remove unused trade_delay parameter from transaction_sim method. 2013-04-12 11:04:01 -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 575d68a4e5 DEV: Allow test_minute_tracker to run by itself.
TradingEnvironment was not set, so this test could not be
run in isolation.
2013-04-11 14:24:42 -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
Jonathan Kamens d61c6c0af5 MAINT: nit: "nose==1.3.0" instead of "nose==1.3" 2013-04-10 10:35:16 -04:00
Eddie Hebert ccc6cd892b BUG: Ensure algorithm tests use test simulation parameters.
To pass sim_params to TradingAlgorithm using kwargs is required.
When just passing sim_params as an arg, it was ignored.
2013-04-09 16:47:25 -04:00
Eddie Hebert 8997b4f68c MAINT: Remove parameters from test that tests lack of parameters.
The `test_multi_source_as_input_no_start_end` test is designed
to test for a lack of simulation parameters, so make that they are
not passed.

Was unnoticed because sim_params passed as an arg are dropped.
2013-04-09 16:46:55 -04:00
Eddie Hebert 57db5bc17c BUG: Fix start and end dates of simulation parameters used in tests.
The start and end of the simulation parameters should be 'normalized'
i.e. midnight timestamped.
However, the algorithm tests were using the timestamp of the
first and last trade, which were in market times,
i.e. 9:30 AM and 4:00 PM EST.

Fix passing the sim_params that is used to create the trade_history,
instead of having the sim_params inferred from the source.

(Also may want to consider fixing the logic that infers the date
range from the sources provided.)

Also, add a `num_days` option to `factory.create_simulation_parameters`
so that the a date range that covers the desired number of days is covered.
Since the default sim_params were covering a year, while the test only
supplies 4 values, causing an alignment issue with the record test,
since a years worth of results were returned, but there were only 4 events.
2013-04-09 15:11:43 -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
Jonathan Kamens 790e588911 MAINT: Upgrade nose==1.3, numpy==1.7.1 2013-04-09 11:55:11 -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