Skip to content

Commit

Permalink
Implement option for right limit ealier than now
Browse files Browse the repository at this point in the history
To `base.PricesBase`:
- adds `live_prices` method.
- adds `limit_right_daily` property.
- adds `limit_right_intraday` property.
- adds `latest_requestable_minute` property.
- adds `_bis_available_any`, `_bis_available_any_no_partial_indicies`
and `_bis_any` to evaluate bis for which ANY data is available over
the requested period. This provides for returning prices when strict
False and end is to the right of the right limit.
- revises `_get_bi_table_intraday` to accommodate returning data when
end is to the right of the right limit and strict is False.
- renames `_bis_available` as `_bis_available_all`.
- revises `_bis_valid` to raise `EndOutOfBoundsError`.
- revises `_bis_available_all` and  `_bis_available_end` to also
raise `PricesUnavailableIntervalError` when start is right of right
limit or end is left of left limit.
- revises `GetPricesParams` to support right limits and adds
`request_all_availabla_data` property to query if the params are
requesting all available data.
- tidies `get` to make code paths clearer.
- revises `price_at` and dependents to support right limit.
  - overhauls implementation of `_price_at_from_daily` to FIX bug where
daily data could return inaccurate prices at a specific minute when
sessions of underlying symbols overlapped.

To `daterange._Getter`:
- adds support for a right limit.
- adds 'limit' parameter to `get_start`, `get_end` and
`_get_start_end`.
- adds 'strict' parameter to `get_end` to override instance stict.
- enforces consistency of behaviour when evaluated period is
partially out-of-limits when strict is False, only start or end is
defined and the other is evaluated from a duration. Now always
evaluates period independent of limits and returns prices for the
part of the period for which prices are available.

To `parsing` module:
- revises `parse_start_end` and dependents to support a right limit.

To `data` module:
- adds `data.Data.available_any` method to query if data is avaialble
for any timestamp within a range.

To `errors` module:
- revises and reworks messages for `PricesIntradayUnavailableError`.
- adds:
  - `EndTooLateError`
  - `PriceAtUnavailableError`
  - `PriceAtUnavailableLimitError`
  - `PriceAtUnavailableLivePricesError`
  - `EndOutOfBoundsRightError`

To `csv` module:
  - implements `_request_data` and calls from constructor to get all
data upfront, after which further calls to method will fail.

To TEST modules:
  - revisions to existing tests to support changes that implemented a
right limit.
  - new `test_limits` test module to test effect of a right limit on
`PricesBase.get` and `PricesBase.price_at`.
  - adds  `test_parsing.test_start_end_right_limit_now_now` to test
support for right limit when parsing start and end params.
  - adds 2 days of daily data to right extreme of some daily .csv
resource files to bring the availability of daily data in line with
that of intraday data.
  • Loading branch information
maread99 committed Jan 25, 2024
1 parent ae48422 commit e609900
Show file tree
Hide file tree
Showing 17 changed files with 3,313 additions and 512 deletions.
3 changes: 2 additions & 1 deletion .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ per-file-ignores =
# D103 Missing docstring in public function - not required for all tests
# D102 Missing docstring in public function - not required for all tests
# D401 First line should be in imperative moood - not useful to describe fixtures
tests/*.py:D103,D102,D401
# E501 line too long - required to ease defining exception text matches
tests/*.py:D103,D102,D401,E501
# E501 line-too-long, provides for a doctest line that overruns
src/market_prices/utils/pandas_utils.py:E501

Expand Down
41 changes: 40 additions & 1 deletion src/market_prices/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

from market_prices import errors, helpers, intervals
from market_prices.utils import calendar_utils as calutils
from market_prices.mptypes import DateRangeReq
from market_prices.mptypes import DateRange, DateRangeReq

from .utils.pandas_utils import (
interval_contains,
Expand Down Expand Up @@ -286,6 +286,45 @@ def available_range(

return avail

# TODO ADD TEST
def available_any(self, daterange: DateRangeReq) -> bool | None:
"""Query if data is available for any timestamp within a range.
Parameters
----------
daterange
Range over which to query.
Returns
-------
bool | None
False: known that no timestamp within range is available from
source.
None: unknown if a timestamp within range is available from
source.
True: known that data is available for at least one timestamp
within range.
"""
left, right = daterange
if left > self.rl:
return False
if self.ll is not None:
if left is None:
return right >= self.ll
else:
return (left <= self.rl) and (right >= self.ll)

leftmost = self.leftmost_requested
if leftmost is None:
return None

if left is None and right >= leftmost:
return True
elif (left <= self.rl) and (right >= leftmost):
return True
return None

def requested(self, timestamps: pd.Timestamp | Sequence[pd.Timestamp]) -> bool:
"""Query if uninterrupted data has been requested.
Expand Down
Loading

0 comments on commit e609900

Please sign in to comment.