1

When pricing a regular vanilla call/put option one can use the build-in function blsprice. It is known that there are also analytic formulae for barrier options (see http://www3.imperial.ac.uk/pls/portallive/docs/1/55071696.PDF page 16, ff). It would obviously not be ideal to copy these formulae into Matlab (it would be easy to make mistakes, etc). So I am wondering, does Matlab provide a function that has these formulae already implemented? I have found instbarrier but I am not sure how to use it.

2 Answers2

2

Personally, I have not yet managed to find any use of instbarrier. Also, Matlab does not currently have analytic formulae for barrier options implemented. It might do so in future releases.

In the meantime, you will have to price barriers via trees:

Sigma           = 0.1;
AssetPrice      = 100;
OptSpec         = 'call';
Strike          = 105;
Settle          = '01-Jan-2003';
ExerciseDates   = '01-jan-2007';
BarrierSpec     = 'ui'; % up and in
Barrier         = 102;
AmericanOpt     = 0;
DividendType    = []; 
DividendAmounts = 0;
ExDividendDates = []; 

StockSpec       = stockspec(Sigma, AssetPrice, DividendType, ...
                  DividendAmounts, ExDividendDates);
RateSpec        = intenvset('Rates', 0.05, 'StartDates', '01-Jan-2003', ...
                  'EndDates', '01-Jan-2007', 'Compounding', -1);

ValuationDate   = '1-Jan-2003';
Maturity        = '01-Jan-2007';


TimeSpecCRR     = crrtimespec(ValuationDate, Maturity, 100);
CRRTree         = crrtree(StockSpec, RateSpec, TimeSpecCRR);
PriceCRR        = barrierbycrr(CRRTree, OptSpec, Strike, Settle, ...
                  ExerciseDates, AmericanOpt, BarrierSpec, Barrier)


TimeSpecEQP     = eqptimespec(ValuationDate, Maturity, 100);
EQPTree         = eqptree(StockSpec, RateSpec, TimeSpecEQP);
PriceEQP        = barrierbyeqp(EQPTree, OptSpec, Strike, Settle, ...
                  ExerciseDates, AmericanOpt, BarrierSpec, Barrier)


Output (in Matlab 2012b):

PriceCRR = 

   16.4225

PriceEQP = 

   16.4397
Phil-ZXX
  • 2,359
  • 2
  • 28
  • 40
0

I implement the down and out, but I'm still thinking how to implement up and in, paste the first section at first.

    function Aerican_Down_and_Out_Call = DownandOut(K,T,S,sig,r,H,N)

        dt = T/N;
        nu = r-0.5*sig^2;
        dxu = sqrt(sig^2*dt+(nu*dt)^2);
        dxd = -dxu;
        pu = 1/2+1/2*(nu*dt/dxu);
        pd = 1-pu;
        %precompute constants
        disc = exp(-r*dt);
        dpu = disc*pu;
        dpd = disc*pd;
        edxud = exp(dxu-dxd);
        edxd = exp(dxd);

        St = zeros(N+1,1);
        C  = zeros(N+1,1);
        St(1)=S*exp(N*dxd);
        for j=2:N+1 St(j) = St(j-1)*edxud;end
        for j=1:N+1
            if(St(j)>H) 
                C(j) = max(0,St(j)-K);    
            else
                C(j) = 0;
            end    
        end
        for i = N:-1:1
            for j = 1:i
                St(j)=St(j)/edxd;
                if(St(j)>H)
                    C(j)=dpd*C(j)+dpu*C(j+1);
                    C(j)=max(C(j),St(j)-K);
                else
                    C(j)=0;
                end
            end
        end
        Aerican_Down_and_Out_Call =C(1);
end