Pricing Credit Risk Derivatives with R

This paper shows the implementation of some pricing techniques for multiname credit derivatives. Among these ﬁnancial instruments we consider Basket Default Swaps (BDS) and Collateralised Debt Obligations (CDO). The pricing methodologies put forward are based on Monte Carlo simulations. These techniques are written in the R programming language. This software framework provides an ample set of functions for credit risk modelling. Two main issues are put forward in this paper: the ﬁrst one is the employment of Quasi Random Number (QRN) for reducing the variance of price estimate in the Monte Carlo experiment; the second one is the code parallelization of some pricing techniques using R end-user techniques .


Introduction
Since the end of the eighties new financial instruments have arisen with the purpose of allowing the exchange of credit risk. These instruments are generically dubbed credit derivatives. Among the most important instruments traded in this market there are: Credit Defaults Swaps (CDS), Basket Default Swaps (BDS) and Collateralised Debt Obligations (CDO) (for example see Gibson [5], Acharya [1] and Bluhm [2] ).
Credit Default Swaps (CDS) are the simplest risk exchanging instruments. These are single name credit derivative contractual agreements yielding a payoff function of the credit quality of a third party called the obligor 1 . Analysis of default time of the obligor has been tackled also with Neural Networks Models (see for example A. Slavova [10]). Other financial instruments of this kind are the multiname credit derivatives such as Basket Default Swaps (BDS) and Collateralised Debt obligations (CDO). Here the term multiname refers to the pooling of credits from different borrowers. Fathi and Nader [4] which employ Gaussian copula and Monte Carlo simulation for pricing BDS and CDO provide Matlab code for their examples. In this paper we will analyze the software implementation of some pricing algorithms 1 There is just one asset and therefore a single name obligor for these multiname credit derivatives. Many useful examples of implementation issues can be found in Fouque [7]. In this work, the software tool employed for these computations is the statistical package R. This is an open software product quite spread among the statistical community but much less known in financial economist circles.
This work will show the feasibility and the performance capabilities of the R software in dealing with these pricing tasks. Furthermore we will also put forward some methods for effectively reducing the pricing estimation variance when employing Monte Carlo methods. Among the available techniques for variance reduction in Monte Carlo simulation, the replacement of standard pseudo random number with the quasi random number sequences has proved a robust methodology. Löffler and Posch [8] propose their use for credit risk modeling in the Visual Basic framework. In the software framework provided by R we have implemented a Monte Carlo pricing procedure taking advantage of the Quasi Random Number (QRN) generators featured in the package randtoolbox. As far as our knowledge goes this is the first time the QRN methodology is applied for pricing multiname credit derivative instruments. As a final point we propose a preliminary path for a software framework taking advantage of the multi-core/processor architecture of the computing platforms. The rest of the paper is organized in the following way. In section 2 we present the basic technical concepts on the credit derivatives instruments. In the following section we provide the modelling framework for pricing multiname credit derivatives. Section 4 puts forward the methodologies for reducing the pricing estimation variance. Section 5 shows the preliminary results achieved through the code parallelization within the R framework. Finally section 6 provides some concluding remarks.
2 Credit derivatives products and their role in the banking balance sheet In this paper we will take into account the problem of implementing the pricing of multiname credit derivatives such as Basket Default Swaps (BDS) and Collateralized Debt Obligation (CDO). Both of these credit derivatives are based on an insurance-like contract with two payment legs. The BDS are made up by a pool of credits referring to different names (obligors) which is split in two by a threshold value of number of acceptable defaults. The losses below the threshold are borne by BDS issuer (the protection buyer). The default exceeding the threshold will trigger the contingent leg and the end of the contract. The CDO instruments consist of a portfolio of defaultable assets such as loans, credit and bonds whose aggregate credit risk is first split into a given number of tranches of increasing seniority. The defaults occurring during the instrument lifetime will generate losses hitting first the most junior tranche, called the equity tranche, successively the losses will start eating up the notional of the more senior tranches. Each tranche will be responsible for the losses within a given percentage interval defined by its attachment and detachment points. These tranches are then separately sold to investors with different risk profiles. Either of these instruments are contractual agreements between a protection purchaser, the issuing organization, and a protection seller, which is the investor. These contractual agreements bind the two parties for a fixed time period ranging from 1 to usually no more than 10 years.
These financial instruments can be compared to a standard insurance contract where we can pin down two separate payment flows: 1. the periodic premium leg (borne by the protection buyer); 2. the default leg (borne by the protection seller).
The protection buyer owns a pool of defaultable assets for which he wants to buy protection against a credit event (i.e. a default). The premium leg constitutes the periodic insurance premium while the default leg conveys the ensuing payments following a default. The structure of the agreement can be better understood by referring to the following figure: The credit risk is shifting away from the protection buyer to the protection seller on the right section of the picture. The payments flowing through the premium leg are settled on a predefined schedule, usually there are quarterly payments in arrears. Assuming a pool of assets with an initial notional amount of M = Σ N j=1 P j composed of N obligors, where each asset has the nominal value P j and a set of regularly spaced payment dates, the amount of each installment will be given by where: T is the expiration time for the instrument, T i is the current time, e −r(T −Ti) is the discount factor with an assumed constant interest rate (r), s is the fair spread required to compensate for the burden of the credit risk, τ j is the default time for obligor j, 1 {τj >Ti} is the event indicator function which takes on values 1 or 0 according to whether the event {τ j > T i } occurs or not. This event indicator signals the occurrence of the default for obligor j. On the default leg there is a flow of payments going in the opposite direction. We will assume these payments occur necessarily on the first premium payment date following the default event. The amount foreseen for the default leg is given by (2) where: δ j is the recovery rate for the default of the asset whose notional amount is P j . Therefore the default leg conveys the discounted sum of the reimbursement for all the assets defaulted before T i . The task of pricing this kind of financial instruments consists in the determination of the fair premium required for insuring a zero value of the contract at its inception. Assuming t 0 = 0 we will have In equation 2 we have taken the standpoint of the protection buyer in giving the negative sign in the premium leg and the positive sign to the default leg. For a BDS we have either no payment or just one payment on the default leg. Assuming the default payment is triggered by the n h default. If this default happens at time τ h then the spread rate can be computed in a similar way according to the following by solving (4) with respect to s we get (5) where we have assumed a common recovery rate δ among the obligors and a premium paid only on the surviving assets.

