portfolio_toolkit.portfolio.portfolio_from_dict module
- portfolio_toolkit.portfolio.portfolio_from_dict.portfolio_from_dict(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.portfolio_from_dict.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.portfolio_from_dict.get_transaction_ticker(transaction, portfolio_currency)[source]
Returns the ticker for a transaction. If the transaction does not have a ticker, it returns the synthetic cash ticker based on the portfolio currency.
- portfolio_toolkit.portfolio.portfolio_from_dict.validate_transaction(transaction)[source]
Validates that a transaction contains the required fields: date, type, and quantity.
- Parameters:
transaction (dict) – The transaction to validate.
- Raises:
ValueError – If the transaction does not contain the required fields.