code: def portfolio_to_dict(portfolio):
      positions = []
      for asset in portfolio.positions:
          p = portfolio.positions[asset]  # Type: Position
  
          position = dict(
              symbol=asset.symbol,
              exchange=asset.exchange,
              amount=p.amount,
              cost_basis=p.cost_basis,
              last_sale_price=p.last_sale_price,
              last_sale_date=p.last_sale_date,
          )
          positions.append(position)
  
      portfolio_dict = vars(portfolio)
      portfolio_dict["positions"] = positions
  
      return portfolio_dict
  
file_path: catalyst/catalyst/exchange/utils/serialization_utils.py
imports: import json
  import re
  from json import JSONEncoder
  import pandas
  from catalyst.constants import DATE_TIME_FORMAT
  from six import string_types
label_desc: Use image node_id 1 for calling a global function with example usage: portfolio_to_dict(portfolio) and returns: portfolio_dict