Introduction to Options - Historical Volatility and Implied Volatility

文章推薦指數: 80 %
投票人數:10人

Calculation. Here we use the bisection method to solve the BSM pricing equation and find the root which is the implied volatility. We use Yahoo Finance Python ... Platform Alpha Market Pricing Datasets Community Algorithm Lab Documentation SIGNIN Signin Don'thaveanaccount?JoinQuantConnectToday SignupforFree HOME APITUTORIALS Introduction ConsolidatingDatatoBuildBars ScheduledEvents TrackingandManagingOrders UsingOptionsinQuantConnect TUTORIALSERIES Introduction IntroductiontoFinancialPython IntroductiontoOptions AppliedOptions OPENSOURCE Introduction DebuggingPython UsingtheAPIFileProvider LeanReportCreator BrokerageDevelopmentGuide GeneratingRandomBacktestData META CreatingBootCampTutorials STRATEGY LIBRARY Tutorials /  IntroductiontoOptions  /  HistoricalVolatilityandImpliedVolatility Contents Introduction HistoricalVolatility ImpliedVolatility VolatilitySkew VolatilitySurface TheReasonforVolatilitySkew Summary References IntroductiontoOptions HistoricalVolatilityandImpliedVolatility Introduction Thechangeofvolatilitycanhaveasignificantimpactontheperformanceofoptionstrading.InadditiontotheVegaweexplainedinGreeksletterchapter,thispartofthevolatilitytutorialwilldiscusstheconceptofvolatility,specifically,wediscussrealizedandimpliedvolatility,theirmeanings,measurements,uses,andlimitations. HistoricalVolatility 1.Definition Itisameasurementofhowmuchthepriceoftheassethaschangedonaverageduringthecertainperiodoftime.Incommon,volatilityissaidtobethestandarddeviationofthereturnofassetsprice. 2.Calculation Nextwediscusshowtoestimatethehistoricalvolatilityoftheoptionempirically. \[r_i=ln(\frac{S_i}{S_{i-1}})\quadfor\i=0,1,2,3,...,n\] Where(n+1)isthenumberofobservations,\(S_i\)isthestockpriceatendofittimeinterval The standarddeviationofthe\(r_i\)isgivenby \[std=\sqrt{\frac{1}{n-1}\sum_{i=1}^n(r_i-\overline{r})^2}\] where\(\overline{r}\)isthemeanof\(r_i\) Ifweassumetherearentradingdaysperyear.Thentheestimateofhistoricalvolatilityperannumis \[std\times\sqrt{n}\] importpandasaspd fromnumpyimportsqrt,mean,log,diff importquandl quandl.ApiConfig.api_key='NxTUTAQswbKs5ybBbwfK' goog_table=quandl.get('WIKI/GOOG') #usethedailydataofGoogle(NASDAQ:GOOG)from01/2016to08/2016 close=goog_table['2016-01':'2016-08']['Adj.Close'] r=diff(log(close)) r_mean=mean(r) diff_square=[(r[i]-r_mean)**2foriinrange(0,len(r))] std=sqrt(sum(diff_square)*(1.0/(len(r)-1))) vol=std*sqrt(252) Anassethasahistoricalvolatilitybasedonitspastperformanceasdescribedabove,investorscangaininsightonthefluctuationsoftheunderlyingpriceduringthepastperiodoftime.Butitdoesnottellusanythingaboutthevolatilityinthemarketnowandinthefuture.Sohereweintroducetheimpliedvolatility. ImpliedVolatility Incontrasttohistoricalvolatility,theimpliedvolatilitylooksahead.Itisofteninterpretedasthemarket’sexpectationforthefuturevolatilityofastockandisimpliedbythepriceofthestock’soptions.Hereimpliedvolatilitymeansitisnotobservableinthemarketbutcanbederivedfromthepriceofanoption. 1.Definition Weusevolatilityasaninputparameterinoptionpricingmodel.IfwetakealookattheBSMpricing, thetheoreticalpriceorthefairvalueofanoptionisP,wherePisafunctionofhistoricalvolatility σ,stock priceS,strikepriceK,risk-freeraterandthetimetoexpirationT.  Thatis\(P=f(\sigma,S,K,r,T)\).Butthemarketpriceofoptionsisnotalwaysthesamewiththetheoreticalprice.Nowincontrast,ifwearegiventhemarket’spricesofcallsandputswrittenonsomeassetandalsothevalueofS,K,r,T.Foreachassetwecansolveanewvolatilitythatcorrespondstothepriceofeachoption–theimpliedvolatility.Thentheimpliedvolatilityis\(\IV=f^{-1}(P,S,K,r,T)\). 2.Calculation HereweusethebisectionmethodtosolvetheBSMpricingequationandfindtherootwhichistheimpliedvolatility.WeuseYahooFinancePythonAPItogettherealtimeoptiondata. defbsm_price(option_type,sigma,s,k,r,T,q): #calculatethebsmpriceofEuropeancallandputoptions sigma=float(sigma) d1=(np.log(s/k)+(r-q+sigma**2*0.5)*T)/(sigma*np.sqrt(T)) d2=d1-sigma*np.sqrt(T) ifoption_type=='c': price=np.exp(-r*T)*(s*np.exp((r-q)*T)*stats.norm.cdf(d1)-k*stats.norm.cdf(d2)) returnprice elifoption_type=='p': price=np.exp(-r*T)*(k*stats.norm.cdf(-d2)-s*np.exp((r-q)*T)*stats.norm.cdf(-d1)) returnprice else: print('Nosuchoptiontype%s')%option_type defimplied_vol(option_type,option_price,s,k,r,T,q): #applybisectionmethodtogettheimpliedvolatilitybysolvingtheBSMfunction precision=0.00001 upper_vol=500.0 max_vol=500.0 min_vol=0.0001 lower_vol=0.0001 iteration=0 while1: iteration+=1 mid_vol=(upper_vol+lower_vol)/2.0 price=bsm_price(option_type,mid_vol,s,k,r,T,q) ifoption_type=='c': lower_price=bsm_price(option_type,lower_vol,s,k,r,T,q) if(lower_price-option_price)*(price-option_price)>0: lower_vol=mid_vol else: upper_vol=mid_vol ifabs(price-option_price)max_vol-5: mid_vol=0.000001 break elifoption_type=='p': upper_price=bsm_price(option_type,upper_vol,s,k,r,T,q) if(upper_price-option_price)*(price-option_price)>0: upper_vol=mid_vol else: lower_vol=mid_vol ifabs(price-option_price)50:break returnmid_vol implied_vol('c',0.3,3,3,0.032,30.0/365,0.01) Fromtheresultabove,theimpliedvolatilityofEuropeancalloption(withpremiumc=0.3,S=3,K=3,r=0.032,T=30days,d=0.01)is0.87. 3.FactorsAffectingImpliedVolatility Accordingtothetimevaluedescriptioninthefirsttutorial,ingeneral,themoretimetoexpiration,thegreaterthetimevalueoftheoption.Investorsarewillingtopayextramoneyforzerointrinsicvalueoptionswhichhavemoretimetoexpirationbecausemoretimeincreasesthelikelihoodofpricemovementandfluctuations,itistheoptionswillbecomeprofitable. Impliedvolatilitytendstobeanincreasingfunctionofmaturity.Ashort-datedoptionoftenhasalowimpliedvolatility,whereasalong-datedoptiontendstohaveahighimpliedvolatility. VolatilitySkew ForEuropeanoptionsofthesamematurityandthesameunderlyingassets,theimpliedvolatilitiesvarywiththestrikes.Foraseriesofputoptionsorcalloptions,ifweplottheseimpliedvolatilitiesforaseriesofoptionswhichhavethesameexpirationdateandthesameunderlyingwiththex-axisbeingthedifferentstrikes,wewouldgetaconvexcurve.Theshapeofthiscurveislikepeople'ssmiling,itisbeingcalledthevolatility.Theshapeofvolatilitysmiledependsontheassetsandthemarketconditions. HerewegiveanexamplehowtoplotthevolatilitysmilebyusingtherealtimeoptionsdataofSPDRS&P500ETF(NYSEARCA:SPY). #downloadoptiondataforallexpirymonthsfromYahooFinance #provideaformattedDataFramewithahierarchicalindex opt=Options('spy','yahoo') opt.expiry_dates#listalltheavailableexpirationdates defIV_plot(opt,option_type,expiry_index): expiry=opt.expiry_dates[expiry_index] ifoption_type=='c': data=opt.get_call_data(expiry=expiry) elifoption_type=='p': data=opt.get_put_data(expiry=expiry) r=0.01#riskfreerate d=0.01#continuousdevidendyield s=opt.underlying_price#data_call['Underlying_Price']undelyingprice expiry=data.index.get_level_values('Expiry')[0]#gettheexpiry current_date=opt.quote_time#current_date=datetime.datetime.now()#getthecurrentdate time_to_expire=float((expiry-current_date).days)/365#computetimetoexpiration premium=(data['Ask']+data['Bid'])/2#optionpremium strike=list(data.index.get_level_values('Strike'))#getthestrikeprice IV=[] foriinrange(len(data)): IV.append(implied_vol(option_type,premium.values[i],s,strike[i],r,time_to_expire,d)) plt.figure(figsize=(16,7)) a=plt.scatter(strike,IV,c='r',label="IVbysolvingBSM") b=plt.scatter(strike,data['IV'],c='b',label="IVfromYahooFinance") plt.grid() plt.xlabel('strike') ifoption_type=='c': plt.ylabel('ImpliedVolatilityforcalloption') plt.legend((a,b),("IV(call)bysolvingBSM","IV(call)fromYahooFinance")) elifoption_type=='p': plt.ylabel('ImpliedVolatilityforputoptions') plt.legend((a,b),("IV(put)bysolvingBSM","IV(put)fromYahooFinance")) returnstrike,IV k_call,IV_call=IV_plot(opt,'c',23) k_put,IV_put=IV_plot(opt,'p',23) plt.figure(figsize=(16,7)) e=plt.scatter(k_call,IV_call,c='red',label="IV(calloptions)") f=plt.scatter(k_put,IV_put,c='black',label="IV(putoptions)") plt.xlabel('strike') plt.ylabel('ImpliedVolatility') plt.legend((e,f),("IV(calloptions)","IV(putoptions)")) Thecurrentdateis08/14/2017.WeplottheimpliedvolatilitiesforSPYoptionswhichexpireon12/21/2018. Plottingtheseimpliedvolatilitiesacrossstrikesgivesustheimpliedvolatilityskew.Fortheshapeofvolatilitysmile,itshouldbeasymmetryconvexcurve.Butfromtheabovechart,theimpliedvolatilitycurveslopesdownwardtotheright.Thisisreferredtotheskew,whichmeansthatoptionswithlowstrikeshavehigherimpliedvolatilitiesthanthosewithhigherstrikes.Thesmileisnot symmetry.Theskewofadistributionisameasureofitsasymmetry.Althoughthevolatilityskewisdynamic,inequitymarketsitisalmostalwaysadecreasingfunctionofthestrike.OtherassetclassessuchasFXandcommoditieshavedifferentlyshapedskews. Ifweplotthecallandputoptionsimpliedvolatilitysmileinthesamechartforthesameexpirationdate: Fromtheabovechart,wecanseetheimpliedvolatilityforputoptionsishigherthancalloptions.Usually,putoptionstradeforahigherpricethancalloptions,becausetradersplacemoreriskintheshortputpositions,whichraisestheamountofrewardtheyrequiretoselltheposition.Higheroptionpricessignifyanincreaseinriskandarerepresentedbyhigherimpliedvolatilitylevelsderivedfromtheoptionpricingmodel.Thenwescatteredalltheimpliedvolatilitiesofcontractsacrossallthestrikes. opt=Options('spy','yahoo') r=0.01#riskfreerate d=0.01#continuousdevidendyield expiry_dates=[iforiinopt.expiry_datesifi>opt.quote_time.date()] current_date=opt.quote_time.date()##getthecurrentdate s=opt.underlying_price#undelyingprice num_expiry=len(expiry_dates) IV=[]#(num_expiry*3)-dimensionlistwitheachrowbeing[time_to_expire,strike,implied_vol] forexpiry_indexinrange(num_expiry): data=opt.get_put_data(expiry=expiry_dates[expiry_index]) expiry=expiry_dates[expiry_index]#gettheexpiry time_to_expire=float((expiry-current_date).days)/365#computetimetoexpiration premium=(data['Ask']+data['Bid'])/2.0#optionpremium strike=data.index.get_level_values('Strike')#getthestrikeprice num_strike=len(data) forjinrange(num_strike): IV.append([time_to_expire,strike[j],implied_vol('c',premium.values[j],s,strike[j],r,time_to_expire,d)]) x=[IV[i][0]foriinrange(len(IV))] y=[IV[i][1]foriinrange(len(IV))] z=[IV[i][2]foriinrange(len(IV))] fig=plt.figure(figsize=(20,11)) ax=fig.add_subplot(111,projection='3d') ax.view_init(20,10) ax.scatter(x,y,z) VolatilitySurface ByfixingthematurityandlookingattheimpliedvolatilitiesofEuropeanoptionsonthesameunderlyingbutdifferentstrikes,weobtaintheimpliedvolatilityskeworsmile.Thevolatilitysurfaceisthethree-dimensionalsurfacewhenweplotsthemarketimpliedvolatilitiesofEuropeanoptionswithdifferentstrikesanddifferentmaturities. Throughtheinterpolationmethod,wecangeneratetheimpliedvolatilitysurfaceofSPYoptionsforbothputandcalloptionsasfollows: TheReasonforVolatilitySkew Thevolatilityskewrevealsthatforputoptions,impliedvolatilityishigherfordeepOTMoptionsandisdecreasingasitmovestowardITMoptions.Forcalloptions,theimpliedvolatilityishigherfordeepITMoptionsandisdecreasingasitmovestowardOTMoptions.Fromthedemandandsupplydegree,theskewreflectsthatinvestorsaremorewillingtobuydeepOTMputsandITMcalls.Whythereisvolatilityskewinthemarket? First,themajorityoftheequitypositionsarelong.Investorsusuallyhavetwowaystohedgethoselongpositionsrisks:Buyingdownsideputsorsellingupsidecalls.Theincreaseindemandcreateincreasesinthepriceofdownsideputsanddecreasesinthepriceofupsidecalls.Thevolatilityisareflectionofoptionsprice.Thereforethevolatilityofin-the-moneyputishigherandthevolatilityofin-the-moneycallislower. Thesecondreasonforvolatilityskewisthatthemarketmovesdownfasterthanitmovesup.Thedownsidemarketmoveisriskierthantheupsidemove.ThusthepriceofOTMputsishigherthanOTMcalls. Summary Inthischapter,wediscussedthehistoricalvolatilityandtheimpliedvolatility.Thehistoricalvolatilityofanassetisthestatisticalmeasureweknowasthestandarddeviationofthestockreturnseries.Theimpliedvolatilityofthesameasset,ontheotherhand,isthevolatilityparameterthatwecaninferfromthepricesoftradedoptionswrittenonthisasset. Incontrasttohistoricalvolatility,whichlooksatfluctuationsofassetpricesinthepast,impliedvolatilitylooksahead.Thetwovolatilitiesdonotnecessarilycoincide,andalthoughtheymaybeclose,theyaretypicallynotequal. NowweknowtheconstantvolatilityassumptioninBlack-Sholes-Mertonmodelisnotapplicableintherealmarketbecausethereisvolatilityskewformostoptions.Innextchapter,wewillintroducesomevolatilitymodelstocapturethevolatilityskewinoptionspricing. References OptionsPricing:IntrinsicValueAndTimeValue,JeanFolger,OnlineCopy YoucanalsoseeourDocumentation and Videos. Youcanalsogetintouchwithusvia Discord. Didyoufindthispagehelpful? Yes No Contributetothetutorials: Contents Introduction HistoricalVolatility ImpliedVolatility VolatilitySkew VolatilitySurface TheReasonforVolatilitySkew Summary References PleaseSelectProfileImage: Browse GIF,JPGorPNG.Lessthan1MB.



請為這篇文章評分?