Commit Graph
1311 Commits
Author SHA1 Message Date
Eddie Hebert d7e670521d MAINT: Use dt in risk update method instead of last return index.
The current dt is already in scope in the update method, so use
that instead of also reading it from the algorithm_returns index.
2013-09-25 13:53:30 -04:00
Eddie Hebert fcd62d538b MAINT: Removed last_return_date from risk object.
Since we are also tracking this value with latest_dt, reading the
last_return_date from the returns is no longer needed.
2013-09-25 13:52:30 -04:00
Eddie Hebert a60d5c99a9 MAINT: Use pandas for daily treasury values in risk. 2013-09-25 13:31:01 -04:00
Eddie Hebert f9e2dd76b4 MAINT: Use pandas for sortino and information ratios.
Continue converting risk values that were stored as lists into
pandas structures.
2013-09-25 12:57:43 -04:00
Eddie Hebert 6a0c494ce0 MAINT: Use pandas for values directly derived from returns in risk.
Remove more use of lists for storing internal risk values to use
pandas structures, for easier matching of time to value.

Accordingy, convert use of -1 for getting last value,
to use current dt.
2013-09-25 12:26:56 -04:00
Eddie Hebert cd3a63415c MAINT: Use pandas for volatility in risk metrics.
Continue on path of converting values stored inside of risk metrics
to use a DataFrame instead of storing multiple lists.

Also, the need for latest_dt in getting the current volatility for
the sharpe calculation, shows that we need to set the lastest_dt at
the beginning of the update loop.
2013-09-25 11:25:57 -04:00
Richard Frank 599ff1ad8a MAINT: Ensure the sign of the result is positive 2013-09-23 16:12:17 -04:00
Richard Frank b4836b976e ENH: Restrict limit prices to a penny precision
to account for minimum price variation.

On an order to buy, between .05 below to .95 above a penny, use that penny.
On an order to sell, between .05 above to .95 below a penny, use that penny.
2013-09-23 16:12:17 -04:00
Richard FrankandEddie Hebert a50fbe9289 MAINT: Some code cleanup in the blotter module 2013-09-23 14:09:59 -04:00
Eddie Hebert 70bcfff289 MAINT: Use DataFrame for more risk metrics.
Use metrics DataFrame for alpha, beta, as previously with sharpe.
2013-09-19 21:55:28 -04:00
Eddie Hebert 29a80c2f98 MAINT: Store sharpe values in a DataFrame instead of list.
Eventually, all cumulative metrics, (alpha, beta, etc.) will be
stored in the same DataFrame

For easier tracking of dt to values during debugging, but should be
some performance gains as well.
2013-09-19 21:55:28 -04:00
Richard Frank e4d298f3a0 MAINT: Factored out adjust_cash method in perf period
with semantics unrelated to dividends/splits
2013-09-19 14:13:50 -04:00
Eddie Hebert 6da62a5a9f MAINT: Refactor setting of indices on risk returns containers.
So that it is easier to add new containers, factor out the creation
of the index.

Also, make the returns frequency a parameter, to make the use of
different frequencies more clear from within the risk metrics object,
rather than hot swapping in the new frequency type via the now
removed `initialize_daily_indices`.
2013-09-19 12:28:41 -04:00
Eddie Hebert 84d20fd551 MAINT: Remove unused values during beta calculation.
The eigen_values, condition_number, algorithm_covariance, and
benchmark variance, which were easy to calculate alongside beta,
since they share the same inputs, but were not passed along to performance.

Remove to trim down the number of risk report members as well as
number of calcluations done.

