Welcome Features News Download Registration Support FAQ Wish list Links
Advanced stock charting and analysis program

AFL Library

This is read-only version of AFL library entry. Ability to add user formulas and comment is only available from members-only area.

Details:

Formula name: Black Scholes Option Pricing
Author/Uploader: Anthony Faragasso - ajf1111 [at] epix.net
Date/Time added: 2005-03-20 13:19:39
Origin:
Keywords: Options, Black Scholes
Level: advanced
Flags: exploration

DISCLAIMER: Most formulas present in AFL on-line library are submitted by the users and are provided here on an "as is" and "as available" basis. AmiBroker.com makes no representations or warranties of any kind to the contents or the operation of material presented here. We do not maintain nor provide technical support for 3rd party formulas.
Description:

Black Scholes Option Pricing returns the Fair Value of call and put options.

Formula:

//BLACK SHCOLES OPTION PRICING FORMULA
//coded by Anthony Faragasso
//1-01-03

// User Variables
 
StockPrice  = Param("stockPrice",81,1,200,1); //Stock Price 
Timedays    = Param("DaysToExpire",30,1,300,1); //Time to expiry ( days to
exp/365 )
StrikePrice = Param("StrikePrice",75,1,300,1); //strike Price of Option to
evaluate
InterestRate= Param("InterestRate",0.06,0.01,0.11,0.001); //prevailing interest
rate 
VKnown =Param("Volatility",0.30,0.10,0.50,0.001);//You can insert Known
volatility here , Implied Volatility. 

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

time=timedays/365;// days to expire conversion formula


//Formula variables below

/*************************************************/
// Solves for ( X )

x = (ln(stockPrice/strikePrice) + (interestrate +
Vknown*Vknown/2)*time)/(Vknown*sqrt(time)); 
/*************************************************/

P =  0.2316419;   
bb1 = 0.31938153; 
bb2 = -0.3565638; 
bb3 = 1.78147794; 
bb4 = -1.821256;
bb5 = 1.33027443;

pi = 3.141592654; // PI

A2 = 1/sqrt(2*pi);
A3 = exp(-(x^2)/2);
y= a2*a3;
A4 = exp(-interestrate*time);
t1 = 1/(1+ P*x);
A5=(bb1*t1)+(bb2*t1^2) +( bb3*t1^3)+(bb4*t1^4)+(bb5*t1^5);
/************************************************************/
//Standard Normal Distribution Function of ( x )


N = 1- y *A5 ;

/************************************************************/
  // Solves for ( X1 )
X1=x-Vknown*sqrt(TIME);

y1=1/sqrt(2*pi);
N0=exp(-(x1^2)/2);
T2=1/(1+ P*X1);
A6=(bb1*t2)+(bb2*t2^2) +( bb3*t2^3)+(bb4*t2^4)+(bb5*t2^5);
A7=exp(-interestrate*time);
y2=y1*n0;

/************************************************************/
/* Standard Normal Distribution Function OF ( x1 )*/
/***********************************************************/
N2= 1-y2 * A6;

/************ CALL OPTION FAIR VALUE************/
Call = stockPrice  * N - strikePrice *  A4  * N2;

/************ PUT OPTION FAIR VALUE*************/

Put =  Call - stockprice  + strikeprice*A7;

 
Filter = 1;
SetOption("nodefaultcolumns",1);
AddColumn(stockPrice,"AssetP",2.2);
AddColumn(strikeprice,"StrikeP",1.2);
AddColumn(InterestRate*100,"InterestRate%",1.2);
AddColumn(VKnown*100,"Volatility%",1.2);
AddColumn(timedays,"DaysToExpire ",1);
AddColumn(Call,"Call FV",1.2);
AddColumn(put,"Put FV",1.2);

//Notes
/* AA window
1. Select current symbol ( could be any stock, output is not associated
with the current stock).
2. n last quotations
3. n = 1
4. Use the Parameters button to make user selections
5. Click explore */

Comments:

Hans

2005-03-27 10:01:30
Here follows code for use with stock relative to option as indicator:

//BLACK SCHOLES OPTION PRICING FORMULA
//coded by Anthony Faragasso
//1-01-03
/*modified by Hans 27/6/2005 for use as Indicator (use with amibroker 4.70)
** user have to copy/create into directory amibroker\formulas\include
following file named "DayToNumFunction.afl" with followin code:

function DayNum(dt)
{
yr= int(Dt/10000);
mo= int((dt-(yr*10000))/100);
dy= int(dt-(yr*10000)-(mo*100));
adj=(mo>1) +( mo>3) + (mo>5) + (mo>7) + (mo>8) + (mo>10) + (mo>12)- ((mo>2)*2);
return ( yr*365) +( (mo-1)*30) +dy +adj;
}

*/

