diff --git a/SimpleStockData.py b/SimpleStockData.py new file mode 100755 index 0000000..a521986 --- /dev/null +++ b/SimpleStockData.py @@ -0,0 +1,41 @@ +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 diff --git a/example1.py b/example1.py new file mode 100644 index 0000000..2ad9b45 --- /dev/null +++ b/example1.py @@ -0,0 +1,14 @@ +from SimpleStockData import SimpleStockData + +ssd = SimpleStockData(["BAS.DE", "AMZN"]) + +print(ssd.get_info(0)) +print(ssd.get_info(0, "address1")) +print(ssd.get_info(0, "country")) +print(ssd.get_info(0, "currency")) +print(ssd.get_info(0, "website")) +print() +print(ssd.get_info(1)) +print(ssd.get_info(1, "currency")) +print(ssd.get_info(1, "website")) +print(ssd._get_history(0, "2023-11-24", "2023-11-25", "1h"))