SwaptionPortfolio Example VBA





http://www.QuantTools.com
CapeTools Swaption Portfolio function list
SwaptionPortfolio function

Welcome | Documentation format | QuantTools Groups | QuantTools Categories | Licence

Key TAGs | Excel Index | API Index



Example Excel VBA Driver function. Preparing the parameters and the final function call (the result).

High level view of the code structure (resulting in the final function call to SwaptionPortfolio() )

These are the financial QuantTools function calls that are used within the examples :





The objects generated by these functions are inter-connected in the following way :




VBA 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. 
    '     ##################################################################################
        


' 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 nCTOSPortfolioGlobal As Long
    
    
Public Function VB_EX_SwaptionPortfolio() As String

    nCTOSPortfolioGlobal = nCTOSPortfolioGlobal + 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 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

            
    
    Exit Function
err_Generic:
    MsgBox "Error: " & Err.Number & vbCrLf & Err.Description    
    
            
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 Variant
        
        SwaptionPortfolio_SwaptionRange = vRange.RangeFromStr _
         ( _
        CStr("{") + _
        CStr("SwaptionName     | Position     | PayRec     | ExerciseDate     | StartDate     | EndDate     | Notional     | Coupon     | FixBDC     | FixDayCount     | FixFreq     | IndexCode     | Margin ;") + _
        CStr("OS-123456     | short     | reciever     | #19/Jul/2011#     | #21/Jul/2011#     | #21/Jul/2016#     | 50000000     | 5.17     | Modifiedfollowing     | ACT365F     | S     | EURLIBOR3M     | 0.0002 ;") + _
        CStr("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 ;") + _
        CStr("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 ;") + _
        CStr("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 ;") + _
        CStr("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 ;") + _
        CStr("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 ;") + _
        CStr("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 ;") + _
        CStr("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 ;") + _
        CStr("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 ;") + _
        CStr("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 ;") + _
        CStr("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") + _
        CStr("}") _
         )
    



    '    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 Long
        Reload = 1

                    
    '  Excel function call is : "CT.BOOK.SwaptionPortfolio()"

    '    Creates a Swaption portfolio object.
        Dim rSwaptionPortfolio As String 
        
        ' We call the CreateCTOSPortfolio() function via the CTQL module exposed from the CTQL_VBA_API.xla addin.
        Dim oCTOSPortfolio As CTOSPortfolio
        Set oCTOSPortfolio = CTQL.CreateCTOSPortfolio()
    
        rSwaptionPortfolio = oCTOSPortfolio.SwaptionPortfolio( _
                MySwaptionPortfolio, _
                Reload, _
                MyGroupedIndex, _
                MyYC_XCCY_DCF, _
                MySABRVolCurve, _
                SwaptionPortfolio_SwaptionRange)


    SwaptionPortfolioPart = rSwaptionPortfolio
    
End Function                        








Copyright (c) 2003-2007 CapeTools - All Rights Reserved.