#include <DayToNumFunction.afl>

// User Variables

//StockPrice = Param("stockPrice",81,0,200,0.001); //Stock Price
StockPrice = Close;
expdate = ParamDate( "Expiring date", "03/06/2005", 0 );
expdate=IIf(expdate>20000000,expdate-19000000,expdate);//correction (bug) of values
Timedays = daynum(expdate)-daynum(DateNum());
StrikePrice = Param("StrikePrice",0.9848,0,300,0.001); //strike Price of Option to evaluate
InterestRate= Param("InterestRate",0.025,0.01,0.11,0.001); //prevailing interest rate
VKnown =Param("Volatility",0.26,0.10,0.50,0.001);//You can insert Known volatility here , Implied Volatility.

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

time=timedays/365;// days to expire conversion formula

//Formula variables below

/*************************************************/
// Solves for ( X )

x = (ln(stockPrice/strikePrice) + (interestrate + Vknown*Vknown/2)*time)/(Vknown*sqrt(time));
/*************************************************/

P = 0.2316419;
bb1 = 0.31938153;
bb2 = -0.3565638;
bb3 = 1.78147794;
bb4 = -1.821256;
bb5 = 1.33027443;

pi = 3.141592654; // PI

A2 = 1/sqrt(2*pi);
A3 = exp(-(x^2)/2);
y= a2*a3;
A4 = exp(-interestrate*time);
t1 = 1/(1+ P*x);
A5=(bb1*t1)+(bb2*t1^2) +( bb3*t1^3)+(bb4*t1^4)+(bb5*t1^5);
/************************************************************/
//Standard Normal Distribution Function of ( x )


N = 1- y *A5 ;

/************************************************************/
// Solves for ( X1 )
X1=x-Vknown*sqrt(TIME);

y1=1/sqrt(2*pi);
N0=exp(-(x1^2)/2);
T2=1/(1+ P*X1);
A6=(bb1*t2)+(bb2*t2^2) +( bb3*t2^3)+(bb4*t2^4)+(bb5*t2^5);
A7=exp(-interestrate*time);
y2=y1*n0;

/************************************************************/
/* Standard Normal Distribution Function OF ( x1 )*/
/***********************************************************/
N2= 1-y2 * A6;

/************ CALL OPTION FAIR VALUE************/
Call = stockPrice * N - strikePrice * A4 * N2;

/************ PUT OPTION FAIR VALUE*************/

Put = Call - stockprice + strikeprice*A7;
Plot(stockprice,Date()+" - Asset price",colorDarkBlue,styleLine|styleLeftAxisScale);
Plot(strikeprice,"Strike price = "+NumToStr(strikeprice,1.4),colorBlack,styleLine|styleLeftAxisScale);
Plot(InterestRate*100,"Interest rate",colorDarkGreen,styleOwnScale|styleNoLine|styleNoLabel);
Plot(VKnown*100,"Volatility%",colorDarkRed,styleOwnScale|styleNoLine|styleNoLabel);
Plot(timedays,"
DaysToExpire "+numtostr(expdate,10.0),colorDarkGrey,styleOwnScale|styleNoLine|styleNoLabel);
Plot(Call,"Call FV = "+NumToStr(Call,1.4),colorGreen,styleLine);
Plot(Put,"Put FV = "+NumToStr(put,1.4),colorRed,styleLine);

Filter = 1;
SetOption("nodefaultcolumns",1);
AddColumn(stockPrice,"AssetP",2.3);
AddColumn(strikeprice,"StrikeP",1.3);
AddColumn(InterestRate*100,"InterestRate%",1.2);
AddColumn(VKnown*100,"Volatility%",1.2);
AddColumn(timedays,"DaysToExpire ",1);
AddColumn(Call,"Call FV",1.4);
AddColumn(put,"Put FV",1.4);

//Notes
/* AA window
1. Select current symbol ( could be any stock, output is not associated
with the current stock).
2. n last quotations
3. n = 1
4. Use the Parameters button to make user selections
5. Click explore */


About | Privacy | Terms of Use | Contact information
Copyright © 2001 AMIBROKER.COM