The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

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

SYNOPSIS

        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
        );

        $volatility=Math::Business::BlackScholes::historical_volatility(
          \@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
        );

DESCRIPTION

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.

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. 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 is usually the same as the price of the corresponding European option, because the expected value of an option is almost always greater than its intrinsic value. However, if the dividend yield (in the case of a call option) or interest rate (in the case of a put option) is high, or if there are tax considerations related to the timing of the exercise, then an American option may be more valuable to the holder.

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.

DIAGNOSTICS

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:

        {
                local($SIG{__WARN__})=sub{};
                $value=call_price( ... );
        }

CAVEATS

  • This module requires Math::CDF.

  • The model assumes that dividends are distributed continuously. In reality, the timing of the distribution 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.

  • The fractional computational error of call_price() and put_price() is usually negligible. However, while the computational error of second result of call_put_prices() is typically small in comparison to the current market price, it might be significant in comparison to the result itself. That's probably unimportant for most purposes.

  • historical_volatility() tends to produce misleading results because the behavior of the underlying security is most likely not truly log-normal. In particular, the price varies predictably after a dividend is distributed, and the daily variance is expected to be greater after financial announcements are made. Also, a large number of data points are required to obtain statistically meaningful results, but having a large number of data points implies that the results are outdated.

  • The author categorically disclaims any liability for this module.

BUGS

  • The length of the namespace component "BlackScholes" is said to cause unspecified portability problems for DOS and other 8.3 filesystems, but the consensus of the Perl community was that it is more important to have a descriptive name.

SEE ALSO

Math::CDF

AUTHOR

Anders Johnson <anders@ieee.org>