Commit Graph
459 Commits
Author SHA1 Message Date
Eddie Hebert b555af157b PERF: Use stored values for open and close.
The market_open_and_close method was a performance bottleneck,
since it was creating new dates on each query for open and close.

Instead use the pre-rendered frame of open and closes values
from the trading environment.
2013-11-12 13:12:12 -05:00
Richard FrankandEddie Hebert 8014d9d938 BUG: Order.status now returns correct value
whether or not Order.open has been queried
2013-11-06 14:31:49 -05:00
Richard FrankandEddie Hebert 4dbdf45006 MAINT: Factored process_transactions out of blotter's process_trade 2013-11-06 14:27:19 -05:00
Eddie Hebert 3f89904e33 MAINT: Remove unused calculations of max_leverage, et al.
In the performance period the max_leverage, max_capital_used,
cumulative_capital_used were calculated but not used.

At least one of those calculations, max_leverage, was causing a
divide by zero error.
Instead of papering over that error, the entire calculation was
a bit suspect so removing, with possibility of adding it back in
later with handling the case (or raising appropriate errors) when
the algorithm has little cash on hand.
2013-11-06 14:22:20 -05:00
Richard Frank 2492feb938 ENH: Keep track of total commissions as attribute on Order
Value is summed from TRANSACTION and COMMISSION events.
Defaults to None, meaning unset.
2013-11-01 17:23:50 -04:00
Eddie Hebert 4b023a852a MAINT: Use 1 as the first bitmask value instead of 0.
To prevent a possible future bug where values like SELL | STOP | LIMIT
would accidentally match STOP | LIMIT.
2013-11-01 16:26:48 -04:00
Eddie Hebert 1575867b40 STY: Use named args for Transaction object creation.
Instead of creating and passing a dict of the object values,
use named args directly.
2013-11-01 16:10:19 -04:00
Jonathan KamensandEddie Hebert 73faf9133e MAINT: Clean up imports of zipline.finance.trading
Use "from zipline.finance import trading" instead of "import
zipline.finance.trading as trading".
2013-10-29 13:50:14 -04:00
Eddie Hebert f0465c5b87 STY: Tweak over-indented code.
flake8 recommendation
2013-10-29 13:38:31 -04:00
Jonathan Kamens 0a7539b6de MAINT: flake8 2013-10-29 12:02:51 -04:00
Eddie Hebert 7412cc97a0 MAINT: Use bitwise flags to help order cases easier to follow.
Instead of nesting order direction and related stop and limit logic,
derive a bitwise mask from the combination of order configurations
and use the mask as a 'switch'.
2013-10-28 20:43:38 -04:00
Peter CawthronandEddie Hebert 28f86bc14e BUG: Fix handling of STOP, LIMIT and STOP LIMIT Orders
Includes specific handling of Buy Stop, Sell Stop, Buy Limit, Sell
Limit, Buy Stop Limit and Sell Stop Limit orders.
2013-10-28 20:40:09 -04:00
Eddie Hebert 37c56b9aa4 MAINT: Use Series throughout for daily returns.
Remove the lists of DailyReturn objects in favor of using pd.Series
to store the return values.

Should make it easier to inspect the values when stepping through,
make the windowing of data to a certain range more facile by using,
and have some performance increases due to removing object creation
and member access.
2013-10-19 23:06:18 -04:00
Eddie Hebert aedf3766a8 Revert "MAINT: Store values for market open and close in environment."
This reverts commit 17b8980fb9.

Backing out rigidness of market and close, while sorting out how
to handle events that are not on a day in the trading calendar.
2013-10-18 12:30:01 -04:00
Eddie Hebert 17b8980fb9 MAINT: Store values for market open and close in environment.
Instead of creating the market open and close mid-simulation,
calculate upfront the values for market open and close in a
DataFrame, so that they values can be looked up by date, as
viewed as series while investigating data issues.

One downside of this implementation is that the entire history
has open and close values calculated, even though the simulation
may only be a subset of the trade data on record.
Should consider moving the `times` property and other methods
that care about the start and end date of a simulation to
SimulationParameters or another like object.
2013-10-17 17:46:23 -04:00
Eddie Hebert 800210fbb3 MAINT: Ensure that test sources only provide market days.
Instead of using all calendar days between start and end in test
sources, use the trading calendar for test sources.

Needed for an incoming refactoring of market open and close,
where the opens and closes are indexed by market days.
2013-10-17 16:45:51 -04:00
fawceandEddie Hebert f8ce7d944b ENH: Add downsampling to BatchTransform.
So that with minute data, 2.5 orders of magnitude of data can
be cut, allowing for longer window_lenghts, when the daily
values are what are desired for a signal.
2013-10-11 16:48:08 -04:00
John Ricklefs 9ac180d4bb BUG: Ensure compounded_log_returns set on first dt. 2013-10-11 13:06:11 -04:00
Eddie Hebert 1bad245675 ENH: Use annualized returns for beta and alpha.
So that the units match the other risk calculations, also
use annualized returns for beat and alpha.

