Exemple #1
0
def get_div_yield(symbol):

    stock = YahooFinancials(symbol)
    if stock.get_dividend_yield() != None:
        y = stock.get_dividend_yield()
    elif stock.get_summary_data()[symbol] != None:
        y = stock.get_summary_data()[symbol]['yield']
    else:
        y = 0

    if y == None:
        return 0
    else:
        return y
Exemple #2
0
def summary_data(ticker):
    #    summary_data_list = []
    #    for ticker in tickers:
    yahoo_financials = YahooFinancials(ticker)
    ass = yahoo_financials.get_summary_data(reformat=True)
    summary_data = pd.DataFrame.from_dict(ass).T
    #        summary_data_list.append(summary_data)
    return summary_data
Exemple #3
0
 def getMarketCap(self, ticker):
     # retrieve stock market cap
     # ----Input-----
     # ticker: ticker name for the stock
     # ----output----
     # stock market cap
     dataSource = YahooFinancials(ticker)
     return dataSource.get_summary_data()[ticker]['marketCap']
Exemple #4
0
def fundamentals(tickers, begin="2020-05-26", end="2020-06-26",):
    format_header = '{:>6} {:>6} {:>6} {:>6} {:>6} {:>6} {:>6} {:>6} {:>6} {:>6} {:>10} {:>10}'
    format_numbers = '{:>6} {:>6} {:>6} {:>6} {:>6} {:>6} {:>6} {:>6} {:>6}  {:>6} {:>10.2e} {:>10.2E}'
    print(format_header.format('ticker', 'P/E', 'EARNSH', 'BK/PR', 'DY', 'DR', 'VAR', 'PEG', 'PS', 'PCI', 'VOLPR', 'CM',))

    for ticker in tickers:
        yf = YF(ticker)

        try:
            pe = get_number_for_None(get_number_for_None(yf.get_pe_ratio()))
            prices = yf.get_historical_price_data(begin, end, "daily")[ticker]['prices']
            stat_pr = calc_statistics(prices)
            var_pr = get_number_for_None(100 * stat_pr[1] / stat_pr[0])
            volume = get_number_for_None(stat_pr[4])
            es = get_number_for_None(yf.get_earnings_per_share())
            sh = get_number_for_None(yf.get_num_shares_outstanding(price_type='current'))
        
            ''' "pegRatio" "priceToBook" "heldPercentInstitutions" '''
            
            statistics = yf.get_key_statistics_data()[ticker]
            summary = yf.get_summary_data()[ticker]
            peg = get_number_for_None(statistics["pegRatio"])
            PCI = get_number_for_None(statistics["heldPercentInstitutions"])
            bv = yf.get_key_statistics_data()[ticker]['bookValue']
            pr = yf.get_current_price()

            if pr is not None and bv is not None:
                pr_bv = get_number_for_None(pr/bv)
            else:
                pr_bv = '-99.99'

            f_s = yf.get_financial_stmts('annual', 'income')['incomeStatementHistory'][ticker][0]
            f_s_key = list(f_s.keys())[0]
            totalRevenue = f_s[f_s_key]['totalRevenue']
            outstanding = statistics["sharesOutstanding"]
            rev_per_share = totalRevenue / outstanding
            
            if pr is not None and es is not None:
                p_s = get_number_for_None(rev_per_share/float(es))
            else:
                p_s = '99'

              
            dy = get_number_for_None(yf.get_dividend_yield())
            dr = get_number_for_None(yf.get_dividend_rate())
        
            volume10days = summary['averageVolume10days']
            marketCap = summary['marketCap']
        
            # float(volume)*pr
            # float(sh)*pr)
            print(format_numbers.format(ticker, pe, es, pr_bv, dy, dr, var_pr, peg, p_s, PCI, volume10days, marketCap))
        except Exception as e:
            print(ticker, e)
Exemple #5
0
 def _DownloadTotalAssetsFromYahooFinance(self, symbols: List[Text]) -> List[Optional[Text]]:
   csv_data = []
   assets = YahooFinancials(symbols)
   summaries = assets.get_summary_data()
   for symbol in symbols:
     today = datetime.datetime.now().strftime("%Y-%m-%d")
     if symbol in summaries and 'totalAssets' in summaries[symbol] and summaries[symbol]['totalAssets'] is not None:
       lines = ['Date,Amount']  # Header
       total_assets = summaries[symbol]['totalAssets']
       csv_data.append(f'Date,TotalAssets\n{today},{total_assets}\n')
     else:
       csv_data.append(None)
   return csv_data
Exemple #6
0
def defaultapi(ticker):
    tick = YF(ticker)
    print(tick.get_summary_data())
    print(mark)
    print(tick.get_stock_quote_type_data())
    print(mark)
    print(tick.get_stock_price_data())
    print(mark)
    print(tick.get_current_price())
    print(mark)
    print(tick.get_dividend_rate())
    try:
        r = tick._cache.keys()
    except AttributeError:
        pass
    else:
        print(mark)
        print(r)
Exemple #7
0
    summary_ticker['diff10Av'] = 100 * diff10Av > limit


def set_ticker(summary_ticker, ticker):
    summary_ticker['ticker'] = ticker


if __name__ == '__main__':
    str_out = '      '
    for key in keys:
        str_out += ' ' + keys_head[key]
    print(str_out)
    for ticker in tickers:
        try:
            yf = YahooFinancials(ticker)
            summary = yf.get_summary_data()
            info_dict[ticker] = summary[ticker]
            # fiftyTwoWeekHigh
            calc_pc_fifty(summary[ticker], 'fiftyTwoWeekHigh')
            volume_diff(summary[ticker])
            str_out = ticker
            for key in keys:
                try:
                    resp = summary[ticker][key]
                    if resp == True or resp == False:
                        str_out += ' ' + "{}".format(resp)
                    else:
                        str_out += ' ' + "{0:.1f}".format(resp)
                except Exception as e:
                    str_out += ' ' + "{:12.12}".format(resp)
Exemple #8
0
    tickerDataFrame = pd.read_csv(csvPath)
    tickerSeries = tickerDataFrame['ticker'][0:nStocks]

    #get the list of tickers from the column named ticker
    #create ASX stocks by appending .AX to the stock name
    if asxStocks:
        for i in range(len(tickerSeries)):
            tickerSeries[i] = tickerSeries[i] + '.AX'

    print('Loaded in tickers series -->\n ', tickerSeries)

    return tickerSeries


if __name__ == '__main__':

    #load ticker series
    #here we use the ASX 200 largest companies by market capitalisation
    tickerSeries = tickers_from_csv(CSV_PATH, nStocks=5)

    #create the YahooFinancials connection object
    stocks = YahooFinancials(tickerSeries)

    #Pull the data and time it
    startTime = time.time()
    data = stocks.get_summary_data()
    timeTaken = time.time() - startTime
    print('Download took {t} seconds'.format(t=timeTaken))

    stockDataFrame = pd.DataFrame(data)
    stockDataFrame.to_csv(OUTPUT_PATH)