[blackcat] L2 Barbara Star Supertrend IndicatorLevel 2
Background
Barbara Star’s article on July 2023, “Stay On Track With The Supertrend Indicator”, I rewrote it as pine script for your information.
Function
A supertrend indicator is displayed either above or below the closing price to signal a buy or sell. The indicator changes color depending on whether you should buy or not. When the Supertrend indicator falls below the closing price, the indicator turns green, signaling one or more entry points to buy.
Author Barbara Star describes the Supertrend indicator and how it can be used as a means for traders to stay in sync with the larger trend. She explains how J. Welles Wilder's Average True Range (ATR) forms a basis for supertrend calculations. ATR does not measure price direction, but rather provides a measure of volatility over a period of time. The Supertrend indicator, on the other hand, provides a more comprehensive view of trend direction. In addition, the indicator provides price levels at which a trend reversal would occur.
Green color stands for up trend;
Red color stands for down trend.
Remarks
Feedbacks are appreciated.
Black
VIX - SKEW DivergenceThe CBOE VIX is a well-known index representing market expectations for volatility over the next 30 days.
The CBOE SKEW is an index reflecting the perceived tail risk over the next 30 days.
When the SKEW rises over a certain level (~140/150), that means investors are hedging their exposure with options, because they are worried about an incoming market crash or a "black swan". If that happens when the VIX is very low and apparently there is no uncertainty, this can warn of a sudden change in direction of the market. You will see for yourself that an increasing divergence often anticipates a sharp fall of leading stock indexes, usually within two to four months.
This is probably not very relevant for the short-term trader but mid/long-term traders and market analysts may find it useful to clearly visualize the extent of the distance between the VIX and the SKEW. For that reason, I wrote this highly customizable script with which you can plot the two indexes and fill the space within them with a color gradient to highlight the maximum and minimum divergence. Additionally, you can fill the beneath VIX area with four different colors. It is also possible to plot the divergence value itself, so if you want you can draw trendlines and support/resistance levels on it.
Please note that the divergence per se doesn't predict anything and it's meant to be used synergistically with other technical analysis tools.
More informations here:
www.cboe.com
www.cboe.com
Black-Scholes Model for American OptionsThis model uses Black's Approximation to price American Options. Black's Approximation is an extension of the traditional Black-Scholes model that allows the price of American Options to be approximated within the Black-Scholes Framework. This is necessary because the traditional Black-Scholes model only works on options that are exercised at expiry, not before; like American Options can be.
Black's Approximation approximates the value of an American option by:
1st. Calculating the theoretical price of a european call or put based on the strike price (K), spot price (S), annual return (sigma), time until expiry (T), times until the next 2 ex-dividend dates (t1 & t2), and the dividend paid out at times t1 and t2 (D1 and D2).
2nd. The theoretical price of an option expiring on the second ex-dividend date (t2) is calculated. This replicates exercising the option early.
3rd. Finally, the highest price of the two theoretical prices calculated in steps 1 & 2 is chosen as the approximated price.
How to use this:
1st. Input your strike price.
2nd. Input the risk-free-rate of the currency the option is based in.
3rd. Input the dividend yield for the next ex-dividend date. For example AAPL's dividend yield is 0.82 and will be paid out on August 7,2020.
4th. Input the time until the next ex-dividend date. For example AAPL's next ex-dividend date is August 7,2020, which is 61 days away. So you'd input 61 (this includes weekends and holidays).
5th. Input the dividend yield for the ex-dividend date after the next one. For example AAPL's dividend yield after the next one is 0.82 and will be paid out on November 6, 2020.
6th. Input the time until the next furthest ex-dividend date. For example AAPL's next ex-dividend date after Aug 7th, is on November 6, 2020, which is 152 days away. So you'd input 152 (this includes weekends and holidays).
7th. Input your time until expiry. You can do so in terms of days, hours, and minutes.
8th. Input your chart time-frame in term of minutes. For example, if you're using the 1 min time-frame enter 1, 4hr time-frame enter 480, daily time-frame enter 1440.
9th. Lastly, pick what type of option you want data for: Long Call or Long Put.
*Disclaimer, because Black's Approximation is mostly geared towards stocks, this will only work for stocks. Also, the time variables: time until expiry and time until the ex-dividend dates; don't automatically update. So you will have to update them each day.
Binomial Option Pricing ModelA binomial option pricing model is an option pricing model that calculates an option's price using binomial trees. The BOPM method of calculating option prices is different from the Black-Scholes Model because it provides more flexibility in the type of options you want to price. The BOPM, unlike the BS model typically used for European style options, allows you to price options which have the ability to exercise early, such as American or Bermudan options. Although you can use the BOPM for any option style.
This specific model allows you to price both American and European vanilla options.
The way the BOPM calculates option prices is by:
First, dividing up the time until expiry into equal parts called steps. This specific model presented only uses 2 steps. For example, say you have an option with an expiry of 60 days, and your binomial tree has only two steps. Then each step will contain 30 days.
Second, the model will project the expected price of the underlying at the end of each step, called a node. The expected price is calculated by using the underlying's volatility and projecting what the price of the underlying would be if it were to rise and fall. This step is repeated until the terminal node, aka the end of the tree, is reached.
Third, once the terminal node's expected underlying prices are calculated, their expected option prices must be calculated.
Finally, after calculating the terminal option prices, backwards induction must be used to calculate the option prices at the previous nodes, until you reach Node 0, aka the current option price.
In order to use this model:
1st. Enter your option's strike price.
2nd. Enter the risk-free-rate of the currency the option is based in.
3rd. Enter the dividend yield of the underlying if it's a stock, or the foreign risk-free-rate if it's an FX option.
*For example, if you were trading an AAPL stock option, in the risk-free-rate box mentioned in step 2, you would enter the US risk-free-rate because AAPL options are traded in US dollars. In the dividend yield box mentioned in step 3, you would enter the stock's dividend yield, which for AAPL is 0.82.
*If you were, for example, trading an option on the EUR/JPY currency pair, the risk-free-rate mentioned in step 2, would be the Japanese risk-free-rate. Then in the the dividend yield box from step 3, you'd input the Eurozone risk-free-rate.
*If you were trading an options on futures contract, the risk-free-rate mentioned in step 2, would be the risk-free-rate for whatever currency the futures contract is denominated in. For example EUR futures are denominated in USD, so you would input the US risk-free-rate. Meanwhile, something like FTSE futures are denominated in GBP, so you would input the British risk-free-rate. As for the dividend yield box mentioned in step 3, for all options on futures, enter 0.
4th. Pick what type of underlying the option is based on: stock, FX, or futures.
5th. Pick the style of option: American or European.
6th. Pick the type of option: Long Call or Long Put.
7th. Input your time until expiry. You can express this in terms of days, hours, and minutes.
8th. Lastly, input your chart time-frame in term of minutes. For example, if you're using the 1 min time-frame enter 1, 4hr time-frame enter 480, daily time-frame enter 1440.
*Disclaimer, because this particular model only uses 2 steps, it won't work on stocks with high prices (over $100). If you want to use this on stocks with prices greater than $100, you would need to add more steps to the code, shown below. The model in its current form should work for stocks below $100.
Black-Scholes Options Pricing ModelThis is an updated version of my "Black-Scholes Model and Greeks for European Options" indicator, that i previously published. I decided to make this updated version open-source, so people can tweak and improve it.
The Black-Scholes model is a mathematical model used for pricing options. From this model you can derive the theoretical fair value of an options contract. Additionally, you can derive various risk parameters called Greeks. This indicator includes three types of data: Theoretical Option Price (blue), the Greeks (green), and implied volatility (red); their values are presented in that order.
1) Theoretical Option Price:
This first value gives only the theoretical fair value of an option with a given strike based on the Black-Scholes framework. Remember this is a model and does not reflect actual option prices, just the theoretical price based on the Black-Scholes model and its parameters and assumptions.
2)Greeks (all of the Greeks included in this indicator are listed below):
a)Delta is the rate of change of the theoretical option price with respect to the change in the underlying's price. This can also be used to approximate the probability of your option expiring in the money. For example, if you have an option with a delta of 0.62, then it has about a 62% chance of expiring in-the-money. This number runs from 0 to 1 for Calls, and 0 to -1 for Puts.
b)Gamma is the rate of change of delta with respect to the change in the underlying's price.
c)Theta, aka "time decay", is the rate of change in the theoretical option price with respect to the change in time. Theta tells you how much an option will lose its value day by day.
d) Vega is the rate of change in the theoretical option price with respect to change in implied volatility .
e)Rho is the rate of change in the theoretical option price with respect to change in the risk-free rate. Rho is rarely used because it is the parameter that options are least effected by, it is more useful for longer term options, like LEAPs.
f)Vanna is the sensitivity of delta to changes in implied volatility . Vanna is useful for checking the effectiveness of delta-hedged and vega-hedged portfolios.
g)Charm, aka "delta decay", is the instantaneous rate of change of delta over time. Charm is useful for monitoring delta-hedged positions.
h)Vomma measures the sensitivity of vega to changes in implied volatility .
i)Veta measures the rate of change in vega with respect to time.
j)Vera measures the rate of change of rho with respect to implied volatility .
k)Speed measures the rate of change in gamma with respect to changes in the underlying's price. Speed can be used when evaluating delta-hedged and gamma hedged portfolios.
l)Zomma measures the rate of change in gamma with respect to changes in implied volatility . Zomma can be used to evaluate the effectiveness of a gamma-hedged portfolio.
m)Color, aka "gamma decay", measures the rate of change of gamma over time. This can also be used to evaluate the effectiveness of a gamma-hedged portfolio.
n)Ultima measures the rate of change in vomma with respect to implied volatility .
o)Probability of Touch, is not a Greek, but a metric that I included, which tells you the probability of price touching your strike price before expiry.
3) Implied Volatility:
This is the market's forecast of future volatility . Implied volatility is directionless, it cannot be used to forecast future direction. All it tells you is the forecast for future volatility.
How to use this indicator:
1st. Input the strike price of your option. If you input a strike that is more than 3 standard deviations away from the current price, the model will return a value of n/a.
2nd. Input the current risk-free rate.(Including this is optional, because the risk-free rate is so small, you can just leave this number at zero.)
3rd. Input the time until expiry. You can enter this in terms of days, hours, and minutes.
4th.Input the chart time frame you are using in terms of minutes. For example if you're using the 1min time frame input 1, 4 hr time frame input 480, daily time frame input 1440, etc.
5th. Pick what style of option you want data for, European Vanilla or Binary.
6th. Pick what type of option you want data for, Long Call or Long Put.
7th . Finally, pick which Greek you want displayed from the drop-down list.
*Remember the Option price presented, and the Greeks presented, are theoretical in nature, and not based upon actual option prices. Also, remember the Black-Scholes model is just a model based upon various parameters, it is not an actual representation of reality, only a theoretical one.
*Note 1. If you choose binary, only data for Long Binary Calls will be presented. All of the Greeks for Long Binary Calls are available, except for rho and vera because they are negligible.
*Note 2. Unlike vanilla european options, the delta of a binary option cannot be used to approximate the probability of the option expiring in-the-money. For binary options, if you want to approximate the probability of the binary option expiring in-the-money, use the price. The price of a binary option can be used to approximate its probability of expiring in-the-money. So if a binary option has a price of $40, then it has approximately a 40% chance of expiring in-the-money.
*Note 3. As time goes on you will have to update the expiry, this model does not do that automatically. So for example, if you originally have an option with 30 days to expiry, tomorrow you would have to manually update that to 29 days, then the next day manually update the expiry to 28, and so on and so forth.
There are various formulas that you can use to calculate the Greeks. I specifically chose the formulations included in this indicator because the Greeks that it presents are the closest to actual options data. I compared the Greeks given by this indicator to brokerage option data on a variety of asset classes from equity index future options to FX options and more. Because the indicator does not use actual option prices, its Greeks do not match the brokerage data exactly, but are close enough.
I may try to make future updates that include data for Long Binary Puts, American Options, Asian Options, etc.
Black-Scholes Model and Greeks for European OptionsThe Black-Scholes model is a mathematical model used for pricing options. From this model you can derive the theoretical fair value of a European option (an option where you have to wait until expiry to exercise). Additionally, you can derive various risk parameters called Greeks. This indicator includes three types of data: Theoretical Option Price (blue), the Greeks (green), and implied volatility (red); their values are presented in that order.
1) Theoretical Option Price:
This first value gives only the theoretical fair value of an option with a given strike based on the Black-Scholes framework. Remember this is a model and does not reflect actual option prices, just the theoretical price based on the Black-Scholes model and its parameters and assumptions.
2)Greeks (all of the Greeks included in this indicator are listed below):
a)Delta is the rate of change of the theoretical option price with respect to the change in the underlying's price. This can also be used to approximate the probability of your option expiring in the money. For example, if you have an option with a delta of 0.62, then it has about a 62% chance of expiring in-the-money. This number runs from 0 to 1 for Calls, and 0 to -1 for Puts.
b)Gamma is the rate of change of delta with respect to the change in the underlying's price.
c)Theta, aka "time decay", is the rate of change in the theoretical option price with respect to the change in time. Theta tells you how much an option will lose its value day by day.
d)Vega is the rate of change in the theoretical option price with respect to change in implied volatility.
e)Rho is the rate of change in the theoretical option price with respect to change in the risk-free rate. Rho is rarely used because it is the parameter that options are least effected by, it is more useful for longer term options, like LEAPs.
f)Vanna is the sensitivity of delta to changes in implied volatility. Vanna is useful for checking the effectiveness of delta-hedged and vega-hedged portfolios.
g)Charm, aka "delta decay", is the instantaneous rate of change of delta over time. Charm is useful for monitoring delta-hedged positions.
h)Vomma measures the sensitivity of vega to changes in implied volatility.
i)Veta measures the rate of change in vega with respect to time.
j)Vera measures the rate of change of rho with respect to implied volatility.
k)Speed measures the rate of change in gamma with respect to changes in the underlying's price. Speed can be used when evaluating delta-hedged and gamma hedged portfolios.
l)Zomma measures the rate of change in gamma with respect to changes in implied volatility. Zomma can be used to evaluate the effectiveness of a gamma-hedged portfolio.
m)Color, aka "gamma decay", measures the rate of change of gamma over time. This can also be used to evaluate the effectiveness of a gamma-hedged portfolio.
n)Ultima measures the rate of change in vomma with respect to implied volatility.
o)Probability of Touch, is not a Greek, but a metric that I included, which tells you the probability of price touching your strike price before expiry.
3) Implied Volatility:
This is the market's forecast of future volatility. Implied volatility is directionless, it cannot be used to forecast future direction. All it tells you is the forecast for future volatility.
How to use this indicator:
1st. Input the strike price of your option. If you input a strike that is more than 3 standard deviations away from the current price, the model will return a value of n/a.
2nd. Input the current risk-free rate.(Including this is optional, because the risk-free rate is so small, you can just leave this number at zero.)
3rd. Input the time until expiry. You can enter this in terms of days, hours, and minutes.
4th.Input the chart time frame you are using in terms of minutes. For example if you're using the 1min time frame input 1, 4 hr time frame input 480, daily time frame input 1440, etc.
5th. Pick what type of option you want data for, Long Call or Long Put.
6th. Finally, pick which Greek you want displayed from the drop-down list.
*Remember the Option price presented, and the Greeks presented, are theoretical in nature, and not based upon actual option prices. Also, remember the Black-Scholes model is just a model based upon various parameters, it is not an actual representation of reality, only a theoretical one.