code: def portfolio_value(portfolio, date, price='close'):
      
      value = 0.0
      for (sym, sym_shares) in portfolio.iteritems():
          sym_price = None
          if sym_shares:
              sym_price = get_price(symbol=sym, date=date, price=price)
          # print sym, sym_shares, sym_price
          # print last_date, k, price
          if sym_price != None:
              if np.isnan(sym_price):
                  print 'Invalid price, shares, value, total: ', sym_price, sym_shares, (float(sym_shares) * float(sym_price)) if sym_shares and sym_price else 'Invalid', value
                  if sym_shares:
                      return float('nan')
              else:
                  # print ('{0} shares of {1} = {2} * {3} = {4}'.format(sym_shares, sym, sym_shares, sym_price, sym_shares * sym_price))
                  value += sym_shares * sym_price
                  # print 'new price, value = {0}, {1}'.format(sym_price, value)
      return value
docs: Total value of a portfolio (dict mapping symbols to numbers of shares)
  
      $CASH used as symbol for USD