Commit Graph

1397 Commits

Author SHA1 Message Date
fawce 2b9368dedf Merge pull request #76 from quantopian/dividends_for_shorts
Implemented dividend costs for short positions.
2013-02-07 10:55:14 -08: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
fawce 372a714eb8 deleting the portfolio object from every event. 2013-02-06 16:35:24 -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
fawce 40d25c5519 Update README.md 2013-02-03 16:28:20 -05:00
Eddie Hebert 8c04621f57 Changes stddev and vwap transforms to accept parameters as kwargs.
So that algorithms that specifiy market_aware, days and delta
as args can be transitioned to just specifying a window_length kwarg.

Moving towards removing market_aware and delta completely.
2013-02-02 13:22:37 -05:00
Eddie Hebert 48c874f22a Deprecates market_aware and delta kwargs to EventWindow.
The eventual goal is to remove the market_aware and delta kwargs,
but removing the kwarg completely would break the init
method of EventWindow based classes for existing algorithms.

In the meantime, this ensures that only market_aware is only ever
set to True and raises an error if it is False.

Also raises exceptions if values are set for delta, which was only
used if market_aware was False

Also, since the logic for checking window length is changed,
because in market aware mode we should always be checking the
window length, this adds some sanity checking to the window length.
2013-02-01 21:05:49 -05:00
Eddie Hebert 1bc19c052b Removes unused test transform. 2013-02-01 21:05:49 -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 18c7905ab9 Merge pull request #69 from mjhanninen/fix-example
Fixes an incorrect order in examples.
2013-02-01 09:50:47 -08:00
Eddie Hebert 3225c03c75 Merge pull request #70 from bernarpa/patch-1
Update zipline/transforms/stddev.py
2013-02-01 09:47:53 -08:00
Paolo Bernardi a11a57cec8 Update zipline/transforms/stddev.py
Fixed typo.
2013-02-01 17:47:31 +01:00
Eddie Hebert 68327f5a10 Removes documentation references to pavement.
The references to pavement were causing confusion on what libraries
are needed for installation.
2013-02-01 11:33:32 -05:00
Matti Hanninen 4026e6122f Fixes an incorrect order in examples. 2013-02-01 18:17:23 +02:00
Eddie Hebert 079d7b322e Updates README to distinguish between backtesting and trading. 2013-02-01 10:17:02 -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 69b87b859b Fixes trading day generation logic in test source.
This uses more of @fawce's original logic from record_var branch.

TODO: Add unit test to ensure that this function generates only
market days.
2013-01-31 13:06:15 -05:00
Eddie Hebert c298cfda03 Adds recorded variable to dual moving average example.
Attr: Thomas Wiecki <thomas.wiecki@gmail.com> (@twiecki)
2013-01-31 08:19:07 -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 dfd9f2105d Changes test_source date_gen to only emit trading days.
Based on @fawce's work on record_vars branch.
2013-01-31 07:13:53 -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 7443b0c602 Pulls alias_dt wrapper out of sequential_transforms.
So that stepping through/cProfile output are a little clearer.
2013-01-30 16:20:58 -05:00
Eddie Hebert 946ecfafc0 Adds a trading day index to tradingcalander.
The trading day index is all business days in range minus the
non trading days we are already calculating.

Also, uses trading calendar indexes for batch transform, since the
batch transform was the only use of non_trading_days.

Instead of constantly adding and removing holidays to do market
day delta math, uses pandas DatetimeIndex to get the index of the dates
and uses the index difference to calculate market days.
2013-01-30 14:36:37 -05:00
Eddie Hebert 47c8015489 Moves creation of non_trading_days into a function.
So that we're not leaving rules used for configuration hanging in
module space.
2013-01-30 14:33:44 -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 2587cd6512 Enriches message returned for test batch transform.
Adds formatting of the failing values when ReturnPriceBatchTransform's
data shape does not match the window_length.
2013-01-30 14:04:17 -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
Eddie Hebert 5b294faf0c Removes unused method. 2013-01-28 23:22:04 -05:00
Eddie Hebert c65522c787 Merge pull request #66 from rday/sortino_ratio
Add the Sortino ratio for downside risk
2013-01-28 11:14:59 -08: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
Eddie Hebert 88070a0f12 Fixes dictionary-style lookup on Position and Portfolio.
Typo on method name, /__getattr__/__getitem__
2013-01-27 22:49:20 -05:00
Eddie Hebert 2352c1e576 Adds dictionary style access to Portfolio object. 2013-01-27 21:21:01 -05:00
Eddie Hebert 480ca65f56 Adds dictionary style access to Position object. 2013-01-27 21:19:59 -05:00
Eddie Hebert b3e8d56c02 Removes unused parameters in test trade info creation.
This code hasn't used `random` in a while, removing the parameter
left as an artifact.
2013-01-26 09:44:43 -05:00
Jonathan Kamens 629b6d6bd8 Upgrade to Pandas 0.10.1 2013-01-24 20:24:44 -05:00
Eddie Hebert a49bd4af4b Adds a contains method to SIDData to support in statement. 2013-01-23 17:17:35 -05:00
Eddie Hebert 87f99331e8 Uses an object for sid data to be passed to handle data.
Moving another datatype off of ndict, to make it easier to inspect
objects in memory when debugging.
2013-01-23 13:41:57 -05:00
Eddie Hebert 4723e836e7 Changes use of ndict in transforms to be name object.
So that when inspecting memory, it's easier to find each datatype.
2013-01-23 09:30:26 -05:00
Eddie Hebert 6f6434cf51 Converts slippage orders to use a simple object.
Reducing the number of ndicts that are created, so that profiling
has less noise.
2013-01-23 09:21:59 -05:00
Eddie Hebert d5a0446f7b Moves slippage transactions off of ndict.
So that the datatype is unique.
2013-01-22 20:55:24 -05:00
Eddie Hebert 649fb10c8e Creates a new averages container for each call to get_averages.
Ideally, we'd want to avoid multiple object creation,
but currently not playing well with generator chain.
2013-01-22 20:40:37 -05:00
Eddie Hebert 9313077152 Creates a container object for averages in mavg window.
Moving another data type off of ndict on the path to making
it easier to discern between types when
2013-01-22 20:21:15 -05:00
Jonathan Kamens e2f091c96e Upgrade nose-parameterized to 0.2 2013-01-21 09:37:37 -05:00
Eddie Hebert f017218b64 Uses class constants for message text instead of ndict.
Reducing use of ndict on the path to fixing a memory leak.

So that pulling an instance of ndict with objgraph is more likely
to be a use of ndict that is causing the leak.

Using a class level constant here suffices for the dot access
desired on messages.
2013-01-21 08:54:19 -05:00
Eddie Hebert b6779a85c7 Removes Jenkins configurations.
Public repo uses Travis-CI.
2013-01-21 01:01:27 -05:00