Skip to content

Commit

Permalink
Update datafetcher.py
Browse files Browse the repository at this point in the history
  • Loading branch information
GiorgioMB authored Apr 8, 2024
1 parent f58ba09 commit 11efd37
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion stockdatamanager/datafetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def __init__(self, ticker:str = None, period:str = 'max'):
self.income_statement, self.balance_sheet, self.cashflow = self.get_financial_statements(self.yf_stock)
else:
print("Warning, no ticker has been specified. Only get_ticker(), get_risk_free_rate() and get_sp500() methods will work.")

def get_ticker(self, company_name:str)->str:
"""
This function returns the ticker of a company, given the name.
Expand All @@ -67,6 +68,7 @@ def get_ticker(self, company_name:str)->str:
company_code = data["quotes"][0]["symbol"]
return company_code
raise AssertionError("Company may not be listed")

def get_historical_data(self, symbol:str, timeframe:str)-> Tuple[pd.DataFrame, str]:
"""
This function returns a PANDAS dataframe about the price of the company and the
Expand Down Expand Up @@ -280,7 +282,6 @@ def get_price_to_sales(self) -> float:
revenue = self.income_statement.loc['Total Revenue'].iloc[0]
return self.yf_stock.info['marketCap'] / revenue


def get_risk_free_rate(self, horizon:str = '13 weeks') -> float:
"""Returns the risk free rate, given an horizon.
Accepted inputs are:
Expand Down Expand Up @@ -316,3 +317,8 @@ def get_earnings_growth_rate(self) -> float:
"""Returns the growth rate"""
return self.yf_stock.info['earningsQuarterlyGrowth']

def __repr__(self) -> str:
try:
return f"Stock: {self.yf_stock.ticker}\nLast Close Value: {self.df['Close'].iloc[-1]}\nBeta: {self.get_beta_value()}"
except:
return f"Stock: {self.yf_stock.ticker}\nLast Close Value: {self.df['Close'].iloc[-1]}\nBeta: Not available"

0 comments on commit 11efd37

Please sign in to comment.