%% Numerix CAIL Callable Reverse Floater example
%
%  This example uses the Numerix CAIL API to price a callable reverse
%  floater from MATLAB.

%% Initialize Numerix environment

import com.numerix.integration.*;
import com.numerix.integration.implementation.*;

n = numerix('i:\NumeriX_java_10_3_0\data');

%% Create market
quotes = java.util.HashMap;
quotes.put('IR.USD-LIBOR-3M.SWAP-1Y.MID', 0.0066056);
quotes.put('IR.USD-LIBOR-3M.SWAP-10Y.MID', 0.022465005);
quotes.put('IR.USD-LIBOR-3M.SWAP-20Y.MID', 0.027544995);
market = Market('EOD_14-NOV-2011', DateExtensions.date('14-Nov-2011'), quotes.entrySet);

%% Create a trade instance based on instrument template found in Repository
tradeDescriptor = 'TRADE.IR.CALLABLEREVERSEFLOATER';
tradeParameters = java.util.HashMap;
tradeParameters.put('Trade ID','1001');
tradeParameters.put('Quote Type', 'MID');
tradeParameters.put('Currency', 'USD');
tradeParameters.put('Notional', 1000000.0);
tradeParameters.put('Effective Date', DateExtensions.date('1-Dec-2011'));
tradeParameters.put('Termination Date', DateExtensions.date('1-Dec-2021'));
tradeParameters.put('IR Index', 'LIBOR');
tradeParameters.put('IR Index Tenor', '3M');
tradeParameters.put('Structured Freq', '3M');
tradeParameters.put('Structured Side', 'Receive');
tradeParameters.put('Structured Coupon Floor', 0.0);
tradeParameters.put('Structured Coupon UpBd', 0.08);
tradeParameters.put('StructuredCoupon Multiplier', 1.4);
tradeParameters.put('Structured Coupon Cap', 0.05);
tradeParameters.put('Structured Basis', 'ACT/360');
tradeParameters.put('Funding Freq', '3M');
tradeParameters.put('Funding Side', 'Pay');
tradeParameters.put('Funding Spread', 0.003);
tradeParameters.put('Funding Basis', 'ACT/360');
tradeParameters.put('Call Start Date', DateExtensions.date('1-Dec-2013'));
tradeParameters.put('Call End Date', DateExtensions.date('1-Dec-2020'));
tradeParameters.put('Option Side', 'Short');
tradeParameters.put('Option Type', 'Right to Terminate');
tradeParameters.put('Call Frequency', '3M');
tradeParameters.put('Model', 'IR.USD-LIBOR-3M.MID.DET');
tradeParameters.put('Method', 'BackwardAnalytic');
                
%% Create trade instance
trade = RepositoryExtensions.createTradeInstance(n.Repository, tradeDescriptor, tradeParameters);
 
%% Price the trades
results = CalculationContextExtensions.calculate(n.Context, trade, market, Request.getAll);

%% Parse the results for MATLAB and display
r = n.parseResults(results);
disp([r.Name r.Category r.Currency r.Data])

%   Copyright 2014 The MathWorks, Inc. 