portfolio_toolkit.asset package

Subpackages

Module contents

class portfolio_toolkit.asset.MarketAsset(ticker: str, prices: pandas.core.series.Series, info: Dict, currency: str | None = None)[source]

Bases: object

__init__(ticker: str, prices: Series, info: Dict, currency: str | None = None) None
currency: str | None = None
to_dict() Dict[str, Any][source]

Convert to a dictionary representation.

ticker: str
prices: Series
info: Dict
sector: str
country: str
class portfolio_toolkit.asset.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)[source]

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[source]

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
class portfolio_toolkit.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>)[source]

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[source]

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.

Parameters:

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)

Returns:

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

(only applies to reverse splits where shares are lost)

Return type:

float

add_transaction(transaction: PortfolioAssetTransaction)[source]

Adds a transaction to the portfolio asset.

add_transaction_from_dict(transaction_dict: dict)[source]

Adds a transaction to the account from a dictionary.

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

Create a PortfolioAsset from a ticker.

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

Convert a list of PortfolioAsset objects to a pandas DataFrame.

transactions: List[PortfolioAssetTransaction]
class portfolio_toolkit.asset.OptimizationAsset(ticker: str, prices: pandas.core.series.Series, info: Dict, currency: str | None = None, quantity: float = 0.0, expected_return: float = 0.0)[source]

Bases: MarketAsset

__init__(ticker: str, prices: Series, info: Dict, currency: str | None = None, quantity: float = 0.0, expected_return: float = 0.0) None
expected_return: float = 0.0
quantity: float = 0.0
classmethod to_dataframe(assets: List[OptimizationAsset]) DataFrame[source]

Convert a list of OptimizationAsset objects to a pandas DataFrame.

returns: Series
log_returns: Series
mean_return: float
volatility: float