Skip to content

Conversation

@mrlimacz
Copy link
Contributor

When there is a bank holiday, no pricing data is available. In case of AAPL (https://finance.yahoo.com/quote/AAPL/history?p=AAPL, see 2023-07-04) timeseries returned by an API call simply skips this particular date. However, securities traded in Warsaw Stock Exchange (e. g. PKO.WA, https://finance.yahoo.com/quote/PKO.WA/history?p=PKO.WA, see 2023-11-01), return timeseries with None as a price for a timestamp of a bank holiday. This causes an exception to by thrown.

This PR simply filters out onle these timestamps with non-None price.

@rizaon
Copy link

rizaon commented Dec 16, 2023

I recently hit an issue that was fixed by this PR. This is a redacted stack trace of my issue.

Traceback (most recent call last):
  File "/Users/redacted/venv/bin/bean-price", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/Users/redacted/venv/lib/python3.11/site-packages/beanprice/price.py", line 854, in main
    price_entries = sorted(price_entries, key=lambda e: e.currency)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/python@3.11/3.11.6/Frameworks/Python.framework/Versions/3.11/lib/python3.11/concurrent/futures/_base.py", line 619, in result_iterator
    yield _result_or_cancel(fs.pop())
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/python@3.11/3.11.6/Frameworks/Python.framework/Versions/3.11/lib/python3.11/concurrent/futures/_base.py", line 317, in _result_or_cancel
    return fut.result(timeout)
           ^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/python@3.11/3.11.6/Frameworks/Python.framework/Versions/3.11/lib/python3.11/concurrent/futures/_base.py", line 456, in result
    return self.__get_result()
           ^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/python@3.11/3.11.6/Frameworks/Python.framework/Versions/3.11/lib/python3.11/concurrent/futures/_base.py", line 401, in __get_result
    raise self._exception
  File "/usr/local/Cellar/python@3.11/3.11.6/Frameworks/Python.framework/Versions/3.11/lib/python3.11/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/redacted/venv/lib/python3.11/site-packages/beanprice/price.py", line 592, in fetch_price
    srcprice = fetch_cached_price(source, psource.symbol, dprice.date)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/redacted/venv/lib/python3.11/site-packages/beanprice/price.py", line 498, in fetch_cached_price
    source.get_historical_price(symbol, time))
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/redacted/venv/lib/python3.11/site-packages/beanprice/sources/yahoo.py", line 157, in get_historical_price
    series, currency = get_price_series(ticker, time - timedelta(days=5), time)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/redacted/venv/lib/python3.11/site-packages/beanprice/sources/yahoo.py", line 102, in get_price_series
    series = [(datetime.fromtimestamp(timestamp, tz=tzone), Decimal(price))
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/redacted/venv/lib/python3.11/site-packages/beanprice/sources/yahoo.py", line 102, in <listcomp>
    series = [(datetime.fromtimestamp(timestamp, tz=tzone), Decimal(price))
                                                            ^^^^^^^^^^^^^^

@blais can we merge this PR please?

@blais blais merged commit 75f07da into beancount:master Dec 16, 2023
@mrlimacz mrlimacz deleted the yahoo-bank-holiday branch June 4, 2024 19:59
@Zhong-z
Copy link

Zhong-z commented Aug 31, 2024

Just realised this PR as my PR that fixes the same issue got conflicts 😄
#79. Should've tagged the author earlier.

Perhaps I can cherry pick the tests and open a new PR instead? @blais

@blais
Copy link
Member

blais commented Sep 9, 2024

SGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants