Commit Graph
69 Commits
Author SHA1 Message Date
Stewart Douglasandjfkirk e529df06ea ENH: Add autoload=True for compatibility with SQLAlchemy < 1.0.0 2015-09-10 11:53:25 -04:00
Stewart Douglasandjfkirk ded6f8543f BUG: Cast datetime to Timestamp to call value 2015-09-10 11:53:25 -04:00
Stewart Douglasandjfkirk c8b88432cc BUG: Account for sid == 0 in if statement 2015-09-10 11:53:25 -04:00
Stewart Douglasandjfkirk 4300ab357a BUG: Convert sqlalchemy RowProxy to dict for assignment 2015-09-10 11:53:25 -04:00
Stewart Douglasandjfkirk 46346ecb5d BUG: Ensure symbols are made upper case in db 2015-09-10 11:53:25 -04:00
Stewart Douglasandjfkirk 678aec2cae MAINT: Convert dates to INTs for SQLite and set default end_date 2015-09-10 11:53:25 -04:00
Stewart Douglasandjfkirk 32b663c5ca MAINT: Enforce uniqueness of sid column 2015-09-10 11:53:25 -04:00
Stewart Douglasandjfkirk 9660447ed0 MAINT: Ensure correct pandas.DataFrame is returned 2015-09-10 11:53:24 -04:00
Stewart Douglasandjfkirk d55920a43b ENH: Return namedtuple from load methods 2015-09-10 11:53:24 -04:00
Stewart Douglasandjfkirk b658f579d2 ENH: Consolidate logic into load_data method 2015-09-10 11:53:24 -04:00
Stewart Douglasandjfkirk 59f5a9683b DEP: Remove legacy writer classes 2015-09-10 11:53:24 -04:00
Stewart Douglasandjfkirk 47ed3a2fdb ENH: Update AssetDBWriterFromList to consume identifiers
Allow consumption of a list of identifiers, including assigning
sids if necessary.
2015-09-10 11:53:24 -04:00
Stewart Douglasandjfkirk 8fc97b99b2 MAINT: Default constraints=True in AssetDBWriter 2015-09-10 11:53:24 -04:00
Stewart Douglasandjfkirk 38f3e6c713 ENH: Add UNIQUE and NOT NULL constraints 2015-09-10 11:53:24 -04:00
llllllllllandjfkirk ee4aa7327b MAINT: more bugfixes 2015-09-10 11:53:23 -04:00
llllllllllandjfkirk 874abee1d8 BUG: itemgetter is in operator 2015-09-10 11:53:23 -04:00
Stewart Douglasandjfkirk fc8ea9b39b MAINT: Remove NOT NULL constraint when constraints=False 2015-09-10 11:53:23 -04:00
llllllllllandjfkirk dd956116b7 ENH: sqlalchemy 2015-09-10 11:53:23 -04:00
Stewart Douglasandjfkirk 17c6ecbfff STY: Formating changes 2015-09-10 11:53:23 -04:00
Stewart Douglasandjfkirk 06894c301e DEP: Stop exporting deprecated methods 2015-09-10 11:53:23 -04:00
Stewart Douglasandjfkirk 4b763f4138 ENH: Update load_data method 2015-09-10 11:53:23 -04:00
Stewart Douglasandjfkirk 97e980751f MAINT: Integrate asset writer changes into TradingEnvironment 2015-09-10 11:53:23 -04:00
Stewart Douglasandjfkirk f12c9aa0b7 ENH: Create AssetDBWriterFromDataFrame class 2015-09-10 11:53:22 -04:00
Stewart Douglasandjfkirk ad28d5ee0a ENH: Remove all writing functionality from AssetFinder 2015-09-10 11:53:22 -04:00
Stewart Douglasandjfkirk 696d8f2846 MAINT: Insert data into asset_router 2015-09-10 11:53:22 -04:00
Stewart Douglasandjfkirk 449400426d ENH: Enable fuzzy matching for equities 2015-09-10 11:53:22 -04:00
Stewart Douglasandjfkirk c8cb2d92dd MAINT: Use raw SQL driver rather than pandas to_sql method
Allows us to create an SQL transaction to avoid errors
from race conditions.
2015-09-10 11:53:22 -04:00
Stewart Douglasandjfkirk 746f70a133 ENH: Create AssetDBWriter class
The AssetDBWriter class and its subclasses will
ultimately be responsible for creating the SQLite
database tables and writing data to these tables.

In the longer term AssetDBWriter and AssetFinder will
be decoupled, sharing only an SQLite connection.
However, for backward compatibility reasons this has
not yet been fully implemented.

Modify tests since AssetFinder no longer has a
metadata_cache attribute.
2015-09-10 11:53:22 -04:00
Stewart Douglas 1e31866471 MAINT: FutureChain should only accept Timestamp 2015-09-08 11:01:04 -04:00
Warren O'NeillandStewart Douglas de09433fd4 MAINT: allows contract_multiplier to be non-integer 2015-09-01 11:54:09 -04:00
dmichalowicz 14ab02bfaa Remove comment 2015-08-28 15:16:04 -04:00
dmichalowicz b7cf84e4ec Add SidNotFound exception case 2015-08-28 13:27:22 -04:00
Scott Sanderson 780263da06 ENH: Return asset-indexed DataFrame for data.factors.
This makes ordering with the returned assets much easier, and there's no
performance degradation for non-broadcasting operations on the Index.

Timings
-------

    from random import sample
    finder = AssetFinder(create_table=False, assets.db')
    assets = load_8000_assets(finder)
    AAPL = finder.retrieve_asset(24)
    RANDOM_ASSETS = sample(assets, 500)
    df = DataFrame(
        index=assets,
        data=np.random.randn(len(assets), 4),
        columns=['a', 'b', 'c', 'd'],
    )
    df_int = DataFrame(
        index=map(int, assets),
        data=np.random.randn(len(assets), 4),
        columns=['a', 'b', 'c', 'd'],
    )

    %timeit df.loc[24]
    %timeit df_int.loc[24]

    10000 loops, best of 3: 45.3 µs per loop
    10000 loops, best of 3: 44.7 µs per loop

    %timeit df.loc[AAPL]
    %timeit df_int.loc[AAPL]

    10000 loops, best of 3: 45.1 µs per loop
    10000 loops, best of 3: 44.8 µs per loop

    %timeit df.loc[RANDOM_ASSETS]
    %timeit df_int.loc[RANDOM_ASSETS]

    1000 loops, best of 3: 1.53 ms per loop
    100 loops, best of 3: 2.18 ms per loop

    %timeit df.sum()
    %timeit df_int.sum()

    10000 loops, best of 3: 56 µs per loop
    10000 loops, best of 3: 55.7 µs per loop

    %timeit df.index == 3
    %timeit df_int.index == 3

    1000 loops, best of 3: 253 µs per loop
    100000 loops, best of 3: 6.76 µs per loop

    %timeit df.iloc[:50]
    %timeit df_int.iloc[:50]

    10000 loops, best of 3: 44.3 µs per loop
    10000 loops, best of 3: 44 µs per loop
2015-08-26 18:33:54 -04:00
Andrew Daniels 48c609debc BUG: Improves lookup_future_chain to handle NaT date args
If lookup_future_chain was provided with an as_of_date or knowledge date that was pandas.NaT, the query we were forming wasn't what we want. Instead, as_of_date, if not NaT, is used for knowledge_date, and if both are NaT, no date filtering is done in the query.
2015-08-05 10:50:14 -04:00
Scott Sanderson ef4f642e62 ENH: Compute engine architecture for FFC API.
This patch lays the groundwork for a compute engine designed to
facilitate construction of factor-based universe screening and portfolio
allocation.  It contains:

A new module, `zipline.modelling`, containing entities that can be used
to express computations as dependency graphs.  Each node in such a graph
is an instance of the base `Term` class, defined in
`zipline.modelling.term`.  Dependency graphs are executed by instances
of `FFCEngine`, defined in `zipline.modelling.engine`.

A new module, `zipline.data.ffc`, containing loaders and dataset
definitions for inputs to the modelling API.

New `TradingAlgorithm` api methods: `add_factor`, and `add_filter`.
These methods can only be called from `initialize`, and are used to
inform the algorithm that each day it should compute the given terms.
Computed factor results are made available through a new attribute of
the `data` object in `before_trading_start` and `handle_data`.  Computed
filter results control which assets are available in the factor matrix
on each day.
2015-07-29 12:30:46 -04:00
Scott Sanderson 20c5fc356f MAINT: Remove unused assets property.
It references a self.cache attribute that no longer exists.
2015-07-21 17:43:43 -04:00
Eddie Hebert f22e9e5122 Revert "PERF: Reuse one cursor in asset finder lookups."
This reverts commit 136a09776d.
2015-07-16 15:36:48 -04:00
Eddie Hebert 136a09776d PERF: Reuse one cursor in asset finder lookups.
Instead of creating a new cursor with each query, use the same cursor
throughout the lifetime of the finder instance to remove any overhead
from creating a new cursor in tight loops.
2015-07-16 15:16:36 -04:00
Eddie Hebert 376dc7b703 BUG: Fix exception on no symbol with fuzzy enabled
If there is no symbol there should be no fuzzy lookup either.
2015-07-15 15:52:33 -04:00
Eddie Hebert 64bbb83ee8 BUG: Force string for asset data values.
Internal tests depend on string vs. unicode for various asset data, so
enforce strings by setting the text_factory on the sqlite connection.
2015-07-15 09:24:42 -04:00
Eddie Hebert 3f57b742d3 BUG: Provide asset data for multiple symbol error.
Fix a change in the information given to the multiple symbol error
during the recent sqlite change to the asset finder.

Instead of the string of sids, return full asset information about the
available options, since internal code relied on the full data.
2015-07-15 09:00:03 -04:00
Eddie Hebert 85b6260d80 BUG: Make sure metadata_cache is created.
Fix issue where metadata_cache was missing causing an AttributeError.
2015-07-14 22:49:00 -04:00
jfkirk a7f967fb20 BUG: Replaces is-check against string
Replaces an " is 'None' " check with " != None "
2015-07-14 15:18:55 -04:00
Eddie HebertandEddie Hebert 36319122cc PERF: Change asset finder to be backed by sqlite3.
Attack the startup bottleneck of creating the asset finders caches for a
large universe, which was between 1-2 seconds on development and
production machines.

Instead, allow the AssetFinder to be passed a sqlite3 file that has
already been populated and then hydrate asset objects only when an
equity is referenced for the first time.

To create aforementioned sqlite3, create an AssetFinder with an db_path
and `create_table` set to True. If `create_table` is set to False, the
prepopulated data in the sqlite file found at db_path will be used.

Default behavior is to use an in memory database.

Behavior that changes:

- Fuzzy lookup now only works on one character, that character needs to be
specified at write/metadata consumption time, since the fuzzy lookup key
is created by dropping the character from each symbol.

- Overwriting partially written metadata is no longer
  supported. i.e. some unit tests allowed for inserting just the identifier,
  and then later updating the symbol, end_date, etc.

  Instead of building an upsert behavior at this time, this patch
  changes the unit tests so that the data for each asset is only
  inserted once.

Other notes:

- populate_cache is now removed, since there is no longer a two step
  process of inserting metadata and then realizing that metadata into
  assets. _spawn_asset is rolled into insert_metadata, so that a call to
  insert_metadata both converts the metadata and makes it available in
  the data store.
2015-07-14 09:54:38 -04:00
Eddie Hebert 3847fa70e0 MAINT: Remove shadowing of built-in type function.
Change variable name in convertible registration so that `type` is not
over-written at module scope.
2015-07-13 16:38:50 -04:00
Andrew Daniels 2ab9f8a63c ENH: Futures API 2015-07-13 09:50:36 -04:00
Andrew Daniels 7cde3939bf BUG: Determine valid future contracts with notice date
Since most brokers will cease accepting trades by the notice date, contracts should not be considered valid after the notice date. This commit adjusts the lookup_future_chain method to consider all contracts with notice dates on or following the current date invalid.
2015-07-09 15:23:29 -04:00
Eddie Hebert bfcb91b359 MAINT: Move possible side assignment to insert metadata method.
The previous workflow was:

- insert basic metadata for all assets

- iterate over all metadata entries. Create a sid if one does not
exist

- call insert_metadata again to update the assigned sid value.

Instead, create a sid, if missing on the initial metadata assignment and
remove the second pass of calling insert_metadata.

Also, since the sid assignment code is only done in this one context,
inline the sid assignment code so that there is less code step through
while looking for where sid assignment is done.
2015-07-08 15:25:18 -04:00
jfkirk 1032972b74 ENH: Adds the full Asset objects to the kwargs of MultipleSymbolsFound 2015-07-08 13:33:04 -04:00
Andrew Daniels 977c6cfcde MAINT: Consolidates and improves future lookup methods
Removes unused future lookup methods and consolidates everything into lookup_future_chain. Since the FutureChain object will have to hold a root symbol and dates, it should be responsible for cleaning the user input, so this is removed from the lookup method.

Adds knowledge date to future lookups. This makes our definition of valid contracts more flexible. We know about a contract if it starts trading by the knowledge date, and a contract is expired if it expires by the as_of_date.

Also fixes a bug with computing future chains, where contracts were not included in the chain on their expiration date.
2015-07-02 10:34:32 -04:00