MGapOption





http://www.QuantTools.com
CapeTools Exotic Analysis function list

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

Key TAGs | Excel Index | API Index



Binary options, also known as digital options, are popular in the OTC markets for hedging speculation.

They are also important to financial engineers as building blocks for constructing more complex options products.

the payoff from a call is 0 if S is less than or equal to X1 and S-X2 if S is greater than X1.

Similarly, the payoff from a put is 0 if S is greater than or equal to X1 and X2-S if S is less than X1.

This option can actually give negative values, depending on the settings of X1 and X2.

When the difference between X1 and X2 is such that the value of the option is zero, the option is often referred to as a pay-later option.

This function utilizes an analytical (closed-form) algorithm.

Note that the risk (greek) numbers produced are the mathematically defined equivalent of a derivative (instantaneous change).

You can convert the risk number to your own definition of risk by multiplying by the shift you require.

For example, for a typical definition of VANNA, (change in underlying and volatility), where one defines the change in the underlying as a single unit of change (1.0) and the change in volatility as a one percent change (0.01), simply multiply the VANNA result calculated by (1.0*0.01).

For VEGA, change in volatility of one percent (0.01), simply multiply the VEGA result by 0.01. Within option contracts THETA is negative, however the mathematically defined equivalent of THETA (instantaneous FORWARD change in time) is positive.

Internally we have negated this value for you.

To express THETA as THETA per day, simply multiply the THETA result by 1/365 or 1/252 (depending on whether you require calendar days or business days).

This function prices a portfolio of equity, commodities, futures or FX option deals from raw inputs.

All memory is discarded once the computation is finished.

You can request for all first and second order risk statistics simply by filling in the greek field with the name of the parameter.

The name of the parameter must be proceeded with the character 'd'. Thus if 'Stock', 'Time' and 'Vol' are the names of three parameters which represent underlying price, Option Maturity and option volatility respectively, you can request DELTA as 'dStock', GAMMA as 'dStockdStock' (dStock twice), VEGA as 'dVol', THETA as 'dTime', VOLGA as 'dVoldVol' (dVol twice) and VANNA (cross-derivative) as 'dStockdVol' or 'dVoldStock'. You can also, if you wish request 'dTimedVol' (second derivative with respect to Time and Vol).

If you wish to view all the second order derivatives within a matrix, please refer to the CapeTools Derivative Matrix category of functions.

This logic can be applied to any parameter which is of a double-valued type (decimal value).

The risk statistics are the partial derivatives with respect to the option price, thus you can scale the results by multiplying by a factor.

For example, to compute the VEGA for a one percent change in volatility (0.01), simply multiply the VEGA result by 0.01. To compute THETA for a one day change (1/365), multiply the THETA result by 1/365. To compute the DELTA for a one-unit change (1), multiply the delta by 1 which is, of course the same result as the original delta.

For second order risks, simply multiply by the product of the changes.



Note: Within Excel, the function is named - CT.MGapOption




High level graphic of MGapOption() function with parameters. Blue square node is the actual function with the parameters ordered.



