api
- class api.api.DataAPI(symbols, num_years=100, period=None, api_source='yahoo', market_symbol='SPY', start_date=None, end_date=None)
Bases:
object- Description:
Class for data api management.
- Parameters:
symbols (list) – List of symbols
num_years (int, optional) – Number of years to look back, default is 100
period (str, optional) – Period, default is ‘None’. Choices include: ‘1d’, ‘5d’, ‘7d’, ‘60d’, ‘1mo’, ‘3mo’, ‘6mo’, ‘1y’, ‘2y’, ‘5y’, ‘10y’, ‘ytd’, ‘max’
api_source (str, optional) – API source, default is yahoo, other option is bloomberg
market_symbol (str, optional) – Market symbol, default is SPY
start_date (str, optional) – Start date, default is None
end_date (str, optional) – End date, default is None
- check_valid_api_source()
- Description:
Check for a valid API source.
- Returns:
None
- get_bloomberg_market_caps(symbols)
- Description:
Get market caps from Bloomberg
- Parameters:
symbols (list) – Symbols
- Returns:
Market caps
- Return type:
dict
- get_bloomberg_market_prices(prices, symbols)
- Description:
Get market prices from Bloomberg
- Parameters:
prices (pandas.DataFrame) – Prices
symbols (list) – Symbols
- Returns:
Market name, market prices
- Return type:
tuple
- get_bloomberg_prices()
- Description:
Get historical prices from Bloomberg
- Returns:
Historical prices
- Return type:
pandas.DataFrame
- get_bloomberg_risk_free_rate(symbol='USGG10YR Index', percent=100, decimals=4)
- Description:
Get risk-free rate from Bloomberg
- Parameters:
symbol (str, optional) – Ticker, default is ‘USGG10YR Index’
percent (int, optional) – Percent, default is 100
decimals (int, optional) – Decimals, default is 4
- Returns:
Risk free rate
- Return type:
float
- get_historical_prices()
- Description:
Get historical prices
- Returns:
Historical prices
- Return type:
pandas.DataFrame
- get_market_caps(prints=False)
- Description:
Calculate market caps
- Parameters:
prints (bool, optional) – Prints, default is False
- Returns:
Market caps
- Return type:
pandas.Series
- get_market_prices(prices, symbols, prints=False)
- Description:
Calculate market values
- Parameters:
prices (pandas.core.frame.DataFrame, required) – Prices
symbols (list, required) – Symbols
prints (bool, optional) – Prints, default is False
- Returns:
Market symbol, market name, market values
- Return type:
tuple
- get_risk_free_rate(prints=False, symbol=None)
- Description:
Calculate risk-free rate
- Parameters:
prints (bool, optional) – Prints, default is False
symbol (str, optional) – Ticker, default is None
- Returns:
Risk free rate
- Return type:
float
- static get_yahoo_market_caps(symbols)
- Description:
Get market caps from Yahoo Finance
- Parameters:
symbols (list) – Symbols
- Returns:
Market caps
- Return type:
dict
- get_yahoo_market_prices(prices, symbols)
- Description:
Get market prices from Yahoo Finance
- Parameters:
prices (pandas.core.frame.DataFrame) – Prices
symbols (list) – Symbols
- Returns:
Market name, market prices
- Return type:
tuple
- get_yahoo_prices()
- Description:
Get historical prices from Yahoo Finance
- Returns:
Historical prices
- Return type:
pandas.DataFrame
- static get_yahoo_risk_free_rate(symbol=None, percent=100, decimals=4)
- Description:
Get risk-free rate from Yahoo Finance
- Parameters:
symbol (str, optional) – Ticker, default is None
percent – Percent, default is 100
decimals – Decimals, default is 4
- Returns:
Risk free rate
- Return type:
float
- static process_symbols(symbols, api_source)
- Description:
Process symbols based on the API source. Bloomberg symbols usually end with ‘ US Equity’, whereas Yahoo symbols do not.
- Parameters:
symbols (list) – List of symbols
api_source (str) – API source, either ‘yahoo’ or ‘bloomberg’
- Returns:
Processed symbols