Implemented first wrappers: get_info and _get_history for Ticker.info and Ticker.history()
This commit is contained in:
parent
5ad88bbc00
commit
51a9d8d673
41
SimpleStockData.py
Executable file
41
SimpleStockData.py
Executable file
@ -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
|
14
example1.py
Normal file
14
example1.py
Normal file
@ -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"))
|
Loading…
Reference in New Issue
Block a user