Commit Graph

149 Commits

Author SHA1 Message Date
Conner Fromknecht 99efa7a9f3 Fixed catalyst tests except example tests 2017-06-19 14:43:10 -07:00
Richard Frank 3ca5a15859 TST: Use fixture's data with tmp_trading_env
instead of env needing to download it
2017-05-18 12:54:05 -04:00
Jean Bredeche 5305fbe471 REF: Remove assetfinder from PerformancePeriod 2017-04-24 15:41:22 -04:00
Jean Bredeche 9a0d9d868c REF: Remove asset_finder and multipliers from PositionTracker 2017-04-24 15:41:22 -04:00
Jean Bredeche 1f8e194e09 BUG: Position cost basis was calculated incorrectly for Futures
For futures, we need to divide the position’s commission by the
contract size to get a per-unit commission in order to properly update
the position’s cost basis.
2017-04-24 15:41:20 -04:00
Jean Bredeche b1248cb6d6 REF: Explicitly use Assets in Position, Order, Transaction
(Instead of `sid`, which were already usually assets)

Perf packets are unchanged and still emit `sid`: int
2017-04-24 15:41:13 -04:00
dmichalowicz b891fd00d5 BUG: Multipliers were not removed when closing a position 2017-01-25 17:23:09 -05:00
Joe Jevnik 1714b2d03a MAINT: remove __getitem__ as alias of __getattr__ 2016-08-31 12:38:20 -04:00
Eddie Hebert db6fd73b39 MAINT: Remove future/equity distinction.
In the data portal, remove methods that make a distinction between
future and equity asset type. Instead rely on the pricing reader
dispatching.

In support of incoming work which will upsample equity history arrays to
the larger future calendar.

Also, remove perf tracker tests which were using an equity
reader/writer, to be added back in later.
2016-08-18 16:18:32 -04:00
Eddie Hebert e934c6aeaf TST: Make room for multiple calendars in tests.
When adding fixtures for futures data, there will be a need for multiple
calendars in the fixture ecosystem. e.g. a test that includes both
equities and futures would need an overall calendar which encompasses
both equities and futures; however, the test data for equities should
still still be limited to the bounds set by the NYSE calendar.

Make the fixtures that setup trading calendars and values dervied from
the trading calendar (e.g. trading sessions) accept an iterable of
calendars which need to be created, then populate those values into a
dict keyed by the calendar name.

Change `WithNYSETradingDays` to include sessions in the name,
since we are moving to session as the name for the 'day' unit.

Provide `trading_days` which is really "NYSE trading sessions` on
`WithTradingSessions` for backwards compatibility.
2016-08-05 12:17:27 -04:00
Jean Bredeche e6af4e4f1b ENH: made exchange a required parameter to Asset and its subclasses
This required updating a lot of tests.
2016-08-02 23:21:39 -04:00
Andrew Liang 98f3fc9326 MAINT: Refactor application of capital changes
Previously, on the dt of a capital change, we use the un-updated
prices to find the ending performance of the previous subperiod and
then got the new prices to determine the portfolio value used to
calculate the delta, without actually updating the performance
before applying the capital change. This logic is confusing and
unintuitive. Instead, save the ending performance as we do previously,
but have temp values for the starting current subperiod value.
Update those temp values after processing the capital change
2016-08-01 11:51:45 -04:00
Jean Bredeche 6fb4923cc7 Re-implemented the Calendar API.
Instead of having separate ExchangeCalendar and TradingSchedule objects, we
now just have TradingCalendar.  The TradingCalendar keeps track of each
session (defined as a contiguous set of minutes between an open and a close).
It's also responsible for handling the grouping logic of any given minute
to its containing session, or the next/previous session if it's not a market
minute for the given calendar.
2016-07-12 13:13:50 -04:00
jfkirk 2a8f69fc01 MAINT: DataPortal env -> asset_finder 2016-06-08 13:34:22 -04:00
jfkirk 581e817603 MAINT: Rebase reconciliation 2016-06-08 13:34:22 -04:00
jfkirk 75e0e4723d TST: Refactors more tests to use WithTradingSchedule 2016-06-08 13:34:20 -04:00
jfkirk c8304e8601 ENH: Adds ExchangeCalendar, TradingSchedule, and implementations
Conflicts:
	tests/data/test_minute_bars.py
	tests/data/test_us_equity_pricing.py
	tests/finance/test_slippage.py
	tests/pipeline/test_engine.py
	tests/pipeline/test_us_equity_pricing_loader.py
	tests/serialization_cases.py
	tests/test_algorithm.py
	tests/test_assets.py
	tests/test_bar_data.py
	tests/test_benchmark.py
	tests/test_exception_handling.py
	tests/test_fetcher.py
	tests/test_finance.py
	tests/test_history.py
	tests/test_perf_tracking.py
	tests/test_security_list.py
	tests/utils/test_events.py
	zipline/algorithm.py
	zipline/data/data_portal.py
	zipline/data/us_equity_loader.py
	zipline/errors.py
	zipline/finance/trading.py
	zipline/testing/core.py
	zipline/utils/events.py
2016-06-08 13:34:18 -04:00
Andrew Liang 40f42b43f5 DEV: Adjust performance calculations for capital changes
Refactor PerformancePeriod so that it creates a sub-period every
time a capital change happens within the period
2016-05-24 17:23:36 -04:00
Jean Bredeche 39bf1dbd7b DEV: Re-implement commission models to return correct results in the case of multiple fills. 2016-05-23 21:19:06 -04:00
Andrew Liang 7641247b41 BUG: DAY_END action not emitted during minute emission
Refactor AlgorithmSimulator so that DAY_END is emitted for both
minute and daily emission, and that handling of end-of-minute
and end-of-day are separated
2016-05-06 10:25:44 -04:00
Joe Jevnik bc0b117dc9 MAINT: make the data loading apis more consistent.
Changes BcolzDailyBarWriter to not be an abc, data is passed as an
iterator of (sid, dataframe) pairs to the write method.

Changes the AssetsDBWriter to be a single class which accepts an engine
at construction time and has a `write` method for writing dataframes for
the various tables. We no longer support writing the various other data
types, callers should coerce their data into a dataframe themselves. See
zipline.assets.synthetic for some helpers to do this.

Adds many new fixtures and updates some existing fixtures to use the new
ones:

WithDefaultDateBounds
  A fixture that provides the suite a START_DATE and END_DATE. This is
  meant to make it easy for other fixtures to synchronize their date
  ranges without depending on eachother in strange ways. For example,
  WithBcolzMinuteBarReader and WithBcolzDailyBarReader by default should
  both have data for the same dates, so they may use depend on
  WithDefaultDates without forcing a dependency between them.

WithTmpDir, WithInstanceTmpDir
  Provides the suite or individual test case a temporary directory.

WithBcolzDailyBarReader
  Provides the suite a BcolzDailyBarReader which reads from bcolz data
  written to a temporary directory. The data will be read from
  dataframes and then converted to bcolz files with
  BcolzDailyBarWriter.write

WithBcolzDailyBarReaderFromCSVs
  Provides the suite a BcolzDailyBarReader which reads from bcolz data
  written to a temporary directory. The data will be read from a
  collection of CSV files and then converted into the bcolz data through
  BcolzDailyBarWriter.write_csvs

WithBcolzMinuteBarReader
  Provides the suite a BcolzMinuteBarReader which reads from bcolz data
  written to a temporary directory. The data will be read from
  dataframes and then converted to bcolz files with
  BcolzMinuteBarWriter.write

WithAdjustmentReader
  Provides the suite a SQLiteAdjustmentReader which reads from an in
  memory sqlite database. The data will be read from dataframes and then
  converted into sqlite with SQLiteAdjustmentWriter.write

WithDataPortal
  Provides each test case a DataPortal object with data from temporary
  resources.
2016-04-15 23:46:10 -04:00
Richard Frank 70befd490b MAINT: Don't store data portal everywhere
Removed lots of data portal references that participated in ref cycles
and prevented deterministic cleanup of dbs.
2016-04-12 19:33:22 -04:00
Jean Bredeche dc01c45dc4 DEV: Apply adjustments for portfolio and account in BTS
completely copied from https://github.com/quantopian/zipline/pull/1104/

All credit goes to Andrew Liang (@lianga888)
2016-04-05 11:37:34 -04:00
Eddie Hebert 16fd6681a6 ENH: Rewrite of Zipline to use lazy access pattern
More documentation to follow in release notes.

Based on lazy-mainline branch, see for more details.

Also-By: Jean Bredeche <jean@quantopian.com>
Also-By: Andrew Liang <aliang@quantopian.com>
Also-By: Abhijeet Kalyan <akalyan@quantopian.com>
2016-04-04 16:12:58 -04:00
Stewart Douglas 0e97a01c05 TST: Test multiple calls to update_positions 2016-03-11 13:16:25 -05:00
jfkirk c9c2e3e60e TST: Updates TestPositionPerformance 2016-01-22 14:56:30 -05:00
jfkirk db1e62971a ENH: Adds tick_size and renames futures multiplier 2016-01-22 14:56:30 -05:00
jfkirk 1365b916c0 TST: Adds tests for the perf tracker with futures 2016-01-19 16:11:22 -05:00
Eddie Hebert 962347318d MAINT: Futures cash adjustment on change and calc.
In preparation for the incoming changes which no longer push every bar
through the tradesimulation, remove the adjustment of the period's cash on
every pricing change of a held futures asset.

Instead hold the last sale price for each held future either:

- At the end of each peformance period update the last sale prices of
  all held futures, so that the pnl for the next period uses values
  derived from the cash difference between the end of the two periods.

- When a transaction is processed for the Future, so that the correct
  amount is applied to each cash adjustment. (i.e. the cash adjustment
  is reset on every change of amount of the Future being held, so that
  multiple size and prices do not need to be tracked for the same asset.)