Pricing Multiname credit derivatives
In this section we examine the computational issues involved in pricing multiname credit derivatives belonging to the category of BDS and CDO. We assume a portfolio of N names of defaultable assets. The BDS is a natural extension to the single name CDS. The basic idea is that of purchasing protection on a basket of different names. The two parties agrees on the event that will trigger the contingent payment. This is the default of order n h where n h ∈ {1, 2, . . . ,N } withN < N default in the basket. For the CDO instruments this portfolio is sliced in J tranches of progressively increasing seniority. These tranches are defined by their two boundaries values, normalized to the total portfolio value, called the attachment and the detachment points: K Lj and K Uj . The first attachment and the last detachment points will always be K L1 = 0 and K UJ = 1 . The problem of pricing multiname credit derivatives consists of determining the break-even premium s j for each tranche j ∈ {1, 2, . . . , J} composing the whole capital structure. This premium is the spread value s j referred in chapter 2 which makes zero the present value of the balance between the two payments flowing of fig. 1. Therefore the crucial element required for pricing these instruments is the distribution function of the total portfolio losses defined as For the following explanation it is useful to introduce also the total percentage loss given by Pj . The premium or fixed leg of the contract represents the payments received by the tranche holders (insurance sellers), whereas the default or floating leg constitutes the payments made by the tranche holders to the protection buyers in case a default has occurred. Let us assume a financial instrument of initial notional amount M whose contractual premium payment dates belong to the set At each payment date t k ∈ T , the premium to pay depends on the stock of survived assets of the tranche: that is the difference between the initial tranche percentage size and the current percent- . The protection seller of tranche j receives a premium whose amount is s j ·∆·Γ j,k . Therefore the present discounted value of the premium leg for tranche j will be: that is the sum over the life span of the instrument of the average tranche value net of losses. On the opposite side of the contractual agreement, in each date t k the protection buyer will receive a compensation proportional to the loss occurred in the interval Thus, the present discounted value of the default leg for the same tranche j will be: The break-even spread s j in equation 7 can be computed as the value which ensures a present value of the tranche equal to zero at contract inception. The value of the tranche over time will be given by the following equation: by setting to zero the left handside of equation 9 we can solve for the spread value which is given by s j,P ar = . By employing the R software framework we have developed a program employing the single factor copula function for pricing a CDO composed of a set of 125 obligors with an homogeneous default intensity and recovery rate 2 . The structure of this CDO reflects closely that one of the iTraxx and CDX family of indices 3 . In our empirical application, we have employed a CDO with the following parameters: 1. annual default intensity λ = .03 2. payment period (normalized to a year) ∆ = .25 2 Some code snippet are shown in Appendix 7.1. The whole R program is available upon request. 3 iTraxx indices cover European and Asian credit exposures, whereas CDX indices cover the North American credit risk market.
3. recovery rate R = .4 and the portfolio losses are distributed in six tranches as described in the following table: The estimation outcome is summarized in the following table:  Table 2 shows the prices of a six tranche CDO over a grid of ten increasing values for default correlation ρ among every couple of obligors. The results have been obtained with the adoption of a t copula with 10 degrees of freedom. In table 2 we see a regular behavior of the tranche price as a function of the tranche seniority and the default correlation. The equity and tranche mezz 1 show a monotone decreasing behavior with the default correlation. This is consequence of the default clustering caused by higher correlation. The two higher mezzanine and the senior tranches show an humpshaped behavior. The super senior tranche presents a spread monotonically increasing with the default correlation. The growth of the default correlation increases the likelihood of a higher number of clustered defaults hitting even the super senior tranche. The R programs provide routines for BDS and CDO pricing sampling from different kind of copulas such as elliptical (e.g. Gaussian and t) and archimedean (e.g. Clayton, Gumbel and Frank).

