Commit Graph

371 Commits

Author SHA1 Message Date
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
Eddie Hebert 08bc42dc0c TST: Fix index to cumulative risk answer key.
Indexes to risk answers were pointing to a previous version.

Also, provide the risk cumulative answers as a pd.Series,
so that it is easier to compare to values produced by risk class.
2013-09-24 21:36: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
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
John Ricklefs 7b8769b3e7 BUG: Fix div-by-zero error in cost_basis adjustment. 2013-08-27 13:24:06 -04:00
John Ricklefs 191715a148 ENH: Add support for asynchronous commission events. 2013-08-26 14:18:32 -04:00
Eddie Hebert 11f9178fd3 TST: Correct annualization of Sharpe in answer key.
Correct the annualization factor from being 1/sqrt(252), since
the annualization was applied to the volatility, by including
252 in the Sharpe's numerator.
2013-08-16 14:26:59 -04:00
Eddie Hebert b9dfda01d2 DOC: Add annotations file for answer key.
Currently, just provide a way to render to some of the data extracted.
Intended to have more thorough documentation of the spreadsheet,
explaining derivation/calculations in each sheet and column.
2013-08-15 15:09:46 -04:00
Eddie Hebert b94d10cfb6 TST: Add answer key indexes for cumulative risk metrics.
Add indexes for Sharpe, returns and other values needed for
reading answers for cumulative risk metrics.

Prepare for unit test and matching change of implementation.
2013-08-15 15:09:44 -04:00
Eddie Hebert f3fd9d598a TST: Add parser for date values from answer key.
Refactor the reading of values from the Excel spreadsheet so that
parsers are configurable by index.

Needed so that we can parse columns that have dates, in addition
to floats as previously.
2013-08-15 15:08:42 -04:00
Eddie Hebert 3732c105b8 TST: Improve answer key interface.
Instead of using the indexes defined in the answer key class
to index back into the answer key object, populate the answers
so that they are available as members of the answer key object.

Update period risk test to use new answer key structure.

Also, remove the rounding behavior from the answer sheet, leaving
the rounding to the consumer of the answer key values, so that
the values can be retrieved from the spreadsheet during answer
key __init__ without knowledge of the decimal point that the calling
code expects.
Correspondingly, change period risk tests to use
np.testing.assert_almost_equal when doing floating point comparison.
2013-08-14 22:41:52 -04:00
Eddie Hebert de4671213b TST: Reduce cumulative risk test to stub.
Remove tests that were a copy of period risk behavior, to prepare
for adding cumulative risk specific tests.
2013-08-14 22:35:57 -04:00
Eddie Hebert ddcddc9351 MAINT: Create separate test risk modules.
As these modules diverge, the tests for each module should
distinguish those changes.
2013-08-14 15:09:01 -04:00
Eddie Hebert 1501e659ce TST: Rename notebook with link to answer key.
Move to a new notebook, the AnswerKeyLink will be for a permalink
to the current version of the answer key, of which the output
won't be too noisy in git.

The annotation notebook will also be kept in source control, but
without output, since the table html output is large.
2013-08-14 14:47:19 -04:00
Eddie Hebert 6f73f68d24 TST: Add output of answer key annotations to notebook.
For more improved viewing experience via nbviewer.ipyhton.org,
include the output of the notebook.

When saving/updating this file, a fresh kernel and evaluation of
the entire notebook should be used so that the cell numbers stay
in order.
2013-08-14 13:12:50 -04:00
Eddie Hebert ead9fc953f TST: Begin annotation notebook for risk answer key.
Read tests.risk.answer_key module into an IPython notebook, to start
a base to which answer key values and explanations can be added and
display without access to Excel.

For now, the notebook just provides the latest download link for
the spreadsheet.
2013-08-14 12:36:47 -04:00
Eddie Hebert bb8a734ae2 TST: Improve cumulative risk metrics sheet in answer key.
Update answer key for cumulative risk:
- Annualization of Sharpe
- Use 10 year period
- Use of daily returns vectors instead of compounded return scalar.

No tests or risk module code are currently reading off of this sheet,
but developing it ahead of work in risk module so that the sheet can
be examined and vetted.
2013-08-14 11:34:48 -04:00
Eddie Hebert cbac1bd6cb TST: Update answer key checksums on upload.
Automate the updating of the answer key when a new key is uploaded
to S3, so that keeping the latest value in sync is more likely.
2013-08-14 11:30:15 -04:00
Eddie Hebert faee91876f MAINT: Add formatting for printing of answer key DataIndex.
Output format of the range compatible with Excel, so that it
can be copy and pasted back into the spread sheet for easier
corroboration.
2013-08-09 17:32:17 -04:00
Thomas Wiecki b89886297f STY: autopep8 codebase. 2013-08-08 16:46:44 -04:00
Thomas Wiecki e590da75fb BUG: Typo in test_batchtransfom. 2013-08-08 16:01:22 -04:00
Thomas Wiecki b1fdebfb7c TST: Added tests for new order methods. 2013-08-08 15:55:08 -04:00
Eddie Hebert c31bbee424 MAINT: Create separate page in risk answer key for period returns.
Copy the `Sim` sheet to `Sim Cumulative` as well as rename it to
`Sim Period`.

Update the answer key module accordingly.
2013-08-07 17:16:01 -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 7139ac7061 TST: Update answer key spreadsheet.
Point tests at version of answer key with explicit use of sample
vs. population for covariance and variance via, `COVARIANCE.S` and
`VAR.S`
2013-07-29 14:47:31 -04:00
Eddie Hebert 3c305bbe35 TST: Add script to automate upload of risk answer sheet to S3.
For maintainer use, requires AWS credentials for the account where
the `zipline-test-data` bucket is hosted.

