SwaptionPortfolio Example VBNET

High level view of the code structure (resulting in the final function call to SwaptionPortfolio() )
VB.NET Example - SwaptionPortfolio![]() ![]() ![]() ![]() ![]() ' ################################################################################## ' The first function here SwaptionPortfolio(), contains a series of ' function calls leading upto the main function call, the second function ' within this file ( SwaptionPortfolioPart() ). ' 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 nCTOSPortfolioGlobal 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_SwaptionPortfolio() As String![]() nCTOSPortfolioGlobal = nCTOSPortfolioGlobal + 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 Swaption portfolio object. Dim MySwaptionPortfolio As String MySwaptionPortfolio = _ SwaptionPortfolioPart( _ MyGroupedIndex, _ MyYC_XCCY_DCF, _ MySABRVolCurve)![]() ' This is the result we are looking for. VB_EX_SwaptionPortfolio = MySwaptionPortfolio![]() Catch e As Exception szErrorMsg = e.Message Throw e Catch e As System.ApplicationException szData = e.Message End Try End Function ![]() ![]() ' ///////////////////////////////////////////////////////////////////![]() Private Function SwaptionPortfolioPart( _ MyGroupedIndex As String, _ MyYC_XCCY_DCF As String, _ MySABRVolCurve As String) As String![]() ![]() ' Create example range for parameter SwaptionPortfolio_SwaptionRange![]() ![]() Dim SwaptionPortfolio_SwaptionRange _ As CTQL.CTRangeData![]() Dim SwaptionPortfolio_SwaptionRange_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. SwaptionPortfolio_SwaptionRange_builder.Append("{") SwaptionPortfolio_SwaptionRange_builder.Append("SwaptionName | Position | PayRec | ExerciseDate | StartDate | EndDate | Notional | Coupon | FixBDC | FixDayCount | FixFreq | IndexCode | Margin ;") SwaptionPortfolio_SwaptionRange_builder.Append("OS-123456 | short | reciever | #19/Jul/2011# | #21/Jul/2011# | #21/Jul/2016# | 50000000 | 5.17 | Modifiedfollowing | ACT365F | S | EURLIBOR3M | 0.0002 ;") SwaptionPortfolio_SwaptionRange_builder.Append("OS : 19-Jul-2012 / 5.31% | short | reciever | #19/Jul/2012# | #21/Jul/2012# | #21/Jul/2017# | 50000000 | 5.31 | Modifiedfollowing | ACT365F | S | EURLIBOR1M | 0.0002 ;") SwaptionPortfolio_SwaptionRange_builder.Append("OS : 19-Jul-2013 / 5.47% | short | reciever | #19/Jul/2013# | #21/Jul/2013# | #21/Jul/2018# | 50000000 | 5.47 | Modifiedfollowing | ACT365F | S | EURLIBOR1M | 0.0002 ;") SwaptionPortfolio_SwaptionRange_builder.Append("OS : 19-Jul-2014 / 5.59% | short | reciever | #19/Jul/2014# | #21/Jul/2014# | #21/Jul/2019# | 50000000 | 5.59 | Modifiedfollowing | ACT365F | S | EURLIBOR6M | 0.0002 ;") SwaptionPortfolio_SwaptionRange_builder.Append("OS : 19-Jul-2015 / 5.74% | short | reciever | #19/Jul/2015# | #21/Jul/2015# | #21/Jul/2020# | 50000000 | 5.74 | Modifiedfollowing | ACT365F | S | EURLIBOR6M | 0.0002 ;") SwaptionPortfolio_SwaptionRange_builder.Append("OS : 19-Jul-2016 / 5.92% | long | payer | #19/Jul/2016# | #21/Jul/2016# | #21/Jul/2021# | 10000000 | 5.92 | Modifiedfollowing | ACT365F | S | EURLIBOR12M | 0.0002 ;") SwaptionPortfolio_SwaptionRange_builder.Append("OS : 19-Jul-2017 / 6.06% | long | payer | #19/Jul/2017# | #21/Jul/2017# | #21/Jul/2022# | 10000000 | 6.06 | Modifiedfollowing | ACT365F | S | EURLIBOR12M | 0.0002 ;") SwaptionPortfolio_SwaptionRange_builder.Append("OS : 19-Jul-2018 / 6.23% | long | payer | #19/Jul/2018# | #21/Jul/2018# | #21/Jul/2023# | 10000000 | 6.23 | Modifiedfollowing | ACT365F | S | EURLIBOR3M | 0.0002 ;") SwaptionPortfolio_SwaptionRange_builder.Append("OS : 19-Jul-2019 / 6.38% | long | payer | #19/Jul/2019# | #21/Jul/2019# | #21/Jul/2024# | 10000000 | 6.38 | Modifiedfollowing | ACT365F | S | EURLIBOR3M | 0.0002 ;") SwaptionPortfolio_SwaptionRange_builder.Append("OS : 19-Jul-2020 / 6.51% | long | payer | #19/Jul/2020# | #21/Jul/2020# | #21/Jul/2025# | 10000000 | 6.51 | Modifiedfollowing | ACT365F | S | EURLIBOR6M | 0.0002 ;") SwaptionPortfolio_SwaptionRange_builder.Append("OS : 19-Jul-2021 / 6.69% | long | payer | #19/Jul/2021# | #21/Jul/2021# | #21/Jul/2026# | 10000000 | 6.69 | Modifiedfollowing | ACT365F | S | EURLIBOR6M | 0.0002") SwaptionPortfolio_SwaptionRange_builder.Append("}") SwaptionPortfolio_SwaptionRange.RangeFromStr _ ( _ SwaptionPortfolio_SwaptionRange_builder.ToString() _ ) ![]() ![]() ![]() ' Key Handle to be used for the new Portfolio object. Dim MySwaptionPortfolio As String MySwaptionPortfolio = "MySwaptionPortfolio" + "_" + CStr(nCTOSPortfolioGlobal)![]() ![]() ' 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.SwaptionPortfolio()"![]() ' Creates a Swaption portfolio object. Dim rSwaptionPortfolio As String Dim oCTOSPortfolio As New CTQL.CTOSPortfolio rSwaptionPortfolio = CTQL.CTOSPortfolioSA.SwaptionPortfolio( _ MySwaptionPortfolio, _ Reload, _ MyGroupedIndex, _ MyYC_XCCY_DCF, _ MySABRVolCurve, _ SwaptionPortfolio_SwaptionRange)![]() ![]() SwaptionPortfolioPart = rSwaptionPortfolio End Function ![]() ![]() ![]() ![]() |