Commit Graph
89 Commits
Author SHA1 Message Date
Eddie Hebert d31303b86c ENH: Add basis for minute rate emission of performance.
- Create different benchmark containers in performance
  depending on emission rate.
- Add a minute close method which updates algorithm and
  benchmark returns, and calculates the risk metrics
  depending on those methods.
- Provide fake 0.0 values for annualized metrics like
  sharpe, sortino, and information, until we figure out
  how they should be treated in the context of minutely
  calculation.

*NOTE* This does not fully work without the changes to the
simulation loop by @fawce
2013-04-25 16:49:38 -04:00
Eddie Hebert 7d615c5af5 MAINT: Improve message for return mismatch by including current dt.
Based on work from @fawce's simulation loop work.
2013-04-25 16:48:19 -04:00
Eddie Hebert fd6c71286d MAINT: Use sim_params for risk metrics init.
Prepare for adding emission_rate in risk metrics logic.
2013-04-25 15:30:34 -04:00
Eddie Hebert 1183c44fad MAINT: Remove unused last_dt member from risk.RiskMetricsIterative 2013-04-25 00:28:35 -04:00
Eddie Hebert bf1fc42acc BUG: Fix time spent checking equality of floating point numbers.
The use of np.allclose introduced a severe performance penalty,
caused by the creation of two `np.array`s for each check.

Instead create and use a similar check which maintains tolerance
to floating point rounding, but operates only on scalars.
2013-04-16 13:09:26 -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
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 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
Eddie Hebert 9627f48963 MAINT: Convert treasury curves data to pd.Series
Instead of using OrderedDict, use a pd.Series so that utilities
like searchsorted, etc. can be used.
2013-04-03 11:59:08 -04:00
Eddie Hebert 39f457ca28 MAINT: Use dateutil module for adding months to a datetime.
Instead of having an advance_by_months function maintained in
Zipline, leverage the relativedelta module provided by dateutil.
2013-04-03 10:41:47 -04:00
Eddie Hebert 0dca5d004a MAINT: Remove unused RiskReport.find_metric_by_end 2013-04-03 10:14:36 -04:00
Eddie Hebert b3c23b0d8b MAINT: Rename risk metric function names to include '_ratio' suffix.
To make the risk metrics being calculated more clear, change the
naming convention that ratios have a '_risk' suffix.

Also, fixes typo in beta docstring.
2013-04-02 11:27:34 -04:00
Eddie Hebert 210a43a306 MAINT: Factor out risk metric logic from risk objects.
Move the risk metric definitions to functions at the module level
with defined parameters.

Both risk implementations call these functions, where the difference
between risk implementations is with which internal data they
send to the various risk metrics.

Metrics moved:
- Sharpe Ratio
- Sortino Ratio
- Information Ration
- Alpha
2013-04-01 12:43:27 -04:00
Eddie Hebert 702e6f00d2 MAINT: Use numpy for risk period returns.
Following the lead of the RiskMetricsBatch conversion to use
more pandas and numpy.
Bringing the iterative and batch versions closer together as we
work towards folding them into one.
2013-03-29 17:06:54 -04:00
Wes McKinneyandEddie Hebert 20d50450b6 ENH: use array and pandas operations to speed up risk computations 2013-03-27 13:42:46 -04:00
Eddie Hebert 08882bc8aa MAINT: Updates copyright on risk module. 2013-03-20 14:30:11 -04:00
fawceandEddie Hebert a4a4d38a73 TradingEnvironment allows the specification of a benchmark index and a local timezone for the exchange. This commit adds tests to verify the TradingEnvironment properly handles London Stock Exchange index, FTSE.
- added LSE reference rrules calendar (thanks to Edward Johns)
    - added tests to verify LSE environment matches rrule calendar
    - added a test to verify global environment behavior can be set.
    - moved DailyReturn class to trading to eliminate circularity from
    risk <-> trading.
    - updated TradingEnvironment to be a context manager. This allows users
    to run algorithms in individually isolated environments in one python
    process. This is useful for managing multiple algorithms in a single
    ipython notebook.
    - added comments to explain behavior and useage of the global environment
2013-02-18 10:24:32 -05:00
fawceandEddie Hebert 2c7355a0dc Refactoring of TradingEnvironment to isolate the global state: index symbol and exchange timezone. Parameters that define the simulation (start, end, and capital base) were put in a new class, SimulationParameters.
Global state for the financial simulation environment is accessed through the
zipline.finance.trading module, which now contains a module variable:
environment.

Parameters are passed into an algorithm as a keyword argument, sim_params.
SimulationParameters creates a trading day index for the test period that
can be used to find trading days, calculate distance between trading days,
and other common operations. The sim params index is just selected from the
global state.

================

Details:

    - adding delorean to the requirements.
    - made index symbol a parameter for loading the benchmark data. changed
    messagepack storage to be symbol specific.
    - ported risk, performance, algorithm, transforms, batch transforms
    and associated tests to use simulation parameters and global environment
    - factory and sim factory use global state and sim params
    - factory method parameter names now reflect the class expected
