Commit graph

26 commits

Author SHA1 Message Date
samatix
b32f55409e STY: Flake8 style amendments 2020-04-20 15:16:28 +02:00
Scott Sanderson
66f144379d MAINT: Updates to fix tests. 2020-04-17 10:19:44 -04:00
Scott Sanderson
464145b8a6 ENH: Rework benchmark handling for zipline CLI.
Reworks how we choose a benchmark source for the zipline CLI and
zipline.utils.run_algo.run_algorithm. The logic for choosing a benchmark is now
consolidated in a new `BenchmarkSpec` class.

Benchmarks can be configured from several possible options:

- An in-memory series can be passed as `benchmark_returns`. This is mostly
  useful for testing, or for use with `run_algorithm`.
- A path or file-like object can be passed as `benchmark_file`.
- A sid can be passed as `benchmark_sid`
- A symbol can be passed as `benchmark_symbol`.
- `no_benchmark` can be passed to use a dummy benchmark of all zero returns.

`BenchmarkSpec` takes all the parameters listed above, and "resolves" them into
either a sid or a series of benchmark returns, which are forwarded to
TradingAlgorithm, which already takes `benchmark_returns` or
`benchmark_sid`. If none of the above parameters are passed, we log a warning,
emit None for both values, and assume that the algorithm will call
`set_benchmark` in its `initialize` method.
2020-04-16 14:49:55 -04:00
samatix
11e7d05cee STY Flake8 style changes 2020-04-05 23:41:40 +02:00
samatix
fabf897a58 TEST Adding tests for the new benchmark parameters. I used mock functions as I couldn't find in the test fixtures a way to call run_algo. 2020-04-05 23:30:49 +02:00
Joe Jevnik
6969ebac53 ENH: vectorize dividend ratio calculation 2018-09-26 14:16:54 -04:00
Scott Sanderson
ce2a2363f8 MAINT: Remove TradingEnvironment. 2018-07-17 09:45:05 -04:00
Eddie Hebert
c1280daaa3 MAINT: Remove environment as an argument to benchmark source. (#1816)
MAINT: Remove environment as an argument to benchmark source.

To allow the BenchmarkSource class to be more easily used in contexts other than
a TradingAlgorithm, remove the TradingEnvironment as an argument to the
benchmark source.

Instead:
- Pass a benchmark Asset, instead of a bencmark sid; so that the asset_finder
does not need to be passed to the benchmark source.
- Pass the pre-calculated benchmark_returns instead of an env,
which contains the benchmark_returns; a consumer can let the benchmark_returns
stay as the default of `None` when using an asset.

We may want to further refactor and make two different classes, instead of
relying on a combination of existence/non-existence of benchmark_asset and
benchmark_returns. That refactoring should be easier to do with this change.
2017-05-25 16:11:25 -04:00
Samantha Klonaris
655bf0f4cb ENH: Add get_range to BenchmarkSource 2017-05-25 10:14:40 -04:00
Andrew Daniels
d155d894fe MAINT: Pass data_frequency to get_history_window
This allows us to remove the check for whether the provided dt had a
time of midnight, which was a flimsy way to infer if the data frequency
was 'daily'. Besides the explicit check being preferable, this method
was broken on the futures calendar, since midnight is a valid market
minute.
2017-05-09 09:34:39 -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
Joe Jevnik
4265a13edf Revert "Merge pull request #1354 from quantopian/revert-1302-point-in-time-asset-db"
This reverts commit 3b633011c6, reversing
changes made to 70ac5323de.
2016-08-02 14:25:10 -04:00
Joe Jevnik
814a2be7b7 Revert "Point in time asset db" 2016-07-27 23:29:08 -04:00
Joe Jevnik
7fd8c29880 ENH: add point in time aspect to equity symbol mapping
Changes the overlap behavior so that it is an error to write data which
would have two companies holding the same ticker. Other than one test
around which company would win in that case, all the other tests are
passing. That single test has been changed to check the write-time
error.
2016-07-26 13:34:58 -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
Eddie Hebert
51eda06323 MAINT: Add equity to naming of bar data classes.
In preparation of adding futures, add equity to the names of both the
classes and methods for writing bcolz data. Futures data will use a
different minutes per day with a separate reader. This change will allow
both equity and futures fixtures to be side by side.

Also, break out the method which generates the dataframes and trading
days member into fixtures (`EquityMinuteBarData` and
`EquityDailyBarData`) on which the `*BarReader` fixture depends.  This
fixture is separated out to enable reader/writers in different formats
to use the same data setup. (There is internal code which needs to write
minute and daily bar data in a database format.)
2016-06-30 08:21:42 -04:00
jfkirk
2a8f69fc01 MAINT: DataPortal env -> asset_finder 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
d9fc514fa8 TST: Adds TradingSchedule test fixture 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 Daniels
71f12ec272 MAINT: Adds first_trading_day arg to DataPortal
Instead of inferring it from the minute/daily writer, we now require the
first trading day to be passed explicitly, so the creator of the
DataPortal controls what is used as the first trading day.
2016-06-02 13:16:43 -04:00
Andrew Liang
fb6bda5840 FIX: Error message for BenchmarkAssetNotAvailableTooLate is wrong
Should be '...does not exist on self.trading_days[-1]...' not
self.trading_days[0]
2016-05-02 12:00:35 -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
8b610a2ab7 TST: Cleaned up test references to adjustments db
If we don't clean them up, then windows can delete
the temp dir with the db.
2016-04-12 19:33:22 -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