Skip to content

Commit

Permalink
clean up financials
Browse files Browse the repository at this point in the history
  • Loading branch information
cortisiko committed Jun 26, 2024
1 parent ae071a0 commit 5e3da84
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 39 deletions.
2 changes: 1 addition & 1 deletion app/charts/plot_earnings.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def plot_earnings(self, container, ticker_symbol, frequency):
None
"""
ticker_object = ticker.get_ticker(ticker_symbol)
earnings_data = earning.get_earnings_data(ticker_object)
earnings_data = ticker_symbol.earnings
company_name = price_data.get_company_name(ticker_object, ticker_symbol)

data = self.get_freqency(earnings_data, ticker_symbol, frequency)
Expand Down
9 changes: 6 additions & 3 deletions app/financials/company_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ def get_company_profile(ticker_object):
try:
company_profile = ticker_object.summary_profile
return company_profile
except Exception as e:
except (AttributeError, KeyError, TypeError, ValueError) as e:
print(e)
return None


def get_company_sector(ticker_object, ticker_symbol):
Expand All @@ -41,8 +42,9 @@ def get_company_sector(ticker_object, ticker_symbol):
company_profile_object = get_company_profile(ticker_object)
company_sector = company_profile_object[ticker_symbol]["sector"]
return company_sector
except Exception as e:
except (AttributeError, KeyError, TypeError, ValueError) as e:
print(e)
return None


def get_company_summary_details(ticker_object, ticker_symbol):
Expand All @@ -60,5 +62,6 @@ def get_company_summary_details(ticker_object, ticker_symbol):
company_profile_object = get_company_profile(ticker_object)
summary_details = company_profile_object[ticker_symbol]["longBusinessSummary"]
return summary_details
except Exception as e:
except (AttributeError, KeyError, TypeError, ValueError) as e:
print(e)
return None
12 changes: 10 additions & 2 deletions app/financials/earnings.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
"""
method to get earnings
"""


def get_earnings_data(ticker_symbol):
"""
method to get earnings
"""
try:
earnings = ticker_symbol.earnings
return earnings

except Exception as e:
except (AttributeError, KeyError, TypeError, ValueError) as e:
print(e)
return None
22 changes: 10 additions & 12 deletions app/financials/income_statement_sheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
get_earnings_per_share(income_statement_data)
"""


# This is the income statement tab on the financials page in yahoo finance


Expand All @@ -25,8 +26,9 @@ def get_income_statement(ticker_object, frequency):
try:
income_statements = ticker_object.income_statement(frequency)
return income_statements
except Exception as e:
except (AttributeError, KeyError, TypeError, ValueError) as e:
print(e)
return None


def get_net_income(income_statement_data):
Expand All @@ -44,12 +46,10 @@ def get_net_income(income_statement_data):
if net_income is not None:
net_income = net_income / 1e3
return net_income
else:
print("There is no net income for", net_income)
except KeyError as e:
print("There is no net income for", net_income)
except (AttributeError, KeyError, TypeError, ValueError) as e:
print(f"KeyError: {e}")
except Exception as e:
print(e)
return None


def get_earnings_per_share(income_statement_data):
Expand All @@ -66,9 +66,7 @@ def get_earnings_per_share(income_statement_data):
basic_eps = income_statement_data["BasicEPS"]
if basic_eps is not None:
return basic_eps
else:
print("There is no basic EPS for", basic_eps)
except KeyError as e:
print(f"KeyError: {e}")
except Exception as e:
print(e)
print("There is no basic EPS for", basic_eps)
except (AttributeError, KeyError, TypeError, ValueError) as e:
print(f"Error: {e}")
return None
26 changes: 23 additions & 3 deletions app/financials/price.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
def get_price_data_object(ticker_object):
"""
File that contains helper functions for getting the stock price, and company name
"""


def get_price_data_object(ticker_object):
"""
Function to get the price data object
:param ticker_object:
:return: price object
"""
if ticker_object is not None:
price_object = ticker_object.price
return price_object
else:
print("User did not enter a valid ticker")
print("User did not enter a valid ticker")
return None


def get_current_stock_price(ticker_object, ticker_symbol):
"""
Function to get the current stock price
:param ticker_object:
:return: price object
"""
price_object = get_price_data_object(ticker_object)
current_stock_price = price_object[ticker_symbol]["regularMarketPrice"]
current_stock_price = float(round(current_stock_price, 2))
Expand All @@ -16,6 +30,12 @@ def get_current_stock_price(ticker_object, ticker_symbol):


def get_company_name(ticker_object, ticker_symbol):
"""
Function to get the company name
:param ticker_object:
:return: price object
"""

price_object = get_price_data_object(ticker_object)
company_name = price_object[ticker_symbol]["shortName"]

Expand Down
31 changes: 13 additions & 18 deletions app/financials/statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ def get_stock_statistics(ticker_object):
"""
try:
return ticker_object.financial_data
except Exception as e:
except (AttributeError, KeyError, TypeError, ValueError) as e:
print(e)

return None

def get_current_stock_price(ticker_object, ticker_symbol):
"""
Expand All @@ -48,7 +48,7 @@ def get_current_stock_price(ticker_object, ticker_symbol):
return current_stock_price
except (AttributeError, KeyError, TypeError, ValueError) as e:
print(f"KeyError: {e}")

return None


def get_debt_to_equity(ticker_object, ticker_symbol):
Expand All @@ -69,12 +69,11 @@ def get_debt_to_equity(ticker_object, ticker_symbol):
debt_to_equity = debt_to_equity / 100
debt_to_equity = float(round(debt_to_equity, 2))
return debt_to_equity
else:
print("There is no Debt to Equity Ratio for", ticker_symbol)
except KeyError as e:
print("There is no Debt to Equity Ratio for", ticker_symbol)
except (AttributeError, KeyError, TypeError, ValueError) as e:
print(f"KeyError: {e}")
except Exception as e:
print(e)
return None



def get_return_on_equity(ticker_object, ticker_symbol):
Expand All @@ -94,12 +93,10 @@ def get_return_on_equity(ticker_object, ticker_symbol):
if return_on_equity is not None:
return_on_equity = float(round(return_on_equity * 100, 2))
return return_on_equity
else:
print("There is no return on equity ratio for", ticker_symbol)
except KeyError as e:
print("There is no return on equity ratio for", ticker_symbol)
except (AttributeError, KeyError, TypeError, ValueError) as e:
print(f"KeyError: {e}")
except Exception as e:
print(e)
return None


def get_profit_margins(ticker_object, ticker_symbol):
Expand All @@ -119,9 +116,7 @@ def get_profit_margins(ticker_object, ticker_symbol):
if profit_margins is not None:
profit_margins = float(round(profit_margins * 100, 2))
return profit_margins
else:
print("There is no net profit margin for", ticker_symbol)
except KeyError as e:
print("There is no net profit margin for", ticker_symbol)
except (AttributeError, KeyError, TypeError, ValueError) as e:
print(f"KeyError: {e}")
except Exception as e:
print(e)
return None

0 comments on commit 5e3da84

Please sign in to comment.