Commit Graph

63 Commits

Author SHA1 Message Date
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
Thomas Wiecki b68c51afb4 ENH: batch_transform now supports sid-filtering. DOC: Added docs to batch_transform. 2013-01-16 10:30:37 -05:00
Eddie Hebert f54881cd08 Changes tests from using an ndict for trades to an Event object.
When run over large amounts of data the use of ndict's gets and sets
become a large bottleneck, around 1/5th of the CPU time is spent
in ndict's __setattr__, __getattr__, etc.

By switching to an object for an event,
we reduce the penalty significantly.

Removes asserts that check for event being an ndict, as well as those
that assume a certain behavior of the __contains__ method for events.
2012-12-21 14:31:40 -05:00
Thomas Wiecki f8e4d8ade6 Revert "BUG: EventWindow now always contains constant number of days."
This reverts commit 7a0a6f5231.
2012-12-11 12:12:51 -05:00
Thomas Wiecki 8621eb2223 Revert "STY: Removed drop_condition arguments."
This reverts commit c7383f6275.
2012-12-11 12:12:32 -05:00
Eddie Hebert 67b8f63972 Limit the fields of batch transform datapanel to ints and floats.
Previously, keys that mapped to functions would be set as field names.
Attempting to assign the datapanel slot to a function causes an error.

This limits the extracted field names to those that map to an int
or a float.
2012-12-07 14:35:55 -05:00
Thomas Wiecki 79a8a08812 STY: Renamed fillna to clean_nans. 2012-12-06 17:23:26 -05:00
Thomas Wiecki c46e09f52a BUG: Do not backfill but drop rows with N/A in them. 2012-12-06 15:52:50 -05:00
Thomas Wiecki c7383f6275 STY: Removed drop_condition arguments. 2012-12-06 15:24:01 -05:00
Thomas Wiecki ba46c6292f ENH: DataPanel is now created more flexible over all sids and all given fields. Added unittest to test for nan-filling. Added backwards filling by default. 2012-12-06 14:43:20 -05:00
Thomas Wiecki 5f6839beea BUG: Refactored batch_transform unittests and fixed some bugs. 2012-12-06 12:36:47 -05:00
Thomas Wiecki c69858f8b9 ENH: Added kwarg to turn off fillna or use different fill method. 2012-12-06 12:35:46 -05:00
Thomas Wiecki 7a0a6f5231 BUG: EventWindow now always contains constant number of days. 2012-12-06 12:33:18 -05:00
Thomas Wiecki ac8ae973bc ENH: replaced union with intersection in assert (more stringent). 2012-12-04 10:17:53 -05:00