BinomialDistribution





http://www.QuantTools.com
CapeTools Statistical Distributions function list

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

Key TAGs | Excel Index | API Index



Creates a Binomial distribution object (Discrete Distribution).

A random variable X is defined to have a binomial distribution if the discrete density function of X is given by pf= [Combination(n, x)*pow(p, x)*pow(1-p, n-x), for x=0,1...,n] or 0 otherwise.

p lies between 0 and i inclusive, n ranges over the positive integers and q=1-p. The mean of a binomial distribution is n*p, the variance of a binomial distribution is n*p*q. The binomial dsitribution reduces to the Bernoulli distribution when n=1. For example, consider sampling with replacement from an urn containing M balls, K of which are defective.

Let X represent the number of defective balls in a sample of size n. The individual draws are Bernoulli trials where 'defective' corresponds to 'success' and the experiment of taking a sample of size n with replacement consists of n repeated independent Bernoulli trials where p=P[Success] = K/M, so X has the binomial distibution.

The string 'Key' resulting from a successful construction of this distribution object can be passed to the following functions in order to query (mean, std deviation and variance) or execute functions (probability function, cumulative density function etc...) based on this distribution object : DDistributionMean(), DDistributionVar(), DDistributionSTD(), DDistributionPF() or DDistributionCDF(). In addition, the string 'Key' resulting from a successful construction of this distribution object will also allow you to construct a process generator object via a call to PGBinomialDistribution(). A process generator object allows you to generate large amounts of random numbers based on this distribution.

Even though PGBinomialDistribution() is the process generator object, the function RandomBinomial() is the actual function that obtains the random numbers given a count parameter and the process generator string 'key'.



This function creates an object and returns a string-key value to represent this created object.
The TAG value of the string-key returned (second part of the key) is : "Binomial"



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




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



Parameter Description


  1. Key parameter

    Key value to use as a handle for the created object
  2. Reload parameter

    When creating this object for the first time, set this parameter to a positive value. Within Excel, when re-computing a worksheet where you do not wish to recreate the object, set this parameter to zero (0).
  3. Trials parameter

    number of trials.
  4. prob parameter

    probability of success on each trial.


Extended information

Function Syntax

VB Syntax


String CTStatDistributions.BinomialDistribution( _
String Key, _
Long Reload, _
Long Trials, _
Double prob)


Excel Spreadsheet Syntax


=CT.STAT.BinomialDistribution(
Excel String Cell Key,
Excel Numeric Cell Reload,
Excel Numeric Cell Trials,
Excel Numeric Cell prob)


C++ Syntax


static std::string BinomialDistribution(
std::string Key,
long Reload,
long Trials,
double prob);


DotNET Syntax


System.String CTStatDistributionsSA.BinomialDistribution(
System.String Key,
System.Int32 Reload,
System.Int32 Trials,
System.Double prob);

Parameter data types

ArgNameArgTypeIsKey
KeyStringFALSE
ReloadLongFALSE
TrialsLongFALSE
probDoubleFALSE


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
KeyFALSEMyBinomialDistribution
ReloadFALSE1
TrialsFALSE1
probFALSE0.5


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.Statistics20 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 BinomialDistribution() 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 BinomialDistribution() function call


MyBinomialDistribution_4.Binomial.0

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