Can add back in if there is an expressed need for eigen_values etc.,
perhaps in an 'opt-in' type configuration.
2013-09-18 15:47:25 -04:00
Eddie Hebert 4f6de61e77 MAINT: Remove unused member from cumulative risk metrics. 2013-09-18 14:17:27 -04:00
Eddie Hebert 35669ce9e2 MAINT: Remove unused created member from risk report.
Risk report doesn't need system time.
2013-09-16 20:59:22 -04:00
Eddie Hebert ddb541b9b3 MAINT: Change shape of supplemental data to match batch data.
Expect the same shape of data for the supplemental data, to make
working and preparing with the supplemental data consistent with
what is passed to the algorithm.
2013-09-16 11:51:22 -04:00
John Ricklefs 7b8769b3e7 BUG: Fix div-by-zero error in cost_basis adjustment. 2013-08-27 13:24:06 -04:00
Richard Frank a86604933e MAINT: Refactored Position.__init__ to accept starting values
Also fixed extra space in __repr__, and some other cleanup
2013-08-27 11:15:18 -04:00
John Ricklefs 191715a148 ENH: Add support for asynchronous commission events. 2013-08-26 14:18:32 -04:00
Richard Frank 57344ee78a MAINT: Call rollover from __init__ instead of duplicating code 2013-08-23 12:41:59 -04:00
Richard Frank ddb3d64526 MAINT: Record a given order only once per bar
even when there are multiple fills during that bar.
2013-08-23 12:41:59 -04:00
Eddie Hebert 9376556e68 BUG: Use dt as a max value in trading get_index.
Instead of sliding to the next trading day because of the behavior
of `searchsorted`, if dt argument is not a trading day use it as a
max value for corresponding date of the index.

Fixes a bug where if the end of the quarter is calculated with
disregard to trading days, get_index would return the first day
of the next quarter, instead of the last trading day of the intended
quarter.
2013-08-23 12:33:09 -04:00
Eddie Hebert 7d5194ec2c ENH: Include TALib output names in ta transform results.
For TALib functions like MACD that have output names, return a
DataFrame that for which the columns are the output names of the
function.

So that when using a TALib function, the algorithm doesn't need
to know the index position of the desired result, in favor of using
the name of the result.

e.g.

```
macd_result['AAPL'][0]
```

becomes,
```
macd_result['AAPL']['macd']
```

and
```
macd_result['AAPL'][1]
```

becomes,
```
macd_result['AAPL']['macdsignal']
```

Also, change return type of functions that return floats from a
dictionary to a Series, so that the function is always returning a
pandas type.
2013-08-19 16:46:11 -04:00
Eddie Hebert ee8baa2a70 MAINT: Add default import of trading of module.
So that zipline.finance.trading can be accessed after importing
zipline.
2013-08-19 15:21:48 -04:00
Eddie Hebert 16fe23b18f REL: Add license to module init file. 2013-08-19 15:19:15 -04:00
Eddie Hebert 1295f45e13 MAINT: Switch treasury curves from Series to DataFrame.
Instead of using a pandas Series of with dictionaries as the
values treasury curves, use a DataFrame which more naturally fits
the data type of a having a timeseries with mulitple values.

Should allow easier slicing/manipulation of the treasury curves,
e.g. getting 10 year curves would now be:
```
treasury_curves['10year']
```
2013-08-13 23:13:19 -04:00
John Ricklefs 36fe790624 BUG: Update market_open value for performance when updating market_close. 2013-08-13 09:23:28 -04:00
Thomas Wiecki b89886297f STY: autopep8 codebase. 2013-08-08 16:46:44 -04:00
Thomas Wiecki a43a122829 TST: Forgot to add order method test algos. 2013-08-08 16:37:31 -04:00
Thomas Wiecki 7a65f4579e Pulled in PR 137 to add new order methods. 2013-08-08 15:57:24 -04:00
Thomas Wiecki b1fdebfb7c TST: Added tests for new order methods. 2013-08-08 15:55:08 -04:00
Jeremiah LowinandThomas Wiecki 48486c9814 ENH: New order methods. 2013-08-08 15:54:59 -04:00
Richard Frank c64a585e54 BUG: TransactionVolumeExceedsOrder was referenced but not defined 2013-08-08 13:21:16 -04:00
Ben McCannandThomas Wiecki eae5803910 BUG: Calculate benchmark returns for first day
Before we were setting benchmark returns on the first day
to 0. This commit changes this by calculating the benchmark
return from open to close.

According to @eherbert this is also what the answer key does.
2013-08-08 12:20:04 -04:00
Thomas Wiecki 43889f4a16 BUG: version tag should be a string. 2013-08-08 11:22:03 -04:00
Thomas Wiecki 2026937dc9 BLD: Add version to zipline, bump to 0.5.11.dev
zipline.__version__ is now present. Closes #94.

