portfolio_toolkit package

Subpackages

Module contents

Portfolio Toolkit - A comprehensive toolkit for portfolio analysis and management.

class portfolio_toolkit.Portfolio(name: str, currency: str, assets: List[portfolio_toolkit.asset.portfolio.portfolio_asset.PortfolioAsset], data_provider: portfolio_toolkit.data_provider.data_provider.DataProvider, account: portfolio_toolkit.account.account.Account, start_date: str)[source]

Bases: object

__init__(name: str, currency: str, assets: List[PortfolioAsset], data_provider: DataProvider, account: Account, start_date: str) None
classmethod from_dict(data: dict, data_provider: DataProvider) Portfolio[source]
get_closed_positions(from_date: str, to_date: str) ClosedPositionList[source]

Returns ClosedPositionList for the given date.

get_open_positions(date: str) OpenPositionList[source]

Returns OpenPositionList for the given date.

get_stats(year: str) PortfolioStats[source]

Returns PortfolioStats for the given year.

get_time_series() PortfolioTimeSeries[source]

Returns a PortfolioTimeSeries for the given portfolio.

name: str
currency: str
assets: List[PortfolioAsset]
data_provider: DataProvider
account: Account
start_date: str
class portfolio_toolkit.Watchlist(name: str, currency: str, assets: List[MarketAsset], data_provider: DataProvider)[source]

Bases: object

Class to represent and manage an asset watchlist.

__init__(name: str, currency: str, assets: List[MarketAsset], data_provider: DataProvider) None
classmethod from_dict(data: dict, data_provider: DataProvider) Watchlist[source]
name: str
currency: str
assets: List[MarketAsset]
data_provider: DataProvider
class portfolio_toolkit.YFDataProvider[source]

Bases: DataProvider

Market data provider using Yahoo Finance.

AAPL = 'AAPL'
AMZN = 'AMZN'
ARCH = 'ARCH'
BA = 'BA'
BBAR = 'BBAR'
BBD = 'BBD'
BMA = 'BMA'
BONO_10_ANIOS_USA = '^TNX'
BRENT = 'BZ=F'
DOLAR_INDEX = 'DX-Y.NYB'
DOW_JONES = '^DJI'
EURUSD = 'EURUSD=X'
EVTL = 'EVTL'
GOOGL = 'GOOGL'
INTC = 'INTC'
JOBY = 'JOBY'
KOS = 'KOS'
LILMF = 'LILMF'
MERVAL = '^MERV'
META = 'META'
MSFT = 'MSFT'
NASDAQ = '^IXIC'
NFE = 'NFE'
NVDA = 'NVDA'
ORO = 'GC=F'
SLDP = 'SLDP'
SP500 = '^GSPC'
TSLA = 'TSLA'
USDARS = 'USDARS=X'
USDEUR = 'USDEUR=X'
VALE = 'VALE'
VIX = '^VIX'
WTI = 'CL=F'
YPF = 'YPF'
__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_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_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_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_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

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