Update answer key to match values calculated on the first day.

Also, update performance tracker test so that the returns used
are fractional instead of > 1, so that the annualized numbers are
more in line with real world values.
2013-10-11 00:27:03 -04:00
Eddie Hebert dcae6af67b ENH: Annualize information ratio.
Use annualized values for information, so that it is calculated
using the same units as sharpe, etc.
2013-10-11 00:27:03 -04:00
Eddie Hebert 0ebdb2fe77 ENH: Annualize sortino ratio.
Use annualized values for sortino, so that it is calculated using the
same units as sharpe, etc.
2013-10-11 00:27:03 -04:00
Eddie Hebert bfa94e9c91 ENH: Approximate stats for the first day of minute emission.
Volatility needs mulitple values to calculate the stddev,
so provide a day with zero returns to base the first day against.
2013-10-10 18:37:53 -04:00
Eddie Hebert 433f97c38f ENH: Improve headline Sharpe risk calculations.
This could perhaps be labelled BUG, as well.

Change the Sharpe (and algorithm volatiilty) value used to compare
algorithms/backtests so that it is annualized and uses daily returns.

Previously, the Sharpe metric was using the same calculation style
as the fixed size periods, i.e. 3 Month, 6 Month, etc., which can
use the geometric mean when comparing against the risk free.

Change the Sharpe calculation to use the arithmetic mean differenc
against the risk free rate, using daily (non-compounded) values.

Also, use annualized mean returns.
2013-10-10 18:37:53 -04:00
Richard Frank 822e21fa84 MAINT: Factored out update_position method
and changed Position default last_sale_date to None
2013-10-10 16:40:14 -04:00
Eddie Hebert 3f260ccaba MAINT: Move market minute function into trading environment.
So that the market minutes are more accessible to other modules.
2013-10-09 14:46:53 -04:00
Eddie Hebert 71907ad427 MAINT: Use pandas instead of Delorean for trading date logic.
Standardize on pandas for date manipulation.
2013-10-08 23:59:09 -04:00
Eddie Hebert 2badf7557b MAINT: Remove redundant create of numpy arrays.
Now that the cumulative risk module uses pd.Series instead of lists,
it is unnecessary to call `np.array` on the stored values.
2013-10-07 18:06:05 -04:00
Eddie Hebert 5041f3e83b MAINT: Make returns frequency and returns index class members.
Hold on to the values set for the returns frequency and the cont
index, mainly for debugging purposes mid-process.

It was useful to have these values when debugging why there was
an extra non-midnight time in the index.
2013-10-03 12:30:57 -04:00
Eddie Hebert fc244c395f MAINT: Use pd.normalize_date in cumulative risk module.
Also, normalize the period close when checking trading days,
so that an extra value isn't added to the index for the returns
containers.
2013-10-03 12:30:52 -04:00
Eddie Hebert 6f9a03aa76 MAINT: Use return scalars in performance instead of object.
Remove another case of creating a DailyReturn object, in favor
of passing the return scalar directly to the risk module.
2013-10-02 15:57:00 -04:00
Eddie Hebert ac6a15f20a MAINT: Use pandas normalize_date instead of datetime.replace
Continue standardizing on using the date normalization provided
by pandas.
2013-10-02 15:52:16 -04:00
Eddie Hebert 31b85239f3 MAINT: Force float in position values in period. 2013-10-01 19:58:06 -04:00
Eddie Hebert 75360610a9 MAINT: Use pd.Series to keep track of positions values in a period.
Instead of using a raw np.array and keeping track of an index into
that array, use a pd.Series to track the last_sale_price and amounts
in a vector format.
2013-10-01 18:43:01 -04:00
Eddie Hebert df9575982a MAINT: Remove extra Series creation in performance to risk.
Instead of creating a new Series object each time values are
passed from performance to risk, pass the scalar values directly.
2013-10-01 17:06:59 -04:00
Eddie Hebert 20113872ee MAINT: Use a Series for returns instead of list.
Make the granularity and range of the returns more explicit.
2013-10-01 16:48:26 -04:00
Eddie Hebert 052e9b6b95 MAINT: Remove extra assignment of emission rate.
Remove a doubled line in performance tracker.
2013-09-27 15:15:21 -04:00
Eddie Hebert 9dd52be73b MAINT: Split performance module into submodules.
So that when searching code for `returns` and `update`, it is
easier to discern which performance class is affected.

Should be no functional changes.
2013-09-26 13:38:27 -04:00
Eddie Hebert a29e0c40b6 MAINT: Reduce the number of minutes included in risk index.
Instead of midnight to midnight for each day, use the trading
environment's market open and close for each day, so that the index
is exactly the trading minutes of each day.

Reduces the amount of memory consumed, but more importantly should
make it easier to inspect the Series that use the index and check
whether the values are correctly being filled.
2013-09-25 16:24:01 -04:00
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