Fast Implied Volatility using Python's Pandas Library and ...

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

Background on Implied Volatility ... The famous Black Scholes formula for pricing a Call/Put option on a stock is a function of 6 variables: the ... Skiptomaincontent FastImpliedVolatilityusingPython'sPandasLibraryandChebyshevInterpolation Published09/04/2021ByEdvinHopkins Pythonhassomenicepackagessuchasnumpy,scipy,andmatplotlibfornumericalcomputinganddatavisualization.AnotherpackagethatdeservesamentionthatwehaveseenincreasinglyisPython'spandaslibrary.Pandashasfastandefficientdataanalysistoolstostoreandprocesslargeamountsofdata.AllofthesepackagescaneasilybeintegratedwiththeNAGLibraryforPython. BelowisanexamplewhichusestheNAGLibraryforPythonandthepandaslibrarytocalculatetheimpliedvolatilityofoptionsprices.AllthecodebelowcanbedownloadedtocalculateyourownimpliedvolatilitysurfacefordataontheChicagoBoardofOptionsExchangewebsite. BackgroundonImpliedVolatility ThefamousBlackScholesformulaforpricingaCall/Putoptiononastockisafunctionof6variables:theunderlyingprice,theinterestrate,thedividendrate,thestrikeprice,thetime-to-expiration,andthevolatility.Notethatforagivenoptioncontractwecanobservetheunderlyingprice,interestrate,anddividendrate.Inaddition,theoptionscontractspecifiesthestrikepriceandtime-to-expiration. Thustheonevariablewehavetotweakisthevolatility.Wecanthenaskthequestion:Forwhatvolatility*doestheBlackScholesequationpriceequalthemarketprice. F(volatility*)=MarketOptionPrice Thisvolatility*isthendenotedastheimpliedvolatilityobservedinthemarket.WecanusetheNAGroutineopt_imp_voltocomputeimpliedvolatilitiesforarraysofinputdata. ThisroutinewasintroducedatMark27.1 andgivestheuserachoiceoftwoalgorithms.ThefirstisthemethodofJäckel(2015),whichusesathirdorderHouseholdermethodtoachieveclosetomachineaccuracyforallbutthemostextremeinputs.Thismethodisfastforshortvectorsofinputdata. ThesecondalgorithmisbasedonthatofGlauetal.(2018),withadditionalperformanceenhancementsdevelopedinaveryproductivecollaborationbetweenNAGandDrKathrinGlauandDrLinusWunderlichatQueenMaryUniversityofLondon.ThismethodusesChebyshevinterpolationandisdesignedforlongvectorsofinputdata,whereSIMDvectorinstructionscanbeexploitedtoimproveperformance.Forapplicationsinwhichaccuracytomachineprecisionisnotrequired,thealgorithmcanalsobeinstructedtoaimforaccuracytoroughlysingleprecision(approximatelysevendecimalplaces),givingevenfurtherperformanceimprovements. Oncewehavecomputedtheimpliedvolatilities,wecanthenusedim2_cheb_linestoperformaleastsquaresChebyshevfittothevolatilitysurface,anddim2_cheb_evaltoevaluatethesurfaceatintermediatepoints. RunningtheScript WehavecreatedanexamplescriptthatwillrunondatafromtheChicagoBoardofOptionsExchange(CBOE)website.TheCBOEprovidesoptionsdataindownloadableformathere. TheprogramusesthepandaspackagetoeasilystoreandmanipulatethedataviaDataFrames.Inthescript,you'llnoticepandastakescareofthemanydataprocessingfunctionsandthencallstheNAGLibraryformorecomplexanalysis.Theprogramwillautomaticallyreadintheoptionsdata,calculateimpliedvolatilityforthecallandputoptions,andplotthevolatilitycurvesandsurface.Theabovecodecanberunasfollows(giventhatyouhavepandas,matplotlib,andtheNAGLibraryforPython): pythonimplied_volatility.pyQuoteData.dat IrantheprogramonAppleOptionsdata(SYMAAPL).Belowistheoutput,generatedinabouttwoseconds: ImpliedVolatilityforAAPL(APPLEINC),546.0255,-4.7445,Dec192013@15:02ET,Bid,545.97,Ask,546.09,Size,2x1,Vol,8897300, Numberofdatapointsfound:17905 CalculatingImpliedVolofCalls... CalculatingImpliedVolofPuts... PlottingVolatilityCurves/Surface Inthepicture(right)weseesomenicevolatilityskews/smilesthatleveloutastheoptionexpirationdateincreases.ThisreflectsthefactthatrealoptionpricesdonotfollowtheBlackScholesmodel.Especiallyforshortmaturities,realpricescandisplayfarmorevariabilitythantheBlackScholesmodelassumes.Hencewhenwecomputeimpliedvolatilityforrealoptionsdata,weseepronouncedcurvatureforshortdatedoptions,andflattersurfacesforlongerdatedoptionswheretheBlackScholesmodelisabetterfit. Belowisthevolatilitysurface(plottingStrike,Expiration,andImpliedVolatilityfromFigure1onthesamegraph). Sogoahead,downloadanyoptionsdatatheCBOEprovides(makesureyoudownloaddataduringCBOEtradinghourstoensurethegraphsarenotnull)andplotyourownvolatilitysurface!ManythankstoJohnMorrisseyandChrisSeymourforcodesuggestions. MoreaboutImpliedVolatilitiesintheNAGLibrary Note:Thisblogisanupdatedversionofablogpostfrom2013writtenbyBrianSpector withsupportfromJohnMorrissey&ChrisSeymour.TheoriginalpostusedNAG's nag4py package.WehavenowupdatedthepostandtheassociatedPythonscripttousethenewNAGLibraryforPython,Mark27.1. Subscribetotheblog Author EdvinHopkins LeaveaComment Submit WenoticedyouarevisitingfromJapan VisitourJapanesesite Nothankyou



請為這篇文章評分?