code: def withdraw_portfolio(p, cash, tdate):
      r"""Withdraw cash from a given portfolio.
  
      Parameters
      ----------
      p : alphapy.Portfolio
          Portfolio to accept the withdrawal.
      cash : float
          Cash amount to withdraw.
      tdate : datetime
          The date of withdrawal.
  
      Returns
      -------
      p : alphapy.Portfolio
          Portfolio with the withdrawn cash.
  
      """
      currentcash = p.cash
      availcash = currentcash - (p.mincash * p.value)
      if cash > availcash:
          logger.info(
              "Withdrawal of %s would exceed reserve amount", cash
          )
      else:
          p.cash = currentcash - cash
          p = valuate_portfolio(p, tdate)
      return p
  
imports: from alphapy.frame import Frame
  from alphapy.frame import frame_name
  from alphapy.frame import read_frame
  from alphapy.frame import write_frame
  from alphapy.globals import MULTIPLIERS, SSEP
  from alphapy.globals import Orders
  from alphapy.space import Space
  import logging
  import math
  import numpy
  from pandas import DataFrame
  from pandas import date_range
  from pandas import Series
label_desc: Use image node_id 8 for calling a global function with example usage: withdraw_portfolio(p, cash, tdate) and returns: p