# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3 (ipykernel)
#     language: python
#     name: python3
# ---

# +
import sys

sys.path.append('../mylib')

from yahoo import Yahoo
# -

# my_yahoo = Yahoo('CVS')
my_yahoo = Yahoo('HYG')

type(my_yahoo)

s_dict=my_yahoo.get()

s_dict.get('open')

s_dict['open']

for key in s_dict.keys():
    print(key)


def return_shortened_list(keyword, full_key_enum):
    short_list = []
    for the_key in full_key_enum:
            # print(the_key)
            if keyword in the_key:
                short_list.append(the_key)
    return(short_list)


my_ratios = return_shortened_list('Ratio', s_dict.keys())
my_ratios

full_list = s_dict.keys()
my_operating = return_shortened_list('oper', full_list)
my_operating
my_margins = return_shortened_list('Margin', full_list)
my_margins
my_prices  = return_shortened_list('Price', full_list)
my_prices

import pandas as pd


def build_df(my_list):
    df_dict={}
    for stock_element in my_list:
        #print(stock_element)
        val = s_dict.get(stock_element)
        print(stock_element, val)
        df_dict[stock_element] = val
    df=pd.DataFrame(df_dict, index=[0])
    return df


my_price_df = build_df(my_prices)

my_price_df

my_price_df.dtypes

# +
my_ratio_df = build_df(my_ratios)

my_margin_df = build_df(my_margins)

my_operating_df = build_df(my_operating)

# -

my_ratio_df

my_margin_df

my_operating_df

s_dict['exchange']

s_dict['priceToBook']

s_dict['pegRatio']

s_dict['dividendYield']

s_dict['fundFamily']

# industry
s_dict['industry']

for key in s_dict.keys():
    print(key)

s_dict['market']

s_dict['morningStarRiskRating']

#annualHoldingsTurnover
s_dict['annualHoldingsTurnover']

s_dict['longName']

s_dict['shortName']



StarcoderdataJupyterScriptsDedupFiltered