portfolio_toolkit.portfolio package
Submodules
portfolio_toolkit.portfolio.load_portfolio_json module
- portfolio_toolkit.portfolio.load_portfolio_json.load_portfolio_json(data: dict, data_provider: DataProvider) Portfolio [source]
Loads and validates a JSON file containing portfolio information.
- Parameters:
data (dict) – The portfolio data as a dictionary.
data_provider (DataProvider) – Data provider instance for fetching ticker information.
- Returns:
The loaded portfolio object.
- Return type:
- portfolio_toolkit.portfolio.load_portfolio_json.process_transactions(transactions: dict, splits: dict, portfolio_currency: str, data_provider: DataProvider) Tuple[List[PortfolioAsset], Account, datetime] [source]
Processes transactions to create asset objects and validate them.
- Parameters:
- Returns:
List of real assets (non-cash). dict: Cash account with all cash transactions. datetime: Calculated portfolio start date.
- Return type:
portfolio_toolkit.portfolio.plot module
- portfolio_toolkit.portfolio.plot.plot_evolution(df_portfolio)[source]
Generates a chart showing the evolution of the portfolio value over time.
- Parameters:
df_portfolio (pd.DataFrame) – Structured DataFrame with the portfolio evolution.
- Returns:
None
- portfolio_toolkit.portfolio.plot.plot_evolution_stacked(df_portfolio)[source]
Generates a stacked area chart showing the evolution of the portfolio value by ticker.
- Parameters:
df_portfolio (pd.DataFrame) – Structured DataFrame with the portfolio evolution.
- Returns:
None
- portfolio_toolkit.portfolio.plot.plot_evolution_vs_cost(df_portfolio)[source]
Plots the evolution of the portfolio value along with the cost of the shares.
- Parameters:
df_portfolio (pd.DataFrame) – DataFrame with the portfolio evolution.
- Returns:
None
- portfolio_toolkit.portfolio.plot.plot_evolution_ticker(df_portfolio, ticker)[source]
Plots the evolution of the value of a specific ticker in the portfolio, including the accumulated cost.
- Parameters:
df_portfolio (pd.DataFrame) – Structured DataFrame with the portfolio evolution.
ticker (str) – The asset symbol.
- Returns:
None
portfolio_toolkit.portfolio.plot_evolution module
- portfolio_toolkit.portfolio.plot_evolution.plot_portfolio_evolution(portfolio: TimeSeriesPortfolio) LineChartData [source]
Plot open positions in the portfolio
portfolio_toolkit.portfolio.portfolio module
- class portfolio_toolkit.portfolio.portfolio.Portfolio(name: str, currency: str, assets: List[portfolio_toolkit.asset.portfolio_asset.PortfolioAsset], data_provider: portfolio_toolkit.data_provider.data_provider.DataProvider, account: portfolio_toolkit.account.account.Account, start_date: str)[source]
Bases:
object
- assets: List[PortfolioAsset]
- data_provider: DataProvider
- __init__(name: str, currency: str, assets: List[PortfolioAsset], data_provider: DataProvider, account: Account, start_date: str) None
portfolio_toolkit.portfolio.preprocesador module
- portfolio_toolkit.portfolio.preprocesador.preprocess_data(assets: List[PortfolioAsset], account: Account, start_date: str, data_provider: DataProvider, currency='EUR')[source]
Preprocesses portfolio data to generate a structured DataFrame, including cost calculation.
- Parameters:
assets (list) – List of assets with their transactions.
account (Account) – Account information for the portfolio.
start_date (datetime) – Portfolio start date.
data_provider (DataProvider) – Data provider to obtain historical prices.
- Returns:
Structured DataFrame with the portfolio evolution.
- Return type:
pd.DataFrame
portfolio_toolkit.portfolio.print_cash_incomes module
portfolio_toolkit.portfolio.print_date_frame module
- portfolio_toolkit.portfolio.print_date_frame.print_data_frame(portfolio: TimeSeriesPortfolio)[source]
Prints the portfolio DataFrame in a readable format for debugging purposes.
portfolio_toolkit.portfolio.time_series_portfolio module
- class portfolio_toolkit.portfolio.time_series_portfolio.TimeSeriesPortfolio(name: str, currency: str, assets: List[PortfolioAsset], data_provider: DataProvider, account: Account, start_date: str)[source]
Bases:
Portfolio
DataFrame with the following structure:
Columns: - Date (str): Date of the transaction or calculation. - Ticker (str): Asset symbol (including synthetic cash tickers like __EUR). - Quantity (int): Accumulated quantity of shares/units on the date. - Price (float): Share price on the date in original currency (1.0 for cash tickers). - Price_Base (float): Share price converted to portfolio base currency, including fees for purchase transactions. - Value (float): Total value of the shares/units on the date (Quantity * Price). - Value_Base (float): Total value in portfolio base currency (Quantity * Price_Base). - Cost (float): Total accumulated cost of the shares/units on the date in base currency. - Sector (str): Sector to which the asset belongs (Cash for synthetic tickers). - Country (str): Country to which the asset belongs.
Each row represents the state of an asset on a specific date. Cash transactions use synthetic tickers (e.g., __EUR) with constant price of 1.0.
- __init__(name: str, currency: str, assets: List[PortfolioAsset], data_provider: DataProvider, account: Account, start_date: str) None
- portfolio_toolkit.portfolio.time_series_portfolio.create_time_series_portfolio_from_portfolio(porfolio: Portfolio) TimeSeriesPortfolio [source]
Creates a TimeSeriesPortfolio from a Portfolio instance.
- Parameters:
porfolio (Portfolio) – The Portfolio instance to convert.
- Returns:
A new TimeSeriesPortfolio instance.
- Return type:
portfolio_toolkit.portfolio.utils module
- portfolio_toolkit.portfolio.utils.get_ticker_holding_intervals(assets, ticker)[source]
Returns the date intervals where a specific ticker was held in the portfolio.
- Parameters:
ticker (str) – The ticker symbol to analyze.
- Returns:
- List of tuples with (start_date, end_date) intervals where the ticker was held.
Returns empty list if ticker was never held or is not found.
- Return type:
Example
[(‘2025-06-01’, ‘2025-06-10’), (‘2025-06-20’, ‘2025-07-03’)]
- portfolio_toolkit.portfolio.utils.create_date_series_from_intervals(intervals)[source]
Creates a pandas Series with all dates from multiple intervals.
- Parameters:
intervals (list) – List of tuples with (start_date, end_date)
- Returns:
Series with all dates from the intervals
- Return type:
pd.DatetimeIndex