portfolio_toolkit.asset.portfolio package

Submodules

portfolio_toolkit.asset.portfolio.asset_from_dict module

portfolio_toolkit.asset.portfolio.asset_from_dict.create_portfolio_asset(data_provider: DataProvider, ticker: str, currency: str | None = None) PortfolioAsset[fuente]

Creates a PortfolioAsset object with market data using a data provider.

Parámetros:
  • data_provider – The data provider instance to fetch ticker information and prices.

  • ticker (str) – The ticker for the asset.

  • currency (Optional[str]) – The currency for price data. If None, uses the asset’s default currency.

Devuelve:

The PortfolioAsset object with market data including:
  • ticker

  • sector

  • prices (historical price data)

  • info (ticker information from data provider)

  • currency

  • transactions (empty list)

Tipo del valor devuelto:

PortfolioAsset

portfolio_toolkit.asset.portfolio.portfolio_asset module

class portfolio_toolkit.asset.portfolio.portfolio_asset.PortfolioAsset(ticker: str, prices: pandas.core.series.Series, info: Dict, currency: Optional[str] = None, transactions: List[portfolio_toolkit.asset.portfolio.portfolio_asset_transaction.PortfolioAssetTransaction] = <factory>)[fuente]

Bases: MarketAsset

transactions: List[PortfolioAssetTransaction]
classmethod from_ticker(data_provider: DataProvider, ticker: str, currency: str | None = None) PortfolioAsset[fuente]

Create a PortfolioAsset from a ticker.

classmethod to_dataframe(assets: List[PortfolioAsset]) DataFrame[fuente]

Convert a list of PortfolioAsset objects to a pandas DataFrame.

add_transaction(transaction: PortfolioAssetTransaction)[fuente]

Adds a transaction to the portfolio asset.

add_transaction_from_dict(transaction_dict: dict)[fuente]

Adds a transaction to the account from a dictionary.

add_split(split_dict: dict) float[fuente]

Adds a stock split to the portfolio asset by simulating sell all + buy equivalent. Creates a sell transaction for all held shares and a buy transaction for split-adjusted quantity.

Parámetros:

split_dict – Dictionary containing split information with keys: - date: Split date (str) - split_factor: Split ratio as float (e.g., 2.0 for 2:1 split, 0.1 for 1:10 reverse split)

Devuelve:

Cash amount to be added to account due to fractional shares sold

(only applies to reverse splits where shares are lost)

Tipo del valor devuelto:

float

__init__(ticker: str, prices: ~pandas.core.series.Series, info: ~typing.Dict, currency: str | None = None, transactions: ~typing.List[~portfolio_toolkit.asset.portfolio.portfolio_asset_transaction.PortfolioAssetTransaction] = <factory>) None
ticker: str
prices: pd.Series
info: Dict
sector: str
country: str

portfolio_toolkit.asset.portfolio.portfolio_asset_transaction module

class portfolio_toolkit.asset.portfolio.portfolio_asset_transaction.PortfolioAssetTransaction(date: str, transaction_type: str, quantity: float, price: float, currency: str, total: float, exchange_rate: float, subtotal_base: float, fees_base: float, total_base: float)[fuente]

Bases: object

date: str
transaction_type: str
quantity: float
price: float
currency: str
total: float
exchange_rate: float
subtotal_base: float
fees_base: float
total_base: float
classmethod to_dataframe(transactions: List[PortfolioAssetTransaction], ticker: str) DataFrame[fuente]

Convert a list of PortfolioAssetTransaction objects to a pandas DataFrame.

__init__(date: str, transaction_type: str, quantity: float, price: float, currency: str, total: float, exchange_rate: float, subtotal_base: float, fees_base: float, total_base: float) None

Module contents

class portfolio_toolkit.asset.portfolio.PortfolioAsset(ticker: str, prices: pandas.core.series.Series, info: Dict, currency: Optional[str] = None, transactions: List[portfolio_toolkit.asset.portfolio.portfolio_asset_transaction.PortfolioAssetTransaction] = <factory>)[fuente]

Bases: MarketAsset

__init__(ticker: str, prices: ~pandas.core.series.Series, info: ~typing.Dict, currency: str | None = None, transactions: ~typing.List[~portfolio_toolkit.asset.portfolio.portfolio_asset_transaction.PortfolioAssetTransaction] = <factory>) None
add_split(split_dict: dict) float[fuente]

Adds a stock split to the portfolio asset by simulating sell all + buy equivalent. Creates a sell transaction for all held shares and a buy transaction for split-adjusted quantity.

Parámetros:

split_dict – Dictionary containing split information with keys: - date: Split date (str) - split_factor: Split ratio as float (e.g., 2.0 for 2:1 split, 0.1 for 1:10 reverse split)

Devuelve:

Cash amount to be added to account due to fractional shares sold

(only applies to reverse splits where shares are lost)

Tipo del valor devuelto:

float

add_transaction(transaction: PortfolioAssetTransaction)[fuente]

Adds a transaction to the portfolio asset.

add_transaction_from_dict(transaction_dict: dict)[fuente]

Adds a transaction to the account from a dictionary.

classmethod from_ticker(data_provider: DataProvider, ticker: str, currency: str | None = None) PortfolioAsset[fuente]

Create a PortfolioAsset from a ticker.

classmethod to_dataframe(assets: List[PortfolioAsset]) DataFrame[fuente]

Convert a list of PortfolioAsset objects to a pandas DataFrame.

transactions: List[PortfolioAssetTransaction]
ticker: str
prices: pd.Series
info: Dict
sector: str
country: str
class portfolio_toolkit.asset.portfolio.PortfolioAssetTransaction(date: str, transaction_type: str, quantity: float, price: float, currency: str, total: float, exchange_rate: float, subtotal_base: float, fees_base: float, total_base: float)[fuente]

Bases: object

__init__(date: str, transaction_type: str, quantity: float, price: float, currency: str, total: float, exchange_rate: float, subtotal_base: float, fees_base: float, total_base: float) None
classmethod to_dataframe(transactions: List[PortfolioAssetTransaction], ticker: str) DataFrame[fuente]

Convert a list of PortfolioAssetTransaction objects to a pandas DataFrame.

date: str
transaction_type: str
quantity: float
price: float
currency: str
total: float
exchange_rate: float
subtotal_base: float
fees_base: float
total_base: float