formula

package
v0.0.0-...-3a72358 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 26, 2018 License: MIT Imports: 3 Imported by: 0

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

View Source
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)

View Source
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

func Years

func Years(from, to time.Time) float64

Years returns the number of years from one time to another. You can also use time.Since(<someTime>).Hours() / 8760 to do this.

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

type Formula struct {
	StockPrice  float64
	StrikePrice float64
	Volatility  float64
	TTL         float64
}

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

func (f *Formula) D1() float64

D1 calculates the interim D1 value

func (*Formula) D2

func (f *Formula) D2() float64

D2 calculates the interim D2 value

func (*Formula) SetStockPrice

func (f *Formula) SetStockPrice(p float64)

func (*Formula) SetStrikePrice

func (f *Formula) SetStrikePrice(p float64)

func (*Formula) SetTTL

func (f *Formula) SetTTL(t time.Duration)

SetTTL sets the TTL in days for now

func (*Formula) SetVolatility

func (f *Formula) SetVolatility(v float64)

SetVolatility sets the volatility in %

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL