Commit Graph

102 Commits

Author SHA1 Message Date
Eddie Hebert 419c03dedb BUG: Smooth test and compile issues with TALib
So that TALib is still available, but smooth out the ability to
run tests with some issues that bear investigating.

- Ignore MAVP during tests.
- Temporarily use a "regular" member instead of  __doc__ string.
  (TODO: look into using `type` to generate the class)
- During tests wait until a window exists.
2013-04-30 20:19:37 -04:00
Jeremiah Lowin cc39ec3aef ENH: Add support for TALib based transforms.
Provide a subclass of BatchTransforms that are powerd by the ta-lib
library.
2013-04-30 17:35:56 -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 b3efb5eb69 MAINT: Remove ndict class.
Now that ndict is no longer used in any part of the system during
a backtest, remove all remaining references in tests, etc.
2013-04-26 16:03:01 -04:00
Eddie Hebert bf1fc42acc BUG: Fix time spent checking equality of floating point numbers.
The use of np.allclose introduced a severe performance penalty,
caused by the creation of two `np.array`s for each check.

Instead create and use a similar check which maintains tolerance
to floating point rounding, but operates only on scalars.
2013-04-16 13:09:26 -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 58af62f18d REL: Update copyright on all files touched since end of 2012.
s/Copyright 2012/Copyright 2013/
2013-04-05 14:28:15 -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
Eddie Hebert 351d5e8686 MAINT: Updates copyright to current year for returns module. 2013-03-19 17:14:01 -04:00
Eddie Hebert d17fb1c266 STY: Removes unused import. 2013-03-19 17:13: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 890762bde7 MAINT: added typed errors module
- added exceptions in place of asserts for expected fields for rolling
transforms.
- removed assertions with Messages in favor of typed exceptions.
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 414e12ecc9 BUG: Fixes error due to floating point rounding in stddev calc.
Adds a check to see if the s_squared value is near 0.

When the number was very near 0, a very small negative floating
point, the sqrt throws a 'math domain error', this prevents that
case.
2013-02-28 22:20:45 -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
Tim 593aaa9880 Remove extra space in comment sentence. 2013-02-16 17:29:36 +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 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
Paolo Bernardi a11a57cec8 Update zipline/transforms/stddev.py
Fixed typo.
2013-02-01 17:47:31 +01: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
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
Eddie Hebert 39f44a44f8 Reverting changes MovingStandardDevWindow.
Though the addition of tracking mulitple values in the window
is powerful, the changes broke behavior of existing algorithms
by changing method signatures and names.

So temporarily reverting these changes, to be pulled back in when
a way to have the multiple fields tracked with the existing API
is written, or a cutover of the API is figured out and determined.
2013-01-21 00:12:33 -05:00
Eddie Hebert 9e31d83084 Fixes check of ticks in stddev, now that __len__ has been removed. 2013-01-17 18:11:27 -05:00
Eddie Hebert dbcfc0a2a5 Restores previous get_stddev method and uses the price value.
To maintain compatibility with existing algorithms.
2013-01-17 17:44:21 -05:00
Thomas Wiecki 685b2ed6fd REF: Fields is kwarg is MovingStandardDevWindow. 2013-01-17 12:10:09 -05:00
Thomas Wiecki eb1cb27a07 REF: fields now defaults to price for mavg and stddev transform. Also allows string specification. 2013-01-17 11:46:17 -05:00