GithubHelp home page GithubHelp logo

kingofknights / greeks Goto Github PK

View Code? Open in Web Editor NEW
7.0 3.0 1.0 26 KB

Option price calculation based on Black Scholes equation

License: Boost Software License 1.0

CMake 3.56% C++ 96.44%
greeks hft-trading options-pricing trading

greeks's Introduction

Option Price Calculation based on Black-Scholes Equation

This project focuses on implementing option price calculation using the Black-Scholes equation. The Black-Scholes model is a widely used mathematical formula for calculating the theoretical price of options. It takes into account factors such as the underlying asset's price, strike price, volatility, risk-free interest rate, and time to expiration.

Functions

The project provides several functions for option price calculation and related metrics:

GetDelta: Calculates the option's delta, which represents the sensitivity of the option price to changes in the underlying asset price. Parameters include the asset price (s), strike price (k), volatility (v), risk-free interest rate (r), time to expiration (t), and a boolean flag (IsCall) indicating whether the option is a call option.

GetGamma: Calculates the option's gamma, which measures the rate of change of the option's delta. It indicates the curvature of the option price with respect to changes in the underlying asset price.

GetVega: Calculates the option's vega, which represents the sensitivity of the option price to changes in volatility. Higher vega values indicate a greater impact of volatility changes on the option price.

GetRho: Calculates the option's rho, which measures the sensitivity of the option price to changes in the risk-free interest rate.

GetTheta: Calculates the option's theta, which represents the rate of change of the option price with respect to time. It indicates the impact of time decay on the option price.

GetIV: Calculates the implied volatility (IV) of an option given its price (p). The implied volatility is the market's expectation of future volatility implied by the current option price. Parameters include the asset price (s), strike price (k), risk-free interest rate (r), time to expiration (t), the option price (p), and a boolean flag (IsCall) indicating whether the option is a call option.

GetOptionPrice: Calculates the theoretical price of an option using the Black-Scholes equation. Parameters include the asset price (s), strike price (k), volatility (v), risk-free interest rate (r), time to expiration (t), and a boolean flag (IsCall) indicating whether the option is a call option.

GetExpiryGap: Calculates the time gap in seconds until the specified Time. This function takes a 32-bit unsigned integer as the input, representing the expiration time of an option.

Usage

To use this code, include the necessary header files and call the desired functions with appropriate parameter values. Ensure that the required input parameters are provided correctly, and make use of the boolean flag (IsCall) to indicate whether the option is a call option.

#include <iostream>
#include "Greeks.hpp"

int main() {
    double assetPrice = 100.0;
	double strikePrice = 110.0;
	double volatility = 0.2;
	double riskFreeRate = 0.05;
	double timeToExpiration = 0.5;

    bool isCallOption = true;

    double optionPrice = GetOptionPrice(assetPrice, strikePrice, volatility, riskFreeRate, timeToExpiration, isCallOption);
	std::cout << "Option Price: " << optionPrice << std::endl;

    return 0;
}

Remember to adjust the input parameter values according to your requirements.

Note

The Black-Scholes model assumes a number of simplifying assumptions and may not fully capture all aspects of the real options market. It's important to consider the limitations and assumptions of the model when using the calculated option prices or related metrics.

CMake

add_subdirectory(Greeks)
target_link_libraries(${PROJECT_NAME} PRIVATE Greeks)

greeks's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

8funtik8

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.