2021-07-03 21:24:19 +08:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: UTF-8 -*-
|
|
|
|
#
|
2021-11-21 04:13:48 +08:00
|
|
|
# yfinance - market data downloader
|
2021-07-03 21:24:19 +08:00
|
|
|
# https://github.com/ranaroussi/yfinance
|
|
|
|
|
|
|
|
"""
|
|
|
|
Sanity check for most common library uses all working
|
|
|
|
- Stock: Microsoft
|
|
|
|
- ETF: Russell 2000 Growth
|
|
|
|
- Mutual fund: Vanguard 500 Index fund
|
|
|
|
- Index: S&P500
|
|
|
|
- Currency BTC-USD
|
|
|
|
"""
|
|
|
|
|
|
|
|
import yfinance as yf
|
|
|
|
import unittest
|
2023-02-16 08:43:42 +08:00
|
|
|
import logging
|
|
|
|
|
|
|
|
logging.basicConfig(level=logging.DEBUG)
|
2021-07-03 21:24:19 +08:00
|
|
|
|
|
|
|
symbols = ['MSFT', 'IWO', 'VFINX', '^GSPC', 'BTC-USD']
|
|
|
|
tickers = [yf.Ticker(symbol) for symbol in symbols]
|
|
|
|
|
|
|
|
|
|
|
|
class TestTicker(unittest.TestCase):
|
|
|
|
def test_info_history(self):
|
|
|
|
for ticker in tickers:
|
|
|
|
# always should have info and history for valid symbols
|
|
|
|
assert(ticker.info is not None and ticker.info != {})
|
2021-12-31 07:37:52 +08:00
|
|
|
history = ticker.history(period="max")
|
|
|
|
assert(history.empty is False and history is not None)
|
2021-07-03 21:24:19 +08:00
|
|
|
|
|
|
|
def test_attributes(self):
|
|
|
|
for ticker in tickers:
|
|
|
|
ticker.isin
|
|
|
|
ticker.major_holders
|
|
|
|
ticker.institutional_holders
|
|
|
|
ticker.mutualfund_holders
|
|
|
|
ticker.dividends
|
|
|
|
ticker.splits
|
|
|
|
ticker.actions
|
2022-10-16 15:34:23 +08:00
|
|
|
ticker.shares
|
2021-07-03 21:24:19 +08:00
|
|
|
ticker.info
|
|
|
|
ticker.calendar
|
|
|
|
ticker.recommendations
|
|
|
|
ticker.earnings
|
|
|
|
ticker.quarterly_earnings
|
2022-10-16 15:34:23 +08:00
|
|
|
ticker.income_stmt
|
|
|
|
ticker.quarterly_income_stmt
|
2021-07-03 21:24:19 +08:00
|
|
|
ticker.balance_sheet
|
|
|
|
ticker.quarterly_balance_sheet
|
|
|
|
ticker.cashflow
|
|
|
|
ticker.quarterly_cashflow
|
2022-10-17 23:40:12 +08:00
|
|
|
ticker.recommendations_summary
|
2021-07-12 17:34:18 +08:00
|
|
|
ticker.analyst_price_target
|
|
|
|
ticker.revenue_forecasts
|
2021-07-03 21:24:19 +08:00
|
|
|
ticker.sustainability
|
|
|
|
ticker.options
|
2021-10-16 22:47:43 +08:00
|
|
|
ticker.news
|
2022-10-17 23:40:12 +08:00
|
|
|
ticker.earnings_trend
|
2022-06-16 00:42:22 +08:00
|
|
|
ticker.earnings_dates
|
2022-10-16 15:34:23 +08:00
|
|
|
ticker.earnings_forecasts
|
2021-07-03 21:24:19 +08:00
|
|
|
|
|
|
|
def test_holders(self):
|
|
|
|
for ticker in tickers:
|
|
|
|
assert(ticker.info is not None and ticker.info != {})
|
|
|
|
assert(ticker.major_holders is not None)
|
|
|
|
assert(ticker.institutional_holders is not None)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|