Commit Graph

34 Commits

Author SHA1 Message Date
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 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
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
Thomas Wiecki 4ab82601a5 Resolved unittest import problems. 2013-01-16 11:54:04 -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
Eddie Hebert fc03e80cdf Removes done message.
Instead of checking for 'DONE' on each call uses generators
builtin StopIteration for signalling the end of input.
2013-01-07 12:06:31 -05:00
Eddie Hebert e7a31c0661 Removes sort module.
Sort module is now unneeded with use of heapq.merge

Also adapts test_perf_tracking so that it uses date_sorted_sources.
2013-01-07 12:06:10 -05:00
Eddie Hebert 75e60fdc91 Fixes number of bars to create covering date range in test.
There are only 6 trading days between the open and close specified
in test_perf test.

Also, removes getting the period_end off of the last trade,
since the test can now use the end date specified for the trading
environment.
2012-12-29 18:45:31 -05:00
Eddie Hebert ec745736ac Fixes period_start in test_perf test. 2012-12-28 13:48:47 -05:00
Eddie Hebert 50f4e1fff2 Fixes bug in test where period_end is too early.
Grabs period end before we remove trades.
2012-12-28 13:46:44 -05:00
Eddie Hebert 1c15e983dc Parameterizes test_tracker test with different days' events dropped.
So that the test ensures that perf messages are returned when
data is missing from the beginning, middle, and end of data.
2012-12-28 13:43:01 -05:00
Eddie Hebert 11fa56e5d9 Breaks up performance tracker tests.
The tests using performance tracker don't need the same setup
as the other performance module tests, breaking out so that
we don't call it needlessly.
2012-12-28 12:08:43 -05:00
Eddie Hebert f7e4f57425 Enables performance messages on days that have no trades.
Previously, on days that were trading days, but there with no
event data to process for that day, performance metrics were
not emitted, since the handling was based on having an event
trigger the daily performance metric.

Handled by grouping together performance messages, on market open,
for all days since the last market close.

Also, changes perf_tracker unit test to simulate missing data.

Taken from @richafrank's branch handling the same case.
2012-12-28 11:43:31 -05:00
Eddie Hebert b5867774e9 Reduces the the dataset size for performance tracker test.
So that the test is easier to debug and walk through on paper.

Also, removes randomly created dataset.
2012-12-27 18:39:22 -05:00
Eddie Hebert c436f85758 Removes random test invocation. 2012-12-27 18:39:22 -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 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 e7b504f4ca Removed list of trading days since we already have an OrderedDict 2012-12-12 15:23:26 -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 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 95ce2d90cf Removes unused constant and redirection of imports.
Removes TRANSFORM_TYPE from protocol, since it is unused.

Also, removes use of ndict as a member of protocol, since it's
import there was for the TRANSFORM_TYPE. Changed to
utils.protocol_utils instead.
2012-10-15 22:57:06 -04:00
fawce 16b0d71506 refactoring of algorithm to make it work for both batch style run method, and generator style consumption. removed the portfolio property from the data parameter. added set_slippage and set_commission methods to algorithm. removed timeout tracking. 2012-10-10 16:06:32 -04:00
Eddie Hebert bbf2317c57 Saving point for adding license files. 2012-10-08 17:32:40 -04:00
Eddie Hebert 0cd8931a5b Whitespace wrangling. According to PEP8 recommendations. 2012-10-03 13:20:26 -04:00
fawce aeb50da170 fixes for unit tests, back to 50/51 passing. 2012-08-07 14:42:43 -04:00
fawce 3d5e084b8d fixed logic bug in creation of sample date range. added assert. 2012-07-05 16:17:51 -04:00
fawce 069dbd1afe removed protocol cruft from transaction transform days. 2012-05-28 21:32:23 -04:00
Stephen Diehl 3ad1f250e6 Cleaned up OOP, first round. 2012-05-16 14:33:16 -04:00
Stephen Diehl e04415e63f Remove all namedicts. 2012-05-14 11:35:43 -04:00
Stephen Diehl 0d8eada763 More tests passing. 2012-05-10 17:10:09 -04:00
Stephen Diehl 62ec591d90 Moved the test folder. 2012-05-09 13:34:13 -04:00