%% Numerix CAIL Credit Default Swap example
%
%  This example uses the Numerix CAIL API to price a credit default swap
%  from MATLAB.   The trade parameters are read from the CDS1.csv in the 
%  Numerix Data Trades directory.

%% Initialize Numerix environment.

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

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

%% Create market.
market = Market('EOD_16-APR-2012', DateExtensions.date('16-APR-2012'), []);

%% Read CDS1.csv from the Numerix Trades directory
[~,~,tradeInfo] = xlsread([n.TradesPath '\Cashdeposit1.csv']);

%% Create a trade instance from the imported instrument.
tradeDescriptor = tradeInfo{1,3};
tradeParameters = java.util.HashMap;
numTradeInfoFields = size(tradeInfo,1);
for i = 2:numTradeInfoFields
  switch tradeInfo{i,2}
    case {'DATE','Date'}
      tradeParameters.put(tradeInfo{i,1},DateExtensions.date(datestr(tradeInfo{i,3},'dd-mmm-yyyy')));
    otherwise
      tradeParameters.put(tradeInfo{i,1},tradeInfo{i,3});
  end
end
                
%% 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 2013 The MathWorks, Inc. 