Anders Johnson > Math-Business-BlackScholes > Math::Business::BlackScholes



Annotate this POD

View/Report Bugs
Module Version: 1.01   Source  


Math::Business::BlackScholes - Black-Scholes option price model functions


        use Math::Business::BlackScholes
          qw/call_price call_put_prices implied_volatility_call/;

        my $volatility=implied_volatility_call(
          $current_market_price, $option_price_in, $strike_price_in,
          $remaining_term_in, $interest_rate, $fractional_yield

        my $call=call_price(
          $current_market_price, $volatility, $strike_price,
          $remaining_term, $interest_rate, $fractional_yield

          \@closing_prices, 251

        my $put=Math::Business::BlackScholes::put_price(
          $current_market_price, $volatility, $strike_price,
          $remaining_term, $interest_rate
        ); # $fractional_yield defaults to 0.0

        my ($c, $p)=call_put_prices(
          $current_market_price, $volatility, $strike_price,
          $remaining_term, $interest_rate, $fractional_yield

        my $call_discrete_div=call_price(
          $current_market_price, $volatility, $strike_price,
          $remaining_term, $interest_rate,
          { 0.3 => 0.35, 0.55 => 0.35 }


Estimates the fair market price of a European stock option according to the Black-Scholes model.

call_price() returns the price of a call option. put_price() returns the value of a put option. call_put_prices() returns a 2-element array whose first element is the price of a call option, and whose second element is the price of the put option with the same parameters; it is expected to be computationally more efficient than calling call_price() and put_price() sequentially with the same arguments. Each of these routines accepts the same set of parameters:

$current_market_price is the price for which the underlying security is currently trading. $volatility is the standard deviation of the probability distribution of the natural logarithm of the stock price one year in the future. $strike_price is the strike price of the option. $remaining_term is the time remaining until the option expires, in years. $interest_rate is the risk-free interest rate (per year) as a fraction. $fractional_yield is the fraction of the stock price that the stock yields in dividends per year; it is assumed to be zero if unspecified.

Discrete Dividends

If $fractional_yield is specified as a number, then the actual timing of the ex-dividend dates relative to the current time and the option expiration time can affect the option price by as much as the value of a single dividend.

$fractional_yield may instead be specified as a hashref, each key of which is the remaining amount of time before the dividend is paid, in years, and each value of which is the dividend amount. This produces more accurate results when the dividends that will be assigned during the term of the option are reliably predictable. The ex-dividend date of each dividend so represented is assumed to occur within the remaining term of the option, even if the dividend is paid after the term expires.

Determining Parameter Values

$volatility and $fractional_yield are traditionally estimated based on historical data. $interest_rate is traditionally equal to the current T-bill rate. The model assumes that these parameters are stable over the term of the option.

$volatility (a.k.a. sigma) is sometimes expressed as a percentage, which is misleading because it's not a ratio. If you have it as a percentage, then you'll need to divide it by 100 before passing it to this module. Ditto for $interest_rate and $fractional_yield.

Two ways to estimate $volatility are provided. historical_volatility() takes an arrayref of at least 10 (preferably 100 or more) consecutive daily closing prices of the underlying security, in either chronological or reverse chronological order. It then multiplies the variance of the log of day-to-day returns by the number of trading days per year specified by the second argument (or 250 by default). The square-root of this yearly variance is returned.

implied_volatility_call() computes the implied volatility based on the known trading price of a "reference" call option on the same underlying security with a different strike price and/or term, using the Newton-Raphson method, or the bisection method if it fails to converge otherwise. It's invoked like call_price(), except that the second argument is taken as the price of the call option, and the volatility is returned. You can override the default option price tolerance of 1e-4 by passing an additional argument beyond $fractional_yield. If called in an array context, the second element of the return value is an estimate of the error magnitude, and the third element is the number of iterations required to obtain the result. The error magnitude may be quite large unless you use a reference option whose price exceeds its intrinsic value by an amount larger than or comparable to the absolute difference of the market price and the strike price, and it is undefined if the price of the reference option is less than what would be calculated with zero volatility. If the price of the reference option is greater than what would be calculated with infinite volatility, then both the result and the error estimate are undefined. An exception is thrown if it fails to converge within $Math::Business::BlackScholes::max_iter (100 by default) iterations. An analogous implied_volatility_put() is also available.

American Options

Whereas a European stock option may be exercised only when it expires, an American option may be exercised any time prior to its expiration. The price of an American option can be approximated as the maximum price of similar European options over all possible remaining terms not greater than the remaining term of the American option. This maximum usually occurs at the end of the remaining term, or just before or just after the final ex-dividend date within the remaining term.

Negative Market Value

An underlying security with a negative market value is assumed to be a short. Buying a short is equivalent to selling the security, so a call option on a short is equivalent to a put option. This is somewhat confusing, and arguably a warning ought to be generated if it gets invoked.


Attempting to evaluate an option with a negative term will result in a croak(), because that's meaningless. Passing suspicious arguments (e.g. a negative interest rate) will result in descriptive warning messages. To disable such messages, try this:

                $value=call_price( ... );






Anders Johnson <>


Thanks to Richard Solberg for helping to debug the implied volatility functions.

syntax highlighting: