hey youtube it's roman today what i want to do is talk about market implied volatility now implied volatility is a very deep sea and it can get complicated very quickly especially when you start to consider the relationship between the implied volatilities and a particular price is it a market price is it a model price there's a lot going on so what i want to do is i want to unpack the implied volatility surface in its most basic form and just give you a fundamental idea of you know what we're looking at all right let's get right into it so what we have here is a very interesting problem space we have an option contract that is uh of a european style payoff meaning we can only exercise at expiration and we want to figure out some theoretical value of this option okay well in order to do that first we need to come up with a model for the underlying equity so in a black scholes framework we're going to assume that the underlying equity follows a geometric brownian motion so you can see this ds over s is essentially the return mu dt is the expected return and sigma dwt is the shock to that expected return so if you haven't seen geometric browning emotion before i've made a bunch of videos on this in the past you should go check those out and then come back if you want deeper understanding of this framework but it's not necessarily uh required to understand this notion of implied volatility so in a black trolls framework we have this this theoretical option price that's fundamentally based on the notion of the underlying equity following a geometric brownian motion so after developing and solving a stochastic differential equation we're and we end up with a closed form solution for a european option parameterized by the risk-free rate r a strike price k the spot price s the time to maturity t and the volatility sigma now when i say closed form pricing solution i mean those five parameters so a vector of r5 gets mapped to a price in r1 and we essentially turn those five parameters into an option price now let's take a closer look at these five parameters we start with the risk-free rate we have plenty of proxies in the market for a risk-free rate so if we ever wanted to get a good value to plug into our pricing function we could find it what about the strike price well that's predefined for whatever contract you're trying to come up with the the price for so again you can define that as needed the spot price you can always just go to yahoo finance and get the value of any equity very easily just type in the ticker it'll give you the value the time to maturity just like the strike price is pre-defined for the particular option contract so that's as needed but then we have this this sigma term this volatility term what about that sigma term well that's not as clear right we we can't just go on yahoo finance and type in a ticker and it's going to spit out the volatility that we're going to want that's that's not how it works right we don't have this notion of a volatility to plug directly into a black shoals pricing function so let's kind of just review what we have so far we have a function that can take five parameters map it to a theoretical option price but in reality we only have four of those five parameters so how can we come up with a price or how is this theoretical pricing function even helpful well if you recall from economics and i am by no means an economist so please economists out there forgive me for butchering this this uh law of supply and demand idea here but we we know that the market is going to set a price for any good or service right so if you go out to walmart and you want to buy a bird house for whatever reason you can go and buy a birdhouse at the market price for the bird house very similarly if you wanted to go out and buy an option that's expiring in one year with a underlying spot price of 100 and a strike price of 100 and a risk free rate of say 0.1 um then you can go into the market and you can find an option that satisfies those particular specifications for that contract and there will be a price there will be a market price for that option and that's what i want to emphasize is in reality the only parameters we have are those four a proxy for a risk-free rate a strike price time to maturity a spot price and then we also have the market option price so we we have what we're trying to end up with mapping five to one where we only have four and then one which already arbitrarily exists in the market so this is this is a major key takeaway is that there is a difference between a theoretical price and the market price so the black shoals framework is going to imply a theoretical price within that framework and then the market for that same contract is going to provide a market price to further hammer home this idea of the market being able to provide a price i want to go ahead and go to yahoo finance and i just pulled up apple and i went over to options over here to take a look at the options chains and if we scroll down here we can see that we actually have the price of these options this is the last price of this particular option contract right here it was 54.25 they're usually traded in blocks of 100 so this would be a very expensive option it's it's deep in the money so you know we're not going to get it very cheap but we have this this market price of an option so so hold on let's take a look at what we have right theoretically if we wanted to come up with a theoretical price right we would need these five parameters the risk-free rate strike price time to maturity spot price and then the volatility to map to a black trolls price but in the market we have only four of those minus the volatility and we have a market price so so what's what's going on here well what we can actually do is we can use the black shoals pricing function to back out of volatility that maps directly to the market price of the option that volatility that we input as the fifth parameter into the pricing function that maps to the market price is called implied volatility so jumping back to our jupiter notebook if we take a look at this chart we can see implied volatility on the z axis and the strike and maturity on the x and y axises and we can see that for a grid of vanilla options the implied volatility is backed out using a black shoals model so i want to emphasize this is another huge key takeaway besides the theoretical and market price being different i want to emphasize that the volatility surface is always quoted in terms of black shoals volatility so there is like i said earlier there is no way to google right apple's volatility right we can't just get a volatility to plug into this pricing function and map to a theoretical price there is no notion of this but what there is a notion of is a black shoals implied volatility which takes the volatility and maps it to the current market price and that's exactly what we have here we have a surface of these volatilities that map perfectly to the market prices all right i think that's enough talking and it's time to actually see this in action so we're gonna go ahead and use the best quantitative finance python library out there i may be a little biased because it's mine but we're going to go ahead and import qfin and get started with seeing how we can actually back out the volatility for these particular options so i'm going to say qfin dot options dot black shoals call and then we can see that the black scholes call class is going to take the five parameters to come up with the theoretical price in a black shells framework now what we can do to actually make this a little more tractable is take a look at the parameters that we do have in the market and then try to back out this notion of a black troll's implied volatility so let's go ahead and do this i think it's a pretty fun exercise so let's go back to our options training for apple and we can consider the current spot price for apple which is 145.38 we'll go down here we'll say s is equal to 145.38 we'll say the time to maturity is at the time that i'm recording this it is six days until the 10th of june 2022 so i will say t is equal to 6 divided by 252 the strike price is going to be 145 so we're going to be considering this option which is at the money and the current risk-free rate we can just say is is negligible so we can just say it's like point .001 or something so .001 those are our four known market parameters now what about the market option price well we can see right here that it's three dollars so i'm just going to go ahead here and put option price op is equal to three dollars so we have four of the five parameters and we have a market option price that we're trying to get to so what we could do conceptually is take this black shells call class we can plug in the market spot price we can guess a volatility so i'll just put in 10 for now we can put in the strike price we can look at the time to maturity and we can also put in the risk-free rate and then we can print out the price of this option in this theoretical framework now if you look we have 1.0985 and the market price is three what can we tinker with well that is the implied volatility that's what we're trying to find we can maybe add a little 0.15 maybe add a little bit more so now that's too high so now we gotta go back down maybe to two five that's too low so so you can see what i'm getting at here i'm essentially just guessing implied volatilities and trying to squeeze the difference between the true market price of three and the output of the theoretical price by the one degree of freedom that we have which is this this volatility parameter this implied volatility by the market now there is a better way to do this and we're actually going to do this using scipy this idea of optimization is another huge concept in financial engineering what we're going to develop this cost function that we want to minimize and that is the distance between the theoretical black shells price and the observed market price so i'm going to say def diff and we're actually going to take volatility as a parameter to this function then we're going to return the numpy absolute value of the observed market price minus this theoretical black shells price with whatever volatility we input into this function here so i actually need to import numpy as mp now what i can do is since this function's defined i can call it with a sigma diff and i'll just put in like 0.1 and that is going to return the absolute difference between the market option price and this theoretical option price for a given sigma in this case the distance is 1.90 now to find the optimal volatility to plug in to minimize this distance what we can do is we can use scipy so i'm going to say from scipy.optimize import least squares now what i can do is i can just say least squares and i can pass the difference function to it and then i can pass an initial guess for volatility i'm just gonna use point one and when we run this we're actually going to minimize that function and we're gonna find the optimal parameter the implied volatility for this particular option and if you take a look here and we actually print out the solution we get 0.3137 so we get 31.38 percent implied volatility meaning if we go back to this original black trolls theoretical pricing function and we plug in this .313759 to our sigma then we get a 2.99999999 and if we cheat and we do mp.round and we round to five decimal places we get our perfect market option price of three so we have successfully found the market implied volatility of approximately 31.38 percent if we go back to our option chain and we look that is pretty darned close to the 36.23 it's all going to depend on the rest of these parameters that you are kind of playing around with thank you so much for watching i hope you enjoyed i hope this kind of solidifies the idea of what implied volatility is you know when we look at an implied volatility surface we are essentially looking at the collection of the black shoals volatilities that create the market prices and in order to do that we we did that together down here uh numerically in python so whenever you look at an implied volatility surface that is essentially what you are looking at um so once again thank you so much for watching if you have any questions please leave them in the comments below if you have any uh you know requests or suggestions for future videos you know feel free to leave them again below or shoot me an email i'm happy to answer any more specific questions there as well we are hard at work on our first course here introduction to python uh heavily oriented towards application so uh stay tuned for that that's coming out in june we are very excited to release our first course so yeah thank you so much again and i will see you in the next one