OPEN-SOURCE SCRIPT

Prometheus Black-Scholes Option Prices

The Black-Scholes Model is an option pricing model developed my Fischer Black and Myron Scholes in 1973 at MIT. This is regarded as the most accurate pricing model and is still used today all over the world. This script is a simulated Black-Scholes model pricing model, I will get into why I say simulated.

What is an option?
An option is the right, but not the obligation, to buy or sell 100 shares of a certain stock, for calls or puts respective, at a certain price, on a certain date (assuming European style options, American options can be exercised early). The reason these agreements, these contracts exist is to provide traders with leverage. Buying 1 contract to represent 100 shares of the underlying, more often than not, at a cheaper price. That is why the price of the option, the premium, is a small number. If an option costs $1.00 we pay $100.00 for it because 100 shares * 1 dollar per share = 100 dollars for all the shares. When a trader purchases a call on stock XYZ with a strike of $105 while XYZ stock is trading at $100, if XYZ stock moves up to $110 dollars before expiration the option has $5 of intrinsic value. You have the right to buy something at $105 when it is trading at $110. That agreement is way more valuable now, as a result the options premium would increase. That is a quick overview about how options are traded, let's get into calculating them.

Inputs for the Black-Scholes model
To calculate the price of an option we need to know 5 things:

Current Price of the asset
Strike Price of the option
Time Till Expiration
Risk-Free Interest rate
Volatility

The price of a European call option 𝐶 is given by:
𝐶 = 𝑆0 * Φ(𝑑1) − 𝐾 * 𝑒^(−𝑟 * 𝑇) * Φ(𝑑2)

where:
𝑆0 is the current price of the underlying asset.
𝐾 is the strike price of the option.
𝑟 is the risk-free interest rate.
𝑇 is the time to expiration.
Φ is the cumulative distribution function of the standard normal distribution.

𝑑1 and 𝑑2 are calculated as:
𝑑1 = (ln(𝑆0 / 𝐾) + (𝑟 + (𝜎^2 / 2)) * 𝑇) / (𝜎 * sqrt(𝑇))
𝑑2= 𝑑1 - (𝜎 * sqrt(𝑇))

𝜎 is the volatility of the underlying asset.

The price of a European put option 𝑃 is given by:

𝑃 = 𝐾 * 𝑒^(−𝑟 * 𝑇) * Φ(−𝑑2) − 𝑆0 * Φ(−𝑑1)

where 𝑑1 and 𝑑2 are as defined above.

Key Assumptions of the Black-Scholes Model
The price of the underlying asset follows a lognormal distribution.
There are no transaction costs or taxes.
The risk-free interest rate and volatility of the underlying asset are constant.
The underlying asset does not pay dividends during the life of the option.
The markets are efficient, meaning that all known information is already reflected in the prices.
Options can only be exercised at expiration (European-style options).

Understanding the Script

https://www.tradingview.com/x/24wG8z0R/

Here I have arrows pointing to specific spots on the table. They point to Historical Volatility and Inputted DTE. Inputted DTE is a value the user may input to calculate premium for options that expire in that many days. Historical Volatility, is the value calculated by this code.



And then made daily like the Black-Scholes model needs from this step in the code.



The user has the option to input their own volatility to the Script. I will get into why that may be advantageous in a moment. If the user chooses to do so the Script will change which value it is using as so.



https://www.tradingview.com/x/HSzYFO7u/

There is a lot going on in this image but bare with me, it will all make sense by the end. The column to the far left of both the green and maroon colored columns represent the strike price of the contract, if the numbers are white that means the contract is out of the money, gray means in the money. If you remember from the calculation this represents the price to buy or sell shares at, for calls or puts respective. The column second from the left shows a value for Simulated Market Price. This is a necessary part of this script so we can show changes in implied volatility. See, when we go to our brokerages and look at options prices, sure the price was calculated by a pricing model, but that is rarely the true price of the model. Market participant sentiment affects this value as their estimates for future volatility, Implied Volatility changes.

For example, if a call option is supposed to be worth $1.00 from the pricing model, however everyone is bullish on the stock and wants to buy calls, the premium may go to $1.20 from $1.00 because participants juice up the Implied Volatility. Higher Implied Volatility generally means higher premium, given enough time to expiration. Buying an option at $0.80 when it should be worth $1.00 due to changes in sentiment is a big part of the Quant Trading industry.

Of course I don't have access to an actual exchange so get prices, so I modeled participant decisions by adding or subtracting a small random value on the "perfect premium" from the Black-Scholes model, and solving for implied volatility using the Newton-Raphson method.

It is like when we have speed = distance / time if we know speed and time, we can solve for distance.

This is what models the changing Implied Volatility in the table. The other column in the table, 3rd from the left, is the Black-Scholes model price without the changes of a random number. Finally, the 4th column from the left is that Implied Volatility value we calculated with the modified option price.

More on Implied Volatility
Implied Volatility represents the future expected volatility of an asset. As it is the value in the future it is not know like Historical Volatility, only projected. We provide the user with the option to enter their own Implied Volatility to start with for better modeling of options close to expiration. If you want to model options 1 day from expiration you will probably have to enter a higher Implied Volatility so that way the prices will be higher. Since the underlying is so close to expiration they are traded so much and traders manipulate their Implied Volatility, increasing their value. Be safe while trading these!

Thank you all for clicking on my indicator and reading this description! Happy coding, Happy trading, Be safe!

Good reference: investopedia.com/terms/b/blackscholes.asp
Chart patterns

Open-source Skript

Ganz im Sinne von TradingView hat dieser Autor sein/ihr Script als Open-Source veröffentlicht. Auf diese Weise können nun das Script auch andere Trader verstehen und prüfen. Vielen Dank an den Autor! Sie können das Script kostenlos verwenden. Die Nutzung dieses Codes in einer Veröffentlichung wird in unseren Hausregeln reguliert. Sie können es als Favoriten auswählen, um es in einem Chart zu verwenden.

Möchten Sie dieses Skript auf einem Chart verwenden?


Auch am:

Haftungsausschluss