-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathExampleFX.R
More file actions
32 lines (27 loc) · 1.07 KB
/
Copy pathExampleFX.R
File metadata and controls
32 lines (27 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#' Calculates the Exposure at Default for the FX product type
#' @title FX Example
#' @return The exposure at default
#' @param JSON (optional) if TRUE it returns a json string
#' @export
#' @author Tasos Grivas <tasos@@openriskcalculator.com>
#' @references Basel Committee: The standardised approach for measuring counterparty credit risk exposures
#' http://www.bis.org/publ/bcbs279.htm
ExampleFX =function(JSON = FALSE)
{
requireNamespace("Trading")
tr1 = Trading::FxForward(external_id = "ext_1",Notional=10000,MtM=30,ccyPair="EUR/USD",Si=0,Ei=10,BuySell='Buy')
tr2 = Trading::FxForward(external_id = "ext_2",Notional=20000,MtM=-20,ccyPair="EUR/USD",Si=0,Ei=4,BuySell='Sell')
tr3 = Trading::FxForward(external_id = "ext_3",Notional=5000,MtM=50,ccyPair="GBP/USD",Si=1,Ei=11,BuySell='Sell')
trades= list(tr1,tr2,tr3)
csas = list()
colls = list()
# calculating the Exposure-at-Default
tree = runExampleCalcs(trades, csas, colls)
if(JSON==TRUE)
{
requireNamespace("jsonlite")
return(jsonlite::toJSON(as.list(tree[[1]])))
}
else
{ return(tree[[1]])}
}