Also, remove now unused dict of payout calculation modifier, since new
calculation reads the value directly off of the asset.

Remove update_last_sale test, since the method no longer returns a cash
value.
2016-01-04 16:52:37 -05:00
Eddie Hebert d07d42263a MAINT: Make tracker stats a method.
Instead of calling a function, where the only parameter is the tracker
object, make it a method, so that the snapshot of position tracker stats
can be more easily called as `pt.stats()`.
2015-12-18 09:52:53 -05:00
Eddie Hebert bbb9cc87a9 REF: Move transaction class to own module. 2015-12-15 16:23:59 -05:00
Eddie Hebert 06d4d7e74b MAINT: Remove perf_periods member.
Refer to cumulative and todays performance explicitly instead of always
looping through.

The third value (minute) for which this was useful, has been removed.

Also, there are some actions where only cumulative may need application,
e.g. application of dividends. (However, this patch does not remove
dividend processing from todays performance, but opens up later patches
to make that distinction.)
2015-12-15 13:47:38 -05:00
Scott Sanderson a14c61e7ff MAINT: Remove unused 'asset_type' metadata entry. 2015-11-05 13:35:05 -05:00
Eddie Hebert 23e7433635 TST: Make params explicit to calc results.
Change calculate_results to take explicit parameters for sim_params, env
and benchmark_events instead of reading those values off of the TestCase
instance.

This prepares for tests setting specific sim_params in each test case,
which is needed for an incoming refactoring of how the test data is set up.
2015-09-29 14:36:45 -04:00
Eddie Hebert 9581afb32a TST: Remove random simulation parameters.
For better predictability/ability to reason and step through the test
cases, use the same start and end for each run of the test suite.
2015-09-29 14:36:45 -04:00
Eddie Hebert c88412e3f1 TST: Add coverage for long and short count.
Make basic checks of position stats test all fields, by adding coverage
for `shorts_count` and `longs_count`.
2015-09-25 16:42:25 -04:00
Eddie Hebert ae97e75388 MAINT: Only calc position values once per packet.
Instead of calculating the position values for each stat result, e.g.
gross_exposure, net_liquidity etc.; get the positions upfront and then
calculate the period and position stats in order, passing each value
explicitly to the ones that follow it in the dependency chain.

e.g. the gross_value depends on the long_value and the short_value,
which called the position_values property for calculating both the
long_value and the short_value.

Removing the repeated calls to position_values (and
position_exposures) removes the need for the caching the last sale
prices and position amounts in separate vectors, since it is inexpensive
enough to read those values off of the positions dictionary held in the
position tracker.

This patch gives a small gain to ~500 sized portfolios, but the main
intent is to clear the path to not storing last_sale_prices on the
position objects at all. Removing all of the caching layer in this class
makes that change easier to apply. Removing the extra calls to
position_values also made this class easier to step through/reason about
when splicing in the new last sale price access, as well.
2015-09-23 22:26:13 -04:00
jfkirk 6e6ef447d2 TST: Adds tearDownClass methods to delete TradingEnvironments 2015-09-10 11:53:29 -04:00
jfkirk 65a4c4523e STY: Renames serialization_utils dump and load methods 2015-09-10 11:53:29 -04:00
jfkirk dc964a7e7d MAINT: Removes the ability to reference a global TradingEnvironment
This commit removes the ability to reference a shared TradingEnvironment through the zipline.finance.trading module. In place, the classes that require a TradingEnvironment, or its child AssetFinder, contain their own references to those objects.

This commit also adds serialization utilities that allow for the pickling/unpickling of objects without unintentionally their TradingEnvironments or AssetFinders.
2015-09-10 11:53:28 -04:00
Stewart Douglas d3516959a3 MAINT: Don't set string to upper before writing, remove unused libs 2015-09-10 11:53:27 -04:00
Stewart Douglas 1ef2274d11 MAINT: Update tests to conform to new reader/writer structure 2015-09-10 11:53:26 -04:00
Stewart Douglas 501fd58fdf ENH: Replace update_asset_finder with write_data
The write_data methods invokes the relevant AssetDBWriter subclass
to write data to the database. update_asset_finder is no longer
a relevant method since the AssetFinder is strictly a reader class.
2015-09-10 11:53:24 -04:00
jfkirk 67c56f768b ENH: Adds auto-closing feature and implements for Futures 2015-07-31 10:38:44 -04:00
jfkirk 8d5bfd3c91 BUG: Aligns performance packet generation between minute and daily modes 2015-07-21 13:25:39 -04:00
Eddie 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
jfkirk efa6d8dbce ENH: Adds a perf tracker method to handle SIDs leaving the universe 2015-07-09 17:03:21 -04:00
jfkirk 9291a89599 BUG: Prevents payout of dividend on final trading close 2015-06-24 21:45:55 -04:00
jfkirk bfc992363e TST: Fixes broken test_close_position_event 2015-06-12 17:17:10 -04:00
jfkirk a5d1f79a37 TST: Reconciles tests with asset management system 2015-06-11 11:35:49 -04:00