Parameter Description


  1. ValueDate parameter

    Valuation Date (typically equal to Today's date)
  2. dayCounter parameter

    For any input parameter within this function that represents a dividend rate, risk free rate, foreign rate or holding cost rate, these rates will be defined as annually compounded using the DayCounter defined within this parameter. Thus if 'actual365' is used for this 'dayCounter' parameter, then all input parameters that represent a dividend, risk free, foreign or holding cost rates will be defined as annually compounded Actual365 rates.
  3. Units parameter

    Number of option contracts you wish to trade in (positive value).
  4. Position parameter

    Whether you are long or short the option.
  5. Level parameter

    Whether you would like to view the PV for the entire structure/portfolio 'TOTAL'. Whether you would like to view the PV for each option 'CASHFLOW'. Or whether you would like to view the PV and extended information, 'ALL'. Thus valid values are - 'TOTAL', 'CASHFLOW' or 'ALL'.
  6. CallPut parameter

    Option Types (C)all or (P)ut
  7. S parameter

    Underlying price
  8. X1 parameter

    First strike price of the option
  9. X2 parameter

    Second strike price of the option
  10. T parameter

    Time to option maturity.
  11. r parameter

    For the underlying (equity, futures, FX or commodity), this should be an annualised rate (risk free rate or foreign rate). If this is an option on a FX underlying, then if the underlying is quoted as domestic/foreign then this rate will be the domestic rate. If, however, the FX underlying is quoted as foreign/domestic then this will be the foreign rate.
  12. b parameter

    For the underlying (equity, futures, FX or commodity), this should be an annualised rate (dividend rate, risk free rate, foreign rate or holding cost rate respectively). If this is an option on a FX underlying, then if the underlying is quoted as domestic/foreign then this rate will be the foreign rate. If, however, the FX underlying is quoted as foreign/domestic then this will be the domestic rate.
  13. v parameter

    Volatility of the underlying.
  14. Greek parameter

    For the option premium specify 'PREMIUM'. For all first derivatives, you can specify one of the following : 'dS' (for the 'S' parameter), 'dX1' (for the 'X1' parameter), 'dX2' (for the 'X2' parameter), 'dT' (for the 'T' parameter), 'dr' (for the 'r' parameter), 'db' (for the 'b' parameter), 'dv' (for the 'v' parameter), For second order derivatives, you can specify combinations of the first order derivatives (i.e. - 'dSdS', 'dvdv', 'dSdv'. )


Extended information

Function Syntax

VB Syntax


Variant CTExoticAnalysis.MGapOption( _
Long ValueDate, _
DayCountEnum dayCounter, _
Variant Units, _
Variant Position, _
String Level, _
Variant CallPut, _
Variant S, _
Variant X1, _
Variant X2, _
Variant T, _
Variant r, _
Variant b, _
Variant v, _
String Greek)


Excel Spreadsheet Syntax


=CT.MGapOption(
Excel Numeric Cell ValueDate,
Excel String Cell dayCounter,
XLRange Units,
XLRange Position,
Excel String Cell Level,
XLRange CallPut,
XLRange S,
XLRange X1,
XLRange X2,
XLRange T,
XLRange r,
XLRange b,
XLRange v,
Excel String Cell Greek)


C++ Syntax


static CTRangeDataCPP MGapOption(
long ValueDate,
DayCountEnum dayCounter,
CTRangeDataCPP Units,
CTRangeDataCPP Position,
std::string Level,
CTRangeDataCPP CallPut,
CTRangeDataCPP S,
CTRangeDataCPP X1,
CTRangeDataCPP X2,
CTRangeDataCPP T,
CTRangeDataCPP r,
CTRangeDataCPP b,
CTRangeDataCPP v,
std::string Greek);


DotNET Syntax


CTRangeData CTExoticAnalysisSA.MGapOption(
System.Int32 ValueDate,
CTIEnums.DayCountEnum dayCounter,
CTRangeData Units,
CTRangeData Position,
System.String Level,
CTRangeData CallPut,
CTRangeData S,
CTRangeData X1,
CTRangeData X2,
CTRangeData T,
CTRangeData r,
CTRangeData b,
CTRangeData v,
System.String Greek);

Parameter data types

ArgNameArgTypeIsKey
ValueDateLongFALSE
dayCounterDayCountEnumFALSE
UnitsRangeFALSE
PositionRangeFALSE
LevelStringFALSE
CallPutRangeFALSE
SRangeFALSE
X1RangeFALSE
X2RangeFALSE
TRangeFALSE
rRangeFALSE
bRangeFALSE
vRangeFALSE
GreekStringFALSE


Example Inputs

The first column represents the name of the parameters. The second column specifies whether the parameters are optional or not. Finally the last column provides some sample input data.
Function call input string-keys are always in the format : "NAME.EXTTAG.TICKER" The "EXTTAG.TICKER" part is determined from the output of other, capetools, object creation functions.


ArgNameIsOptional (Excel only)Example
ValueDateFALSE19/Jul/2005 (serial date type)
dayCounterFALSEACT365
UnitsFALSEMGapOption_Units_Range (creates a range object)
PositionFALSEMGapOption_Position_Range (creates a range object)
LevelFALSEALL
CallPutFALSEMGapOption_CallPut_Range (creates a range object)
SFALSEMGapOption_S_Range (creates a range object)
X1FALSEMGapOption_X1_Range (creates a range object)
X2FALSEMGapOption_X2_Range (creates a range object)
TFALSEMGapOption_T_Range (creates a range object)
rFALSEMGapOption_r_Range (creates a range object)
bFALSEMGapOption_b_Range (creates a range object)
vFALSEMGapOption_v_Range (creates a range object)
GreekFALSEPREMIUM


Example range for parameter : Units

Within Excel, a range such as this can be passed directly into the Units parameter.


Data is stored within the second column (Vector of data)..

Example C# API usage for setting the range data for parameter : Units



CTQL.CTRangeData MGapOption_Units;


int[] arrBMGapOption_Units = {
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1  //  Array Data

};

CTQL.IntVector arrMGapOption_Units =
new  CTQL.IntVector(arrBMGapOption_Units);

// Second parameter determines whether the array is a column array (false) or a row array (true)
MGapOption_Units = new  CTQL.CTRangeData(arrMGapOption_Units, false);


Example range for parameter : Position

Within Excel, a range such as this can be passed directly into the Position parameter.


Data is stored within the second column (Vector of data)..

Example C# API usage for setting the range data for parameter : Position



CTQL.CTRangeData MGapOption_Position;


string[] arrBMGapOption_Position = {
"LONG",
"LONG",
"LONG",
"LONG",
"LONG",
"LONG",
"LONG",
"LONG",
"LONG",
"LONG",
"LONG",
"LONG",
"LONG",
"LONG",
"LONG",
"LONG",
"LONG",
"LONG",
"LONG",
"LONG"  //  Array Data

};

CTQL.StringVector arrMGapOption_Position =
new  CTQL.StringVector(arrBMGapOption_Position);

// Second parameter determines whether the array is a column array (false) or a row array (true)
MGapOption_Position = new  CTQL.CTRangeData(arrMGapOption_Position, false);


Example range for parameter : CallPut

Within Excel, a range such as this can be passed directly into the CallPut parameter.


Data is stored within the second column (Vector of data)..

Example C# API usage for setting the range data for parameter : CallPut



CTQL.CTRangeData MGapOption_CallPut;


string[] arrBMGapOption_CallPut = {
"Call",
"Call",
"Call",
"Call",
"Call",
"Call",
"Call",
"Call",
"Call",
"Call",
"Call",
"Call",
"Call",
"Call",
"Call",
"Call",
"Call",
"Call",
"Call",
"Call"  //  Array Data

};

CTQL.StringVector arrMGapOption_CallPut =
new  CTQL.StringVector(arrBMGapOption_CallPut);

// Second parameter determines whether the array is a column array (false) or a row array (true)
MGapOption_CallPut = new  CTQL.CTRangeData(arrMGapOption_CallPut, false);


Example range for parameter : S

Within Excel, a range such as this can be passed directly into the S parameter.


Data is stored within the second column (Vector of data)..

Example C# API usage for setting the range data for parameter : S



CTQL.CTRangeData MGapOption_S;


double[] arrBMGapOption_S = {
54.3239,
45.7873,
50.161,
45.1229,
52.8636,
51.1374,
53.7031,
48.2197,
54.9037,
53.5253,
53.5145,
50.3603,
46.2579,
48.6353,
53.1675,
48.9525,
50.3275,
49.3878,
54.5256,
50.0  //  Array Data

};

CTQL.DoubleVector arrMGapOption_S =
new  CTQL.DoubleVector(arrBMGapOption_S);

// Second parameter determines whether the array is a column array (false) or a row array (true)
MGapOption_S = new  CTQL.CTRangeData(arrMGapOption_S, false);


Example range for parameter : X1

Within Excel, a range such as this can be passed directly into the X1 parameter.


Data is stored within the second column (Vector of data)..

Example C# API usage for setting the range data for parameter : X1



CTQL.CTRangeData MGapOption_X1;


double[] arrBMGapOption_X1 = {
48.0287,
47.2883,
45.9369,
52.5833,
49.2426,
46.3441,
53.1763,
50.1449,
51.2186,
48.9345,
52.351,
54.2834,
46.3154,
53.6074,
50.9421,
53.1805,
48.1128,
45.2487,
47.417,
50.0  //  Array Data

};

CTQL.DoubleVector arrMGapOption_X1 =
new  CTQL.DoubleVector(arrBMGapOption_X1);

// Second parameter determines whether the array is a column array (false) or a row array (true)
MGapOption_X1 = new  CTQL.CTRangeData(arrMGapOption_X1, false);


Example range for parameter : X2

Within Excel, a range such as this can be passed directly into the X2 parameter.


Data is stored within the second column (Vector of data)..

Example C# API usage for setting the range data for parameter : X2



CTQL.CTRangeData MGapOption_X2;


double[] arrBMGapOption_X2 = {
53.3828,
62.1604,
61.4992,
54.1557,
60.7053,
58.2865,
55.89,
57.1257,
62.0179,
60.7308,
55.0616,
54.3476,
54.7912,
52.1433,
60.4761,
56.3983,
53.6073,
55.0409,
56.5954,
57.0  //  Array Data

};

CTQL.DoubleVector arrMGapOption_X2 =
new  CTQL.DoubleVector(arrBMGapOption_X2);

// Second parameter determines whether the array is a column array (false) or a row array (true)
MGapOption_X2 = new  CTQL.CTRangeData(arrMGapOption_X2, false);


Example range for parameter : T

Within Excel, a range such as this can be passed directly into the T parameter.


Data is stored within the second column (Vector of data)..

Example C# API usage for setting the range data for parameter : T



CTQL.CTRangeData MGapOption_T;


int[] arrBMGapOption_T = {
CTQL.Date.serialNumber("17/1/2006", "dd/mm/yyyy"),
CTQL.Date.serialNumber("17/1/2006", "dd/mm/yyyy"),
CTQL.Date.serialNumber("17/1/2006", "dd/mm/yyyy"),
CTQL.Date.serialNumber("17/1/2006", "dd/mm/yyyy"),
CTQL.Date.serialNumber("17/1/2006", "dd/mm/yyyy"),
CTQL.Date.serialNumber("17/1/2006", "dd/mm/yyyy"),
CTQL.Date.serialNumber("17/1/2006", "dd/mm/yyyy"),
CTQL.Date.serialNumber("17/1/2006", "dd/mm/yyyy"),
CTQL.Date.serialNumber("17/1/2006", "dd/mm/yyyy"),
CTQL.Date.serialNumber("17/1/2006", "dd/mm/yyyy"),
CTQL.Date.serialNumber("17/1/2006", "dd/mm/yyyy"),
CTQL.Date.serialNumber("17/1/2006", "dd/mm/yyyy"),
CTQL.Date.serialNumber("17/1/2006", "dd/mm/yyyy"),
CTQL.Date.serialNumber("17/1/2006", "dd/mm/yyyy"),
CTQL.Date.serialNumber("17/1/2006", "dd/mm/yyyy"),
CTQL.Date.serialNumber("17/1/2006", "dd/mm/yyyy"),
CTQL.Date.serialNumber("17/1/2006", "dd/mm/yyyy"),
CTQL.Date.serialNumber("17/1/2006", "dd/mm/yyyy"),
CTQL.Date.serialNumber("17/1/2006", "dd/mm/yyyy"),
CTQL.Date.serialNumber("17/1/2006", "dd/mm/yyyy")  //  Array Data

};

CTQL.IntVector arrMGapOption_T =
new  CTQL.IntVector(arrBMGapOption_T);

// Second parameter determines whether the array is a column array (false) or a row array (true)
MGapOption_T = new  CTQL.CTRangeData(arrMGapOption_T, false);


Example range for parameter : r

Within Excel, a range such as this can be passed directly into the r parameter.


Data is stored within the second column (Vector of data)..

Example C# API usage for setting the range data for parameter : r



CTQL.CTRangeData MGapOption_r;


double[] arrBMGapOption_r = {
0.0848,
0.0818,
0.0883,
0.0882,
0.0836,
0.0978,
0.0976,
0.0911,
0.0952,
0.0966,
0.0951,
0.0858,
0.0818,
0.0847,
0.0937,
0.0977,
0.0813,
0.0934,
0.0862,
0.09  //  Array Data

};

CTQL.DoubleVector arrMGapOption_r =
new  CTQL.DoubleVector(arrBMGapOption_r);

// Second parameter determines whether the array is a column array (false) or a row array (true)
MGapOption_r = new  CTQL.CTRangeData(arrMGapOption_r, false);


Example range for parameter : b

Within Excel, a range such as this can be passed directly into the b parameter.


Data is stored within the second column (Vector of data)..

Example C# API usage for setting the range data for parameter : b



CTQL.CTRangeData MGapOption_b = new CTQL.CTRangeData();

System.Text.StringBuilder MGapOption_b_builder =
new System.Text.StringBuilder(100);

MGapOption_b_builder.Append("{");
MGapOption_b_builder.Append("0 ;");
MGapOption_b_builder.Append("0 ;");
MGapOption_b_builder.Append("0 ;");
MGapOption_b_builder.Append("0 ;");
MGapOption_b_builder.Append("0 ;");
MGapOption_b_builder.Append("0 ;");
MGapOption_b_builder.Append("0 ;");
MGapOption_b_builder.Append("0 ;");
MGapOption_b_builder.Append("0 ;");
MGapOption_b_builder.Append("0 ;");
MGapOption_b_builder.Append("0 ;");
MGapOption_b_builder.Append("0 ;");
MGapOption_b_builder.Append("0 ;");
MGapOption_b_builder.Append("0 ;");
MGapOption_b_builder.Append("0 ;");
MGapOption_b_builder.Append("0 ;");
MGapOption_b_builder.Append("0 ;");
MGapOption_b_builder.Append("0 ;");
MGapOption_b_builder.Append("0 ;");
MGapOption_b_builder.Append("0.00");
MGapOption_b_builder.Append("}");

// Parse the string into the Range object.
MGapOption_b.RangeFromStr( MGapOption_b_builder.ToString() );


Example range for parameter : v

Within Excel, a range such as this can be passed directly into the v parameter.


Data is stored within the second column (Vector of data)..

Example C# API usage for setting the range data for parameter : v



CTQL.CTRangeData MGapOption_v;


double[] arrBMGapOption_v = {
0.2076,
0.216,
0.1929,
0.1838,
0.184,
0.2118,
0.2004,
0.1864,
0.191,
0.1966,
0.1986,
0.1837,
0.1926,
0.1811,
0.208,
0.1973,
0.1968,
0.2032,
0.2071,
0.2  //  Array Data

};

CTQL.DoubleVector arrMGapOption_v =
new  CTQL.DoubleVector(arrBMGapOption_v);

// Second parameter determines whether the array is a column array (false) or a row array (true)
MGapOption_v = new  CTQL.CTRangeData(arrMGapOption_v, false);



Example function usage


The C# example below contains all the sub-function calls leading up to this function call. As a result, the example can contain a lot of code.

The VB.NET, J#, C++.NET, Java, Excel VBA, Visual Basic 6 (via COM) and C++ examples below contain function code stubs for the calls leading up to this function call. However, the function call for this function is displayed.
You can easily reproduce the stub functions code from the C# example.


If you are accessing this functrion via the MiniXL libraries, this function is present within the CT.QL.Pricing20 MiniXL Excel Addin.

Within our Excel Example Addin Generator, we have used the following QuantTools sub-functions in order to prepare the arguments needed to call the MGapOption() function. If you are executing this function via the MiniXL libraries, the module addin name, (in brackets, to the right of the sub-functions listed below), indicates the MiniXL library in which the sub-function is held. You will need to load this library into your Excel session (along with any other libraries that the sub-function call within the addin requires (ie - CT.QT.Utils20 addin in almost all cases) in order for the example to compute successfully.


The following four examples demostrate calling this function within a Microsoft .NET environment

The following four examples demostrate calling this function within a non .NET environment

The following is a sample output from executing the MGapOption() function call


Example
NoOfUnitsPositionCallPutSX1X2TrbvPREMIUM
1LONGCall52.874450.70260.7489387340.086400.1892-1.50128
1LONGCall46.000648.797858.6768387340.087500.2069-1.7013
1LONGCall47.551550.945462.4183387340.081400.2059-2.18115
1LONGCall51.985154.572855.0562387340.097500.212.85682
1LONGCall45.800445.35553.4428387340.085900.2024-0.892131
1LONGCall49.881452.3951.7195387340.081700.18872.74611
1LONGCall50.433350.01558.7674387340.088600.2066-0.802495
1LONGCall52.268150.325362.6273387340.093100.2196-2.32086
1LONGCall50.666951.713155.1242387340.088800.18861.51975
1LONGCall50.635954.968656.141387340.090800.19531.57363
1LONGCall54.607649.820754.1558387340.084700.18123.86454
1LONGCall52.93150.783653.3532387340.093100.20263.91175
1LONGCall51.6253.211952.5235387340.092300.2093.76777
1LONGCall51.450954.351555.4627387340.092500.19562.15078
1LONGCall53.639752.533661.682387340.083600.2056-0.704852
1LONGCall53.903752.559451.3508387340.088800.1845.67271
1LONGCall46.995350.640656.6517387340.096600.1912-0.286956
1LONGCall52.944646.296351.5639387340.091800.19964.58624
1LONGCall48.799646.506362.1703387340.089800.1921-5.70057
1LONGCall505057387340.0900.2-0.0119749



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