Commit Graph

299 Commits

Author SHA1 Message Date
Thomas Wiecki 2be7014d51 ENH: Rewrite of batch_transform to use rolling panel.
- Added unittest to test for newly appearing sids.
- Fixed logic bug where window was only full after
  window_length+1 events got passed.
2013-04-29 15:30:40 -04:00
Wes McKinney c5f4d00bf1 ENH: prototype data structure for managing a rolling datapanel
Manage a rolling window collection of collection of panels
for computation purposes.
2013-04-29 15:19:02 -04:00
Eddie Hebert a4ea33218d TST: Move batch transform tests to their own file.
From @twiecki's rolling batch transform work.
2013-04-26 23:56:35 -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 d4a8878c6e TST: Ensure holiday edge case is covered in dividend performance test.
Add a test suite of dividend performance that ensures a holiday
is covered, needed because tests usually go over a random test range,
so holiday coverage isn't covered in basic test.

From @fawce.
2013-04-26 10:56:54 -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 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 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 c6cbc9f8e2 TST: Explicitly define the data frequency of record incr test. 2013-04-25 01:12:58 -04:00
fawce ca0bce1680 TST: Refactor so tests can exercise internal methods in blotter. 2013-04-18 16:09:24 -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 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
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 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 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 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 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 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 95ca73b15f MAINT: Remove unused members from risk test module. 2013-04-03 13:56:26 -04:00
Eddie Hebert a620afe639 STY: Add Test prefix to risk module test case. 2013-04-03 13:55:33 -04:00
Eddie Hebert dd172dd42a MAINT: Use trading day increment instead of timedelta in test factory.
In the test factory creation of returns, the date creation was using
a timedelta of one day instead of incrementing by trading days.

Working towards changing risk module behavior which would leverage
the trading day map, but tests fail because non-trading days are
created.

Remove `factory.create_returns`, moving uses of that function to us
`factory.create_returns_from_period`, since the number of days input
for `create_returns` was more difficult to use when specifying ranges
over arbirtray dates.
2013-04-01 23:52:50 -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 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
Eddie Hebert d87213a5f1 MAINT: Adds floating point tolerance to risk metric comparison tests.
In preparation of changing how risk metrics are calculated,
this makes the checking of results more tolerant to floating point
rounding, since upcoming changes change the results by a neglible margin.
2013-03-27 13:42:16 -04:00
Eddie Hebert 94e70a394b MAINT: Restricts dates to trading calendar in risk comparison test.
Converts the risk iterative and batch comparison tests to use
the trading environments next date, instead of just advancing by day,
so that the returns being passed into the RiskMetrics in the unit
test are using the same trading calendar as the internal checks for
trading days.

Fixes a case where empty return periods were being into
`calculate_period_returns`

Clearing the way for the pandas based optimization of the risk module.
2013-03-27 11:42:40 -04:00
Eddie Hebert a05039c514 MAINT: Uses Transaction object in tests instead of ndict.
So that Transaction object behavior is exercised, uses the Transaction
object in performance module tests instead of ndict.

Also, adds fields to the __init__ of Transaction, to make the
definition of the object more well defined.
2013-03-25 23:51:34 -04:00
Eddie Hebert 47f3192728 MAINT: Updates copyright year of perf_tracking tests. 2013-03-25 23:50:23 -04:00
Tony Worm 086679c3d6 ENH: Adds new order types.
Adds the following order types:
- market
- limit
- stop
- stop limit
2013-03-19 14:32:11 -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
Eddie Hebert e53622c930 MAINT: Changes unittest use of ndict to use specific objects.
Instead of using ndict, changing over to using the objects that
are created used when an algorithm is run.
2013-03-06 15:48:01 -05: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
Thomas Wiecki 46104fcd7c BUG: DataPanelSource was looping in the incorrect order. 2013-02-28 21:33:49 -05:00
Jonathan Kamens 368a31587f Fix flake8 problem 2013-02-21 11:13:18 -05:00
Jonathan Kamens 8120fd1bf7 Disable test_{,lse_}calendar_vs_environment until issue #93 is addressed
These two tests are nonessential and the test failures reflect bugs in
the tests, not bugs in the code.
2013-02-21 11:03:55 -05:00