door GMe » do 16 sep 2004, 11:59
{***********************************************************************
Description:This Function returns Black option valuation model
Provided By: Omega Research, Inc. (c) Copyright 1999
************************************************************************}
Inputs: DaysLeft(Numeric), Strike(Numeric), AssetPrice(Numeric), InterestRate(Numeric), Volty(Numeric), OptionType(Numeric);
Variables: Answer(0), D1(0), D2(0), Nd1(0), ND2(0), e(2.71828183), ERT(0), NprimeX(0), pi(3.14159), Price(0), StrikePrice(0), r(0), Vty(0), TInDays(0), TAnnual(0), SQRootTime(0), skip(0), OT(0);
StrikePrice = Strike;
Price = AssetPrice;
Vty = volty * .01;
If OptionType = 1 OR OptionType = Call Then
OT = Call;
If OptionType = 0 OR OptionType = Put Then
OT = Put;
If Price > 0 Then Begin
If StrikePrice > 0 Then Begin
If Vty > 0 Then Begin
TInDays = DaysLeft;
If TInDays > 0 Then Begin
TAnnual = TInDays * 0.002739;
? ? SQRootTime = SquareRoot(TAnnual);
If InterestRate > 0 Then Begin
?r = InterestRate * .01;
skip = 1;
D1 = (Log(Price / StrikePrice) + ((r + ((Vty * Vty) * .5)) * TAnnual)) / (Vty * SQRootTime);
NprimeX = (1 / SquareRoot(2 * pi)) * Power(e, -(D1 * D1) * .5);
ERT = Power(e, -1 * r * TAnnual);
If OT = Put Then Begin
?Nd1 = NormalSCDensity(-D1);
?D2 = (Vty * SQRootTime) - D1;
ND2 = NormalSCDensity(D2); ? ?
Answer = (-Price * Nd1) + StrikePrice * ERT * ND2;
If Answer > StrikePrice Then
Answer = StrikePrice;
If Answer < StrikePrice - Price Then
Answer = StrikePrice - Price;
? BlackScholes = Answer;
End
Else
If OT = Call Then Begin
Nd1 = NormalSCdensity(D1);
D2 = D1 - (Vty * SQRootTime);
ND2 = NormalSCDensity(D2); ?
Answer = Price * Nd1 - StrikePrice * ERT * ND2;
If Answer < Price - StrikePrice Then
Answer = Price - StrikePrice;
BlackScholes = Answer;
End;
End;
End;
End;
End;
End;
If skip = 0 Then Begin
Answer = 0;
If OT = Put Then Begin
If 0 < StrikePrice - Price Then
Answer = StrikePrice - Price;
BlackScholes = Answer;
End
Else
If OT = Call Then Begin
If 0 < Price - StrikePrice Then
Answer = Price - StrikePrice;
BlackScholes = Answer;
End;
End;