Documentation
¶
Overview ¶
package formula contains functions for calculating option prices.
based on the pricing model developed by Fischer Black and Myron Scholes in 1973. For many options, the Black-Scholes model is reasonably close to the actual market price.
This package uses S to represent the stock price, X to represent the strike price, T to represent time in number of years, and v to represent volatility in all of the functions. The risk free interest rate is set as a global variable for both convenience and to keep it out of your code unless you want to set it.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var N func(float64) float64 = distuv.UnitNormal.CDF // nolint: gochecknoglobals
N is the Normalized CDF (NORMSDIST in Excel/Sheets) function. The current implementation comes from gonum, although the use of this variable allows the implementation to vary without modifying the interface (aka The Adapter Pattern)
var RiskFree = 2.34 // nolint: gochecknoglobals
RiskFree represents r in the Black-Scholes formula. It is generally defined as the rate of a 3-month T-Bill.
Functions ¶
Types ¶
type BlackScholes ¶
type BlackScholes struct {
Formula
}
func (*BlackScholes) Calculate ¶
func (b *BlackScholes) Calculate() (call, put float64)
Calculate returns the Black-Scholes call and put price, respectively
func (*BlackScholes) Call ¶
func (b *BlackScholes) Call() float64
Call returns the Black-Scholes call price
func (*BlackScholes) Put ¶
func (b *BlackScholes) Put() float64
Put returns the Black-Scholes put price
type Calculator ¶
type Calculator interface { Call() float64 Put() float64 Calculate() (float64, float64) SetStockPrice(float64) SetStrikePrice(float64) SetVolatility(float64) SetTTL(time.Duration) }
Calculator types are capable of calculating prices for options. BlackScholes and Binomial would be examples of Calculators.
type Formula ¶
Formula is a base type that the formulae embed. It provides methods that are common to all pricing types such as Greeks and some interim calculations (for example d1, which is used by Black-Scholes). This type can't calculate option prices by itself, but it provides a lot of handy information.
func (*Formula) SetStockPrice ¶
func (*Formula) SetStrikePrice ¶
func (*Formula) SetVolatility ¶
SetVolatility sets the volatility in %