GithubHelp home page GithubHelp logo

colbyhemond / blackscholesjs Goto Github PK

View Code? Open in Web Editor NEW
34.0 3.0 13.0 8.6 MB

Black-Scholes fair option price calculator in JS. Greeks included.

License: MIT License

JavaScript 45.44% HTML 53.24% CSS 1.31%

blackscholesjs's Introduction

BlackScholesJS

Black-Scholes fair option price calculator in JS. Greeks included.

API

The library can be added to your website for use via CDN by adding the following tag to your website:

<script src="https://black-scholes-js.netlify.app/js/blackscholes.js"></script>

https://black-scholes-js.netlify.app

Setting up Black-Scholes variables

Before even starting to calculate a fair option price, we need to set up the needed variables. Our variables are held in an instance of BSHolder:

  • stock: underlying's asset price
  • strike: strike price
  • interest: the annualized risk-free interest rate (e.g. 0.05 corresponds 5%)
  • vola: volatility (e.g. 0.3 corresponds 30%)
  • term: a time in years (e.g. 0.5 corresponds half-year)
var bsholder = new BSHolder(stock,strike,interest,vola,term);

Calculation

All function regarding calculations are members in BS. Pass an instance of BSHolder to a function from BS. E.g.: calculating put price:

var put = BS.put(bsholder);

Credit

blackscholesjs's People

Contributors

colbyhemond avatar paggist avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

blackscholesjs's Issues

Define and Add Unit Tests to library

Requirements:

  • Each function should have a passing test for a correct calculation
  • Each function should have a passing test if a calculation cannot be performed

Preferred:

  • Edge cases can be defined for precision up to the 4th decimal place (0.0000)

Add Documentation to index.html

Required:

  • Add same documentation as README to index.html

Preferred:

  • Add any additional explanations/examples for further clarity

Add calculator form

Requirements:

  • Add form to index.html or linked page
  • Inputs: (stock price, strike price, volatility, interest rate, term)
  • Outputs: (call price, put price, call delta, put delta, gamma, vega, call theta, put theta, call rho, and put rho)

Vega unit

Hi Stefano,

First, thank you for your lib, it help a lot to learn Black and Scholes.

When trying the vega(), it seems the result is 100 times more than that it should be. My understanding of the vega is that it is the option's price increment when the volatility increase of 0.01.

Here an example with a spot at 100 and a volatility at 20% on one years. "Price2" is the price for the same option for a volatility at 21%.

var bs = new BSHolder(100, 100, 0, 0.20, 1);
var price1 = BS.call(bs);
var price2 = BS.call(new BSHolder(100, 100, 0, 0.21, 1));
var vega = BS.vega(bs);
console.log("Vega: " + vega + "; Price: " + price1 + "; p2-p1: " + (price2 - price1));
//it show: Vega: 39.69525474770118; Price: 7.97; p2-p1: 0.3899999999999997

My understanding is that the price should be 0.39 instead of 39, in order to be in range with the option's price of 7.97.

Best Regards,
Olivier

Black Scholes Calculation

simple black-scholes-model calculator. Includes delta, gamma, theta, vega, rho and omega (lambda, kappa) calculation.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.