CFLib.org – Common Function Library Project

BlackScholes(call_put_flag, S, X, T, r, v)

Last updated May 9, 2003

Version: 1 | Requires: ColdFusion 5 | Library: FinancialLib

 
Rated 2 time(s). Average Rating: 3.5

Description:
Returns the value of call and put options using the Black-Scholes pricing formula. S is the current asset price, X is the exercise price, r is the risk-free interest rate, T is the time to maturity of the option in years, v is annualized volatility. This code requires the cumulative normal distribution function CND().

Return Values:
Returns a number.

Example:

view plain print about
<CFSET CallPutFlag = 'c'>
<CFSET S='49.25'>
<CFSET X='50.00'>
<CFSET T='0.1'>
<CFSET r='0.35'>
<CFSET v='0.30'>
<cfoutput>
#BlackScholes(CallPutFlag,S,X,T,r,v)#
</cfoutput>

Parameters:

Name Description Required
call_put_flag The Call Put Flag. Yes
S The current asset price. Yes
X Exercise price. Yes
T Time to maturity. Yes
r Risk-free Interest rate. Yes
v Annualized volatility. Yes

Full UDF Source:

view plain print about
<cfscript>
/**
 * Computes the theoretical price of an equity option.
 * 
 * @param call_put_flag      The Call Put Flag. (Required)
 * @param S      The current asset price. (Required)
 * @param X      Exercise price. (Required)
 * @param T      Time to maturity. (Required)
 * @param r      Risk-free Interest rate. (Required)
 * @param v      Annualized volatility. (Required)
 * @return Returns a number. 
 * @author Alex (axs@arbornet.org) 
 * @version 1, May 9, 2003 
 */

function BlackScholes (call_put_flag,S,X,T,r,v) {
    var d1 = ( log(S / X) + (r + (v^2) / 2) * T ) / ( v * (T^0.5) );
    var d2 = d1 - v * (T^0.5);

    if (call_put_flag eq 'c')
        return S * CND(d1) - X * exp( -r * T ) * CND(d2);
    else
        return X * exp( -r * T ) * CND(-d2) - S * CND(-d1);
}
</cfscript>
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Adam Cameron Adam Cameron added
composeDateTime
20 day(s) ago

Chris Weller Chris Weller added
convertQueryStri...
a while ago

Greg Nettles Greg Nettles added
arrayDiff
a while ago

Nathan Dintenfass Nathan Dintenfass added
ArrayOfStructsSo...
a while ago

Top Rated

Darwan Leonardo Sitepu backupDatabase
Rated 5.0, 36 time(s)

Barney Boisvert indentXml
Rated 5.0, 10 time(s)

Rachel Lehman deAccent
Rated 5.0, 6 time(s)

Isaac Dealey                                      countArbitraryDa...
Rated 5.0, 5 time(s)

Created by Raymond Camden / Design by Justin Johnson