EquitySABRVolCurve Example CPP

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. // ################################################################################## ![]() #include <string> #include <exception>![]() #include <sstream> #include <iomanip>![]() // Point the "additional includes directory" within your editor to the following paths ( where <InstallFolder> is your installation folder) // <InstallFolder>/Libs/Headers/ (For the library header files) // <InstallFolder>/Libs/Client/ (For the client helper header and source files)![]() // The helper files are optional and you can include only those files needed for your functionality // Each helper header/source file pair corresponds to a single QuantTools category of functions.![]() // Include QuantTools library header files #include <QuantTools_all.hpp>![]() // Include Client Helper QuantTools header files #include <QuantToolsClient_all.hpp>![]() // For Debug builds add a reference to the CTQuantToolsCPPAPI20D.lib // For Release builds add a reference to the CTQuantToolsCPPAPI20.lib // You add a reference via the ProjectProperties->Linker->Input menu item![]() // 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 long nCTVolatiltyCurvesGlobal = 0;![]() // Used by parameters that take an optional range value. // In Excel we simply omit the value, within the API functions, // we pass an empty range object CTRangeDataCPP oEmptyRange;![]() std::string szTickedKeyName; std::ostringstream szTemp; std::string CPP_EX_EquitySABRVolCurve() { nCTVolatiltyCurvesGlobal += 1; std::string szErrorMsg = ""; try {![]() ![]() // Creates a centralized valuation date object. ![]() std::string MyValuationDate; MyValuationDate = ValueDateObjPart(); ![]() ![]() // EURO calendar used for holiday adjustments. ![]() std::string MyEuroCal; MyEuroCal = CALEUROPart(); ![]() ![]() // Creates an equity/FX/commodity SABR object to model the dynamics // of the volatility curve (smile). std::string MyEquitySABRVolCurve; MyEquitySABRVolCurve = EquitySABRVolCurvePart( MyValuationDate, MyEuroCal); // This is the result we are looking for. return MyEquitySABRVolCurve; ![]() } catch(std::exception e) { szErrorMsg = e.what(); throw; } catch(...) { throw; } } ![]() ![]() // ///////////////////////////////////////////////////////////////////![]() std::string EquitySABRVolCurvePart( std::string MyValuationDate, std::string MyEuroCal) {![]() // Create example range for parameter EquitySABRVolCurve_SABRMatrix CTRangeDataCPP EquitySABRVolCurve_SABRMatrix; // We could set the value for each cell individually, but for display // purposes, this is quicker and more informative. EquitySABRVolCurve_SABRMatrix.RangeFromStr ( "{" "'Opt\\SABR' | ATM | ALPHA | BETA | RHO | FWD ;" "'3M' | 20.01 | 3.8 | 0.7 | 0.25 | 207.04 ;" "'6M' | 20.02 | 3.8 | 0.7 | 0.25 | 215.04 ;" "'9M' | 20.02 | 3.8 | 0.7 | 0.25 | 223.68 ;" "'12M' | 20.03 | 3.81 | 0.7 | 0.25 | 229.31 ;" "'2Y' | 20.04 | 3.81 | 0.7 | 0.25 | 237.12 ;" "'3Y' | 20.05 | 3.81 | 0.7 | 0.25 | 247.11 ;" "'4Y' | 20.06 | 3.81 | 0.7 | 0.25 | 253.04 ;" "'5Y' | 20.07 | 3.81 | 0.7 | 0.25 | 261.81 ;" "'6Y' | 20.08 | 3.81 | 0.7 | 0.25 | 267.77 ;" "'7Y' | 20.09 | 3.81 | 0.7 | 0.25 | 277.48 ;" "'8Y' | 20.09 | 3.82 | 0.7 | 0.25 | 282.77 ;" "'9Y' | 20.1 | 3.82 | 0.7 | 0.25 | 290.6 ;" "'10Y' | 20.11 | 3.82 | 0.7 | 0.25 | 295.62 ;" "'11Y' | 20.12 | 3.82 | 0.7 | 0.25 | 301.61 ;" "'12Y' | 20.13 | 3.82 | 0.7 | 0.25 | 306.96" "}" ); ![]() ![]() std::ostringstream szTemp; szTemp.str(""); szTemp << std::setw(0) << nCTVolatiltyCurvesGlobal;![]() ![]() // Key value to use as a handle for the created object std::string MyEquitySABRVolCurve = std::string("MyEquitySABRVolCurve") + std::string("_") + szTemp.str(); ![]() // When creating this object for the first time, set this parameter // to a positive value. long Reload = 1; ![]() // Number of days between the Exercise date of the options and // the STARTDATE of the instrument. long SettleDays = 2; ![]() // Is the input volatility entered as a percentage value (true), // or the raw volatility value (false). bool DivideVolBy100 = true; ![]() // Business Day Convention. BDCEnum BusDayConv = BDC_modifiedfollowing; ![]() // DayCounter used for the calculation of option maturity in year // units. DayCountEnum DayCount = DayCount_30360; ![]() // Interpolation method to use when interpolating the curve for // vols, - LINEAR, LOGLINEAR, CUBIC. InterpEnum InterpType = 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). std::string rEquitySABRVolCurve; rEquitySABRVolCurve = CTVolatiltyCurvesSA::EquitySABRVolCurve( MyEquitySABRVolCurve, Reload, MyValuationDate, SettleDays, EquitySABRVolCurve_SABRMatrix, DivideVolBy100, BusDayConv, DayCount, MyEuroCal, InterpType);![]() ![]() return rEquitySABRVolCurve; } ![]() ![]() ![]() ![]() |