Commit Graph

267 Commits

Author SHA1 Message Date
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 95ca73b15f MAINT: Remove unused members from risk test module. 2013-04-03 13:56:26 -04:00
Eddie Hebert a620afe639 STY: Add Test prefix to risk module test case. 2013-04-03 13:55:33 -04:00
Eddie Hebert dd172dd42a MAINT: Use trading day increment instead of timedelta in test factory.
In the test factory creation of returns, the date creation was using
a timedelta of one day instead of incrementing by trading days.

Working towards changing risk module behavior which would leverage
the trading day map, but tests fail because non-trading days are
created.

Remove `factory.create_returns`, moving uses of that function to us
`factory.create_returns_from_period`, since the number of days input
for `create_returns` was more difficult to use when specifying ranges
over arbirtray dates.
2013-04-01 23:52:50 -04:00
Eddie Hebert 147e806bb0 MAINT: Moves exchange to utc conversion inside of environment object.
So that the environments' exchange time is used without having to
specify it independently.

Also, moves uses of Delorean.shift for the exchange conversion inside
of environment to use the exchange_dt_to_utc method.
2013-03-28 12:29:52 -04:00
Eddie Hebert 7679e5a581 ENH: Wires minutely emission of data from performance tracker.
Wires up performance tracker so that when `emission_rate` is set
to `minute`, the performance packets are sent out every minute,
instead of once per day.

Please note, the performance packets that are generated are not
ready for prime time consumption, this patch is merely a step towards
hooking up the ability to inspect minute data.

Known issues:
- The packets do not currently include risk information.
  Since we need to consider how this affects the denominators
  of the risk calculations.
2013-03-27 16:58:56 -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
Eddie Hebert a05039c514 MAINT: Uses Transaction object in tests instead of ndict.
So that Transaction object behavior is exercised, uses the Transaction
object in performance module tests instead of ndict.

Also, adds fields to the __init__ of Transaction, to make the
definition of the object more well defined.
2013-03-25 23:51:34 -04:00
Eddie Hebert 47f3192728 MAINT: Updates copyright year of perf_tracking tests. 2013-03-25 23:50:23 -04:00
Tony Worm 086679c3d6 ENH: Adds new order types.
Adds the following order types:
- market
- limit
- stop
- stop limit
2013-03-19 14:32:11 -04:00
Eddie Hebert 632cbf2e62 MAINT: Updates copyright for recently changed files. 2013-03-18 18:04:34 -04:00
Eddie Hebert 77bc821025 MAINT: Defines members of the Order object.
Instead of a loosely defined object for Order, explicitly
defines the parameters and corresponding members.

Clearing the way for adding more members to the Order object.
2013-03-18 17:59:14 -04:00
Eddie Hebert e53622c930 MAINT: Changes unittest use of ndict to use specific objects.
Instead of using ndict, changing over to using the objects that
are created used when an algorithm is run.
2013-03-06 15:48:01 -05: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
Thomas Wiecki 46104fcd7c BUG: DataPanelSource was looping in the incorrect order. 2013-02-28 21:33:49 -05:00
Jonathan Kamens 368a31587f Fix flake8 problem 2013-02-21 11:13:18 -05:00
Jonathan Kamens 8120fd1bf7 Disable test_{,lse_}calendar_vs_environment until issue #93 is addressed
These two tests are nonessential and the test failures reflect bugs in
the tests, not bugs in the code.
2013-02-21 11:03:55 -05:00
Jonathan Kamens 0de67d8096 Fix flake8 error 2013-02-19 23:28:18 -05:00
fawce 866d45403b tradingcalendar was assuming eastern time when calculating its end date,
switched to use UTC and utcnow. Also factored the common code out of
the nyse and lse specific tests into a helper method.
2013-02-19 19:08:24 -05:00
fawce 791328c5ad changing the calendar test for lse to use the last available date
rather than the end date.
2013-02-19 00:14:08 -05:00
fawce 1a85781170 updated run method to use sim_params. 2013-02-18 10:24:32 -05:00
fawce d67e5d7a4b factory had a bug in the creation of trade history that traversed daylight savings time changes. added a fix and a test. 2013-02-18 10:24:32 -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
fawce 3ae02281da Fixed bugs in the sequence of dividend payment calculations. Previously, we were using midnight of the current trading day in market close. That meant that we were "rewinding" the clock, and then checking the ex_date and pay_date. As a result, we were delaying payments by one day.
With this patch, on the close of markets we "fast forward" to midnight of the
next trading day and calculate the dividend payments. This patch assumes that
the dividend dates are all at midnight UTC.
2013-02-15 22:52:38 -05:00
Thomas Wiecki 8c182ad66e ENH: load_bars_from_yahoo provides OHLC. Based on Brian Cappello's code. 2013-02-12 13:26:13 -05:00
Eddie Hebert aa1caae261 Fixes for trading calendar holidays for weekend holidays.
- Removes New Year's on Saturday, in that case there is no New Year's observed.
- Adds Monday after a July 4th Sunday
- Adds Friday before a July 4th Saturday
- Adds Monday after a Christmas Sunday
- Adds Friday before a Christmas Saturday
2013-02-10 17:23:29 -05:00
Eddie Hebert 3e050dff9c Changes rules for generating Thanksgiving holiday.
Thanksgiving is the 4th week of November, not the last Thursday
in November.

Some Novembers have 5 Thursdays, e.g. 2006
2013-02-09 23:42:31 -05:00
fawce 31b528e8dd Implemented dividend costs for short positions.
Based on user feedback in Quantopian forums:
https://www.quantopian.com/posts/total-return-slash-dividends
2013-02-06 23:34:14 -05:00
fawce 817ed88e38 Adds dividends to performance tracking.
Algorithm returns and the risk calculations that depend on them now include
cash dividends. This commit does _not_ provide an API for user algorithms to
access dividends.