Script does the following steps which used to be manual:
- Create a key name based on the md5 of the answer key file.
- Upload the answer key to S3 bucket.
- Make the file publically downloadable over HTTP.
2013-07-29 14:42:53 -04:00
Jean Bredeche 8f1d599fc6 fixing some bugs with splits (ratios and empty positions) 2013-07-24 15:26:15 -07:00
Jean Bredeche 6fc077a573 ENH: Add support for splits in zipline.
When a split is encountered, open positions and open orders
are updated accordingly.
2013-07-23 16:22:58 -04:00
Eddie Hebert 9b73373978 BUG: Revert returns cov to use ddof of 1.
Fix the spreadsheet to apply a factor of COUNT / COUNT - 1
to the COVAR value.

Also, go back to using the C[1][1] index instead of calculating
var independently.
2013-07-23 13:17:10 -04:00
Eddie Hebert f451efe483 TST: Read alpha values from answer key.
Corroborate alpha values with Excel answer key.
2013-07-23 12:15:24 -04:00
Eddie Hebert 7c01d39858 BUG: Fix beta calculation.
Use recent change to benchmark variance in the beta calculation,
instead of referring to the 4th quadrant of the covariance.

Also, read answers from answer key for corroboration of beta values.
2013-07-23 12:07:24 -04:00
Eddie Hebert 3164aa9016 BUG: Make covariance match values in answer key.
The np.cov call needs a ddof of 0 to match the answer key, which uses
Excel's VAR.

When switching np.cov to use a ddof of 0, the benchmark variance is
no longer the 4th quadrant of the cov result, so use np.var directly.
2013-07-23 11:30:48 -04:00
Eddie Hebert 2314e8a281 TST: Read benchmark variance from answer key.
Add reference to updated answer key with benchmark variance cells,
and use the new cells as the reference for the benchmark variance
test.

The values changed from the original hardcoded values, due to the
change to close over close benchmarks.
2013-07-19 20:28:12 -04:00
Eddie Hebert 56c7c840fa TST: Fix answer key index converter for values larger than 'AB'
Change logic so that it uses the 26 ^ n as the base for each letters
index value.
2013-07-19 20:26:30 -04:00
Eddie Hebert de608b0b05 TST: Read more sharpe values from the answer key.
Recent conversion of sharpe to reading from the answer key had left
a few tests with hard coded answers.
2013-07-19 12:10:17 -04:00
Eddie Hebert 8c006fc347 TST: Use xlsx format instead of xls.
The xls conversion was corrupting some equations, so switching to
use Excel produced xlsx.
2013-07-19 11:06:37 -04:00
Eddie Hebert 135b872a58 DOC: Fix typo in xslx format name. 2013-07-18 18:36:42 -04:00
Eddie Hebert 575e45ab4e TST: Read more risk expected values from the answer spreadsheet.
Convert test_risk from hardcoded values to reading algorithm
returns, volatility, and sharpe answers from the spreadsheet.
2013-07-18 18:09:49 -04:00
Eddie Hebert d58181db34 TST: Fix case where there is no existing risk answer key.
The download checksum was not being correctly set when no file existed.
Set the checksum to the latest value so that a download is triggered.
2013-07-18 14:47:33 -04:00
Eddie Hebert e5e38a437b TST: Download risk answer key from S3.
So that the answer key does not onerous on the SCM repo size, add a
utility to download the answer key automatically.

Prevent re-download on every test suite run if the local answer key
matches the latest version.
2013-07-18 14:31:08 -04:00
Eddie Hebert 5579e54c6f TST: Read benchmark returns directly from answer key spreadsheet.
The risk tests originally were based on a spread sheet, with the
results of returns etc copy and pasted into the `test_risk` module.

Include the spreadsheet and read the values directly using a Python
Excel spreadsheet library.
2013-07-18 14:31:08 -04:00
Eddie Hebert 87c0f40aa0 TST: Move risk tests to their own module.
Will be adding the Excel spreadsheet answer key, a dedicatetd
directory for risk should help make clear why and where the spreadsheet
is used.
2013-07-18 14:31:08 -04:00
Thomas Wiecki 940ddd22d3 TST: Added testing of order timings and price. 2013-07-17 19:56:55 -04:00
Richard Frank 75dd77ea03 ENH: Added early closes to trading environment
specifically, expected 1 PM closes since 1993
2013-07-16 12:02:34 -04:00
Ben McCann efe50f8494 BUG: Fix get_benchmark_returns.
It should calculate the return off the pervious day's close, instead
of current day's open.
2013-07-15 15:35:09 -04:00
Eddie Hebert eac882b773 ENH: Enable TALib transforms to perform on multiple stocks.
The TALib transform only supported operating on the first value
of a given batch transform panel row.

Instead of returning the one value, even if an panel with multiple
sids was provided, return a dictionary that maps stock to TALib
result.
2013-07-10 14:40:58 -04:00
Eddie Hebert 3d8bdeb429 ENH: Enable minute bar data with TALib transform.
Add a `bars` keyword arg, as is used with BatchTransform.

Also, instead of overwriting the window_length kwarg with timeperiod,
always use the lookback value from the created TALib function,
as timeperiod will be an input into that value if it exists.

Calculate `window_length` in minute mode so that there are enough
days to cover the minutes in the timeperiod.
2013-07-09 11:26:26 -04:00
Eddie Hebert 5fb837bf37 MAINT: Use numpy testing method instead of assertTrue.
So that when the test fails, the comparison is in a more readable
format.
2013-07-08 17:30:48 -04:00