Skip to content

Sebastian-git/BinomialBeacon

Repository files navigation

Introduction

This project offers an in-depth exploration into the intricate realm of quantitative finance. Initially, I aimed to visualize option strategies rooted in the Black-Scholes Model, a Nobel Prize-winning model in Economic Sciences. However, I transitioned to the Binomial Option Pricing Model for its robust assumptions critical for pricing American options. My motivation for this project comes from my passion about the complexity in financial markets, eager to decode it through explanatory visualizations.

Usage

Setup

  1. Clone the master repository:
git clone https://github.com/Sebastian-git/BinomialBeacon.git
  1. Install Node.js from here.
  2. Install Rust from here.
  3. Navigate to your cloned repository's directory and type npm install to download all dependencies:
cd BinomialBeacon
npm install
  1. Compile Rust to WebAssembly (only necessary if you intend to make changes to the Rust code):
npm run build-wasm
  1. Start the Project:
npm run start

Previews

Previews & Screenshots coming soon

Technical Information

This project was built on a variety of technologies, with each offering its unique challenges and learning curves:

React

The core library used for building the UI. After experimenting with several other libraries, I created the visualizations with React ECharts, a React wrapper for Apache ECharts.

CODE SNIPPET OF "createGraphData" function. Explain how this is the main function with recursive complexity that essentially handles the entire logic behind the binomial model, with the logic generating every node which is displayed. Mention difficulty in back-links from children to parents due to recursive nature & how you overcame the challenge.

TypeScript

To develop a custom interface with an emphasis on type safety, enabling efficient switches between different options pricing API's for the live data. This search took so long because most finance API's don't provide an option's strike price, a critical variable in the equation. After experimenting with over 5 different API's, I was sure that the Polygon API was the best choice for the project.

The OptionsData interface ensures that regardless of the API which is used to retrieve data, the website will still work as long as each method has an implementation:

interface OptionsData {
  getDailyClosingPrices: (ticker: string) => Promise<number[]>;
  getStandardDeviation: (ticker: string) => Promise<number>;
  getStockPrice: (ticker: string) => Promise<number>;
  getRiskFreeRate: () => Promise<number>;
}

Rust

This performant and reliable language was used to optimize all computational functions for the application. The computation necessary for this recursive model seems fit for a language with a run time speed often outranking historically fast languages like C.


ADD CODE SNIPPET FOR IMPLIED VOLATILITY DERIVATION USING BLACK SCHOLES

WebAssembly

My project values the portability of a website more than the performance of a pure Rust application. Integrating Rust into an existing React application and having it work harmoniously with WebAssembly was a significant challenge.

GitHub Pages & Actions

To avoid manually compiling & linking Rust code to the rest of the project, a Github workflow was configured to automate deployment to Github Pages. Live hosting presented several challenges like adding environment secrets for the API keys, learning about an entirely new workflow syntax, and finally triggering workflows on each push to main for continuous deployment.


ADD CODE SNIPPET OF PORTIONS OF ACTION THAT COMPILE & DEPLOY CODE

Other

A noteworthy implementation detail is the algorithm to select relevant option contracts. The typescript API only fetches a large set of option contracts, so this algorithm must calculate the mean strike price, then select the next 4 strike prices every half standard deviation, ensuring the user gets the most relevant results.

Additionally, the application is designed with responsiveness in mind, ensuring a seamless experience for both desktop and mobile users.

Launch

The application is built on JavaScript ES6+ and uses the latest web technologies for a smooth user experience.

Status:

In Progress




This section will be deleted once readme is complete. Topics to mention in README :

  • Black–Scholes model (Finance)
  • Binomial Option Pricing Model (Finance)
  • React echarts (React)
  • Options Data API (Polygon API) (Touchscript)
  • Formula to get data points which are most desirable using std dev, map, etc
  • Wireframes (time spent designing)
  • Rust (new language, learning about benefits)
  • Web Assembly (difficult adding Rust to existing project)
  • Deployment (1st time using Github pages, learned about Actions & Workflows to use .env)

Stuff I'm currently working on:

  • Switching to Leisen-Reimer Model for accuracy
    • need to get stock dividend data (currently setting variable as 0 for all calculations)
    • need to review equations; different probability structure may be causing errors
    • need to talk more about it in readme, almost like using black scholes model
    • WILL LIKELY HAVE TO USE BLACK SCHOLES TO SOLVE FOR IMPLIED VOLATILITY, SINCE THAT API CALL ISN'T OFFERED

Stuff I'd like to add in the future:

  • LinkedIn polls checking which UI is better (with side bar of options chain vs not)
  • Tests to see accuracy of option pricing? Possibly through a whole new kind of backtesting program, can make a options finance program suite?
  • Account for dividend yields in calculation for risk neutral probability