QBSBondOption Example Java





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 Java 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 :




Java 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. 
    //     ##################################################################################
        

public class Java_EX_QBSBondOption()
{
    static 
    {
        try 
        {
            System.loadLibrary("CTQuantToolsAPI20");
        } 
        catch (UnsatisfiedLinkError e) 
        {
            System.err.println("Native code library failed to load. Make sure that the CTQuantToolsAPI20.dll is installed correctly.\n" + e);
            System.exit(1);
        }
    }

    static int nCTBondOptionsGlobal = 0;
    
    // 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
    static CTQL.CTRangeData oEmptyRange = new CTQL.CTRangeData();
    static String szTickedKeyName;
                

    public static String Java_EX_QBSBondOption(String argv[])
    {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
    nCTBondOptionsGlobal += 1;
            
    String szErrorMsg = "";

    try
    {



    //    Creates an European Exercise object.
    

    String MyEuropeanExercise;
    MyEuropeanExercise = 
        EuropeanExercisePart();
    
    


    //    Creates a generic calendar object.
    

    String MyNewCalendar;
    MyNewCalendar = 
        GenericCalendarPart();
    
    


    //    Creates a fixed coupon bond object.
    
    String MyFixedCouponBond_y;
    MyFixedCouponBond_y = 
        FixedCouponBond_yPart(
        MyNewCalendar);
    
    


    //    Creates a BondOption object that will price the option via a 
    //    Black Scholes methodology.
    
    String MyQBSBondOption;
    MyQBSBondOption = 
        QBSBondOptionPart(
        MyFixedCouponBond_y,
        MyEuropeanExercise);
    
    // This is the result we are looking for.
    return MyQBSBondOption;
    
    
    }
    catch(Exception e)
    {
        szErrorMsg = e.getMessage();
        System.exit(1);
    }
                    
}                
        


// ///////////////////////////////////////////////////////////////////

private static String QBSBondOptionPart(
    String MyFixedCouponBond_y,
    String MyEuropeanExercise)
{




    //    Key Handle to be used for the new Bond object.
        String MyQBSBondOption = "MyQBSBondOption" + "_" + Integer.toString(nCTBondOptionsGlobal);


    //    When creating this object for the first time, set this parameter 
    //    to a positive value.
        int Reload = 1;


    //    Type of option (C)all or (P)ut.
        String OptionType = "Call";


    //    The exercise price of the BondOption.
        double exercisePrice = 101;


    //    The volatility of the Bond.
        double Vol = 0.2;


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


    //    A repurchase rate (repo rate) value.
        double reporate = 0.055;


    //    The compounding of the repurchase rate (repo rate) passed in.
        CTIEnums.COMPEnum compounding = CTIEnums.COMPEnum.COMP_Compounded;


    //    Frequency of the repo rate.
        CTIEnums.FreqEnum Freq = CTIEnums.FreqEnum.Freq_annual;


    //    The DayCounter of the repo rate.
        CTIEnums.DayCountEnum DayCount = CTIEnums.DayCountEnum.DayCount_actual360;

    
    //  Excel function call would be this - "CT.BNDOPT.QBSBondOption()"

    //    Creates a BondOption object that will price the option via a 
    //    Black Scholes methodology.
        String rQBSBondOption;
                                    
        rQBSBondOption = CTQL.CTBondOptionsSA.QBSBondOption(
                MyQBSBondOption,
                Reload,
                MyFixedCouponBond_y,
                OptionType,
                MyEuropeanExercise,
                exercisePrice,
                Vol,
                VolType,
                reporate,
                compounding,
                Freq,
                DayCount);


    return rQBSBondOption;

}        








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