clc
clear all
close all
tic
[L_0,BDates,MDates] = Storage(); 
          
n = length(L_0);
tau = 30/n; % Time decrement
m = 1; % No. of simulation
g = 500; % No. of graph to be be ploted
sigma = 0.45; % Volatility
r = 0.0625; % Interest rate
L = zeros(1,n); % Storage vector for Interest rates
for j=1:g
    MeanRate = Simulation(tau, sigma, L_0, m, n, L);
    x = 1:n;
    plot(x,MeanRate)
    hold on
    grid on
end
plot(L_0,'r')
CapeRate = 0.002;
          

    % Calculating the price of caplet
    % CapData = [CapRates, Basis], where basis can be from 0-13 and
    % we will get:
    % 0 = actual/actual (default)
    % 1 = 30/360 (SIA)
    % 2 = actual/360
    % 3 = actual/365
    % 4 = 30/360 (BMA)
    % 5 = 30/360 (ISDA)
    % 6 = 30/360 (European)
    % 7 = actual/365 (Japanese)
    % 8 = actual/actual (ICMA)
    % 9 = actual/360 (ICMA)
    % 10 = actual/365 (ICMA)
    % 11 = 30/360E (ICMA)
    % 12 = actual/actual (ISDA)
    % 13 = BUS/252
    CapData = [CapeRate, 2];
    %   FwdRates is the value of our simulated forward rate
    FwdRates = MeanRate(1:120);
    % Scalar or NCAP-by-1 vector containing zero coupon
    % prices with maturities corresponding to those of
    % each cap in CapData, per $100 nominal value.
    ZeroPrice = 100*L_0(1:120);
     % settlement date of caplets.
    Settle = datenum('15-Sep-2013'); 
    %365/4*(i-1); %datenum('15-Oct-2002');
    % start dates of the caplets.
    BeginDates = BDates(1:120); %365/4*i; %datenum('15-Oct-2003');
    % maturity dates of caplets.
    EndDates =  MDates(1:120); %365/4*(i+1); %datenum('15-Jan-2004');
    % Caplet is $100 notional, divide $1,000,000 by $100
    %Notional   = 1000000/100;
    % we can just remove/add the "Notional*" in the beginning of 
    % the following formula
    CapPrice = bkcaplet(CapData, FwdRates, ZeroPrice, ...
               Settle, BeginDates, EndDates, sigma)
    
plot(CapPrice,'g')
plot(1:.1:120,CapeRate, 'black')
toc