EquitySABRVolCurve Example VBA

VBA Example - EquitySABRVolCurve![]() ![]() ![]() ![]() ![]() ' ################################################################################## ' The first function here EquitySABRVolCurve(), contains a series of ' function calls leading upto the main function call, the second function ' within this file ( EquitySABRVolCurvePart() ). ' which contains the answer that we are looking for.![]() ' The first function here is simply an example of how to construct the parameters ' in order acquire either a string Key (that is to be passed to other functions) ' or a computed result.![]() ' If you are viewing this source code from the chm or web help file you can use the ' outlining features to collapse certain sections of the code for better readability. ' ################################################################################## ![]() ![]() ' Add a reference to the CTQL_VBA_API.xla file via the Tools->Reference menu (within the VBA editor). ' This holds VBA class objects for communicating with the CTQuantToolsXL20.dll Excel Addin ' This XLA does not use COM and has access to all the financial objects created via the spreadsheet functions.![]() ![]() ' Some global parameter in order to append to user defined keys. ' We use it here to ensure that we have unique Keys (in the case several of our examples ' use the same key-name) ' In normal use, a user defined string will be used and so this variable will be pointless. Global nCTVolatiltyCurvesGlobal As Long Public Function VB_EX_EquitySABRVolCurve() As String![]() nCTVolatiltyCurvesGlobal = nCTVolatiltyCurvesGlobal + 1 On Error GoTo err_Generic ![]() ' Creates a centralized valuation date object.![]() Dim MyValuationDate As String MyValuationDate = _ ValueDateObjPart()![]() ![]() ![]() ' EURO calendar used for holiday adjustments.![]() Dim MyEuroCal As String MyEuroCal = _ CALEUROPart()![]() ![]() ![]() ' Creates an equity/FX/commodity SABR object to model the dynamics ' of the volatility curve (smile). Dim MyEquitySABRVolCurve As String MyEquitySABRVolCurve = _ EquitySABRVolCurvePart( _ MyValuationDate, _ MyEuroCal)![]() ' This is the result we are looking for. VB_EX_EquitySABRVolCurve = MyEquitySABRVolCurve![]() Exit Function err_Generic: MsgBox "Error: " & Err.Number & vbCrLf & Err.Description End Function ![]() ![]() ' ///////////////////////////////////////////////////////////////////![]() Private Function EquitySABRVolCurvePart( _ MyValuationDate As String, _ MyEuroCal As String) As String![]() ![]() ' Create example range for parameter EquitySABRVolCurve_SABRMatrix![]() ![]() Dim EquitySABRVolCurve_SABRMatrix As Variant EquitySABRVolCurve_SABRMatrix = vRange.RangeFromStr _ ( _ CStr("{") + _ CStr("'Opt\SABR' | ATM | ALPHA | BETA | RHO | FWD ;") + _ CStr("'3M' | 20.01 | 3.8 | 0.7 | 0.25 | 207.04 ;") + _ CStr("'6M' | 20.02 | 3.8 | 0.7 | 0.25 | 215.04 ;") + _ CStr("'9M' | 20.02 | 3.8 | 0.7 | 0.25 | 223.68 ;") + _ CStr("'12M' | 20.03 | 3.81 | 0.7 | 0.25 | 229.31 ;") + _ CStr("'2Y' | 20.04 | 3.81 | 0.7 | 0.25 | 237.12 ;") + _ CStr("'3Y' | 20.05 | 3.81 | 0.7 | 0.25 | 247.11 ;") + _ CStr("'4Y' | 20.06 | 3.81 | 0.7 | 0.25 | 253.04 ;") + _ CStr("'5Y' | 20.07 | 3.81 | 0.7 | 0.25 | 261.81 ;") + _ CStr("'6Y' | 20.08 | 3.81 | 0.7 | 0.25 | 267.77 ;") + _ CStr("'7Y' | 20.09 | 3.81 | 0.7 | 0.25 | 277.48 ;") + _ CStr("'8Y' | 20.09 | 3.82 | 0.7 | 0.25 | 282.77 ;") + _ CStr("'9Y' | 20.1 | 3.82 | 0.7 | 0.25 | 290.6 ;") + _ CStr("'10Y' | 20.11 | 3.82 | 0.7 | 0.25 | 295.62 ;") + _ CStr("'11Y' | 20.12 | 3.82 | 0.7 | 0.25 | 301.61 ;") + _ CStr("'12Y' | 20.13 | 3.82 | 0.7 | 0.25 | 306.96") + _ CStr("}") _ ) ![]() ![]() ![]() ' Key value to use as a handle for the created object Dim MyEquitySABRVolCurve As String MyEquitySABRVolCurve = "MyEquitySABRVolCurve" & "_" & CStr(nCTVolatiltyCurvesGlobal)![]() ![]() ' When creating this object for the first time, set this parameter ' to a positive value. Dim Reload As Long Reload = 1![]() ![]() ' Number of days between the Exercise date of the options and ' the STARTDATE of the instrument. Dim SettleDays As Long SettleDays = 2![]() ![]() ' Is the input volatility entered as a percentage value (true), ' or the raw volatility value (false). Dim DivideVolBy100 As Boolean DivideVolBy100 = true![]() ![]() ' Business Day Convention. Dim BusDayConv As String BusDayConv = "ModifiedFollowing"![]() ![]() ' DayCounter used for the calculation of option maturity in year ' units. Dim DayCount As String DayCount = "30360"![]() ![]() ' Interpolation method to use when interpolating the curve for ' vols, - LINEAR, LOGLINEAR, CUBIC. Dim InterpType As String InterpType = "LINEAR"![]() ' Excel function call is : "CT.CRV.EquitySABRVolCurve()"![]() ' Creates an equity/FX/commodity SABR object to model the dynamics ' of the volatility curve (smile). Dim rEquitySABRVolCurve As String ' We call the CreateCTVolatiltyCurves() function via the CTQL module exposed from the CTQL_VBA_API.xla addin. Dim oCTVolatiltyCurves As CTVolatiltyCurves Set oCTVolatiltyCurves = CTQL.CreateCTVolatiltyCurves() rEquitySABRVolCurve = oCTVolatiltyCurves.EquitySABRVolCurve( _ MyEquitySABRVolCurve, _ Reload, _ MyValuationDate, _ SettleDays, _ EquitySABRVolCurve_SABRMatrix, _ DivideVolBy100, _ BusDayConv, _ DayCount, _ MyEuroCal, _ InterpType)![]() ![]() EquitySABRVolCurvePart = rEquitySABRVolCurve End Function ![]() ![]() ![]() ![]() |