Black-Scholes library implemented as a Cairo smart contract

Overview

Cairo Black-Scholes Library

Black-Scholes library implemented as a Cairo smart contract.

All inputs, outputs, and internal calculations use 27-digit fixed-point numbers.

Library

This library implements the interface described here. The external functions exposed allow you to retrieve the Black-Scholes call and put option prices and the option greeks, given the expiration time, volatility, spot price, strike price, and interest rate.

Validation

The pytest deploys the smart contract in a local test environment and queries for the call and put option prices with randomly generated test inputs. Each test input consists of (expiration time, volatility, spot price, strike price, interest rate).

The results are compared against the options prices as computed by the py_vollib library. The test validates that the error from the Cairo library and the py_vollib libary is minimal. Option greeks were validated against online tools such as this one.

Test Instructions

  1. First make sure you can run a basic StarkNet contract unit test (see here).
  2. Install py_vollib: pip install py_vollib.
  3. Clone this repo and run pytest black_scholes_test.py.

SHARP

In the sharp/ folder, you can generate a proof of call option price computation for a given input (input.json) using the Shared Prover (SHARP) and check that the proof gets verified on-chain by running:

cairo-sharp submit --source black_scholes.cairo --program_input input.json

cairo-sharp status {JOB_KEY}

When the status is "PROCESSED", you can check to see if it is verified on chain.

cairo-sharp is_verified {FACT} --node_url https://goerli-light.eth.linkpool.io/

You might also like...
This is the improvised version of Dobot Magician which can be implemented for Dobot M1

pydobotM1 This is the edited driver for Dobot M1 version of the original pydobot library intended for use with the Dobot Magician. Here's what you nee

Neogex is a human readable parser standard, being implemented in Python

Neogex (New Expressions) Parsing Standard Much like Regex, Neogex allows for string parsing and validation based on a set of requirements. Unlike Rege

JLC2KICAD_lib is a python script that generate a component library for KiCad from the JLCPCB/easyEDA library.

JLC2KiCad_lib is a python script that generate a component library (schematic, footprint and 3D model) for KiCad from the JLCPCB/easyEDA library. This script requires Python 3.6 or higher.

K2HASH Python library - NoSQL Key Value Store(KVS) library
K2HASH Python library - NoSQL Key Value Store(KVS) library

k2hash_python Overview k2hash_python is an official python driver for k2hash. Install Firstly you must install the k2hash shared library: curl -o- htt

🔩 Like builtins, but boltons. 250+ constructs, recipes, and snippets which extend (and rely on nothing but) the Python standard library. Nothing like Michael Bolton.

Boltons boltons should be builtins. Boltons is a set of over 230 BSD-licensed, pure-Python utilities in the same spirit as — and yet conspicuously mis

A Python library to simulate a Zoom H6 recorder remote control
A Python library to simulate a Zoom H6 recorder remote control

H6 A Python library to emulate a Zoom H6 recorder remote control Introduction This library allows you to control your Zoom H6 recorder from your compu

Integration of Hotwire's Turbo library with Flask.
Integration of Hotwire's Turbo library with Flask.

turbo-flask Integration of Hotwire's Turbo library with Flask, to allow you to create applications that look and feel like single-page apps without us

Python library for creating PEG parsers

PyParsing -- A Python Parsing Module Introduction The pyparsing module is an alternative approach to creating and executing simple grammars, vs. the t

Python library to natively send files to Trash (or Recycle bin) on all platforms.

Send2Trash -- Send files to trash on all platforms Send2Trash is a small package that sends files to the Trash (or Recycle Bin) natively and on all pl

Comments
  • verify hint computations

    verify hint computations

    Check hint results (ln, exp, sqrt) in Cairo in order for them to be trusted. ln and exp are tricky to check, so it may be better to implement them a approximations in Cairo. sqrt can probably do something similar to the Cairo library impl: https://github.com/starkware-libs/cairo-lang/blob/64a7f6aed9757d3d8d6c28bd972df73272b0cb0a/src/starkware/cairo/common/math.cairo#L342

    opened by araghava 0
  • Code / file structure cleanup

    Code / file structure cleanup

    • Move math helpers (ln, exp, std_normal, std_normal_cdf) into a separate file math_helpers.cairo
    • Create helper functions in math_helpers.cairo for fixed point math and use them instead of doing it inline
    good first issue 
    opened by araghava 0
  • Add tests for option greeks

    Add tests for option greeks

    Currently black_scholes_test.py only verifies call and put options prices. Greeks were verified against online sources, but they should have tests as well.

    good first issue 
    opened by araghava 0
Owner
Aditya Raghavan
Aditya Raghavan
Cairo-integer-types - A library for bitwise integer types (e.g. int64 or uint32) in Cairo, with a test suite

The Cairo bitwise integer library (cairo-bitwise-int v0.1.1) The Cairo smart tes

null 27 Sep 23, 2022
Cairo-bloom - A naive bloom filter implementation in Cairo

?? cairo-bloom A naive bloom filter implementation in Cairo. A Bloom filter is a

Sam Barnes 37 Oct 1, 2022
Xoroshiro-cairo - A xoroshiro128** pseudorandom number generator implementation in Cairo

xoroshiro-cairo A xoroshiro128** pseudorandom number generator implementation in

Milan Cermak 26 Oct 5, 2022
A proof-of-concept package manager for Cairo contracts/libraries

glyph A proof-of-concept package manager for Cairo contracts/libraries. Distribution through pypi. Installation through existing package managers -- p

Sam Barnes 11 Jun 6, 2022
A command line interface tool converting starknet warp transpiled outputs into readable cairo contracts.

warp-to-cairo warp-to-cairo is a simple tool converting starknet warp outputs (NethermindEth/warp) outputs into readable cairo contracts. The warp out

Michael K 5 Jun 10, 2022
Cairo hooks for pre-commit

pre-commit-cairo Cairo hooks for pre-commit. See pre-commit for more details Using pre-commit-cairo with pre-commit Add this to your .pre-commit-confi

Fran Algaba 16 Sep 21, 2022
Chess bot can play automatically as white or black on lichess.com, chess.com and any website using drag and drop to move pieces

Chessbot "Why create another chessbot ?" The explanation is simple : I did not find a free bot I liked online : all the bots I saw on internet are par

Dhimas Bagus Prayoga 2 Nov 11, 2021
A smart personal companion and health assistant.

Steps to Install : Clone the repository Go to ResQ-Sources Execute ResQ-Lite.py --: Manual Controls : DanceRobot.py --: You can call functions like fo

Tuhinadri Banerjee 1 May 25, 2022
Here is my Senior Design Project that I implemented to graduate from Computer Engineering.

Here is my Senior Design Project that I implemented to graduate from Computer Engineering. It is a chatbot made in RASA and helps the user to plan their vacation in the Turkish language. In order to plan the user's vacation, it provides reservations by asking various questions for hotel, flight, or event.

Ezgi Subaşı 25 May 31, 2022
This repository contains a lot of short scripting programs implemented both in Python (Flask) and TypeScript (NodeJS).

fast-scripts This repository contains a lot of short scripting programs implemented both in Python (Flask) and TypeScript (NodeJS). In python These wi

Nahum Maurice 3 Dec 10, 2022