6093 Commits

Author SHA1 Message Date
Eddie Hebert 1794e4e716 DEV: Update flake8 to latest release. 2013-10-29 13:40:28 -04:00
Eddie Hebert f0465c5b87 STY: Tweak over-indented code.
flake8 recommendation
2013-10-29 13:38:31 -04:00
Eddie Hebert c45c1a22e1 BUG: Only localize benchmark index if it is naive.
Check for whether or not the index's timezone is UTC or not before
attempting to localize, since an already localized index throws an
error when tz_localize is called.
2013-10-29 13:17:58 -04:00
Jonathan Kamens 0a7539b6de MAINT: flake8 2013-10-29 12:02:51 -04:00
Jonathan Kamens c3ddbc258d ENH: Accept simulation parameters and benchmark source args to create_test_zipline 2013-10-29 11:39:07 -04:00
Jonathan Kamens e36f70f541 ENH: Allow market data loader to be specified to create_simulation_parameters 2013-10-29 11:17:41 -04:00
Eddie Hebert 2d64ab8bfe BUG: Fix naive timestamps in benchmarks.
Always convert the benchmarks to UTC, not just on reload.
2013-10-29 08:36:53 -04:00
Eddie Hebert 912539248f Merge fix for stop orders.
Pull in patch that fixes the stop orders so they behave correctly
with regard to the price being greater or less than the stop for both
buys and sells.

Also, update unit test and add a refactoring on top of the fix to
make each sell/buy, stop and limit combination more clear.
2013-10-28 21:10:46 -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
Eddie Hebert 32c1f93572 TST: Updates tests to fit fixed stop behavior.
Change the answers to the stop order tests to match the corrected
behavior, where results are opposite from previous behavior.
2013-10-28 20:40:32 -04:00
Peter Cawthron 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 0c71f95016 TST: Parameterize stop order test.
So that we can more clearly demarcate each case of buy/sell and
price compared to stop, and their expected outputs.

Also, add comment about the current behavior versus the behavior
that will be moved to in an upcoming fix.
2013-10-28 15:12:29 -04:00
fawce 279605dfb5 BUG: Fix excessive recalcuations in batch.
Downsampled batch transforms should only recalcuate on close
2013-10-20 08:06:39 -04:00
Eddie Hebert cdbafc534a BUG: Fix mismatch of stored benchmark timestamps.
Normalize the date, so that there is not an EST/EDT and UTC mismatch.
2013-10-20 08:00:17 -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
fawce 76887e2855 BUG: Fix non-trading advancement of trading day count and downsample.
Add a guard so that we do not advance trading day count or downsample
on non-trading days.
2013-10-18 14:07:49 -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
fawce 0ceabb590b BUG: Group and aggregate downsampling by trading day.
Otherwise, out of market events would result in a mishaped
panel.
2013-10-17 22:41:20 -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
fawce 3a1ca1ddb2 BUG: Mask of batch_transform columns to match keys in data parameter.
The underlying RollingPanel in batch_transform was always accumulating
all values to ever appear in data.

However, at any given algo time the desired return value is what the
current active sids are.

Instead, mask down to the sids that are passed in as the data parameter.
2013-10-16 15:16:03 -04:00
Eddie Hebert 0224aeb552 MAINT: Use enviroment normalize_date instead of dt.replace
Continue path of removing scattered calls to dt.replace.
2013-10-16 15:14:24 -04:00
Eddie Hebert 37e1e74391 TST: Add logging of sim params for perf tracker tests.
These tests use the random simulation parameters, which is leading
to an intermittent failure.

We may want to consider removing the randomness, but in the meantime
the randomness is exposing a case where the cost basis is not the value
expected, so logging the sim parameter values to help track down what
parameters cause the failure.
2013-10-16 12:07:14 -04:00
fawce 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 d177ddd860 Merge branch with annualized cumulative risk metrics. 2013-10-11 00:27:20 -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 dad34d2ddb TST: Add annualized alpha and beta to answer key.
Add a column that uses annualized mean returns as the inputs into
alpha and beta.
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 1afc9069b1 TST: Update answer key with annualized sortino and information.
Include in the Excel answer sheet the sortino and information
metrics using annualized inputs.
2013-10-10 18:37:53 -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 71f03e9537 BUG: Ensure loading benchmarks include latest dates.
The Series `.append` does not update in-place, assign the value
to `saved_benchmarks` so that we update the newest benchmarks.
2013-10-07 12:17:26 -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 6ac5d49573 MAINT: Remove duplicated treasury loading code.
The dump and update of curves were both using the entire history.
So instead of having the update use a different code path, always
use dump and overwrite.
2013-10-02 11:10:15 -04:00
Thomas Wiecki 65637b9430 ENH: Add option of instantly filling orders. 2013-10-01 20:30:01 -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 5ddc134379 ENH: Cache daily data to eliminate repeat network calls.
Both unit tests and repeated runs while developing an algorithm
can benefit from having a local copy of the Yahoo data, instead
of doing a network call each time.

Store the web request results as a csv file in a cache directory,
named by symbol and date range.
2013-10-01 15:04:02 -04:00
Eddie Hebert b44fc20e4e MAINT: Remove msgpack as a dependency.
Now that the data serialization uses pandas, msgpack is no longer
needed.
2013-10-01 14:28:11 -04:00