# Black Scholes formula

### Syntax

```
public enum CalcEx.CallPutFlag { Call, Put };
public static double BlackScholes(this double S, double X, double D, double R, double V, CallPutFlag flag)public enum CallPutFlag { Call, Put };
public static double BlackScholes(CallPutFlag flag, double S, double X, double D, double R, double V)
```

### Parameter Description

 flag Call or Put option - pass either CallPutFlag.Call or CallPutFlag.Put S Stock price X Strike price of option D Days to expiry R Risk-free rate, % V Volatility, %

### Description

This Black Scholes formula is courtesy espenhaug.com, slightly modified by Eugene.

### Example

Code below illustrates a couple of examples illustrating the Black Scholes formula usage:

Example using C# extension methods:

```
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using WealthLab;
using Community.Components;namespace WealthLab.Strategies
{
public class MyStrategy : WealthScript
{
private string str (double s) { return String.Format("{0:0.00}", s); }

protected override void Execute()
{
double price = Bars.Close[Bars.Count-1];
if( price < 10 ) Abort();
double call =
price.BlackScholes( price + 5.0d, 60, 1d, 20.0, CalcEx.CallPutFlag.Call ); // days=60, rate=1%, volatility=20%=0.20
double put =
price.BlackScholes( price - 5.0d, 60, 1d, 20.0, CalcEx.CallPutFlag.Put ); // days=60, rate=1%, volatility=20%=0.20
PrintDebug( string.Concat( "Call = ", str(call),  " Put = ", str(put) ) );
}
}
}
```

Legacy syntax example:

```
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using WealthLab;
using Community.Components;namespace WealthLab.Strategies
{
public class MyStrategy : WealthScript
{
private string str (double s) { return String.Format("{0:0.00}", s); }

protected override void Execute()
{
double price = Bars.Close[Bars.Count-1];
if( price < 10 ) Abort();
double call =
Calculate.BlackScholes( Calculate.CallPutFlag.Call,
price,
price + 5.0d,
60,
1d,
20.0 ); // days=60, rate=1%, volatility=20%=0.20
double put =
Calculate.BlackScholes( Calculate.CallPutFlag.Put,
price,
price - 5.0d,
60,
1d,
20.0 ); // days=60, rate=1%, volatility=20%=0.20
PrintDebug( string.Concat( "Call = ", str(call),  " Put = ", str(put) ) );
}
}
}
```
 Important Disclaimer: The information provided by Wealth-Lab is strictly for informational purposes and is not to be construed as advice or solicitation to buy or sell any security.  The owner of Wealth-Lab.com assumes no liability resulting from the use of the material contained herein for investment purposes. By using this web site, you agree to the terms of this disclaimer and our Terms of Use.

ScrewTurn Wiki. Some of the icons created by FamFamFam.