Moreover, git master should have a .dev version string according
to convention. Releases then get the .dev label removed.
2013-08-08 11:12:10 -04:00
Thomas Wiecki f75d781b02 DOC: Fix talib sphinx warnings. Closes #171. 2013-08-08 10:50:00 -04:00
Eddie Hebert 5b2a23ddd0 MAINT: Break period and cumulative risk metrics into submodules.
In anticipation of changing the sharpe, beta, et al. calculations
dependent on whether the period returns or the overall returns
are being calculated.
2013-08-06 17:49:19 -04:00
Eddie Hebert 66e7f48cdd MAINT: Split apart risk metrics classes.
Also remove test that compares risk metrics batch to iterative,
since the 'iterative' calculations, replaced by the cumulative
calculations, will intentionally drift from the results in the risk
report due to annualization and other factors.

Work towards having separate calculations for the fixed periods versus
the cumulative/headline risk metrics.
Different sumbodules for each type should help make the calculations
type distinct and easier to find.
2013-08-06 17:21:34 -04:00
Eddie Hebert 4a11a872fc MAINT: Move risk to its own module.
In anticipation of splitting apart the different risk classes
into their own submodules, a distinct risk module should help
organize those new classes.
2013-08-06 17:19:43 -04:00
Jonathan KamensandEddie Hebert 3541115b4e BUG: Trading calendar dates should always be midnight UTC
For consistency, datetimes returned by the trading calendar should
always show HHMMSS of midnight UTC. Not only is this useful for
consistency, but it also allows us to check if a particular date() is
in an array of these datetimes, because they will hash to the same
thing. For example:

early_closes = get_early_closes()
... later ...
if current_bar_datetime.date() in early_closes:
    ... today closes early ...

If if the datetimes returned by the trading calendar functions don't
have 00:00:00 for HHMMSS, then the "in" check above will fail because
the date and the datetimes in early_closes won't hash to the same
thing.
2013-08-06 15:53:41 -04:00
Eddie Hebert e85306524b BUG: Prevent crashes for TALib functions when stocks have nans.
If a stock stops gettign updated values, e.g. if a stock rolls out
of a universe strategy, currently the underlying batch transform
for TALib may have nans (which is another issue that could be addressed),
the nans cause crashes when passed to some TALib function, e.g. Bollinger
Bands are incompatible with all nan values.

So, drop sids that only have nan values for the current data panel.
2013-08-05 18:17:20 -04:00
Eddie Hebert 73eb3f12f5 BUG: Prevent unintended keys from appearing in data bar.
The defaultdict behavior was allowing both algo code and
TradingAlgorithm wrappers to add unintended keys.

Remove use of defaultdict in favor of a dictionary that explicitly
adds the values in tradesimulation, otherwise allow a KeyError
if the bar is indexed with a sid that doesn't exist.

Also, when iterating over the keys in the data bar, only return
those keys that have pricing data.
2013-08-01 22:41:58 -04:00
Thomas Wiecki 963324723c STY: Flake8 line break. 2013-08-01 17:14:56 -04:00
Ben McCannandThomas Wiecki 8dd4230fd0 ENH: Plot benchmark returns in DMA example. 2013-08-01 16:55:12 -04:00
Thomas Wiecki e1475cc24f BUG: cum_perfs defined but not used. 2013-08-01 16:33:26 -04:00
Thomas Wiecki 1635a54fb8 ENH: Add print of monthly Sharpe to DMA example. 2013-08-01 16:09:38 -04:00
Thomas Wiecki 37bab9bb72 ENH: Safe risk_report in TradingAlgorthm. 2013-08-01 16:08:56 -04:00
Eddie Hebert 376ae33264 PERF: Remove deepcopy from EventWindow ticks.
The deepcopy of events into the EventWindow's ticks was causing
a significant increase in memory consumption, e.g. an algorithm with
almost 200 sids and 14 vwaps removing the deepcopy reduces the amount
of memory consumed by about 40%.

The downside is that if an event's properties are changed, which is
not advised, later on, then the signal derived from vwap etc.
may be changed.
2013-07-31 18:55:07 -04:00