Skip to content

A bot that trades stock option by using Binomial Monte Carlo Simulation and Black Scholes Model

Notifications You must be signed in to change notification settings

MananPatel-1/Trading_Bot

Repository files navigation

Trading Bot

  • This is a stock call/put option projection algorithm to find the theoretical price of an option and option Greeks.
  • All the orders are automated using Interactive Brokers TWS API by building a network socket to IB client application.

Black Scholes Model

Black-Scholes is a pricing model that uses six factors to calculate the theoretical value of a call or put option, including volatility, option type, underlying stock price, period, strike price, and risk-free rate.

Option Pricing

Premiums are made up of the total of the intrinsic and time values of an option. The price difference between the current stock price and the strike price is known as intrinsic value. The amount of premium over an option's inherent value is known as the time value or extrinsic value of an option. Moreover, hedging a portfolio is accomplished through the use of options contracts. In other words, the purpose is to counteract any adverse movements in other assets. Option contracts are sometimes used to speculate on whether the price of an asset will rise or decline.

  • Intrinsic value is the amount of money that each given option would be worth if it were exercised today. The intrinsic value of an option is the amount by which the strike price is profitable or in-the-money as compared to the market price of the stock.
  • Extrinsic value refers to the difference between an option's market price, or premium, and its intrinsic value. Extrinsic value is the part of an option's worth that has been allocated to it by variables other than the price of the underlying asset.

Screen Shot 2021-12-24

Option Greeks

The price of an option may be impacted by a variety of variables, which can assist or hinder traders depending on the sort of positions they have taken. Successful traders are aware of the elements that impact option pricing, including the so-called option greeks.

Screen Shot 2021-12-24 at 2 15 45 PM

  • Delta: The rate of change of the option price respected to the rate of the change of underlying asset price.
  • Gamma: The rate of change of delta respected to the rate of change of underlying asset price.
  • Vega: The rate of change of the option price respected to the volatility of the underlying asset.
  • Rho: The rate of the option price respected to the interest rate.
  • Theta: The rate of change of the option price respected to the passage of time.

Monte Carlo simulation

Monte-Carlo simulation is a computerised mathematical approach that permits quantitative analysis to account for risk. Furthermore, they are a vast category of computer algorithms that produce numerical results by repeated random sampling. The basic idea is to utilize randomness to solve problems that are in essence deterministic.

Financial derivatives such as options are dependent on the underlying asset, stocks which follows a Brownian motion or Wiener process. So, by simulating these stochastic processes we could determine the prices of financial instrument(option in this case)

Screen Shot 2022-01-12 at 10 34 38 PM
Now we could obtain the log S(t) because we know that stock prices can not be negative. By Ito's lemma we could say that F(S) = log S(t)
Screen Shot 2022-01-12 at 10 40 16 PM
Screen Shot 2022-01-12 at 10 41 10 PM

Here the Brownian motion is a random walk with mean 0 and variance t so, N(0,t) which could be re-writen as √t N(0,1) Now, if we make a risk-netural assumption the μ drift becomes r risk-free interest rate and we get

Screen Shot 2022-01-12 at 10 50 25 PM
The exponential function defined stock price at T maturity For a call option we would calculate max(S - E, 0) and for a put option we would calculate max(E - S, 0)

About

A bot that trades stock option by using Binomial Monte Carlo Simulation and Black Scholes Model

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages