Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

Working with Advanced Numerix Trades

This example shows how to price multiple trades from MATLAB® using Numerix® CAIL.

Initialize Numerix environment.

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

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

              Path: 'i:\NumeriX_java_10_3_0\data'
    RepositoryPath: 'i:\NumeriX_java_10_3_0\data\Repository'
        Repository: [1x1 com.numerix.integration.implementation.FileSystemRepository]
           Context: [1x1 com.numerix.integration.implementation.LocalCalculationContext]
       LookupsPath: 'i:\NumeriX_java_10_3_0\data\Data\LookupRules'
       MarketsPath: 'i:\NumeriX_java_10_3_0\data\Data\Markets'
       FixingsPath: 'i:\NumeriX_java_10_3_0\data\Data\Fixings'
        TradesPath: 'i:\NumeriX_java_10_3_0\data\Data\Trades'
        Parameters: [1x1 com.numerix.integration.implementation.CalculationParameters]

Specify the hybrid model for multiple trades.

hySpec = HybridModelSpecification;
hySpec.addHW1F('IR-USD', 'USD', 'LIBOR', '3M', 'MeanReversion(0.5),DiagonalSwaption(ATM, 10Y)');
hySpec.addHW1F('IR-EUR', 'EUR', 'EURIBOR', '6M', 'MeanReversion(0.5),DiagonalSwaption(ATM, 10Y)');
hySpec.addFXBlack('FX-USDEUR', 'USD', 'EUR', 'LIBOR', '3M', 'EURIBOR', '6M', 'StrikeFXEuropean(ATM, 10Y)');
% 5 Specify the factor correlations.
hyCorrelations = HybridModelCorrelationMatrix(hySpec);
hyCorrelations.add('IR-USD', 'IR-EUR', 0.5);
hyCorrelations.add('IR-USD', 'FX-USDEUR', 0.25);
hyCorrelations.add('IR-EUR', 'FX-USDEUR', 0.25);

% Specify the model parameters.
hybridModelParameters = java.util.HashMap;
hybridModelParameters.put('Quote Type', 'MID');
hybridModelParameters.put('Payout Currency', 'USD');
hybridModelParameters.put('Specification', hySpec);
hybridModelParameters.put('Correlations', hyCorrelations);

Specify exposure calculation parameters.

observationDates = CustomObservationSchedule;
observationDates.add(DateExtensions.date(2011, 12, 1));
for y = 2012:2013
  for m = 1:12
    observationDates.add(DateExtensions.date(y, m, 1));
  end
end

exposureParameters = java.util.HashMap;
exposureParameters.put('Model ID', 'HYBRID');
exposureParameters.put('Observation Dates', observationDates);

Define the first trade instance.

tradeParameters1 = java.util.HashMap;
tradeParameters1.put('Trade ID', 'RVFL1001');
tradeParameters1.put('Quote Type', 'MID');
tradeParameters1.put('Currency', 'USD');
tradeParameters1.put('Notional', 1000000.0);
tradeParameters1.put('Effective Date', DateExtensions.date('1-Dec-2011'));
tradeParameters1.put('Termination Date', DateExtensions.date('1-Dec-2021'));
tradeParameters1.put('IR Index', 'LIBOR');
tradeParameters1.put('IR Index Tenor', '3M');
tradeParameters1.put('Structured Freq', '3M');
tradeParameters1.put('Structured Side', 'Receive');
tradeParameters1.put('Structured Coupon Floor', 0.0);
tradeParameters1.put('Structured Coupon UpBd', 0.08);
tradeParameters1.put('StructuredCoupon Multiplier', 1.4);
tradeParameters1.put('Structured Coupon Cap', 0.05);
tradeParameters1.put('Structured Basis', 'ACT/360');
tradeParameters1.put('Funding Freq', '3M');
tradeParameters1.put('Funding Side', 'Pay');
tradeParameters1.put('Funding Spread', 0.003);
tradeParameters1.put('Funding Basis', 'ACT/360');
tradeParameters1.put('Call Start Date', DateExtensions.date('1-Dec-2013'));
tradeParameters1.put('Call End Date', DateExtensions.date('1-Dec-2020'));
tradeParameters1.put('Option Side', 'Short');
tradeParameters1.put('Option Type', 'Right to Terminate');
tradeParameters1.put('Call Frequency', '3M');
tradeParameters1.put('Model', 'HYBRID');
tradeParameters1.put('Method', 'BackwardMC');
tradeInstance1 = RepositoryExtensions.createTradeInstance(n.Repository, 'TRADE.IR.CALLABLEREVERSEFLOATER', tradeParameters1);

Define the second trade instance.

tradeParameters2 = java.util.HashMap;
tradeParameters2.put('Trade ID', 'CASHDEP1001');
tradeParameters2.put('Quote Type', 'MID');
tradeParameters2.put('Currency', 'USD');
tradeParameters2.put('Coupon Rate', 0.05);
tradeParameters2.put('Yield', 0.044);
tradeParameters2.put('Notional', 100.0);
tradeParameters2.put('Effective Date', DateExtensions.date('1-Apr-2012'));
tradeParameters2.put('Maturity', DateExtensions.date('1-Apr-2013'));
tradeParameters2.put('IR Index', 'LIBOR');
tradeParameters2.put('IR Index Tenor', '3M');
tradeParameters2.put('Model', 'HYBRID');
tradeParameters2.put('Method', 'BACKWARDMC');
tradeInstance2 = RepositoryExtensions.createTradeInstance(n.Repository, 'IR.CASHDEPOSIT', tradeParameters2);

Create the third trade instance.

tradeParameters3 = java.util.HashMap;
tradeParameters3.put('Trade ID', 'FXFWD1001');
tradeParameters3.put('Quote Type', 'MID');
tradeParameters3.put('Base Currency', 'USD');
tradeParameters3.put('Term Currency', 'EUR');
tradeParameters3.put('Delivery Date', DateExtensions.date('1-Jun-2012'));
tradeParameters3.put('Contract FX Forward Rate', 80.5);
tradeParameters3.put('Base Notional', 10000000.0);
tradeParameters3.put('Base IR Index', 'LIBOR');
tradeParameters3.put('Term IR Index', 'EURIBOR');
tradeParameters3.put('Base IR Index Tenor', '3m');
tradeParameters3.put('Term IR Index Tenor', '6m');
tradeParameters3.put('Calendar', 'NewYork Target');
tradeParameters3.put('Spot Lag', '2bd');
tradeParameters3.put('Model', 'HYBRID');
tradeParameters3.put('Method', 'BACKWARDMC');
tradeInstance3 = RepositoryExtensions.createTradeInstance(n.Repository, 'FX.FXFORWARD', tradeParameters3);

Set tradeInstances for all three trade instances.

tradeInstances = java.util.ArrayList;
tradeInstances.add(tradeInstance1);
tradeInstances.add(tradeInstance2);
tradeInstances.add(tradeInstance3);
n.Parameters.setInstances(tradeInstances);

Add a custom lookup so these trade instances reference the hybrid model.

n.Parameters.getLookups.add(0,ExactLookupRule('HYBRID','MODEL.HYBRID',hybridModelParameters.entrySet));

Add another custom lookup so that exposure report has parameters defined.

n.Parameters.getLookups.add(1,ExactLookupRule('RISK.REPORT.EXPOSURE','REPORT.EXPOSURE',exposureParameters.entrySet));

Perform the calculation.

results = n.Context.calculate(n.Parameters, Request.getExposure);

Parse the results for MATLAB and display.

r = n.parseResults(results)

disp([r.Trade(2) r.Market(2)])
disp([r.Results{2}.Name r.Results{2}.Category r.Results{2}.Currency r.Results{2}.Data])
disp([r.Results{2}.Name{1}])
disp([r.Results{2}.Data{1}])
r = 

      Trade: {3x1 cell}
     Market: {3x1 cell}
    Results: {3x1 cell}

 'CASHDEP1001'    'EOD'

    'Exposure'                     ''    ''    {21x501 cell}
    'Exposure.Discount Factors'    ''    ''    {21x501 cell}
    'Messages'                     ''    ''    {12x1   cell}

Exposure
  Columns 1 through 3

    'DATE'                            'VALUE 1'             'VALUE 2'         
    'Tue May 01 13:00:00 EDT 2012'    [104.198166609924]    [103.386222783828]
    'Fri Jun 01 13:00:00 EDT 2012'    [ 104.09953599675]    [102.117465067435]
    'Sun Jul 01 13:00:00 EDT 2012'    [105.524567506006]    [100.055731577867]
    'Wed Aug 01 13:00:00 EDT 2012'    [105.787455961524]    [100.318762976796]
    'Sat Sep 01 13:00:00 EDT 2012'    [104.417483614373]    [100.764337265155]
    'Mon Oct 01 13:00:00 EDT 2012'    [104.692275556824]    [100.980213613911]
    'Thu Nov 01 13:00:00 EDT 2012'    [104.443818312902]    [101.478508725115]
    'Sat Dec 01 12:00:00 EST 2012'    [104.736646932343]    [101.679769557039]
    'Tue Jan 01 12:00:00 EST 2013'    [104.577562970494]    [102.423339265735]
    'Fri Feb 01 12:00:00 EST 2013'    [ 104.28994278039]    [103.117326879887]
    'Fri Mar 01 12:00:00 EST 2013'    [ 104.70469459715]    [104.232180198939]
    'Mon Apr 01 13:00:00 EDT 2013'    [ 105.07334321718]    [ 105.05089338769]
    'Wed May 01 13:00:00 EDT 2013'    [               0]    [               0]
    'Sat Jun 01 13:00:00 EDT 2013'    [               0]    [               0]
    'Mon Jul 01 13:00:00 EDT 2013'    [               0]    [               0]
    'Thu Aug 01 13:00:00 EDT 2013'    [               0]    [               0]
    'Sun Sep 01 13:00:00 EDT 2013'    [               0]    [               0]
    'Tue Oct 01 13:00:00 EDT 2013'    [               0]    [               0]
    'Fri Nov 01 13:00:00 EDT 2013'    [               0]    [               0]
    'Sun Dec 01 12:00:00 EST 2013'    [               0]    [               0]

.

.

.

  Columns 499 through 501

    'VALUE 498'           'VALUE 499'           'VALUE 500'       
    [ 105.36273206453]    [104.335982034187]    [104.141595030057]
    [105.904822463264]    [104.238089023172]    [104.276676080686]
    [103.893060436208]    [103.613968079212]    [106.188617261199]
    [103.183889382889]    [105.499763150412]    [105.440275818983]
    [103.310404527817]    [105.233622768447]    [105.267337892552]
    [103.274239052394]    [104.716952177783]    [ 104.33099834332]
    [103.583983117053]    [104.710250522521]    [105.501004542869]
    [103.379982561438]    [105.146939039653]    [104.681616459661]
    [103.821169954095]    [105.567274949306]    [104.835971977691]
    [104.016530403399]    [105.254054161819]    [104.842156238753]
    [104.481475787501]    [105.197179985119]    [104.962752610848]
    [105.061984636083]    [105.077227736476]    [105.077766765965]
    [               0]    [               0]    [               0]
    [               0]    [               0]    [               0]
    [               0]    [               0]    [               0]
    [               0]    [               0]    [               0]
    [               0]    [               0]    [               0]
    [               0]    [               0]    [               0]
    [               0]    [               0]    [               0]
    [               0]    [               0]    [               0]

Plot the results for the second trade instance, CASHDEP1001, with the corresponding Exposure Discount Factors.

figure('Tag','NumerixAdvancedRiskExample');

for ii=1:3
   % Get dates
   dates = cell2mat(r.Results{ii}.Data{expIndex}(2:end,1));
   dates = dates(:,4:end);
   dates = floor(datenum(dates));
   % Get exposures
   mtm = cell2mat(r.Results{ii}.Data{expIndex}(2:end,2:end))';
   exposures = max(0,mtm);  % Exposure at contract level, no netting
   EE = mean(exposures);  % Expected Exposure
   PFE = prctile(exposures,95);  % Potential Future Exposure
   subplot(3,1,ii)
   plot(dates,EE,dates,PFE)
   title(r.Trade{ii})
   datetick
end

See Also

| |

Related Examples

External Websites

Was this topic helpful?