portfolio_toolkit.portfolio package

Subpackages

Submodules

Module contents

class portfolio_toolkit.portfolio.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.portfolio.PortfolioStats(realized_profit: float, unrealized_profit: float, initial_cash: float, final_cash: float, initial_valuation: float, final_valuation: float, incomes: float, deposits: float, withdrawals: float, commission: float, closed_positions_stats: Dict[str, Any], closed_positions: DataFrame, open_positions: DataFrame, transactions: DataFrame)[source]

Bases: object

Portfolio statistics dataclass containing all financial metrics and data for a given period.

realized_profit

Total profit/loss from closed positions

Type:

float

unrealized_profit

Unrealized gains/losses from current open positions

Type:

float

initial_valuation

Portfolio valuation at start of period

Type:

float

final_valuation

Portfolio valuation at end of period

Type:

float

incomes

Total income transactions in period

Type:

float

deposits

Total deposit transactions in period

Type:

float

withdrawals

Total withdrawal transactions in period

Type:

float

commission

Total commission fees (currently 0.0)

Type:

float

closed_positions_stats

Statistics about closed positions

Type:

Dict[str, Any]

closed_positions

DataFrame of closed positions

Type:

pd.DataFrame

open_positions

DataFrame of current open positions

Type:

pd.DataFrame

transactions

DataFrame of account transactions

Type:

pd.DataFrame

__init__(realized_profit: float, unrealized_profit: float, initial_cash: float, final_cash: float, initial_valuation: float, final_valuation: float, incomes: float, deposits: float, withdrawals: float, commission: float, closed_positions_stats: Dict[str, Any], closed_positions: DataFrame, open_positions: DataFrame, transactions: DataFrame) None
classmethod from_portfolio(portfolio: Portfolio, year: str) PortfolioStats[source]

Alternate constructor that builds PortfolioStats from a Portfolio and year.

property net_cash_flow: float

Net cash flow (deposits - withdrawals + incomes)

property return_percentage: float

Portfolio return percentage for the period

to_dict() Dict[str, Any][source]

Convert PortfolioStats to dictionary for backward compatibility

property total_profit: float

Total profit including both realized and unrealized gains

property valuation_change: float

Change in portfolio valuation from start to end of period

realized_profit: float
unrealized_profit: float
initial_cash: float
final_cash: float
initial_valuation: float
final_valuation: float
incomes: float
deposits: float
withdrawals: float
commission: float
closed_positions_stats: Dict[str, Any]
closed_positions: DataFrame
open_positions: DataFrame
transactions: DataFrame
class portfolio_toolkit.portfolio.PortfolioTimeSeries(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
classmethod from_portfolio(portfolio: Portfolio) PortfolioTimeSeries[source]

Alternate constructor that builds PortfolioTimeSeries from a Portfolio.

plot_evolution() LineChartData[source]
print() None[source]
portfolio_timeseries: DataFrame