def get_portfolio_assets(portfolio_id): managed_portfolio = portfolio_manager.get_portfolio(portfolio_id) portfolio_assets = asset_manager.get_assets(managed_portfolio) return flask.jsonify([ portfolio_asset.to_dict() for portfolio_asset in portfolio_assets.values() ])
def get_operations(managed_portfolio: portfolio.Portfolio ) -> Mapping[Text, operation.Operation]: """Gets all the position of all assets in the portfolio. Args: managed_portfolio: Portfolio from which to obtain operations. Returns: Map of portfolio operations to its ids. """ managed_assets = asset_manager.get_assets(managed_portfolio) portfolio_operations = {} for managed_asset in managed_assets.values(): asset_operations = asset_manager.get_operations(managed_asset) portfolio_operations.update(asset_operations) return portfolio_operations
def get_positions(managed_portfolio: portfolio.Portfolio ) -> Mapping[asset.Asset, position.Position]: """Gets the position of all assets in the portfolio. Args: managed_portfolio: Portfolio from which to obtain position. Returns: Map of assets and their current positions. """ portfolio_assets = asset_manager.get_assets(managed_portfolio) portfolio_positions = { managed_asset: get_position(managed_asset) for managed_asset in portfolio_assets.values() } return portfolio_positions
def get_portfolio_stats( managed_portfolio: portfolio.Portfolio ) -> Mapping[asset.Asset, stats.AssetStats]: """Gets the stats for all assets in the portfolio. Args: managed_portfolio: Portfolio from which to obtain stats. Returns: Map of asssets and their stats. """ portfolio_assets = asset_manager.get_assets(managed_portfolio) portfolio_stats = { managed_asset: get_asset_stats(managed_asset) for managed_asset in portfolio_assets.values() } return portfolio_stats
def get_positions( managed_portfolio: portfolio.Portfolio, valuation_method: ValuationMethod = ValuationMethod.FIFO ) -> Mapping[asset.Asset, position.Position]: """Gets the position of all assets in the portfolio. Args: managed_portfolio: Portfolio from which to obtain position. valuation_method: Inventory valuation method to calculate returns. Returns: Map of assets and their current positions. """ portfolio_assets = asset_manager.get_assets(managed_portfolio) portfolio_positions = { managed_asset: get_position(managed_asset, valuation_method) for managed_asset in portfolio_assets.values() } return portfolio_positions