portfolio_toolkit.data_provider package

Submodules

portfolio_toolkit.data_provider.data_provider module

class portfolio_toolkit.data_provider.data_provider.DataProvider[source]

Bases: ABC

Common interface for market data providers.

abstractmethod get_price(ticker, date)[source]

Gets the price of an asset on a specific date.

Parameters:
  • ticker (str) – The ticker symbol.

  • date (datetime) – The date for which to get the price.

Returns:

The price of the asset on the specified date.

Return type:

float

abstractmethod get_raw_data(ticker, period='5y')[source]

Gets all historical data for a ticker.

Parameters:
  • ticker (str) – The ticker symbol.

  • period (str) – The time period for historical data (default “5y”).

Returns:

The historical data for the ticker.

Return type:

pd.DataFrame

abstractmethod get_price_series(ticker, column='Close')[source]

Gets the price series of an asset for a specific column.

Parameters:
  • ticker (str) – The ticker symbol.

  • column (str) – The price column to get (default “Close”).

Returns:

Price series of the asset.

Return type:

pd.Series

abstractmethod get_price_series_converted(ticker, target_currency, column='Close')[source]

Gets the price series of an asset for a specific column, converted to a target currency.

Parameters:
  • ticker (str) – The ticker symbol.

  • target_currency (str) – The currency to convert prices to.

  • column (str) – The price column to get (default “Close”).

Returns:

Price series of the asset in the target currency.

Return type:

pd.Series

abstractmethod get_ticker_info(ticker)[source]

Gets detailed information for a ticker (e.g., P/E ratio, market cap, etc.).

Parameters:

ticker (str) – The ticker symbol.

Returns:

Dictionary with company information and key statistics.

Return type:

dict

portfolio_toolkit.data_provider.yf_data_provider module

class portfolio_toolkit.data_provider.yf_data_provider.YFDataProvider[source]

Bases: DataProvider

Market data provider using Yahoo Finance.

NASDAQ = '^IXIC'
SP500 = '^GSPC'
DOW_JONES = '^DJI'
MERVAL = '^MERV'
VIX = '^VIX'
BONO_10_ANIOS_USA = '^TNX'
DOLAR_INDEX = 'DX-Y.NYB'
BRENT = 'BZ=F'
WTI = 'CL=F'
ORO = 'GC=F'
USDARS = 'USDARS=X'
USDEUR = 'USDEUR=X'
EURUSD = 'EURUSD=X'
AAPL = 'AAPL'
MSFT = 'MSFT'
GOOGL = 'GOOGL'
AMZN = 'AMZN'
TSLA = 'TSLA'
META = 'META'
NVDA = 'NVDA'
INTC = 'INTC'
BA = 'BA'
YPF = 'YPF'
BBAR = 'BBAR'
BMA = 'BMA'
VALE = 'VALE'
ARCH = 'ARCH'
SLDP = 'SLDP'
LILMF = 'LILMF'
JOBY = 'JOBY'
NFE = 'NFE'
KOS = 'KOS'
BBD = 'BBD'
EVTL = 'EVTL'
__init__()[source]

Initializes the YFDataProvider class with in-memory caches for ticker data, info, and currencies.

get_price(ticker, fecha)[source]

Gets the price of an asset on a specific date.

Parameters:
  • ticker (str) – The ticker symbol.

  • fecha (datetime) – The date for which to get the price.

Returns:

The asset price on the specified date.

Return type:

float

get_raw_data(ticker, periodo='5y')[source]

Gets all historical data for a ticker directly.

Parameters:
  • ticker (str) – The ticker symbol.

  • periodo (str) – The time period for historical data (default “5y”).

Returns:

The historical data for the ticker.

Return type:

pd.DataFrame

Example DataFrame returned:

# Open High Low Close Adj Close Volume #2024-07-01 10.00 10.50 9.80 10.20 10.10 1000000 #2024-07-02 10.20 10.60 10.00 10.40 10.30 1200000 #… … … … … … …

get_price_series(ticker, columna='Close', period='5y')[source]

Gets the price series of an asset for a specific column.

Parameters:
  • ticker (str) – The ticker symbol.

  • columna (str) – The price column to get (default “Close”).

Returns:

Price series of the asset.

Return type:

pd.Series

get_ticker_info(ticker)[source]

Gets detailed information for a ticker using yfinance’s Ticker.info.

Parameters:

ticker (str) – The ticker symbol.

Returns:

Dictionary with company information and key statistics (e.g., P/E ratio, market cap, etc.).

Return type:

dict

get_price_series_converted(ticker, target_currency, columna='Close')[source]

Gets the price series of an asset converted to a target currency.

Parameters:
  • ticker (str) – The ticker symbol.

  • target_currency (str) – Target currency code (e.g., ‘EUR’, ‘USD’, ‘CAD’).

  • columna (str) – The price column to get (default “Close”).

Returns:

Price series of the asset converted to target currency.

Return type:

pd.Series

get_ticker_currency(ticker)[source]

Gets the currency of a ticker from its info.

Parameters:

ticker (str) – The ticker symbol.

Returns:

The currency code (e.g., ‘USD’, ‘EUR’, ‘CAD’) or ‘USD’ as default.

Return type:

str

Module contents