Skip to content

Commit

Permalink
fix second set of linting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
cortisiko committed Jun 12, 2024
1 parent 1fb9384 commit 8175919
Show file tree
Hide file tree
Showing 20 changed files with 161 additions and 87 deletions.
1 change: 0 additions & 1 deletion app/charts/plot_cash_based_earnings.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ def plot_cash_to_earnings(self, container, ticker_symbol, frequency):
else:
print(f"{company_name} has low quality earnings")


ax = self.fig.add_subplot(111)
y_label_text = "Amount in $"
graph_title = company_name + " " + self.title
Expand Down
13 changes: 7 additions & 6 deletions app/charts/plot_cash_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,21 @@ class CashFlowGraph:
"""
Free cash flow graph class.
"""

def __init__(self):
self.canvas = None
self.fig = Figure(figsize=(12, 5), dpi=80)
self.y_label_text = "Free Cash Flow in $"

def plot_cash_graph(self, container, ticker_symbol, frequency):
"""
Plots the Cash flow for a given stock symbol and frequency.
Plots the Cash flow for a given stock symbol and frequency.
:param container: The container widget where the plot will be displayed.
:param ticker_symbol: The stock symbol.
:param frequency: The frequency of the data (annual or quarterly).
:return: None
"""
:param container: The container widget where the plot will be displayed.
:param ticker_symbol: The stock symbol.
:param frequency: The frequency of the data (annual or quarterly).
:return: None
"""
ticker_object = ticker.get_ticker(
ticker_symbol
) ## Gets the ticker object so you can access the various objects
Expand Down
7 changes: 3 additions & 4 deletions app/charts/plot_earnings.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,15 @@

class EarningsGraph:
"""
Earnings graph class.
"""
Earnings graph class.
"""

def __init__(self):
self.canvas = None
self.fig = Figure(figsize=(12, 5), dpi=80)
self.y_label_text = "Amount in $"
self.earnings_title = "Earnings"



def plot_earnings(self, container, ticker_symbol, frequency):
ticker_object = ticker.get_ticker(
ticker_symbol
Expand Down
File renamed without changes.
99 changes: 72 additions & 27 deletions app/financials/analyze.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
from app.financials import statistics as statistics_tab, balancesheet as balance_sheet, \
companyprofile as company_profile, cash_flow_sheet as cash_flow_page, summary as summary_page, price as price_data
from app.financials import (
statistics as statistics_tab,
balancesheet as balance_sheet,
companyprofile as company_profile,
cash_flow_sheet as cash_flow_page,
summary as summary_page,
price as price_data,
)

from app.helpers import tickers as ticker

Expand All @@ -9,17 +15,24 @@
def get_company_sector(ticker_symbol):
try:
ticker_symbol_object = ticker.get_ticker(
ticker_symbol) # Gets the ticker_symbol object so you can access the various objects
company_sector = company_profile.get_company_sector(ticker_symbol_object, ticker_symbol)
ticker_symbol
) # Gets the ticker_symbol object so you can access the various objects
company_sector = company_profile.get_company_sector(
ticker_symbol_object, ticker_symbol
)
return company_sector
except TypeError:
return error_message


def get_company_details(ticker_symbol_symbol):
try:
ticker_symbol_object = ticker.get_ticker(
ticker_symbol_symbol) # Gets the ticker_symbol object so you can access the various objects
company_details = company_profile.get_company_summary_details(ticker_symbol_object, ticker_symbol_symbol)
ticker_symbol_symbol
) # Gets the ticker_symbol object so you can access the various objects
company_details = company_profile.get_company_summary_details(
ticker_symbol_object, ticker_symbol_symbol
)
return company_details
except TypeError:
return error_message
Expand All @@ -28,8 +41,11 @@ def get_company_details(ticker_symbol_symbol):
def get_stock_name(ticker_symbol_symbol):
try:
ticker_symbol_object = ticker.get_ticker(
ticker_symbol_symbol) # Gets the ticker_symbol object so you can access the various objects
stock_name = price_data.get_company_name(ticker_symbol_object, ticker_symbol_symbol)
ticker_symbol_symbol
) # Gets the ticker_symbol object so you can access the various objects
stock_name = price_data.get_company_name(
ticker_symbol_object, ticker_symbol_symbol
)
return stock_name
except TypeError:
return error_message
Expand All @@ -39,74 +55,103 @@ def get_stock_name(ticker_symbol_symbol):

def get_current_stock_price(ticker_symbol_symbol):
ticker_symbol_object = ticker.get_ticker(
ticker_symbol_symbol) # Gets the ticker_symbol object so you can access the various objects
current_stock_price = price_data.get_current_stock_price(ticker_symbol_object, ticker_symbol_symbol)
ticker_symbol_symbol
) # Gets the ticker_symbol object so you can access the various objects
current_stock_price = price_data.get_current_stock_price(
ticker_symbol_object, ticker_symbol_symbol
)

