gouant

package module
v0.0.0-...-95041bc Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2024 License: MIT Imports: 1 Imported by: 0

README

Gouant: Black-Scholes Options Pricing Library

Overview

Gouant is a Go library for calculating option pricing and Greeks using the Black-Scholes model. It provides comprehensive functionality for options pricing, including price calculation, implied volatility, and option Greeks.

Features

  • Calculate option prices for both call and put options
  • Compute option Greeks (Delta, Gamma, Theta, Rho, Vega)
  • Calculate implied volatility using Newton-Raphson method
  • Support for dividend-paying underlying assets
  • Precise mathematical calculations using standard financial formulas

Installation

go get github.com/asargin-dev/gouant

Usage Example

package main

import (
    "fmt"
    "github.com/asargin-dev/gouant"
)

func main() {
    // Create a Black-Scholes option
    option := &gouant.BlackScholes{
        UnderlyingPrice: 100.0,
        StrikePrice:     105.0,
        TimeToMaturity:  1.0,
        RiskRate:        0.05,
        Dividend:        0.02,
        IsCall:          true,
        DerivativePrice: 5.0,
    }

    // Calculate option price
    price := option.Price(0.25)
    fmt.Printf("Option Price: %.2f\n", price)

    // Get option Greeks
    greeks := option.Greeks()
    fmt.Printf("Delta: %.4f\n", greeks.Delta)
    fmt.Printf("Gamma: %.4f\n", greeks.Gamma)
}

Methods

BlackScholes Struct Methods
  • Price(sigma float64): Calculate option price
  • IV(): Calculate implied volatility
  • Delta(sigma float64): Calculate option delta
  • Gamma(sigma float64): Calculate option gamma
  • Theta(sigma float64): Calculate option theta
  • Rho(sigma float64): Calculate option rho
  • Vega(sigma float64): Calculate option vega
  • Greeks(): Calculate all Greeks using implied volatility

Mathematical Background

The library implements the Black-Scholes option pricing model, which uses the following key components:

  • Cumulative Normal Distribution (CND)
  • Probability Density Function (PDF)
  • Volatility calculation
  • Risk-free rate
  • Dividend yield
  • Time to maturity

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Distributed under the MIT License. See LICENSE for more information.

Contact

Ahmet Sargın - contact@ahmetsargin.com

Project Link: https://github.com/asargin-dev/gouant

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CND

func CND(x float64) float64

CND Cumulative Normal Distribution

func PD

func PD(x float64) float64

PD Probability Density

Types

type BlackScholes

type BlackScholes struct {
	DerivativePrice float64 // The price of the option.
	UnderlyingPrice float64 // The price of the underlying asset.
	StrikePrice     float64 // The strike price.
	TimeToMaturity  float64 // The annualized time to expiration. Must be positive.
	RiskRate        float64 // The Interest Free Rate.
	Dividend        float64 // The annualized continuous dividend yield.
	IsCall          bool    // For each contract, this should be specified as tru for a call option and false for a put option.
}

func (*BlackScholes) Delta

func (b *BlackScholes) Delta(sigma float64) float64

Delta Calculate Delta

func (*BlackScholes) Gamma

func (b *BlackScholes) Gamma(sigma float64) float64

Gamma Calculate Gamma

func (*BlackScholes) Greeks

func (b *BlackScholes) Greeks() *Greeks

func (*BlackScholes) IV

func (b *BlackScholes) IV() float64

IV Implied Volatility calculation using Newton-Raphson method

func (*BlackScholes) Price

func (b *BlackScholes) Price(sigma float64) float64

func (*BlackScholes) Rho

func (b *BlackScholes) Rho(sigma float64) float64

Rho Calculate Rho

func (*BlackScholes) Theta

func (b *BlackScholes) Theta(sigma float64) float64

Theta Calculate Theta

func (*BlackScholes) Vega

func (b *BlackScholes) Vega(sigma float64) float64

Vega Calculate Vega

type Greeks

type Greeks struct {
	Delta float64
	Gamma float64
	Theta float64
	Rho   float64
	Vega  float64
}

Jump to

Keyboard shortcuts

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