python-holidays
python-holidays copied to clipboard
Market holidays clarification?
Hi, I'm wondering if someone can clarify how the financial package is intended to be used with a code sample. Code looks simple enough but using NYSE as a country, as the docs suggest, results in an error. I downgraded to the previous release and encountered the same issue.
Hi Tim, it's always a good idea to attach the error message to a bug report and make it as detailed as possible.
As there are no clear steps to reproduce the issue I've just tried these:
❯ virtualenv venv
created virtual environment CPython3.9.13.final.0-64 in 266ms creator CPython3Posix(dest=/Users/ark/Dev/python-holidays/venv, clear=False, no_vcs_ignore=False, global=False) seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=/Users/ark/Library/Application Support/virtualenv) added seed packages: pip==22.2.2, setuptools==63.4.3, wheel==0.37.1 activators BashActivator,CShellActivator,FishActivator,NushellActivator,PowerShellActivator,PythonActivator
❯ pip install holidays
Collecting holidays Downloading holidays-0.15-py3-none-any.whl (181 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 181.3/181.3 kB 802.2 kB/s eta 0:00:00 Collecting convertdate>=2.3.0 Using cached convertdate-2.4.0-py3-none-any.whl (47 kB) Collecting korean-lunar-calendar Using cached korean_lunar_calendar-0.2.1-py3-none-any.whl (8.0 kB) Collecting hijri-converter Using cached hijri_converter-2.2.4-py3-none-any.whl (14 kB) Collecting python-dateutil Using cached python_dateutil-2.8.2-py2.py3-none-any.whl (247 kB) Collecting pymeeus<=1,>=0.3.13 Using cached PyMeeus-0.5.11.tar.gz (5.4 MB) Preparing metadata (setup.py) ... done Collecting six>=1.5 Using cached six-1.16.0-py2.py3-none-any.whl (11 kB) Building wheels for collected packages: pymeeus Building wheel for pymeeus (setup.py) ... done Created wheel for pymeeus: filename=PyMeeus-0.5.11-py3-none-any.whl size=730971 sha256=e07715b75457573b8fcbbf2acb68014c7aa3a8a3d7005135e3d5effe54a43acb Stored in directory: /Users/ark/Library/Caches/pip/wheels/33/3d/82/4579e9cca41ff991140b2e050bc6df3a38292f26e4fa06b15d Successfully built pymeeus Installing collected packages: pymeeus, korean-lunar-calendar, six, hijri-converter, convertdate, python-dateutil, holidays Successfully installed convertdate-2.4.0 hijri-converter-2.2.4 holidays-0.15 korean-lunar-calendar-0.2.1 pymeeus-0.5.11 python-dateutil-2.8.2 six-1.16.0
❯ python
import holidays
print(holidays.financial.ny_stock_exchange.NYSE(years=2022))
{datetime.date(2022, 1, 3): "New Year's Day (Observed)", datetime.date(2022, 1, 17): 'Martin Luther King Jr. Day', datetime.date(2022, 2, 21): "Washington's Birthday", datetime.date(2022, 4, 15): 'Good Friday', datetime.date(2022, 5, 30): 'Memorial Day', datetime.date(2022, 6, 20): 'Juneteenth National Independence Day (Observed)', datetime.date(2022, 7, 4): 'Independence Day', datetime.date(2022, 9, 5): 'Labor Day', datetime.date(2022, 11, 24): 'Thanksgiving Day', datetime.date(2022, 12, 26): 'Christmas Day (Observed)'}
In general you should use NewYorkStockExchange
class (or its alias NYSE
) of holidays.financial.ny_stock_exchange
module. Example:
from holidays.financial import ny_stock_exchange
nyse_holidays_2022 = ny_stock_exchange.NYSE(years=2022)
I hope this'll help you get started. I may be able to assist more if you provide the error you mentioned.
hi everyone! @arkid15r thank you so much for the complete explanation. Indeed, providing a complete issue report (with an enclosed code sample, whenever possible) is vital to obtain valuable support.
This said, everything explained here above should be more than enough to get things done in the right way. Willing to get deeper in all the possible ways to use python holidays, there are 2 other main sources to take into account:
While official documentation provides all the required details, unit test code include a near-100% coverage of the whole library, and therefore provides valid examples for all its use cases.
@aJetHorn please let us know if this clarifies your doubts, thx
The language used in the docs:
"The standard way to refer to a financial market is to use its ISO 10383 MIC (Market Identifier Code) as a “country” code when available."
Was interpreted as this usage being possible:
us_market_holidays = holidays.country_holidays('NYSE')
I guess I understand why usage is different, I just couldn't find it documented and couldn't find any code samples on Github. Thank you for clarifying.
Hi @aJetHorn , this definitely clarifies your issue report, thank you very much.
Although, as you could notice after, country_holidays('..')
method is meant for countries only, a similar method should in fact be available for financial holidays too (which is not yet the case: this went unnoticed since we split financial holidays from country ones). I'm then reopening this, and we will take care of it in the next release.
Thanks again :+1:
Hi @aJetHorn
I've just pushed in beta an update that should address your issue. This involved a larger refactoring regarding all the financial holidays code, including adding a new BaseHoliday property (market
), used for financial holidays instead of the usual country
.
Could you please make a check on it and confirm it works as expected?
Thanks!
Closing this out as the required functionality was added.