import yfinance as yf class SimpleStockData: """ Function __init__ - ticker_list: list that contains all stocks/exchange rates (yfinance considers both as "Tickers") - to_currency: currency to convert rates to """ def __init__(self, ticker_list: list, to_currency: str = ""): self.ticker_list = ticker_list self.to_currency = to_currency def _get_history(self, idx, start, end, interval="1d"): """ Function for internal use; Just a wrapper around the .history method of the yfinance Ticker class :param idx: the index of the share :param start: start date (format YYYY-MM-DD) :param end: end date (format YYYY-MM-DD) :param interval: granularity of data - valid values are 1m, 2m, 5m, 15m, 30m, 60m, 90m, 1h, 1d, 5d, 1wk, 1mo, 3mo :return: pandas.DataFrame """ return yf.Ticker(self.ticker_list[idx]).history(interval=interval, start=start, end=end) def get_info(self, idx, key=""): """ :param idx: the index of the share :param key: OPTIONAL. gives which specific datum is wanted :return: """ info = yf.Ticker(self.ticker_list[idx]).info if key != "": # if just one specific information is wanted return info[key] return info