Commit Graph

12 Commits

Author SHA1 Message Date
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 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
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 d87213a5f1 MAINT: Adds floating point tolerance to risk metric comparison tests.
In preparation of changing how risk metrics are calculated,
this makes the checking of results more tolerant to floating point
rounding, since upcoming changes change the results by a neglible margin.
2013-03-27 13:42:16 -04:00
Eddie Hebert 94e70a394b MAINT: Restricts dates to trading calendar in risk comparison test.
Converts the risk iterative and batch comparison tests to use
the trading environments next date, instead of just advancing by day,
so that the returns being passed into the RiskMetrics in the unit
test are using the same trading calendar as the internal checks for
trading days.

Fixes a case where empty return periods were being into
`calculate_period_returns`

Clearing the way for the pandas based optimization of the risk module.
2013-03-27 11:42:40 -04:00
Richard Frank ebdb5429aa MAINT: Moved DailyReturn to protocol module to break circular references
and removed code that solved that same problem with conditional imports.
2013-03-01 16:05:39 -05:00
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
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
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 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
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