Commit Graph
64 Commits
Author SHA1 Message Date
fawce 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
fawce 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 Day 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 Frank 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 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 Wiecki 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
fawce 89e52c6758 better filter for nan check 2012-06-19 20:03:37 -04:00
fawce e1db77fb64 fixed comprehension 2012-06-19 17:06:40 -04:00
fawce 5d97469a24 added a filter for nan values in risk data relay 2012-06-19 15:52:47 -04:00
fawce 036f9e93a7 fixed a type-o in the documentation. 2012-05-31 23:15:53 -04:00
fawce a4ea3e3343 marked a todo for a calculation bug 2012-05-30 23:55:25 -04:00
fawce ef763f28d0 added a created date to the risk report. 2012-05-29 21:20:16 -04:00
fawce 23fb5fa083 cleanup 2012-05-28 15:25:44 -04:00
Stephen Diehl 3ad1f250e6 Cleaned up OOP, first round. 2012-05-16 14:33:16 -04:00
Stephen Diehl 133d9c03af One test passing, progress! 2012-05-10 16:38:04 -04:00
Stephen Diehl 00de461da8 Made more submodules. 2012-05-10 15:46:19 -04:00
fawce 54d3579ceb added boolean to results for exceeding max losses in a single simulated day. 2012-04-23 15:10:44 -04:00
fawce bab0e2bd19 made distinction between cumulative behavior and daily behavior a bit more clear. 2012-04-20 15:08:39 -04:00
fawce 08a5bd5a0d re-arranged fields so that history includes daily snapshots for cumulative measures. 2012-04-19 23:27:35 -04:00
fawce 7eb0ba67ac clarifying the results protocol for the backtest. 2012-04-18 12:36:46 -04:00
fawce 30dfc86ba9 fixed dates front to back to be proper market open/close, and to use start/end first_open/last_close from the TradingEnvironment. 2012-04-06 20:49:56 -04:00
fawce aaf2fae2b8 patched guard logic in max drawdown calculation. needs real work. 2012-04-05 12:43:43 -04:00
fawce 14b57dad07 patching the filter test because we are now trying to calculate end of test risk 2012-04-04 18:44:19 -04:00
fawce 4adf8ff854 changes risk report period label to YYYY-MM format 2012-04-04 17:01:49 -04:00
fawce 701687b812 fixed bug where year report list included months instead. added a period_label to risk metrics corresponding to the end date. e.g. April 2006 2012-04-04 11:37:19 -04:00
fawce 7a7833a540 fixed missing fields, added a new random source option to test zipline (still buggy). 2012-03-30 17:48:05 -04:00
fawce ce6a91adb6 added a frame to get performance data written to the result stream. not complete, but functional. 2012-03-29 17:13:28 -04:00
fawce 7a57c27295 this is a hotfix to the accidental commit on master, but I lost my bearings again and added pycco, so this is a bit more than a hotfix now. 2012-03-20 23:10:24 -04:00
fawce 2324c054e9 added more documentation to the lines.py. refactoring relationship between zipline and algorithm. 2012-03-19 11:40:48 -04:00
fawce dcc471cc93 refactoring tests to combine common code into factory for creation of test data sources. also created new zipline/lines module, which will
hold classes that instantiate entire zipline topologies.
2012-03-17 23:15:38 -04:00
Stephen Diehl b61b69a8dd Merge branch 'master' into dataflow
Conflicts:
	zipline/finance/risk.py
	zipline/protocol_utils.py
2012-03-16 15:04:23 -04:00