Commit Graph

76 Commits

Author SHA1 Message Date
Eddie Hebert 8481e2df49 MAINT: Use Python 3 compatible metaclass.
Use six's with_metaclass to have objects that use metaclasses, in
both Python 2 and 3.

Otherwise, in Python 3 the objects were being treated as if they
did not have a metaclass, when the Python 2 syntax is used, leading
to errors because of missing attributes, etc.
2014-01-07 11:58:01 -05:00
Eddie Hebert 045e2975b7 MAINT: Remove type checking which trip up Python 3 compatibility.
Instead of porting these cases of type checking, remove them instead.
Slightly more Python-ic to be more generous in what is allowed, and
the conversion to make these compatible with Python 3 are more trouble
than they are worth.
2014-01-07 11:44:25 -05:00
Jonathan Kamens 73faf9133e MAINT: Clean up imports of zipline.finance.trading
Use "from zipline.finance import trading" instead of "import
zipline.finance.trading as trading".
2013-10-29 13:50:14 -04:00
Eddie Hebert 90d8570f70 MAINT: Remove debug logging about stateful transforms.
The noise outweighed the signal with logging before and after each
time the transform generator is called.
2013-09-27 15:55:35 -04:00
Eddie Hebert 376ae33264 PERF: Remove deepcopy from EventWindow ticks.
The deepcopy of events into the EventWindow's ticks was causing
a significant increase in memory consumption, e.g. an algorithm with
almost 200 sids and 14 vwaps removing the deepcopy reduces the amount
of memory consumed by about 40%.

The downside is that if an event's properties are changed, which is
not advised, later on, then the signal derived from vwap etc.
may be changed.
2013-07-31 18:55:07 -04:00
Eddie Hebert fa845cbf03 MAINT: Move batch transform into a dedicated module.
Break the BatchTransform class and decorator function into a
separate module, with hope that it makes it easier to zero in on
batch transform logic.
2013-07-10 17:56:32 -04:00
Thomas Wiecki 33c23af503 BUG: Do not try to set non-existent items. 2013-06-20 18:32:05 -04:00
Thomas Wiecki 3ea8ac8da2 BUG: Fix updating of trading_days_total in minute.
In the batch_transform we were incrementing the trading_days counter if there
is a new day event. Thus with a window_length of 1 and daily bars you will
update the batch_transform on the first day which is correct. But with minutes
you update with the first minute bar of the day which is not correct.

This is fixed by calculating the market_close explicity and seeing whether the
event.dt is on or past it.

I also added a unittest to test the correct behavior of this.
2013-05-16 14:51:19 -04:00
Eddie Hebert 54541eb24c BUG: Fix short circuit in StateTransform loop.
A missing `continue` statement was causing the short circuit on
event type to not have the intended effect of skipping the update
portion of the loop.
2013-05-15 16:57:09 -04:00
Thomas Wiecki b87d454938 BUG: Add bar kwarg to batch_transform.
Before the change to the RollingPanel, window_length
specified the number of days that should be in a window.

The previous commit broke this if data was minute resolution.

By passing bar='minute' to the batch_transform we internally
multiply the window_length by 60*6.5 to have a full day.

Also adds a (still rudamentary) test for batch_transform
with minute data.
2013-05-13 16:42:58 -04:00
Eddie Hebert 5c883659b5 BUG: Fix missing values from supplemental data in batch transform.
Adapt the supplemental data fill so that it works with the new
shape of the batch transform that was switched to with the rolling
panel optimizations.
2013-05-07 18:17:08 -04:00
Eddie Hebert d3ade5050c MAINT: Tune logging of StateTransform start/end to debug.
These log lines are useful for debugging, but a bit spurious
on every algorithm run.
2013-05-07 17:27:06 -04:00
fawce 59dcf0f6cd exposes stateful transform's window length 2013-05-01 22:05:06 -04:00
Eddie Hebert 06a01b1469 BUG: Explicitly add support for refresh period of 0.
In the previous implementation of batch transform it happened
that a window_length of `0` caused the transform to update on every
bar, for the time being that behavior should be retained,
though the new rolling implementation more correctly aligns to the
term of 'period' so a period of 1 would achieve the same effect.
2013-04-29 15:30:42 -04:00
Eddie Hebert 38ae8bbb67 BUG: Ensure that window length value is sanity checked.
When moving BatchTransform off of EventWindow as a base object,
the checking of window length was lost, restore that check using
the same function as EventWindow.
2013-04-29 15:30:42 -04:00
Thomas Wiecki c12102d7b1 MAINT: Removed self.sids from batchtransform. Externally sets static_sids. 2013-04-29 15:30:42 -04:00
Thomas Wiecki 2be7014d51 ENH: Rewrite of batch_transform to use rolling panel.
- Added unittest to test for newly appearing sids.
- Fixed logic bug where window was only full after
  window_length+1 events got passed.
