A previous article described the business case for creating a mashup scenario quickly. Often, this needs to be a self-service solution created by risk managers or business analysts themselves. One approach to doing this is to use R, an open source language for statistical use that has very good capabilities for transforming data. This article will use R to calculate the mashup scenario. The next article will use R to provide graphs of the results.
The first step is to load the stress data of the four original scenarios into an R data frame (R’s equivalent of a database table). Figure 1 shows some of the stress data in an R data frame.
Now we can build the mashup scenario in a few steps. The previous post described the business rules. The first rule is to copy over trades from the Grexit scenario where either the issuer or counterparty is from Greece. Figure 2 shows the single line of code necessary.
The next step is to add trades from the Rally scenario where the instrument currency is in Euros. However, as this is not the first step, we have to be careful not to copy over any trades already in the mashup scenario. Figure 3 shows the code.
The following steps to append the trades from the other two scenarios are similar. The final steps are just tidying up the scenario names and appending the mashup data set onto the original data set. Figure 4 shows the newly created mashup scenario rows
Figure 5 shows the code in its entirety. It shows how R can perform quite complicated operations very concisely.