ppf/core/black_scholes.py
def black_scholes(S, K, r, sig, T, CP, *arguments, **keywords):
  """The classic Black and Scholes formula.

  >>> print black_scholes(S=42., K=40., r=0.1, sig= 0.2, T=0.5, CP=CALL)
  4.75942193531

  >>> print black_scholes(S=42., K=40., r=0.1, sig= 0.2, T=0.5, CP=PUT)
  0.808598915338

  """
  if K <= 0:
    raise RuntimeError, "strike must be non-negative"
  if sig <= 0:
    raise RuntimeError, "vol must be non-negative"
  if T <= 0:
    raise RuntimeError, "time to maturity must be non-negative"

  d1 = (log(S/K) + (r + 0.5*(sig*sig))*T)/(sig*sqrt(T))
  d2 = d1 - sig*sqrt(T)

  return CP*S*N(CP*d1) - CP*K*exp(-r*T)*N(CP*d2)
The classic Black and Scholes formula.

  >>> print black_scholes(S=42., K=40., r=0.1, sig= 0.2, T=0.5, CP=CALL)
  4.75942193531

  >>> print black_scholes(S=42., K=40., r=0.1, sig= 0.2, T=0.5, CP=PUT)
  0.808598915338

  
The classic Black and Scholes formula.


The classic Black and Scholes formula .
def black_scholes(S, K, r, sig, T, CP, *arguments, **keywords):
  if K <= 0:
    raise RuntimeError, "strike must be non-negative"
  if sig <= 0:
    raise RuntimeError, "vol must be non-negative"
  if T <= 0:
    raise RuntimeError, "time to maturity must be non-negative"
  d1 = (log(S/K) + (r + 0.5*(sig*sig))*T)/(sig*sqrt(T))
  d2 = d1 - sig*sqrt(T)
  return CP*S*N(CP*d1) - CP*K*exp(-r*T)*N(CP*d2)
def black_scholes ( S , K , r , sig , T , CP , * arguments , ** keywords ) : if K <= 0 : raise RuntimeError , "strike must be non-negative" if sig <= 0 : raise RuntimeError , "vol must be non-negative" if T <= 0 : raise RuntimeError , "time to maturity must be non-negative" d1 = ( log ( S / K ) + ( r + 0.5 * ( sig * sig ) ) * T ) / ( sig * sqrt ( T ) ) d2 = d1 - sig * sqrt ( T ) return CP * S * N ( CP * d1 ) - CP * K * exp ( - r * T ) * N ( CP * d2 )
The classic Black and Scholes formula.
The classic Black and Scholes formula .
"""The classic Black and Scholes formula.

  >>> print black_scholes(S=42., K=40., r=0.1, sig= 0.2, T=0.5, CP=CALL)
  4.75942193531

  >>> print black_scholes(S=42., K=40., r=0.1, sig= 0.2, T=0.5, CP=PUT)
  0.808598915338

  """
S
K
r
sig
T
CP