return current_stock_price


def get_eps(ticker_symbol_symbol):
ticker_symbol_object = ticker.get_ticker(
ticker_symbol_symbol) # Gets the ticker_symbol object so you can access the various objects
ticker_symbol_symbol
) # Gets the ticker_symbol object so you can access the various objects
eps = summary_page.earnings_per_share(ticker_symbol_object, ticker_symbol_symbol)
return eps


def get_pe_ratio(ticker_symbol_symbol):
ticker_symbol_object = ticker.get_ticker(
ticker_symbol_symbol) # Gets the ticker_symbol object so you can access the various objects
ticker_symbol_symbol
) # Gets the ticker_symbol object so you can access the various objects
pe_ratio = summary_page.get_pe_ratio(ticker_symbol_object, ticker_symbol_symbol)

return pe_ratio


def get_debt_to_equity(ticker_symbol):
ticker_symbol_object = ticker.get_ticker(
ticker_symbol) # Gets the ticker_symbol object so you can access the various objects
debt_to_equity_ratio = statistics_tab.get_debt_to_equity(ticker_symbol_object, ticker_symbol)
ticker_symbol
) # Gets the ticker_symbol object so you can access the various objects
debt_to_equity_ratio = statistics_tab.get_debt_to_equity(
ticker_symbol_object, ticker_symbol
)

return debt_to_equity_ratio


def get_return_on_equity(ticker_symbol):
ticker_symbol_object = ticker.get_ticker(
ticker_symbol) # Gets the ticker_symbol object so you can access the various objects
return_on_equity = statistics_tab.get_return_on_equity(ticker_symbol_object, ticker_symbol)
ticker_symbol
) # Gets the ticker_symbol object so you can access the various objects
return_on_equity = statistics_tab.get_return_on_equity(
ticker_symbol_object, ticker_symbol
)

return return_on_equity


def get_profit_margin(ticker_symbol):
ticker_symbol_object = ticker.get_ticker(
ticker_symbol) # Gets the ticker_symbol object so you can access the various objects
profit_margin = statistics_tab.get_profit_margins(ticker_symbol_object, ticker_symbol)
ticker_symbol
) # Gets the ticker_symbol object so you can access the various objects
profit_margin = statistics_tab.get_profit_margins(
ticker_symbol_object, ticker_symbol
)

return profit_margin


def get_cash_burn_number(ticker_symbol):
global most_recent_cash_flow
ticker_symbol_object = ticker.get_ticker(
ticker_symbol) # Gets the ticker_symbol object so you can access the various objects
balance_sheet_data_frame = balance_sheet.get_balance_sheet_data(ticker_symbol_object, 'a')
cash_flow_data_frame = cash_flow_page.get_cash_flow_data(ticker_symbol_object, 'a')
ticker_symbol
) # Gets the ticker_symbol object so you can access the various objects
balance_sheet_data_frame = balance_sheet.get_balance_sheet_data(
ticker_symbol_object, "a"
)
cash_flow_data_frame = cash_flow_page.get_cash_flow_data(ticker_symbol_object, "a")

cash_and_cash_equivalents = balance_sheet.get_cash_and_expenses(balance_sheet_data_frame,ticker_symbol)
cash_and_cash_equivalents = balance_sheet.get_cash_and_expenses(
balance_sheet_data_frame, ticker_symbol
)

"""
because balance sheet does not have a TTM.## if the size of the cash flow data frame > balance sheet select
the most recent year(not TTM)
"""
try:
if cash_flow_data_frame.shape[0] > balance_sheet_data_frame.shape[0]:
most_recent_cash_flow = cash_flow_page.get_most_recent_cash_flow_total(cash_flow_data_frame, -2)
most_recent_cash_flow = cash_flow_page.get_most_recent_cash_flow_total(
cash_flow_data_frame, -2
)

cash_burn = cash_flow_page.calculate_cash_burn(cash_and_cash_equivalents, most_recent_cash_flow)
cash_burn = cash_flow_page.calculate_cash_burn(
cash_and_cash_equivalents, most_recent_cash_flow
)

ticker_symbol_name = get_stock_name(ticker_symbol)
if cash_burn < 0:
print(f'{ticker_symbol_name} is already running out of money. Their cash burn is:{cash_burn:,.1f} months')
print(
f"{ticker_symbol_name} is already running out of money. Their cash burn is:{cash_burn:,.1f} months"
)
else:
print(f'It will take {cash_burn:,.1f} months before {ticker_symbol_name} runs out of money')
print(
f"It will take {cash_burn:,.1f} months before {ticker_symbol_name} runs out of money"
)
except Exception as e:
print(f'yikes, seems like I cannot get the cash burn for {ticker_symbol} because "{e}"')
print(
f'yikes, seems like I cannot get the cash burn for {ticker_symbol} because "{e}"'
)
11 changes: 6 additions & 5 deletions app/financials/balancesheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,20 @@ def get_balance_sheet_data(ticker_symbol, frequency):

def get_long_term_debt(long_term_debt_data):
try:
long_term_debt = long_term_debt_data['LongTermDebt']
long_term_debt = long_term_debt_data["LongTermDebt"]
long_term_debt = long_term_debt / 1e3

return long_term_debt
except KeyError:
print(error_message)


def get_cash_and_expenses(balance_sheet_data,ticker_symbol):
def get_cash_and_expenses(balance_sheet_data, ticker_symbol):
try:
cash_and_cash_equivalents = balance_sheet_data['CashAndCashEquivalents'].iloc[
-1] ## getting the data for the most recent year
cash_and_cash_equivalents = balance_sheet_data["CashAndCashEquivalents"].iloc[
-1
] ## getting the data for the most recent year
cash_and_cash_equivalents = cash_and_cash_equivalents / 1e3
return cash_and_cash_equivalents
except Exception as e:
print(f'I do not see anything on the balance sheet for {ticker_symbol}')
print(f"I do not see anything on the balance sheet for {ticker_symbol}")
10 changes: 7 additions & 3 deletions app/financials/cash_flow_sheet.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,36 @@
# This is the cashflow tab on the financials page in yahoo finance


def get_cash_flow_data(ticker_object, frequency):
cash_flow_data = ticker_object.cash_flow(frequency=frequency)
return cash_flow_data


def get_free_cash_flow(cash_flow_data):
free_cash_flow = cash_flow_data['FreeCashFlow']
free_cash_flow = cash_flow_data["FreeCashFlow"]
free_cash_flow = free_cash_flow / 1e3

return free_cash_flow


def get_operating_cash_flow(cash_flow_data):
operating_cash_flow = cash_flow_data['OperatingCashFlow']
operating_cash_flow = cash_flow_data["OperatingCashFlow"]
operating_cash_flow = operating_cash_flow / 1e3

return operating_cash_flow


def get_most_recent_cash_flow_total(cash_flow_data, position):
try:
most_recent_cash_flow = cash_flow_data['FreeCashFlow'].iloc[position] ## takes the most recent cashflow
most_recent_cash_flow = cash_flow_data["FreeCashFlow"].iloc[
position
] ## takes the most recent cashflow
most_recent_cash_flow = most_recent_cash_flow / 1e3
return most_recent_cash_flow
except Exception as e:
print(e)


def calculate_cash_burn(cash_and_cash_equivalents, free_cash_flow):
cash_burn = cash_and_cash_equivalents / free_cash_flow
cash_burn = cash_burn * 12
Expand Down
5 changes: 3 additions & 2 deletions app/financials/companyprofile.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"""


def get_company_profile(ticker_object):
try:
company_profile = ticker_object.summary_profile
Expand All @@ -14,13 +15,13 @@ def get_company_profile(ticker_object):

def get_company_sector(ticker_object, ticker_symbol):
company_profile_object = get_company_profile(ticker_object)
company_sector = company_profile_object[ticker_symbol]['sector']
company_sector = company_profile_object[ticker_symbol]["sector"]

return company_sector


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']
summary_details = company_profile_object[ticker_symbol]["longBusinessSummary"]

return summary_details
3 changes: 2 additions & 1 deletion app/financials/incomestatementsheet.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# This is the income statement tab on the financials page in yahoo finance


def get_income_statement(ticker_object, frequency):
income_statements = ticker_object.income_statement(frequency)

return income_statements


def get_net_income(income_statement_data):
net_income = income_statement_data['NetIncome']
net_income = income_statement_data["NetIncome"]

if net_income is not None:
net_income = net_income / 1e3
Expand Down
12 changes: 6 additions & 6 deletions app/financials/price.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@

def get_price_data_object(ticker_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")


def get_current_stock_price(ticker_object,ticker_symbol):
def get_current_stock_price(ticker_object, ticker_symbol):
price_object = get_price_data_object(ticker_object)
current_stock_price = price_object[ticker_symbol]['regularMarketPrice']
current_stock_price = price_object[ticker_symbol]["regularMarketPrice"]
current_stock_price = float(round(current_stock_price, 2))

return current_stock_price

def get_company_name(ticker_object,ticker_symbol):

def get_company_name(ticker_object, ticker_symbol):
price_object = get_price_data_object(ticker_object)
company_name = price_object[ticker_symbol]['shortName']
company_name = price_object[ticker_symbol]["shortName"]

return company_name
Loading

0 comments on commit 8175919

Please sign in to comment.