Commit Graph

1588 Commits

Author SHA1 Message Date
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
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
Ben McCann dc11534d54 ENH: Provide better defaults for load_from_yahoo.
Set the default end date to current date, so that trading on
'fresh' data is the default case.

Set the default begin date at 1/1/1990, since that is when the
treasury benchmark data is first available.
2013-04-09 10:49:08 -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 dd76386e56 REL: Updates copyright on transforms.utils module. 2013-04-05 12:03:50 -04:00
Jason Kölker 16660cf414 BUG: Preseve docstring in batch functions
The batch_transform decorator wipes out the doc string of the function
it wraps. Decorate the creator with functools.wraps to preserve function
metadata.
2013-04-05 11:55:10 -04:00
Eddie Hebert 1906c2d416 DEV: Add notes on dependency installation to README 2013-04-05 11:38:24 -04:00
Ben McCann 7608cbdd1b DEV: Add note about running tests to README 2013-04-05 11:38:14 -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
Jonathan Kamens 564c81f4a7 MAINT: PyPI upgrade mccabe==0.2.1 2013-04-04 16:13:48 -04:00
Jonathan Kamens a021d6d259 MAINT: Add --use-mirrors to Travis CI build script 2013-04-04 15:37:50 -04:00
Eddie Hebert b7743e0f02 Merge move of risk module treasury curve methods to module functions.
Intent is to both make the inputs to the treasury curve logic
more clear/explicit, as well as reducing the responsibilities
of the RiskMetrics classes.

Functions to move:
- search_day_distance
- get_treasury_rate
- choose_treasury

Also add new function:
- select_treasury_duration, split out of choose_treasury
2013-04-04 13:44:55 -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
Jonathan Kamens 4971d8478e MAINT: Specify --use-mirrors to pip install 2013-04-04 11:40:47 -04:00
Richard Frank 5a7702c22d MAINT: Factored out _create_data_generator helper method 2013-04-03 16:04:33 -04:00
Eddie Hebert 95ca73b15f MAINT: Remove unused members from risk test module. 2013-04-03 13:56:26 -04:00