2013-04-29 15:30:40 -04:00
Eddie Hebert 2522a6fc4c MAINT: Remove unused Passthrough transform.
Passthrough transform had been removed previously, removing remaining
references to the class.
2013-04-29 14:58:29 -04:00
Eddie Hebert 9ffaec64d8 MAINT: Factor out check for window length value sanity.
Preparing for BatchTransform not using EventWindow, so
factoring out the checks for window length into a
function that can be shared.
2013-04-29 14:56:04 -04:00
Eddie Hebert 38bd4214a2 MAINT: Remove unused TransformMessage class. 2013-04-29 14:55:38 -04:00
Eddie Hebert 9099d301f3 ENH: Stream benchmark returns as events.
Instead of creating a list of benchmarks in the risk module,
stream benchmarks through the system as events, starting from the
algorithm generator.

Works towards more easily setting arbritrary pricing data as
a a benchmark, as well as working towards live minutely benchmarks.
2013-04-15 11:43:13 -04:00
Eddie Hebert dd76386e56 REL: Updates copyright on transforms.utils module. 2013-04-05 12:03:50 -04:00
Jason Kölker 16660cf414 BUG: Preseve docstring in batch functions
The batch_transform decorator wipes out the doc string of the function
it wraps. Decorate the creator with functools.wraps to preserve function
metadata.
2013-04-05 11:55:10 -04:00
fawce 93e22aa8b7 added more acceptable number types for event fields in batch
transforms.
2013-03-20 02:21:44 -04:00
fawce dba86153d2 ENH: added a CUSTOM datasource type for custom data.
- perf modified to let non-performance related events flow through.
- changes to support streaming non-trading data through batch transforms
and for mixing in sids with just custom data.
- allowing CUSTOM events to flow through to transforms.
- Added logic to maintain pre-specified sid filter.
2013-03-19 11:39:23 -04:00
fawce a12eeb2383 incorporating feedback from @richafrank 2013-03-06 16:49:31 -05:00
fawce b8144cea2a added tests to ensure:
- repeated calls with the same data window do not update batch transform
    windows.
    - repeated calls with the same data and same supplemental parameters do
    not update batch transform results
    - repeated calls with the same data and different supplemental params
    do update batch transform results
2013-03-05 22:59:31 -05:00
fawce 530f1cce55 added checks for change in optional parameters to trigger transform
recalculation.
2013-03-04 22:33:30 -05:00
fawce a47143099c refining the batch transform interface:
- removed use_panel
  - default for refresh_period is now 0
  - refresh_period will only affect the recreation of the datapanel
  - user's transform method is invoked on every call to batch transform
2013-03-04 21:08:15 -05:00
fawce 6329f477b8 removed data_panel option from BatchTransform.
- the underlying dequeue shouldn't be modified, so forwarding to the
user function is a bit misleading
- if we want to provide a dequeue we should consider another class
or an EventWindow decorator.
2013-03-04 06:26:41 -05: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
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 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
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
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 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
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 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 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 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
Thomas Wiecki 0ecdac83f4 DOC: Typo. 2013-01-16 10:30:38 -05:00
Thomas Wiecki abf482c2a6 MIN: Changed isinstance check to allow more types. 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 a63d4bca28 ENH: sid and field filter kwargs can also be strings or ints. 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