QBSBondOption Example VBNET





http://www.QuantTools.com
CapeTools Bond Options function list
QBSBondOption function

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

Key TAGs | Excel Index | API Index



Example VB.NET 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 QBSBondOption() )

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 :




VB.NET Example - QBSBondOption





    '     ##################################################################################
    '     The first function here QBSBondOption(), contains a series of
    '     function calls leading upto the main function call, the second function
    '     within this file ( QBSBondOptionPart() ).
    '     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 nCTBondOptionsGlobal 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_QBSBondOption() As String

    nCTBondOptionsGlobal = nCTBondOptionsGlobal + 1
            

    Dim szErrorMsg As String
          
    Try

            
    

    '    Creates an European Exercise object.

    Dim MyEuropeanExercise As String
    MyEuropeanExercise = _
        EuropeanExercisePart()


    

    '    Creates a generic calendar object.

    Dim MyNewCalendar As String
    MyNewCalendar = _
        GenericCalendarPart()


    

    '    Creates a fixed coupon bond object.
    Dim MyFixedCouponBond_y As String
    MyFixedCouponBond_y = _
        FixedCouponBond_yPart( _
        MyNewCalendar)


    

    '    Creates a BondOption object that will price the option via a 
    '    Black Scholes methodology.
    Dim MyQBSBondOption As String
    MyQBSBondOption = _
        QBSBondOptionPart( _
        MyFixedCouponBond_y, _
        MyEuropeanExercise)

    ' This is the result we are looking for.
    VB_EX_QBSBondOption = MyQBSBondOption

            
    Catch e As Exception
        szErrorMsg = e.Message
        Throw e
    Catch e As System.ApplicationException
        szData = e.Message
    End Try
            
End Function                
        


' ///////////////////////////////////////////////////////////////////

Private Function QBSBondOptionPart( _
    MyFixedCouponBond_y As String, _                
    MyEuropeanExercise As String) As String


    



    '    Key Handle to be used for the new Bond object.
        Dim MyQBSBondOption As String
        MyQBSBondOption = "MyQBSBondOption" + "_" + CStr(nCTBondOptionsGlobal)


    '    When creating this object for the first time, set this parameter 
    '    to a positive value.
        Dim Reload As Integer
        Reload = 1


    '    Type of option (C)all or (P)ut.
        Dim OptionType As String
        OptionType = "Call"


    '    The exercise price of the BondOption.
        Dim exercisePrice As Double
        exercisePrice = 101


    '    The volatility of the Bond.
        Dim Vol As Double
        Vol = 0.2


    '    The type of volatility passed in : Either 'Yield' or 'Price' 
    '    vol.
        Dim VolType As String
        VolType = "Yield"


    '    A repurchase rate (repo rate) value.
        Dim reporate As Double
        reporate = 0.055


    '    The compounding of the repurchase rate (repo rate) passed in.
        Dim compounding As CTIEnums.COMPEnum
        compounding = CTIEnums.COMPEnum.COMP_Compounded


    '    Frequency of the repo rate.
        Dim Freq As CTIEnums.FreqEnum
        Freq = CTIEnums.FreqEnum.Freq_annual


    '    The DayCounter of the repo rate.
        Dim DayCount As CTIEnums.DayCountEnum
        DayCount = CTIEnums.DayCountEnum.DayCount_actual360

                    
    '  Excel function call is : "CT.BNDOPT.QBSBondOption()"

    '    Creates a BondOption object that will price the option via a 
    '    Black Scholes methodology.
        Dim rQBSBondOption As String 
        Dim oCTBondOptions As New CTQL.CTBondOptions
    
        rQBSBondOption = CTQL.CTBondOptionsSA.QBSBondOption( _
                MyQBSBondOption, _
                Reload, _
                MyFixedCouponBond_y, _
                OptionType, _
                MyEuropeanExercise, _
                exercisePrice, _
                Vol, _
                VolType, _
                reporate, _
                compounding, _
                Freq, _
                DayCount)


    QBSBondOptionPart = rQBSBondOption
    
End Function                        








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