function pv = pvBond (SD, MD, CPNRATE, PER, T, SPOT)

  basis = 0;

  SDnum = datenum (SD);
  MDnum = datenum (MD);

  cpndates(1) = cpndatep (SD, MD, PER, 0);
  cpn = SDnum + 1;
  i = 1;
  while cpn < MDnum,
    cpn = cpndaten (datestr(cpn+1), MD, PER, 0);
    i = i + 1;
    cpndates(i) = cpn;
  end

  n = ceil (yearfrac(SD,MD,1)*PER);

  if n ~= length(cpndates) - 1
    error (sprintf('number of coupons does not match'))
  end
  if i ~= length(cpndates)
    error (sprintf('i != n'))
  end

  a = SDnum - cpndates(1);
  dsr = cpndates(2) - SDnum;
  if basis == 0 
    e = daysact(cpndates(1),datemnth(cpndates(1),12/PER,0,0));
  elseif basis == 1 | basis == 2 
    e = 360/PER;
  elseif basis == 3 
    e = 365/PER;
  end 

  pv = 0;
  cpnsize = 100 * CPNRATE / PER;
  for i=2:length(cpndates)
    delta_t = (cpndates(i)-SDnum) / 365;
    r = csapi (T, SPOT, delta_t);
    pv = pv + cpnsize / (1+r/PER)^(i - 2 + dsr/e);
  end

  ai = a / e * cpnsize;
  r = csapi (T, SPOT, (MDnum-SDnum)/365);
  pv = pv + 100 / (1+r/PER)^(n-1+dsr/e) - ai;

end