Richard's answer is the correct answer to a slightly different question. I think what you’re asking for is the weighted average option implied volatility for a stock.
The implied volatility of a stock is analogous to the CBOE’s VIX Index for the S&P 500 Index (other securities have IV indices as well). The VIX uses a known methodology for imputing the implied volatility of a weighted strip of options in order to interpolate the one-month implied volatility of the index. A detailed description of the VIX' calculation is available on the CBOE website. Also, see the previous post for a detailed explanation on the evolution of the VIX.
The first step is always to determine the implied volatilities a cross-section of option contracts. Richard provides one such method. I do not want to detract from it.
The next task is to aggregate the individual option contracts in a meaningful way. There are likely significant differences in how the “sausage is made” amongst various brokers and data-providers.
I assume that most use methods and heuristics to come up with something analogous to the VIX. On the simplest level, the implied volatility index for any given stock is an open-interest-weighted and maturity-weighted weighted average of the individual options’ implied volatilities.
I cannot speak to ThinkOrSwim’s exact approach, but I would be willing to bet it mirrors CBOE’s pre-2014 approach. Also, I do recall that TradeSation’s stock implied volatility algorithm is available in its native programming language—EasyLanguage. From what I recall, TradeStation calculates a stock’s implied volatility as a weighted average of out of the money puts and calls going forward on both the first and second expiration months.
On a side note, just you can't actually trade an index, you cannot trade IV directly, but rather have to take a position in a tracking instrument or create a synthetic position.
Also, I am copying code from VBA which uses the Newton's algorithm to find the implied volatility of a call option given the underlying price, exercise price, time, interest, target (usually market) price of a call, and dividend yield.
Function dOne(UnderlyingPrice, ExercisePrice, Time, Interest, Volatility, Dividend)
dOne = (Log(UnderlyingPrice / ExercisePrice) + (Interest - Dividend + 0.5 * Volatility ^ 2) * Time) / (Volatility * (Sqr(Time)))
- Value of call options
Function CallOption(UnderlyingPrice, ExercisePrice, Time, Interest, Volatility, Dividend)
CallOption = Exp(-Dividend * Time) * UnderlyingPrice * Application.NormSDist(dOne(UnderlyingPrice, ExercisePrice, Time, Interest, Volatility, Dividend)) - ExercisePrice * Exp(-Interest * Time) * Application.NormSDist(dOne(UnderlyingPrice, ExercisePrice, Time, Interest, Volatility, Dividend) - Volatility * Sqr(Time))
- Implied call volatility
Function ImpliedCallVolatility(UnderlyingPrice, ExercisePrice, Time, Interest, Target, Dividend)
High = 5
Low = 0
Do While (High - Low) > 0.0001
If CallOption(UnderlyingPrice, ExercisePrice, Time, Interest, (High + Low) / 2, Dividend) > Target Then
High = (High + Low) / 2
Else: Low = (High + Low) / 2
ImpliedCallVolatility = (High + Low) / 2