def calculate_ps_metrics(stock): yahoo_stock = YahooFinancials(stock.symbol) market_cup = yahoo_stock.get_market_cap() if stock.target_avg_sales: multiplier = FilteredStocks.get_multiplier( stock.target_avg_sales[-1]) target_avg_sales = float(stock.target_avg_sales[:-1]) * multiplier try: stock.price_to_sell_ratio = round( market_cup / target_avg_sales, 2) stock.ps_to_growth_ratio = round( stock.price_to_sell_ratio / float(stock.target_sales_growth[:-1]), 2) ev = (yahoo_stock.get_key_statistics_data()[stock.symbol] ["enterpriseValue"]) profit_margins = (yahoo_stock.get_key_statistics_data()[ stock.symbol]["profitMargins"]) stock.ev_to_sell_ratio = round(ev / target_avg_sales, 2) stock.gross_margins = round( yahoo_stock.get_gross_profit() / yahoo_stock.get_total_revenue() * 100, 2) ev_to_profit_ratio = round( stock.ev_to_sell_ratio / profit_margins, 2) print("gross_margins : " + str(stock.gross_margins)) print("ev sells : " + str(stock.ev_to_sell_ratio)) print("ev / earnings : " + str(ev_to_profit_ratio)) print("ps_to_growth : " + str(stock.ps_to_growth_ratio)) print("sales targets:" + str(stock.target_sales_growth[:-1])) print("growth adujsted ev / sells: " + str( round( stock.ev_to_sell_ratio / float(stock.target_sales_growth[:-1]), 2))) except Exception as e: print(str(e))
def getMarketData(): tickers = 'AAPL' financials = YahooFinancials(tickers) # company_stock_price = financials.get_stock_price_data() #gets stock price information historical_stock_prices_data = financials.get_historical_price_data( '2015-11-21', '2020-11-21', 'daily') #gets historical daily stock price of company # get_Div_data(historical_stock_prices_data[tickers]) get_stock_price_data(historical_stock_prices_data[tickers]) # company_balance_sheet_data_qt = financials.get_financial_stmts('quarterly', 'balance') #get balance sheet # company_income_statement_data_qt = financials.get_financial_stmts('quarterly', 'income') #get income statement company_key_statistics_data = financials.get_key_statistics_data( ) #includes profit margins, forward eps, yearly change etc. # get_forward_pe(company_key_statistics_data[tickers]) # get_trailing_eps(company_key_statistics_data[tickers]) # get_foward_eps(company_key_statistics_data[tickers]) # get_ytdReturn(company_key_statistics_data[tickers]) company_earnings_data = financials.get_stock_earnings_data( ) #historical eps only for 1 year span # get_earnings_data(company_earnings_data[tickers]) company_dividend_yield = financials.get_dividend_yield( ) #current dividends yield company_dividend = financials.get_dividend_rate() #current dividends rate company_avg_div_yield_1year = financials.get_annual_avg_div_yield( ) #average 1 year div yield company_avg_div_yield_5year = financials.get_five_yr_avg_div_yield( ) #average 5 year div yield company_eps = financials.get_earnings_per_share() #current eps company_pe = financials.get_pe_ratio() #current pe ratio company_beta = financials.get_beta() #current beta company_current_stock_price = financials.get_current_price( ) #current stock price company_revenue = financials.get_total_revenue() #current company revenue company_operating_income = financials.get_operating_income( ) #current company operating income company_net_income = financials.get_net_income() #current net income company_yearly_high = financials.get_yearly_high() #get yearly high company_yearly_low = financials.get_yearly_low() #get yearly low company_moving_50 = financials.get_50day_moving_avg( ) #50 day moving average of stock company_moving_200 = financials.get_200day_moving_avg( ) #200 day moving average of stock
async def stock(ctx, ticker, info): yahoo_financials = YahooFinancials(ticker) if (info == "current"): await ctx.send(ticker.upper() + " current share price: $" + str(yahoo_financials.get_current_price())) if (info == "open"): await ctx.send(ticker.upper() + " share price at opening: $" + str(yahoo_financials.get_open_price())) if (info == "prevclose"): await ctx.send(ticker.upper() + " share priced at previous close: $" + str(yahoo_financials.get_prev_close_price())) if (info == "cap"): await ctx.send(ticker.upper() + " market cap: $" + str("{:,}".format(yahoo_financials.get_market_cap()))) if (info == "dailylow"): await ctx.send(ticker.upper() + " daily low: $" + str(yahoo_financials.get_daily_low())) if (info == "dailyhigh"): await ctx.send(ticker.upper() + " daily high: $" + str(yahoo_financials.get_daily_high())) if (info == "yearlow"): await ctx.send(ticker.upper() + " yearly low: $" + str(yahoo_financials.get_yearly_low())) if (info == "yearhigh"): await ctx.send(ticker.upper() + " yearly high: $" + str(yahoo_financials.get_yearly_high())) if (info == "rev"): await ctx.send(ticker.upper() + " total revenue: $" + str("{:,}".format(yahoo_financials.get_total_revenue())) ) if (info == "net"): await ctx.send(ticker.upper() + " net income: $" + str("{:,}".format(yahoo_financials.get_net_income()))) if (info == "op"): await ctx.send( ticker.upper() + " operating income: $" + str("{:,}".format(yahoo_financials.get_operating_income()))) if (info == "profit"): await ctx.send(ticker.upper() + " gross profit: $" + str("{:,}".format(yahoo_financials.get_gross_profit())))
from yahoofinancials import YahooFinancials yahoo_financials = YahooFinancials(list_names) # pullling operating income data for most recent year reported minilist_opinc = yahoo_financials.get_operating_income() minilist_opinc_df = pd.Series(minilist_opinc).to_frame('op_inc') print(minilist_opinc_df) # pulling operating expense data for most recent year reported minilist_opex = yahoo_financials.get_total_operating_expense() minilist_opex_df = pd.Series(minilist_opex).to_frame('op_ex') print(minilist_opex_df) # pulling total revenue data for most recent year reported minilist_rev = yahoo_financials.get_total_revenue() minilist_rev_df = pd.Series(minilist_rev).to_frame('rev') print(minilist_rev_df) mergeddf = minilist_opinc_df.join( minilist_opex_df ) # merging operating income dataframe and operating expense dataframe mergeddf = mergeddf.join(minilist_rev_df) # joining revenue dataframe mergeddf['MTC'] = mergeddf['op_inc'] / mergeddf[ 'op_ex'] # generating col for markup on total cost mergeddf['OM'] = mergeddf['op_inc'] / mergeddf[ 'rev'] # generating col for operating margin mergeddf.drop( ['op_inc', 'op_ex'], axis=1,