Commit graph

154 commits

Author SHA1 Message Date
Scott Sanderson
8195f3a5d2
Merge pull request #2644 from quantopian/ffill-past-fx-end
MAINT: Forward-fill fx rates past file end.
2020-02-04 18:54:16 -05:00
Scott Sanderson
2546708d0e MAINT: Forward-fill fx rates past file end.
If an FX rate query requests a date that's greater than the last date in the fx
rate file, forward-fill from the last value in the file rather than raising an
error.

We do this for a few reasons:

1. We'd like to gracefully handle the possibility of an FX rates file that's
   older than another input file.

2. Relative to other non-erroring behaviors, forward-filling is the simplest
   thing to implement. Specifically, it's what the implementation prior to this
   change would do naturally if there weren't an explicit check to prevent it.

3. For an FX rates file containing prices on a 24/5 calendar, some amount of
   forward-filling is required to handle any market with a non-weekday date.
2020-02-04 18:23:53 -05:00
Scott Sanderson
b43b558475
Merge pull request #2622 from samatix/assertregex
DEP: Replacing the assertRaisesRegexp which is deprecated by assertRaisesRegex
2020-02-04 14:45:19 -05:00
Scott Sanderson
3841944fae BUG: Use value from loop. 2020-01-30 11:05:10 -05:00
Scott Sanderson
7f4baa6bd5 TEST: Add test coverage for loading fx rates of None.
We should always return NaN on a request to load None as an FX rate.
2020-01-30 11:03:33 -05:00
Scott Sanderson
a7e089809e MAINT: Clarify handling of edge cases in fx readers.
- When reading before the start of data, return NaN. We do this because it's
  hard to reliably apply a lower bound to the queried dates in core-loader
  style pipeline loaders.

- When reading an unknown base currency, return NaN. We might get data from
  third parties with unknown currencies. Doing so should not be an error.

- When reading after the end of data, emit an error rather than forward-filling
  forever. We may want to revisit this in the future.
2020-01-30 10:10:40 -05:00
samatix
86ddd6072f DEP: Replacing the assertRaisesRegexp which is deprecated by assertRaisesRegex
This deprecation will enable the upgrade to add support for python 3.7 and higher
2020-01-19 10:46:31 +01:00
Scott Sanderson
c6bb9768b6 ENH: Add get_rates_columnar method to FXRatesReader. 2020-01-15 11:09:03 -05:00
Scott Sanderson
b842b87e8e TEST: Add test coverage for get_rate_scalar. 2020-01-14 16:05:44 -05:00
Scott Sanderson
13777f9fdf MAINT: Use object arrays with None for currency codes.
Rather than trying to use S3s everywhere, which is annoying in Python 3 and
makes it harder to represent missing data, just use object arrays with None as
the missing value. This is the representation we want anyway for loading
currency data in pipelines, and the main downsides are performance (which
doesn't appear to be meaningfully affected) and difficulty with sorting, which
we don't need to do (at least right now).
2020-01-11 12:23:13 -05:00
Scott Sanderson
d41914284d MAINT: Move expected rate lookup functions into fixture for reuse. 2020-01-10 12:55:25 -05:00
Scott Sanderson
006b7b9aed BUG: Handle currency conversions for unknown sids.
Don't crash on queries for currency codes of possibly-unknown sids on calls to
`SessionBarReader.currency_codes`. When a currency code is requested for an
unknown sid, we return zipline.currency.MISSING_CURRENCY_CODE for that sid.
2020-01-09 15:03:49 -05:00
Scott Sanderson
fb07353c4f BUG: Return correct currency codes when loading subset of sids.
- Fixes a bug where we only returned the correct currency codes when loading
  all sids stored in an hdf5 file.
- Adds a failing test for the bug.
2020-01-09 11:59:55 -05:00
Scott Sanderson
4eb7641708 ENH: Move reader construction into shared fixture. 2020-01-08 15:34:27 -05:00
Scott Sanderson
66b83e2b5a MAINT: Replace usages of 'default' with named sentinel.
This makes it easier to distinguish different usages of 'default', and makes it
easier in the future to change how we handle defaults.
2020-01-02 10:53:37 -05:00
Scott Sanderson
7a6c2ae585 BUG: Clarify bases type for currency queries.
- Rather than using numpy's S3 and U3 types, which behave differently in py2
  and py3, just expect object arrays of `str` everywhere.

  This makes it slightly more expensive for us to read the currency index from
  the file in py3, but that array is on the order of a hundred or so elements
  total, so that's not a major concern, and it simplifies the handling
  elsewhere.
2019-12-19 11:52:23 -05:00
Scott Sanderson
6b90f98a0c ENH: More complete support for defaults in fx readers.
Explicitly require that pipeline-compatible readers support 'default' as a
key. I'm currently just using the string 'default' for this. We should probably
move that value to a shared location, but it's not clear to me that value
should live since it's defining an interface boundary between pipeline and fx
data.
2019-12-17 16:25:50 -05:00
Scott Sanderson
b85ad28f2a MAINT: Updates to fx reader/writer.
- Add test coverage for non-scalar lookups.
- Performance optimizations for InMemoryFXRateReader and HDF5FXRateReader. We
  no longer construct a DataFrame on each call to get_rates, since doing so is
  surprisingly expensive and caused test_lookup_scalar to take more time than
  was reasonable.
2019-12-17 14:34:16 -05:00
Scott Sanderson
bcbda706a0 ENH: HDF5-based FX Reader/Writer. 2019-12-16 19:18:00 -05:00
Scott Sanderson
bfe0f90e70 ENH: Add currency-aware session bar readers. 2019-11-25 12:48:39 -05:00
Scott Sanderson
06588f8a4d BUG: Ensure correct dtypes when unpacking empty dataframes.
Fixes a bug where columns of adjustment db dataframes would come back as object
dtype when the table is empty.
2019-03-18 18:53:36 -04:00
Ernesto Perez
2fdd5e59b5 MAINT: Use load_adjustments_from_sqlite new interface. 2019-03-04 12:54:47 -06:00
Andrew Daniels
e38a2cfeed MAINT: Raise an error when only unknown sids are requested 2018-10-30 17:23:45 -04:00
Andrew Daniels
7ed4a536e6 MAINT: Make load_raw_arrays for daily bar readers handle unknown sids
The readers would previously error, they'll now return nan/0 for
these sids.
2018-10-30 17:22:59 -04:00
Scott Sanderson
ba94d6a87a TEST: Add test coverage for sessions. 2018-10-12 12:26:31 -04:00
Scott Sanderson
e537a351c7 BUG: Use correct attribute name. 2018-10-12 12:26:31 -04:00
Scott Sanderson
f61978e093 ENH: Support writing empty country groups. 2018-10-12 12:26:31 -04:00
Scott Sanderson
1b26db0c5c MAINT: Remove unused calendar arg from SQLiteAdjustmentWriter. 2018-10-12 12:26:31 -04:00
Vikram Narayan
0766178846
BUG: don't crash on dividend warning (#2323)
* BUG: don't crash on dividend warning

* TST: add extra test cases to dividend ratio test
2018-10-04 21:42:54 -04:00
ernestoeperez88
5cda2ad542
Merge pull request #2309 from quantopian/float-precision-fix
BUG: Round values before truncating when writing bcolz minute/day tables.
2018-10-01 14:21:29 -07:00
Andrew Daniels
a7db215bbe BUG: Fixes for compatibility with newer numpy/pandas 2018-10-01 16:00:00 -04:00
Andrew Daniels
e0f3f7907f MAINT: Clean up organization of HDF5 daily bar tests 2018-10-01 16:00:00 -04:00
Andrew Daniels
46758fcff6 TST: Generalize remaining US-specific tests in _DailyBarsTestCase
`test_unadjusted_get_value` and `test_unadjusted_get_value_no_data` were
hardcoded to reference US sids, so we were running checks through the
US machinery, even in the CA tests. This commit refactors both so that
they are general across countries.
2018-10-01 16:00:00 -04:00
Andrew Daniels
b6aa5ddef9 MAINT: Handle invalid sids in single country HDF5DailyBarReader 2018-10-01 16:00:00 -04:00
Andrew Daniels
0a353ff059 MAINT: Validate dates passed to HDF5DailyBarReader 2018-10-01 16:00:00 -04:00
Andrew Daniels
368906ecc3 MAINT: Raise NoDataForSid when requested assets not in the daily bars 2018-10-01 16:00:00 -04:00
vikram-narayan
d708817e44 MAINT: use ISO 10383 codes for exchanges 2018-10-01 12:45:27 -04:00
Ernesto Perez
2766d2bfe5 BUG: Round values before truncating to uint32 when writing minute/day bcolz files. 2018-10-01 09:38:08 -04:00
Joe Jevnik
cc7998ef8e MAINT: remove unused param 2018-09-28 11:06:19 -04:00
Joe Jevnik
3fb8d2666a BUG: fix truncation when converting floats to uint32 2018-09-28 11:06:19 -04:00
Andrew Daniels
d6833e58dd MAINT: Break out a new function to create synthetic data with holes 2018-09-27 13:28:13 -04:00
Andrew Daniels
7186b1c049 MAINT: PR feedback 2018-09-27 13:28:13 -04:00
Andrew Daniels
beb11558ea TST: Test that daily bar readers return nan/0 for holes
- Adds a `holes` arg to make_bar_data() and expected_bar_values_2d(),
  to allow adding gaps of missing values in the synthetic data.
- Updates test_unadjusted_get_value_no_data to check that missing values
  within an asset's lifetime are return as nan for OHLC, and 0.0 for
  volume.
- Removes the ultra-hacky test_unadjusted_get_value_empty_value from,
  the bcolz daily bar tests, since test_unadjusted_get_value_no_data now
  covers the same behavior.
2018-09-27 13:28:13 -04:00
Andrew Daniels
598165ff33 TST: Add test coverage for HDF5 daily bar asset start and end dates 2018-09-27 13:28:13 -04:00
Joe Jevnik
2bfd89e21f ENH: make adjustment reader and writer ctx managers 2018-09-26 17:03:51 -04:00
Joe Jevnik
61f15cc191 TST: add tests for adjustments writer 2018-09-26 14:16:54 -04:00
Joe Jevnik
90f4346395 BUG: fix load_raw_arrays for a subset of the possible assets 2018-09-26 14:16:54 -04:00
Scott Sanderson
82b572fd44 MAINT: Rename test_us_equity_pricing. 2018-09-22 20:52:55 -04:00
Andrew Daniels
4ea71f3326 MAINT: PR feedback 2018-09-22 20:52:55 -04:00
Andrew Daniels
a33d9a489f TST: Test HDF5 daily pricing in multiple countries
Updates _DailyBarsTestCase handle writing data for both US and CA
equities. The tests will the be run against the assets from the country
specified by the DAILY_BARS_TEST_QUERY_COUNTRY class attribute.

BcolzDailyBarTestCase uses 'US' to preserve its current behavior, and
HDF5DailyBarTestCase becomes HDF5DailyBarUSTestCase, with the new
HDF5DailyBarCanadaTestCase.
2018-09-22 20:52:55 -04:00