Commit Graph

1438 Commits

Author SHA1 Message Date
Thomas Wiecki 46104fcd7c BUG: DataPanelSource was looping in the incorrect order. 2013-02-28 21:33:49 -05:00
Jonathan Kamens f38ed47773 DEV: List mccabe, pep8, pyflakes (used by flake8) in dev requirements 2013-02-26 11:11:23 -05:00
Jonathan Kamens cfd0fa507b MAINT: Upgrade dev requirements to flake8 2.0 2013-02-25 11:22:48 -05:00
Thomas Wiecki bea325f25a Merge pull request #95 from sender/delorean-fix
Add Delorean to dependency list in setup.py
2013-02-24 06:26:20 -08:00
Aidan 724fe60f20 adding delorean to dependency list 2013-02-24 18:10:19 +11:00
Eddie Hebert 4c761c6708 Prevents entire data panel being collapsed when a stock stops trading.
The call to `Panel.dropna` after the fillna was deleting all values,
if a stock stopped trading mid run and thus provided volume 0.

i.e. if any sid had 0 non-null values the entire panel of frames
would be truncated.

It's possible to avoid the collapse via by adding the `how='all'` flag
to `dropna`, however with the current tick based creation of the panel,
the `dropna` with `how='all'` should be functionally equivalent to
not dropping at all.

The dropna has been dropped in favor of leaving the drop to algorithm
code.
2013-02-21 11:32:20 -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
Jonathan Kamens 1a30bdf93a Upgrade msgpack-python to 0.3.0 2013-02-19 23:09:38 -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 bf25e695ce Merge pull request #92 from quantopian/noop_env_fix_1470
added a decorator for applying an environment to a function context.
2013-02-19 10:17:58 -08:00
fawce 5587c1bc64 added functools.wraps as per @richafrank 2013-02-19 13:15:57 -05:00
fawce 9cc043f130 added a decorator for applying an environment to a function context. 2013-02-19 12:52:17 -05:00
Eddie Hebert 97cbea2514 Fixes crashes when using numpy log on a batch transform data panel.
The recent change to the creation of the data panel ended up with
a panel with the dtype of 'object', which was causing numpy ufuncs
like `log` to crash out on an `AttributeError`.

This forces all frames in the panel to use a dtype of 'float',
we may want to look at seeting a dtype on a frame by frame basis,
e.g. 'volume' may more accurately be 'int'.
2013-02-19 11:20:04 -05:00
fawce e6b9a355c1 Merge pull request #91 from quantopian/calendar_fix
changing the calendar test for lse to use the last available date
(confirmed this branch builds on jenkins before merging)
2013-02-18 21:18:56 -08: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 4199b530b9 trying to fix broken jenkins build that seems to be due to the end time
of the trading calendar calculations and availability of data from yhoo.
2013-02-18 23:46:08 -05:00
fawce b8a885a2d6 Merge pull request #90 from quantopian/fake_environment
Fake environment
2013-02-18 20:37:37 -08:00
fawce 2db01b3935 created a new generator-backed trading environment for testing.
other details:
    - also fixed grammatical errors in loader's status messages.
    - converting the treasury curves to an ordered dict.
    - moved to using a lambda for clarity as per @ehebert
    - initializing calendar end dates to be midnight of current date in
    - US/Eastern. Yahoo data isn't available until midnight eastern.
2013-02-18 23:35:38 -05:00
Jonathan Kamens 8eb92830c9 Don't capitalize delorean in requirements.txt 2013-02-18 14:20:58 -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
Thomas Wiecki 8f37b794e5 Merge pull request #85 from twmeggs/master
A few clerical corrections to comments and notes within the code.
2013-02-16 11:44:07 -08:00
Tim d3f1e0ffa9 Small spelling change. 2013-02-16 17:43:38 +00:00
Tim b09ab5da99 Added closing parenthesis to comment note. 2013-02-16 17:39:18 +00:00
Tim 593aaa9880 Remove extra space in comment sentence. 2013-02-16 17:29:36 +00: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
Jonathan Kamens ccd3ab33e7 Upgrade numpy to 1.7.0 2013-02-14 11:48:05 -05:00
Thomas Wiecki 3c2e1d0726 Merge pull request #80 from quantopian/add_bars_yahoo
ENH: load_bars_from_yahoo provides OHLC. Based on Brian Cappello's code.
2013-02-13 13:23:42 -08: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
Richard Frank f914c53790 Added parameter type validation to record_variables 2013-02-11 18:07:05 -05:00
Richard Frank 59d76ce378 Don't let record_variables be used after initialize. 2013-02-11 14:44:46 -05:00
Eddie Hebert 2600bbe1de Backfills a batch transform panel with supplemental data.
For the case where the window isn't covered by the data streaming
through the simulator.

e.g. in a case where the stocks being iterated over change every
quarter, the supplemental data will fill in the 'gap' missing from
the transform since the 'new' stocks were not streaming before
the beginning of the quarter.

Of note, test cases are covered by internal suites, but this could
use tests with completely mocked data.
2013-02-10 21:35:41 -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
Eddie Hebert 699a47fe3d Converts batch transform panel to use pd.Panel dictionary arg.
Based on @twiecki's work in batch_to_pandas branch.
2013-02-08 00:01:41 -05:00
Eddie Hebert 79f7fe69ef Checks to make sure that an Event has a type before checking type.
The Dividend event is currently missing 'type', causing the type
check to fail.

TODO: Add a type to Dividends.
2013-02-07 18:17:26 -05:00
fawce 26ff73072c Emergency fix - filtering down to TRADE events in the transforms. 2013-02-07 18:01:21 -05:00
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