EquitySABRVolCurve Example CS

C# 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. // ################################################################################## ![]() using System;![]() // Optional using instruction. We will use a mix of utilising fully qualified names (in the case of the financial objects) // and using the reduced version (in the case of declaring enumerations). // This is just to demostrate both types of coding.![]() using CTQL; // You need to add a reference to the QuantToolsNET.v2.dll also![]() // 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. static int nCTVolatiltyCurvesGlobal; // Used by function parameters that take an optional range value. // In Excel we simply omit the value, within the API functions, // we pass an empty range object static CTQL.CTRangeData oEmptyRange = new CTQL.CTRangeData(); public string CS_EX_EquitySABRVolCurve() { nCTVolatiltyCurvesGlobal += 1; string szErrorMsg = "";![]() try {![]() ![]() // Creates a centralized valuation date object. ![]() string MyValuationDate; MyValuationDate = ValueDateObjPart(); ![]() ![]() // EURO calendar used for holiday adjustments. ![]() string MyEuroCal; MyEuroCal = CALEUROPart(); ![]() ![]() // Creates an equity/FX/commodity SABR object to model the dynamics // of the volatility curve (smile). string MyEquitySABRVolCurve; MyEquitySABRVolCurve = EquitySABRVolCurvePart( MyValuationDate, MyEuroCal); // This is the result we are looking for. return MyEquitySABRVolCurve; ![]() } catch(Exception e) { szErrorMsg = e.Message; throw e; } } ![]() ![]() // ///////////////////////////////////////////////////////////////////![]() private string EquitySABRVolCurvePart( string MyValuationDate, string MyEuroCal) {![]() // Create example range for parameter EquitySABRVolCurve_SABRMatrix CTQL.CTRangeData EquitySABRVolCurve_SABRMatrix = new CTQL.CTRangeData(); System.Text.StringBuilder EquitySABRVolCurve_SABRMatrix_builder = new System.Text.StringBuilder(100); // We could set the value for each cell individually, but for display // purposes, this is quicker and more informative. EquitySABRVolCurve_SABRMatrix_builder.Append("{"); EquitySABRVolCurve_SABRMatrix_builder.Append("'Opt\\SABR' | ATM | ALPHA | BETA | RHO | FWD ;"); EquitySABRVolCurve_SABRMatrix_builder.Append("'3M' | 20.01 | 3.8 | 0.7 | 0.25 | 207.04 ;"); EquitySABRVolCurve_SABRMatrix_builder.Append("'6M' | 20.02 | 3.8 | 0.7 | 0.25 | 215.04 ;"); EquitySABRVolCurve_SABRMatrix_builder.Append("'9M' | 20.02 | 3.8 | 0.7 | 0.25 | 223.68 ;"); EquitySABRVolCurve_SABRMatrix_builder.Append("'12M' | 20.03 | 3.81 | 0.7 | 0.25 | 229.31 ;"); EquitySABRVolCurve_SABRMatrix_builder.Append("'2Y' | 20.04 | 3.81 | 0.7 | 0.25 | 237.12 ;"); EquitySABRVolCurve_SABRMatrix_builder.Append("'3Y' | 20.05 | 3.81 | 0.7 | 0.25 | 247.11 ;"); EquitySABRVolCurve_SABRMatrix_builder.Append("'4Y' | 20.06 | 3.81 | 0.7 | 0.25 | 253.04 ;"); EquitySABRVolCurve_SABRMatrix_builder.Append("'5Y' | 20.07 | 3.81 | 0.7 | 0.25 | 261.81 ;"); EquitySABRVolCurve_SABRMatrix_builder.Append("'6Y' | 20.08 | 3.81 | 0.7 | 0.25 | 267.77 ;"); EquitySABRVolCurve_SABRMatrix_builder.Append("'7Y' | 20.09 | 3.81 | 0.7 | 0.25 | 277.48 ;"); EquitySABRVolCurve_SABRMatrix_builder.Append("'8Y' | 20.09 | 3.82 | 0.7 | 0.25 | 282.77 ;"); EquitySABRVolCurve_SABRMatrix_builder.Append("'9Y' | 20.1 | 3.82 | 0.7 | 0.25 | 290.6 ;"); EquitySABRVolCurve_SABRMatrix_builder.Append("'10Y' | 20.11 | 3.82 | 0.7 | 0.25 | 295.62 ;"); EquitySABRVolCurve_SABRMatrix_builder.Append("'11Y' | 20.12 | 3.82 | 0.7 | 0.25 | 301.61 ;"); EquitySABRVolCurve_SABRMatrix_builder.Append("'12Y' | 20.13 | 3.82 | 0.7 | 0.25 | 306.96"); EquitySABRVolCurve_SABRMatrix_builder.Append("}"); EquitySABRVolCurve_SABRMatrix.RangeFromStr ( EquitySABRVolCurve_SABRMatrix_builder.ToString() ); ![]() ![]() // Key value to use as a handle for the created object string MyEquitySABRVolCurve = "MyEquitySABRVolCurve" + "_" + System.Convert.ToString(nCTVolatiltyCurvesGlobal);![]() // When creating this object for the first time, set this parameter // to a positive value. int Reload = 1;![]() // Number of days between the Exercise date of the options and // the STARTDATE of the instrument. int SettleDays = 2;![]() // Is the input volatility entered as a percentage value (true), // or the raw volatility value (false). bool DivideVolBy100 = true;![]() // Business Day Convention. CTIEnums.BDCEnum BusDayConv = CTIEnums.BDCEnum.BDC_modifiedfollowing;![]() // DayCounter used for the calculation of option maturity in year // units. CTIEnums.DayCountEnum DayCount = CTIEnums.DayCountEnum.DayCount_30360;![]() // Interpolation method to use when interpolating the curve for // vols, - LINEAR, LOGLINEAR, CUBIC. CTIEnums.InterpEnum InterpType = CTIEnums.InterpEnum.Interp_LINEAR;![]() // Excel function call would be this - "CT.CRV.EquitySABRVolCurve()"![]() // Creates an equity/FX/commodity SABR object to model the dynamics // of the volatility curve (smile). string rEquitySABRVolCurve; rEquitySABRVolCurve = CTQL.CTVolatiltyCurvesSA.EquitySABRVolCurve( MyEquitySABRVolCurve, Reload, MyValuationDate, SettleDays, EquitySABRVolCurve_SABRMatrix, DivideVolBy100, BusDayConv, DayCount, MyEuroCal, InterpType);![]() ![]() return rEquitySABRVolCurve; } ![]() ![]() ![]() // ///////////////////////////////////////////////////////////////////![]() private string ValueDateObjPart() {![]() ![]() ![]() // Key value to use as a handle for the created object string MyValuationDate = "MyValuationDate" + "_" + System.Convert.ToString(nCTVolatiltyCurvesGlobal);![]() // When creating this object for the first time, set this parameter // to a positive value. int Reload = 1;![]() // Valuation Date (typically equal to Today's date) CTQL.Date ValueDate = new CTQL.Date("19/7/2005", "dd/mm/yyyy");![]() // Excel function call would be this - "CT.DATE.ValueDateObj()"![]() // Creates a centralized valuation date object. string rValueDateObj; rValueDateObj = CTQL.CTUtilsSA.ValueDateObj( MyValuationDate, Reload, ValueDate.serialNumber());![]() ![]() return rValueDateObj; } ![]() ![]() ![]() // ///////////////////////////////////////////////////////////////////![]() private string CALEUROPart() {![]() // Create example range for parameter CALEURO_AddHols CTQL.CTRangeData CALEURO_AddHols; ![]() int[] arrBCALEURO_AddHols = { CTQL.Date.serialNumber("1/2/2006", "dd/mm/yyyy"), CTQL.Date.serialNumber("2/2/2006", "dd/mm/yyyy"), CTQL.Date.serialNumber("3/2/2006", "dd/mm/yyyy"), CTQL.Date.serialNumber("4/2/2006", "dd/mm/yyyy"), CTQL.Date.serialNumber("5/2/2006", "dd/mm/yyyy"), CTQL.Date.serialNumber("6/2/2006", "dd/mm/yyyy") // Array Data }; CTQL.IntVector arrCALEURO_AddHols = new CTQL.IntVector(arrBCALEURO_AddHols); // Second parameter determines whether the array is a column array (false) or a row array (true) CALEURO_AddHols = new CTQL.CTRangeData(arrCALEURO_AddHols, false); // Create example range for parameter CALEURO_RemoveHols CTQL.CTRangeData CALEURO_RemoveHols; ![]() int[] arrBCALEURO_RemoveHols = { CTQL.Date.serialNumber("25/12/2006", "dd/mm/yyyy"), CTQL.Date.serialNumber("25/12/2007", "dd/mm/yyyy") // Array Data }; CTQL.IntVector arrCALEURO_RemoveHols = new CTQL.IntVector(arrBCALEURO_RemoveHols); // Second parameter determines whether the array is a column array (false) or a row array (true) CALEURO_RemoveHols = new CTQL.CTRangeData(arrCALEURO_RemoveHols, false); ![]() ![]() // Key value to use as a handle for the created object string MyEuroCal = "MyEuroCal" + "_" + System.Convert.ToString(nCTVolatiltyCurvesGlobal);![]() // When creating this object for the first time, set this parameter // to a positive value. int Reload = 1;![]() // Excel function call would be this - "CT.CAL.EURO()"![]() // EURO calendar used for holiday adjustments. string rCALEURO; rCALEURO = CTQL.CTCalendarsSA.CALEURO( MyEuroCal, Reload, CALEURO_AddHols, CALEURO_RemoveHols);![]() ![]() return rCALEURO; } ![]() ![]() ![]() ![]() |