PerformanceTracker expects the dividend data to arrive as events, similar to
the way that Trades arrive. Dividends are expected to have adjusted payment
amounts that are inline with adjusted trades.

PerformanceTracker maintains state of all the unpaid dividends in the position
objects held in PerformancePeriod. Dividend objects contain all the relevant
dates (declared, ex, payment) as well as net and gross amounts. Dividends are
removed from the list as they are paid. Cash flow is not incremented until the
payment day. This creates the possibility of a dividend being owed but not
paid or realized before the end of a test. For example, a dividend with an
ex_date of today may have a pay date 2 weeks in the future. Right now the
algorithm does not receive any credit for unpaid dividends.

Tests cover buying/selling around the ex_date and payment_date, and checking
that the performance calculated is as expected.
2013-02-06 16:39:39 -05:00
Eddie Hebert 983f3fab30 Fixes New Year's holidays inclusion in trading calendar.
If NYE lands on the weekend, the Monday following is a holiday.
2013-02-04 23:22:42 -05:00
Eddie Hebert be6572f1aa Change flag value on unit tests that use market_aware==False.
Changes these tests to use market_aware==True, so that unit tests
follow the same code path as actual execution.

All use of EventWindows against data follows market_aware behavior.

These tests are the only use of market_aware==False, so heading
down the path of removing market aware completely.
2013-02-01 21:05:49 -05:00
Eddie Hebert 2859afa032 Fixes assert type of window length check. 2013-01-31 21:16:41 -05:00
Eddie Hebert 3dd1b36d38 Changes unit tests asserts to UnitTest methods.
So that evaluated variables are printed on fail.
2013-01-31 20:10:47 -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
Eddie Hebert e43dfef65d Adjusts start date of test algo gen to account for market dates.
When date_gen changed to use market dates, the end of this env
was run over by the date_gen.
2013-01-31 13:20:11 -05:00
Eddie Hebert 81337d1306 Adds the ability to record variables.
Takes the value set for a variable on handle_data and records it,
e.g.:
```
    def initialize(self):
        self.incr = 0
        self.record_variables(['incr'])

    def handle_data(self, data):
        self.incr += 1
```

Would record a variable of `incr`.

Emits the recorded variables as part of the daily performance.

This batch combins work from:
Thomas Wiecki <thomas.wiecki@gmail.com> (@twiecki)
fawce <fawce@quantopian.com> (@fawce)
2013-01-31 08:16:54 -05:00
Eddie Hebert a6ce57ef4f Removes code branching on sequential/merged flags in StatefulTransform.
So that the unit tests exercise the same transform logic as what
is executed a TradingAlgorithm object.
2013-01-30 16:23:40 -05:00
Eddie Hebert 44140d2de7 Fixes dates used in test factory for batch transforms.
The test factory was creating non-market days.
i.e. the date range spanned the weekend.

Using pandas' BDay frequency so that only business days are created.

This specific date range doesn't have holidays, so not accounting
for holidays in the factory.

Also, widens the range of the trading calendar to cover the test dates
generated by the factory which include 1990.
Previously the trading calendar began with 2002, meaning that holiday
and weekend adjustments with the data exercised by the factory did
not trigger when run with data in 1990.

This does increase the memory footprint of the tradingcalendar module.
However, only by a couple MB, so taking the hit there to enable
correct behavior.
2013-01-30 14:06:56 -05:00
Eddie Hebert d52a9f3a67 Corrects wording on event_window test, with regards to empty values.
These tests ensure that there are three, not two, empty values
at the beginning of the transform.

Also, ensures that we are using a window length of 3 on the tests.
So that wordings of errors,etc. match the window length.
2013-01-30 14:00:06 -05:00
Ryan Day 64ffa055c9 Add the Sortino ratio for downside risk 2013-01-28 08:55:14 -05:00
Eddie Hebert 39f44a44f8 Reverting changes MovingStandardDevWindow.
Though the addition of tracking mulitple values in the window
is powerful, the changes broke behavior of existing algorithms
by changing method signatures and names.

So temporarily reverting these changes, to be pulled back in when
a way to have the multiple fields tracked with the existing API
is written, or a cutover of the API is figured out and determined.
2013-01-21 00:12:33 -05:00
Thomas Wiecki 4ab82601a5 Resolved unittest import problems. 2013-01-16 11:54:04 -05:00
Thomas Wiecki 77e9147a8b Merge branch 'master' of github.com:quantopian/zipline into stddev_multifield 2013-01-16 11:42:11 -05:00
Elektra58 d0640d56c8 Refactored stdev transform to be applied to multiple fields, not just price
UnitTest for transforms refactored to account for changed stdev transform, introduced AssertAlmostEqual
2013-01-16 10:33:38 -05:00
Eddie Hebert c044648275 Rolls over existing PerformancePeriod.
Instead of doing the rollover by creating a new PerformancePeriod,
introduces a `rollover` method that resets the values that need
to be fresh in a new period, and moves the ending values to starting
values, and leaves positions intact.

This isn't a major runtime improvement in of itself, but it does
allow us to more easily keep track of position values from period
to period, which other improvements will use.
2013-01-16 10:30:38 -05:00
Thomas Wiecki 456639d02c ENH: New batch_transform feature: compute_only_full. 2013-01-16 10:30:37 -05:00
Thomas Wiecki 52b099f6db ENH: Added new kwarg to batch_transform: create_panel. 2013-01-16 10:30:37 -05:00
Thomas Wiecki b815a57430 ENH: batch_transform now supports field filtering. 2013-01-16 10:30:37 -05:00