FloatLegPortfolio Example VBNET

High level view of the code structure (resulting in the final function call to FloatLegPortfolio() )
VB.NET 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. ' ################################################################################## ![]() Imports 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.![]() Imports 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. Global nCTLegPortfolioGlobal As Integer ' 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 Global oEmptyRange As CTQL.CTRangeData Public Function VB_EX_FloatLegPortfolio() As String![]() nCTLegPortfolioGlobal = nCTLegPortfolioGlobal + 1 ![]() Dim szErrorMsg As String Try![]() ![]() ' 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![]() Catch e As Exception szErrorMsg = e.Message Throw e Catch e As System.ApplicationException szData = e.Message End Try 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 CTQL.CTRangeData![]() Dim FloatLegPortfolio_FLTRange_builder _ As New System.Text.StringBuilder(100) ' We could set the value for each cell individually, but for display ' purposes, this is quicker and more informative. FloatLegPortfolio_FLTRange_builder.Append("{") FloatLegPortfolio_FLTRange_builder.Append("FLTName | PayRec | StartDate | EndDate | Notional | IndexCode | InArrears | Margin | CMSRho ;") FloatLegPortfolio_FLTRange_builder.Append("FLT-123456 | reciever | #24/Jan/2005# | #24/Jan/2010# | 50000000 | EURLIBOR3M | False | 0.0002 | 0 ;") FloatLegPortfolio_FLTRange_builder.Append("FLT : 25-Jul-2005 - EURLIBOR6M | reciever | #25/Jul/2005# | #25/Jul/2010# | 50000000 | EURLIBOR6M | False | 0.0002 | 0 ;") FloatLegPortfolio_FLTRange_builder.Append("FLT : 25-Jan-2006 - EURLIBOR6M | payer | #25/Jan/2006# | #25/Jan/2011# | 10000000 | EURLIBOR6M | True | 0.0002 | 0 ;") FloatLegPortfolio_FLTRange_builder.Append("FLT : 25-Jul-2006 - EURCMS5Y | payer | #25/Jul/2006# | #25/Jul/2011# | 10000000 | EURCMS5Y | True | 0.0002 | 0.8 ;") FloatLegPortfolio_FLTRange_builder.Append("FLT : 25-Jan-2007 - EURCMS5Y | payer | #25/Jan/2007# | #25/Jan/2012# | 10000000 | EURCMS5Y | True | 0.0002 | 0.8") FloatLegPortfolio_FLTRange_builder.Append("}") FloatLegPortfolio_FLTRange.RangeFromStr _ ( _ FloatLegPortfolio_FLTRange_builder.ToString() _ ) ![]() ![]() ![]() ' 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 Integer 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 Dim oCTLegPortfolio As New CTQL.CTLegPortfolio rFloatLegPortfolio = CTQL.CTLegPortfolioSA.FloatLegPortfolio( _ MyFloatLegPortfolio, _ Reload, _ MyGroupedIndex, _ MyYC_XCCY_DCF, _ MySABRVolCurve, _ FloatLegPortfolio_FLTRange)![]() ![]() FloatLegPortfolioPart = rFloatLegPortfolio End Function ![]() ![]() ![]() ![]() |