NOT FINISHED (but working so far). End of workflow. Coming back tomorrow (hopefully).
This commit is contained in:
parent
baf6614491
commit
62cbceba6f
@ -69,9 +69,11 @@ class SimpleStockData:
|
||||
# for simplicity: using the conversion factor of closing (.Close at the end)
|
||||
exchange_rates.append(tickers.tickers[i].history(start=self._period_start, end=self._period_end).Close)
|
||||
|
||||
self._exchange_df = pd.DataFrame(exchange_rates).T # transpose the dataframe (imagine just switching rows and columns)
|
||||
self._exchange_df = pd.DataFrame(
|
||||
exchange_rates).T # transpose the dataframe (imagine just switching rows and columns)
|
||||
self._exchange_df.columns = _from_currency_list # set the right names for the columns in the dataframe
|
||||
self._exchange_df[f"{self.to_currency}{self.to_currency}=X"] = 1.0 # for FROM and TO being equal: set factor to 1
|
||||
self._exchange_df[
|
||||
f"{self.to_currency}{self.to_currency}=X"] = 1.0 # for FROM and TO being equal: set factor to 1
|
||||
|
||||
return True
|
||||
|
||||
@ -86,18 +88,34 @@ class SimpleStockData:
|
||||
|
||||
info = yf.Ticker(self.ticker_list[idx]).info
|
||||
if key != "": # if just one specific information is wanted
|
||||
return info[key]
|
||||
return info[key.lower()]
|
||||
return info
|
||||
|
||||
def get_history(self, idx, interval="1d"):
|
||||
def get_history(self, idx, interval="1d", convert=True):
|
||||
"""
|
||||
Just a wrapper around the .history method of the yfinance Ticker class
|
||||
Just a wrapper around the .history method of the yfinance Ticker class.
|
||||
Adds a new column containing the internal index of the ticker.
|
||||
:param idx:
|
||||
the index of the share
|
||||
:param interval:
|
||||
granularity of data - valid values are 1m, 2m, 5m, 15m, 30m, 60m, 90m, 1h, 1d, 5d, 1wk, 1mo, 3mo
|
||||
:param convert:
|
||||
decides if the resulting values should be converted to the specified to_convert currency (given at
|
||||
object creation)
|
||||
:return: pandas.DataFrame
|
||||
"""
|
||||
|
||||
ret = self._get_history(idx, interval)
|
||||
return ret
|
||||
# TODO: Not working. Something is wrong with the access to the _exchange_df via [].
|
||||
|
||||
result = self._get_history(idx, interval)
|
||||
result["Ticker Index"] = idx
|
||||
ticker_currency = self.get_info(idx, "currency")
|
||||
|
||||
if convert:
|
||||
value_list = ["Open", "High", "Low", "Close"]
|
||||
for value in value_list:
|
||||
result["rating_name"] = f"{ticker_currency}{self.to_currency}=X"
|
||||
result["rating"] = self._exchange_df[f"{ticker_currency}{self.to_currency}=X"]
|
||||
result[f"{value}.conv"] = result[value] / result["rating"]
|
||||
|
||||
return result
|
||||
|
14
example1.py
14
example1.py
@ -2,14 +2,6 @@ from SimpleStockData import SimpleStockData
|
||||
|
||||
ssd = SimpleStockData(["BAS.DE", "AMZN"], "2023-11-20", "2023-11-24", "EUR")
|
||||
|
||||
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, "1h"))
|
||||
print(ssd._exchange_df)
|
||||
print(ssd._exchange_df)
|
||||
print(ssd.get_history(0, "1d"))
|
||||
print("---\n")
|
Loading…
Reference in New Issue
Block a user