function Price=TNote(Y,Md,today,F,T,I,N)
% Octave/Matlab function to compute Price from Yield
% to Maturity (YTM) for 2,3,5,7,10-year US Treasury
% notes with semiannual coupons.
% INPUTS:                              (Example)
%   Y = published Yield percentage       (1.407)
%   Md = maturity date            ([2031,11,15])
%   td = pricing date             ([2021,12,20])
%   F = Face value                         (100)
%   T = term, in years                      (10)
%   I = annualized interest percentage   (1.375)
% OUTPUTS:
%   Price = price at issuance
% EXAMPLE:
%   TNote(1.407,100,10,1.375,0.5)
%
  coupon=F*I/200; % semiannual coupon amount
  dtm=datenum(Md)-datenum(td); % days to maturity
  PVF = F*exp(-(Y/100)*); % PV(principal@T)
  % Semiannual coupon compounding:
  for t=dtm:-0.5:T   % add PV(semiannual coupons)
    Price = Price + coupon*exp(-Y*t/100);
  end
  return; 
end


% Continuous compounding:
%  Price = F*exp(-Y*T/100); % PV(principal@T)
%  for t=1:0.5:T   % add PV(semiannual coupons)
%    Price = Price + coupon*exp(-Y*t/100);
%  end
