FloatLegPortfolio Example VBA

High level view of the code structure (resulting in the final function call to FloatLegPortfolio() )
VBA Example - FloatLegPortfolio![]() ![]() ![]() ![]() ![]() ' ################################################################################## ' The first function here FloatLegPortfolio(), contains a series of ' function calls leading upto the main function call, the second function ' within this file ( FloatLegPortfolioPart() ). ' 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 nCTLegPortfolioGlobal As Long Public Function VB_EX_FloatLegPortfolio() As String![]() nCTLegPortfolioGlobal = nCTLegPortfolioGlobal + 1 On Error GoTo err_Generic ![]() ' UK date calendar used within the UK stock exchange.![]() Dim MyCALUKExchange As String MyCALUKExchange = _ CALUKExchangePart()![]() ![]() ![]() ' EURO calendar used for holiday adjustments.![]() Dim MyEuroCal As String MyEuroCal = _ CALEUROPart()![]() ![]() ![]() ' Creates a centralized valuation date object.![]() Dim MyValuationDate As String MyValuationDate = _ ValueDateObjPart()![]() ![]() ![]() ' UK date calendar.![]() Dim MyCALUKSettlement As String MyCALUKSettlement = _ CALUKSettlementPart()![]() ![]() ![]() ' TARGET calendar used for holiday adjustments.![]() Dim MyTargetCal2 As String MyTargetCal2 = _ CALTARGET__2Part()![]() ![]() ![]() ' Creates a Deposit template which is almost identical to a Libor ' Index, but without the YieldCurve information. Dim MyGBPDepoTPL As String MyGBPDepoTPL = _ CreateDepoTemplate__3Part( _ MyCALUKExchange, _ MyCALUKSettlement)![]() ![]() ![]() ' Creates a Swap template which is almost identical to the definition ' of the parameters of a swap contract, but without the swap duration, ' buysell, and YieldCurve information. Dim MyGBPSwapTPL As String MyGBPSwapTPL = _ CreateSwapTemplate__4Part( _ MyCALUKSettlement, _ MyGBPDepoTPL)![]() ![]() ![]() ' Creates a Deposit template which is almost identical to a Libor ' Index, but without the YieldCurve information. Dim MyDepoTPL As String MyDepoTPL = _ CreateDepoTemplatePart( _ MyCALUKExchange, _ MyEuroCal)![]() ![]() ![]() ' Creates a Swap template which is almost identical to the definition ' of the parameters of a swap contract, but without the swap duration, ' buysell, and YieldCurve information. Dim MySwapTPL As String MySwapTPL = _ CreateSwapTemplatePart( _ MyEuroCal, _ MyDepoTPL)![]() ![]() ![]() ' Creates a yield curve using market rates and cross currency ' swaps (against the dollar). Dim MyYC_XCCY_DCF As String MyYC_XCCY_DCF = _ MKTYC_XCCY_DPart( _ MyValuationDate, _ MyDepoTPL, _ MySwapTPL)![]() ![]() ![]() ' Creates a SABR curve to model the dynamics of the volatility ' curve (smile). Dim MySABRVolCurve As String MySABRVolCurve = _ SABRVolCurvePart( _ MyValuationDate, _ MyDepoTPL, _ MySwapTPL)![]() ![]() ![]() ' Creates a new Index code. Dim My1MIndex As String My1MIndex = _ CreateIndex__5Part( _ MyCALUKExchange, _ MyEuroCal, _ MyYC_XCCY_DCF)![]() ![]() ![]() ' Creates a new Index code. Dim My2MIndex As String My2MIndex = _ CreateIndex__6Part( _ MyCALUKExchange, _ MyEuroCal, _ MyYC_XCCY_DCF)![]() ![]() ![]() ' Creates a new Index code. Dim My3MIndex As String My3MIndex = _ CreateIndex__7Part( _ MyCALUKExchange, _ MyEuroCal, _ MyYC_XCCY_DCF)![]() ![]() ![]() ' Creates a new Index code. Dim My6MIndex As String My6MIndex = _ CreateIndex__8Part( _ MyCALUKExchange, _ MyEuroCal, _ MyYC_XCCY_DCF)![]() ![]() ![]() ' Creates a new Index code. Dim My12MIndex As String My12MIndex = _ CreateIndex__9Part( _ MyCALUKExchange, _ MyEuroCal, _ MyYC_XCCY_DCF)![]() ![]() ![]() ' Creates a new Index based on SWAP details. Dim MyCMS5Y As String MyCMS5Y = _ CreateSwapIndex__2Part( _ MyTargetCal2, _ My3MIndex)![]() ![]() ![]() ' Creates a new Index based on SWAP details. Dim MyCMS10Y As String MyCMS10Y = _ CreateSwapIndex__3Part( _ MyTargetCal2, _ My3MIndex)![]() ![]() ![]() ' Creates a yield curve using market rates (No cross-currency ' Swaps). Dim MyGBPYC As String MyGBPYC = _ MKTYC_D__4Part( _ MyValuationDate, _ MyGBPDepoTPL, _ MyGBPSwapTPL)![]() ![]() ![]() ' GBPLibor, Pound Sterling LIBOR fixed by BBA. Dim MyGBPIndex As String MyGBPIndex = _ IDXGBPLiborPart( _ MyGBPYC)![]() ![]() ![]() ' Creates a container to hold a group of Index objects. Dim MyGroupedIndex As String MyGroupedIndex = _ GroupedIndexPart( _ My1MIndex, _ My2MIndex, _ My3MIndex, _ My6MIndex, _ My12MIndex, _ MyGBPIndex, _ MyCMS5Y, _ MyCMS10Y)![]() ![]() ![]() ' Creates a floating rate leg portfolio object (No quanto legs ' at this time). Dim MyFloatLegPortfolio As String MyFloatLegPortfolio = _ FloatLegPortfolioPart( _ MyGroupedIndex, _ MyYC_XCCY_DCF, _ MySABRVolCurve)![]() ' This is the result we are looking for. VB_EX_FloatLegPortfolio = MyFloatLegPortfolio![]() Exit Function err_Generic: MsgBox "Error: " & Err.Number & vbCrLf & Err.Description End Function ![]() ![]() ' ///////////////////////////////////////////////////////////////////![]() Private Function FloatLegPortfolioPart( _ MyGroupedIndex As String, _ MyYC_XCCY_DCF As String, _ MySABRVolCurve As String) As String![]() ![]() ' Create example range for parameter FloatLegPortfolio_FLTRange![]() ![]() Dim FloatLegPortfolio_FLTRange As Variant FloatLegPortfolio_FLTRange = vRange.RangeFromStr _ ( _ CStr("{") + _ CStr("FLTName | PayRec | StartDate | EndDate | Notional | IndexCode | InArrears | Margin | CMSRho ;") + _ CStr("FLT-123456 | reciever | #24/Jan/2005# | #24/Jan/2010# | 50000000 | EURLIBOR3M | False | 0.0002 | 0 ;") + _ CStr("FLT : 25-Jul-2005 - EURLIBOR6M | reciever | #25/Jul/2005# | #25/Jul/2010# | 50000000 | EURLIBOR6M | False | 0.0002 | 0 ;") + _ CStr("FLT : 25-Jan-2006 - EURLIBOR6M | payer | #25/Jan/2006# | #25/Jan/2011# | 10000000 | EURLIBOR6M | True | 0.0002 | 0 ;") + _ CStr("FLT : 25-Jul-2006 - EURCMS5Y | payer | #25/Jul/2006# | #25/Jul/2011# | 10000000 | EURCMS5Y | True | 0.0002 | 0.8 ;") + _ CStr("FLT : 25-Jan-2007 - EURCMS5Y | payer | #25/Jan/2007# | #25/Jan/2012# | 10000000 | EURCMS5Y | True | 0.0002 | 0.8") + _ CStr("}") _ ) ![]() ![]() ![]() ' Key Handle to be used for the new Portfolio object. Dim MyFloatLegPortfolio As String MyFloatLegPortfolio = "MyFloatLegPortfolio" & "_" & CStr(nCTLegPortfolioGlobal)![]() ![]() ' When creating this object for the first time, set this parameter ' to a positive value. Dim Reload As Long Reload = 1![]() ' Excel function call is : "CT.BOOK.FloatLegPortfolio()"![]() ' Creates a floating rate leg portfolio object (No quanto legs ' at this time). Dim rFloatLegPortfolio As String ' We call the CreateCTLegPortfolio() function via the CTQL module exposed from the CTQL_VBA_API.xla addin. Dim oCTLegPortfolio As CTLegPortfolio Set oCTLegPortfolio = CTQL.CreateCTLegPortfolio() rFloatLegPortfolio = oCTLegPortfolio.FloatLegPortfolio( _ MyFloatLegPortfolio, _ Reload, _ MyGroupedIndex, _ MyYC_XCCY_DCF, _ MySABRVolCurve, _ FloatLegPortfolio_FLTRange)![]() ![]() FloatLegPortfolioPart = rFloatLegPortfolio End Function ![]() ![]() ![]() ![]() |