def metrics_initializer(m_data: dict, period='2y'):
    """Metrics Initializer

    Keyword Arguments:
        period {str} -- (default: {'2y'})

    Returns:
        list -- downloaded_data, sector_list, index, metrics_file data
    """
    sectors = m_data['Components']
    tickers = " ".join(sectors)
    tickers = index_appender(tickers)
    all_tickers = tickers.split(' ')

    if isinstance(period, (list)):
        period = period[0]

    # tickers = index_appender(tickers)
    print(" ")
    print(f'Fetching Type Composite Index funds for {period}...')
    data, _ = download_data_indexes(indexes=sectors,
                                    tickers=all_tickers,
                                    period=period,
                                    interval='1d')
    print(" ")

    return data, sectors
def metrics_initializer(period='2y', bond_type='Treasury'):
    """Metrics Initializer

    Keyword Arguments:
        period {str} -- (default: {'2y'})
        bond_type {str} -- (default: {'Treasury'})

    Returns:
        list -- downloaded_data, sector_list, index, metrics_file data
    """
    metrics_file = os.path.join("resources", "sectors.json")
    if not os.path.exists(metrics_file):
        print(f"{WARNING}WARNING: '{metrics_file}' not found for " +
              f"'metrics_initializer'. Failed.{NORMAL}")
        return {}, [], '', None

    with open(metrics_file) as m_file:
        m_data = json.load(m_file)
        m_file.close()
        m_data = m_data.get("Bond_Weight")

    if bond_type == 'Treasury':
        # Treasury (Gov't only - general alternative would be BSV/BIV/BLV)
        data = m_data[bond_type]
        tickers = list(data.keys())
        tickers = ' '.join(tickers)
        index = 'Government'

    elif bond_type == 'Corporate':
        # Corporate investment-grade bonds (BBB/BAA or higher)
        data = m_data[bond_type]
        tickers = list(data.keys())
        tickers = ' '.join(tickers)
        index = 'Corporate'

    elif bond_type == 'International':
        # BNDX & VWOB
        data = m_data[bond_type]
        tickers = list(data.keys())
        tickers = ' '.join(tickers)
        index = 'International'

    else:
        tickers = 'BND'

    if isinstance(period, (list)):
        period = period[0]

    sectors = tickers.split(' ')
    # tickers = index_appender(tickers)
    print(" ")
    print(f'Fetching {bond_type} Bond Composite Index funds for {period}...')
    data, _ = download_data_indexes(indexes=sectors,
                                    tickers=tickers,
                                    period=period,
                                    interval='1d')
    print(" ")
    return data, sectors, index, m_data
Example #3
0
def metrics_initializer(duration: str = 'short') -> list:
    """Metrics Initializer

    Keyword Arguments:
        duration {str} -- duration of view (default: {'short'})

    Returns:
        list -- data downloaded and sector list
    """
    metrics_file = os.path.join("resources", "sectors.json")
    if not os.path.exists(metrics_file):
        return None, []

    with open(metrics_file) as m_file:
        m_data = json.load(m_file)
        m_file.close()
        m_data = m_data.get("Correlation")

    sectors = m_data['tickers']
    tickers = " ".join(m_data['tickers'])
    START = m_data['start']

    tickers = index_appender(tickers)
    all_tickers = tickers.split(' ')
    date = datetime.now().strftime('%Y-%m-%d')

    print(" ")
    print('Fetching Correlation Composite Index funds...')

    if duration == 'short':
        START = datetime.today() - timedelta(days=900)
        START = START.strftime('%Y-%m-%d')

    data, _ = download_data_indexes(indexes=all_tickers,
                                    tickers=tickers,
                                    start=START,
                                    end=date,
                                    interval='1d')
    print(" ")

    return data, sectors
def metrics_initializer(period='5y', name='Market Composite Index'):
    """Metrics Initializer

    Keyword Arguments:
        period {str/list} -- duration of view (default: {'5y'})
        name {str} -- (default: {'Market Composite Index'})

    Returns:
        list -- data downloaded, sector list
    """
    metrics_file = os.path.join("resources", "sectors.json")
    if not os.path.exists(metrics_file):
        print(f"{WARNING}WARNING: '{metrics_file}' not found for " +
              f"'metrics_initializer'. Failed.{NORMAL_COLOR}")
        return None, []

    with open(metrics_file) as m_file:
        m_data = json.load(m_file)
        m_file.close()
        m_data = m_data.get("Market_Composite")

    sectors = m_data['tickers']
    tickers = " ".join(m_data['tickers'])

    tickers = index_appender(tickers)
    all_tickers = tickers.split(' ')

    if isinstance(period, (list)):
        period = period[0]

    print(" ")
    print(f'Fetching {name} funds for {period}...')
    data, _ = download_data_indexes(indexes=all_tickers,
                                    tickers=tickers,
                                    period=period,
                                    interval='1d')
    print(" ")

    return data, sectors