2013-02-18 10:24:32 -05:00
Ryan DayandEddie Hebert 4d56f57468 Add the information ratio to risk metrics.
Calculates relative to the benchmark returns.
2013-01-31 18:25:36 -05:00
Ryan Day bb16eda1fa Force float value, and compare result against boundary 2013-01-28 14:08:44 -05:00
Ryan Day 64ffa055c9 Add the Sortino ratio for downside risk 2013-01-28 08:55:14 -05:00
Richard Frank 805bfe0f30 Moved treasury_durations from property to module constant 2012-12-28 13:40:09 -05:00
Richard Frank 54063854aa Forward-fill missing treasury data
To handle, for instance, Columbus Day (Oct 10),
on which there is no treasury data.

We're only forward-filling data now, and
no longer searching both back and forward in time.
2012-12-14 17:29:27 -05:00
Richard Frank 3684a85474 Don't log warning when we only have a partial month's data
which is an expected case.
2012-12-12 15:23:26 -05:00
Richard Frank 095f2dd65b Date bookkeeping fixes in perf and risk
Issues appeared when we were close to the end of our
historical data.

Yielding DONE event with both perf and risk messages now
2012-12-12 15:23:26 -05:00
Richard FrankandEddie Hebert 4981c67c31 Handle missing historical data more elegantly
Updated the search for treasury data when there is none for the
test end date.
It could be that the end date is not a trading day, or we could
just be missing treasury data. In either case, we try to recover
more gracefully now, by searching as far as possible and maybe
logging a warning.

Similarly, if there is no benchmark data for the test end date,
look for the next trading day. If we really have no data,
blow up with our own explicit exception, instead of overflowing
in our search for dates in the future.
2012-12-10 13:03:25 -05:00
Eddie Hebert 0617e53d69 Upgrades flake8 from 1.5 -> 1.6
Also, removes flake8 ignores, since the warnings that were
at odds with eachother now work.
2012-11-19 12:49:09 -05:00
Eddie HebertandEddie Hebert d5697cdf0a Fixes under-incrementation of risk report.
We were only incrementing the risk report by one day, and never
checking to see if that day we incremented into was a trading day
or not.

We now increment by day until we are on a trading day.

With an assist from @twiecki on:

Adapted test_risk_compare_batch_iterative to work with fixed
iterative risk class.
2012-11-15 14:13:04 -05:00
Eddie Hebert 4c3554042e Revert "Removes created member from risk metrics."
This reverts commit 18587b0623.

Reverting until we can support the removal in internal code.
2012-11-14 18:25:57 -05:00
Tobias Brandt e0ef6586a2 DOC: Fixed escaping of special chars in math environment. 2012-11-14 11:26:02 +02:00
Eddie Hebert 18587b0623 Removes created member from risk metrics.
`created` was being set, but unused.

It is one of the rare uses of the epoch_now and EPOCH,
so removing on the path of trimming down date_utils.
2012-11-09 06:58:06 -05:00
Eddie Hebert 7904773d00 Updates flake8 to latest.
The latest flake8 release in now 1.5, which pulls in pep8: 1.3.4a0

The upgrade pep8 has changes to what it picks up as lint.
Making code base compatible, so that new devs can install pep8
from PyPI and not have friction over the version difference.

Currently using these ignores in the config file:

```
[pep8]
ignore = E124,E125,E126
```

Ignoring these since they are difficult to squash while maintaining
an 80 char line length, and appear spurious.
Should address later.

Updates Travis config, README, and pip requirements to reflect change.
2012-10-22 11:57:16 -04:00
Eddie Hebert 05bb179aba Accounts for negative values when creating compounded returns.
Sets the value sent to log to a value that doesn't crash out because
of negative value.
Setting the value to 0 instead.
2012-10-19 11:18:26 -04:00
Thomas WieckiandEddie Hebert b976c1252b Provides an iterative version of risk metrics.
I wrote this a little while ago as I noticed that a lot of time is spent
computing risk statistics. This is done over the complete history over
and over again while this could be done just by using the previously
computed value (iteratively).

We didn't go forward back then because for minute trade data the
difference was not significant enough. However, now with zipline
standalone I think most people will use daily (because that's
what's available) and it makes a huge difference
(speed-up of a couple of 100%).

Unfortunately, we can't just replace the existing one with an
iterative as for the final cumulative stats the batch is still
better. So that's not as nice, but the performance increase is
big enough for me to issue this PR (zipline is actually painfully
slow with daily data).

There is a unittest that compares that both produce exactly
the same outputs.

Speed measurements (for 500 trading days, daily source):

with iterative:
real 26.617 user 12.909 sys 6.112 pcpu 71.46

prior:
real 44.176 user 31.030 sys 11.381 pcpu 96.00
2012-10-17 23:41:30 -04:00
Eddie Hebert bbf2317c57 Saving point for adding license files. 2012-10-08 17:32:40 -04:00
Eddie Hebert 77af1ca632 Applies PEP-8 and pyflakes style to tests and zipline.
Mostly whitespace, line width and other spacing changes.
Also, removes use of deprecated has_key in favor of `in`

Going forward new patches should pass running `flake8` before
submission.
2012-10-05 12:14:09 -04:00
fawce fe8e107c59 dropping max drawdown, adding pytz to whitelist. 2012-09-14 16:00:13 -04:00
fawce 19f00e867b indentation bug 2012-08-12 00:53:23 -04:00
fawce 500e6a9f24 fixed #563 2012-08-12 00:48:00 -04:00
fawce 18cd9a02df added more frequent heartbeating between requests from monitor. seems to work. 2012-07-17 11:04:32 -04:00
Stephen Diehl 7ffdff64a1 Remove other refs to stdlib logging. 2012-07-06 10:47:11 -04:00