Skip to content

Simple Golang implementation of Black-Scholes pricing model and Newton-Raphson Method

Notifications You must be signed in to change notification settings

AnthonyLaiuppa/guant

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

guant

Go Report Card codecov Build Status

A simple go implemention of the Black-Scholes pricing model and Newton-Raphson Method.

Writeup

Black Scholes pricing model:

Forumla provided by wikipedia

Newton-Raphson Method:

Newtons Method

Derivative Struct:
        N     distuv.Normal  // Cumulative Normal Distribution function with {Mu: 0, Sigma: 1} 
   	S     float64        // S - stock price
   	K     float64        // K - strike price
   	R     float64        // r - risk free interest rate
   	Sigma float64        // sigma - std deviation of log returns (Implied volatility)
   	T     float64        // T - time to exercise date in years
        Put   bool           // Put - set to true when computing Put option value

Example usage:

    var currPrice float64 = 180.34
    var strike float64 = 185.00
    expiry := "2020-06-05"    
    t := guant.TimeToExpiry(expiry)

    // With provided contract price calculate Sigma
    var mid float64 = 0.11
	fmt.Println("Mid:", mid)
	x := guant.Derivative{
		N: distuv.Normal{Mu: 0, Sigma: 1},
		S: currPrice,
		K: strike,
		R: guant.DefaultRfir(),
		T: t,
	}
	x.Sigma = guant.NewtonRaphson(x, mid)
	y := guant.BlackScholes(x)

    //Given sigma calculate the value of a Call option
    var sigma float64 = 1.384
	i := guant.Derivative{
		N:     distuv.Normal{Mu: 0, Sigma: 1},
		S:     currPrice,
		K:     strike,
		R:     guant.DefaultRfir(),
		Sigma: sigma,
		T:     t,
	}
    a := guant.BlackScholes(i)

	fmt.Println("BS W/Given IV:", a)
	fmt.Println("BS W/Calculated IV:", y)
	fmt.Println("Calculated IV:", x.Sigma)
	fmt.Println("Given IV", i.Sigma)

About

Simple Golang implementation of Black-Scholes pricing model and Newton-Raphson Method

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages