Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed missing kwargs in get_price function #141

Merged
merged 1 commit into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion qf_lib/backtesting/data_handler/data_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def historical_price(self, tickers: Union[Ticker, Sequence[Ticker]],
return self.data_provider.historical_price(tickers, fields, nr_of_bars, end_date, frequency)

def get_price(self, tickers: Union[Ticker, Sequence[Ticker]], fields: Union[PriceField, Sequence[PriceField]],
start_date: datetime, end_date: datetime = None, frequency: Frequency = None) -> \
start_date: datetime, end_date: datetime = None, frequency: Frequency = None, **kwargs) -> \
Union[PricesSeries, PricesDataFrame, QFDataArray]:
"""
Runs DataProvider.get_price(...) but before makes sure that the query doesn't concern data from
Expand All @@ -129,6 +129,7 @@ def get_price(self, tickers: Union[Ticker, Sequence[Ticker]], fields: Union[Pric
Returns
-------
None, PricesSeries, PricesDataFrame, QFDataArray
:param **kwargs:
"""
frequency = frequency or self.default_frequency
assert frequency is not None, "Frequency cannot be equal to None"
Expand Down
3 changes: 2 additions & 1 deletion qf_lib/data_providers/general_price_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ def __init__(self, bloomberg: BloombergDataProvider = None, quandl: QuandlDataPr
self._register_data_provider(provider)

def get_price(self, tickers: Union[Ticker, Sequence[Ticker]], fields: Union[PriceField, Sequence[PriceField]],
start_date: datetime, end_date: datetime = None, frequency: Frequency = Frequency.DAILY) -> Union[None, PricesSeries, PricesDataFrame, QFDataArray]:
start_date: datetime, end_date: datetime = None, frequency: Frequency = Frequency.DAILY, **kwargs) \
-> Union[None, PricesSeries, PricesDataFrame, QFDataArray]:
"""
Implements the functionality of AbstractPriceDataProvider using duck-typing.

Expand Down
2 changes: 1 addition & 1 deletion qf_lib/data_providers/preset_data_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def supported_ticker_types(self) -> Set[Type[Ticker]]:
return self._ticker_types

def get_price(self, tickers: Union[Ticker, Sequence[Ticker]], fields: Union[PriceField, Sequence[PriceField]],
start_date: datetime, end_date: datetime = None, frequency: Frequency = Frequency.DAILY) -> \
start_date: datetime, end_date: datetime = None, frequency: Frequency = Frequency.DAILY, **kwargs) -> \
Union[None, PricesSeries, PricesDataFrame, QFDataArray]:
# The passed desired data frequency should be at most equal to the frequency of the initially loaded data
# (in case of downsampling the data may be aggregated, but no data upsampling is supported).
Expand Down
2 changes: 1 addition & 1 deletion qf_lib/data_providers/quandl/quandl_data_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def __init__(self, settings: Settings):

def get_price(self, tickers: Union[QuandlTicker, Sequence[QuandlTicker]],
fields: Union[PriceField, Sequence[PriceField]], start_date: datetime, end_date: datetime = None,
frequency: Frequency = Frequency.DAILY):
frequency: Frequency = Frequency.DAILY, **kwargs):
start_date = self._adjust_start_date(start_date, frequency)
return self._get_history(
convert_to_prices_types=True, tickers=tickers, fields=fields, start_date=start_date, end_date=end_date)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,17 @@ def setUp(self):

def test_get_price_when_end_date_is_in_the_past(self):
self.timer.set_current_time(str_to_date("2018-02-12 00:00:00.000000", DateFormat.FULL_ISO))
prices_tms = self.data_handler.get_price(self.spx_index_ticker, PriceField.Close,
self.start_date, self.end_date)
prices_tms = self.data_handler.get_price(self.spx_index_ticker, PriceField.Close, self.start_date,
self.end_date)

self.assertEqual(self.start_date, prices_tms.index[0].to_pydatetime())
self.assertEqual(self.end_date, prices_tms.index[-1].to_pydatetime())

def test_get_price_when_end_date_is_today_after_market_close(self):
self.timer.set_current_time(
str_to_date("2018-01-31") + MarketCloseEvent.trigger_time() + RelativeDelta(hours=1))
prices_tms = self.data_handler.get_price(self.spx_index_ticker, PriceField.Close,
self.start_date, self.end_date)
prices_tms = self.data_handler.get_price(self.spx_index_ticker, PriceField.Close, self.start_date,
self.end_date)

self.assertEqual(self.start_date, prices_tms.index[0].to_pydatetime())
self.assertEqual(self.end_date, prices_tms.index[-1].to_pydatetime())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ def test_market_open_price_before_market_open(self):

def test_market_open_price_before_market_open__single_date(self):
self.timer.set_current_time(datetime(2022, 4, 26, 1))
prices = self.daily_data_handler.get_price(BloombergTicker("SPX Index"), PriceField.Open,
datetime(2022, 4, 26), datetime(2022, 4, 26))
prices = self.daily_data_handler.get_price(BloombergTicker("SPX Index"), PriceField.Open, datetime(2022, 4, 26),
datetime(2022, 4, 26))
self.assertFalse(is_finite_number(prices))

def test_market_open_price_before_market_close__single_date(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@ def test_price_single_ticker_single_field(self):
def test_price_single_ticker_single_field_single_date(self):
# single ticker, single field; end_date by default now, frequency by default DAILY, currency by default None
data = self.bbg_provider.get_price(tickers=self.SINGLE_TICKER, fields=self.SINGLE_PRICE_FIELD,
start_date=self.END_DATE, end_date=self.END_DATE,
frequency=Frequency.DAILY)
start_date=self.END_DATE, end_date=self.END_DATE, frequency=Frequency.DAILY)

self.assertIsInstance(data, float)
self.assertEqual(data, 147.7257)
Expand Down