Variance reduction techniques for CDO pricing
The various CDO pricing algorithms available in literature are concerned with the computation of credit derivatives prices and their sensitivities to variation of the different model parameters. Closed form analytic methods provide deterministic values for the prices. When Monte Carlo Methods are employed the achieved prices are averages of given probability distributions. In these cases it is of paramount importance to integrate the average measures with an index of dispersion. In this work we employed the R features to compute averages and standard deviation of the Monte Carlo experiments. Different algorithms yield different standard deviations. One of the main goals of the analysis of Monte Carlo methods is to achieve the optimal trade-off between numerical accuracy and computational time. In other words, given a particular numerical accuracy we would like to minimize the number of Monte Carlo replications. Variance reduction techniques aim at making the most efficient use for each Monte Carlo replication. For the computation of CDO prices, besides the basic approach, we have used two families of variance reduction algorithms: The use of antithetic variates is based on the principle of drawing the samples with a given negative correlation to reduce the total sample variance 4 . In our empirical applications, for the Gaussian copula model, we have generated the default times assuming an exponential distribution function for the survival time: S j (t) = e −hj t . In this case the default times can be simulated in a straightforward way by where: α is the replication count, h j is the asset j default intensity 5 and the sample x is drawn from a standard normal distribution function whose cumulant is indicated as Φ(·). When we adopt the antithetic variates only n 2 of the required sample are drawn from standard normal sample: Z 1 , Z 2 , . . . , Z n/2 the remaining n 2 values are taken as their opposite: Z n/2+1 = −Z 1 , Z n/2+2 = −Z 2 , . . . , Z n = −Z n/2 . In this way we take advantage of the negative correlation present in the sample for decreasing the variance of the average. Aside from the difference in the random number sequences, the simulation code remains exactly the same. Quasi-Monte Carlo methods can be defined as the deterministic countepart of the Monte Carlo simulation techniques. While the latter use random or pseudo-random, the former employ some kind of deterministic sequences called Low Discrepancy Sequences (henceforth LDS). One of the most critical issues with Monte Carlo methods is the generation of good random points. In practical applications, software routines can only generate pseudo-random sequences, which, especially in higher dimensions, can lead to clumping of points. The accuracy of integration for methods based on pseudorandom points can be substantially improved by using more uniformly distributed sequences. The employment of LDS sequences has proved an effective avenue for generating high dimensional quasi random number suitable for Monte Carlo experiments. Different techniques for generating these sequences have been proposed in the literature. To the best V ar[ therefore the variance is reduced when Cov(X 1 , X 2 ) ≤ 0 5 The default intensity is assumed constant. of our knowledge these QRN numbers have never been employed for carrying out Monte Carlo experiment for CDO pricing.
In our empirical application we have employed the package randtoolbox (see Chalabi [3] 2013 for details). This package has allowed us to carry out experiment with the Halton (Halton [6] ) and the Sobol sequences (see Sobol [9]). In our experiments we have compared the BDS and CDO pricing and their standard deviation with classical pseudo-random and antithetic variates samples.
In the following table we show a comparison among four different Monte Carlo techniques for pricing a BDS of 100 names up to the third default in the portfolio: The relevant section for the R code is shown in appendix 7.1. The results presented in table 3 show a clear advantage in the use of the Halton and the Sobol QRN sequences for reducing the estimate standard deviation. Our empirical application shows also a clear dominance of the antithetic variates over the classical Monte Carlo methods. Table 4 shows the elapsed time required for the different algorithms 6 . In employing the QRN sequences, we have only experienced an increase of about 20% in the computing times for the Halton and Sobol sequences, Monte Carlo experiments with the antithetic variates require a computing time about 8% smaller than a standard pseudo-random number procedure.

20
Pricing Credit Risk Derivatives with R

The parallelization experiences with R
The R programming environment provides many packages addressing the issues of increasing the computing performances taking advantage of the parallelism present in the CPUs. In this paper we have tested three different parallel back-ends provided by R under the UNIX/LINUX Operating Systems 7 . These three different back-ends are equipped with an interface for the R foreach package. The following table summarizes the parallel frameworks employed: The foreach package provides a looping construct to execute R code repeatedly. The main advantage in employing the foreach package is that it allows both serial and parallel execution. A foreach loop can execute the operations included in the body of a loop on multiple processors/cores of a computing platform, or on multiple nodes of a cluster. The multicore package is aimed towards a shared memory platform. It dispatches parallel tasks on the different cores of a single computing node. The SNOW package is geared for a distributed memory platform 8 . Finally the parallel package provides a hybrid parallel back-end that is a combination of multicore and SNOW. By default, the parallel package adopts the multicore functionality on UNIX-like systems and SNOW functionality on Windows platforms. In our empirical application we have estimated the price of a CDO and a CDO 2 (CDO squared) instrument within the same program. The computing time results are summarized in the following table: A code snippet describing the main sections employed in the code parallelization is shown in Appendix 7.2. The performance results present some confirmations and leave some questions. First of all, on a single computing machine the use of multicore outpaces both the SNOW and the parallel packages. This is a consequence of the fact that multicore employs the faster pipes instead of the sockets for communication among tasks, furthermore the time required to fork a process is smaller than that required for the initialization of 7 Windows operating systems do not provide the fork system call and this reduces the parallelization opportunities. 8 The name stands for Simple Network Of Workstations.
new processes required by the other two back-ends. In some instances the wide difference should be deeply investigated at the compiler level.

Conclusions
In this paper we have considered some methods for pricing multiname credit risk derivatives instruments such as BDS and CDO. We have shown the feasibility and the performance of these algorithms when they are written in the open source package R. We have shown some R procedures implementing different variance reduction techniques for pricing CDO. In particular, we have put forward the QRN technique as a strategy to effectively decrease the variance of the price estimate of the credit risk derivatives. In the preliminary empirical analysis we have verified the superiority of the Sobol QRN sequence in achieving the lowest sampling variance in many examples. Also the antithetic variates Monte Carlo simulation has proved very effective achieving, in some cases, the smallest variance. Besides this algorithmic proposal, we have shown some of the possible avenues for writing a parallel version of these algorithms by employing three of the most widespread parallel back-ends provided in R. Our implementation has shown that by employing the multicore package we reached the shortest execution time. We have also tried the features of the compiler package which provides a bytecode translation of the original R code. In these pricing procedures the use of the bytecode yielded an improvement of less the 20%. A relevant avenue for further analysis should include some sort of code adaption for testing the performance on computing platforms equipped with numerical boards such as a Graphical Processing Unit (GPU) or Many Integrated Core (MIC). Here it is shown the relevant code section for the multiple loop over runs and replications with two different QRN sequences (Halton and Sobol), the antithetic variates and the classical pseudo random number generation.