Black Scholes and Option Greeks in Python

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

Implement Black-Scholes Model using Opstrat ... Opstrat is a python package which deals with options. This package can be used to determine option pricing as well ... SigninAboutSubmitDDIntelDDIChatDDImarioStartHereBlackScholesandOptionGreeksinPythonImplementingBlack-ScholesOptionPricingModelusingOpstratpackageinpythonAbhijithChandradasFollowJun30·4minreadWhatisBlack-ScholesModel?TheBlack-Scholesmodel,alsoknownastheBlack-Scholes-Merton(BSM)model,isamathematicalmodelusedtodeterminethefairpricesofoptionscontract.ThemodelowesitsnametoeconomistsFischerBlackandMyronScholes.RobertC.Mertonwasthefirsttopublishapaperexpandingthemathematicalunderstandingoftheoptionspricingmodel,andcoinedtheterm“Black–Scholesoptionspricingmodel”.ThemodelrevolutionizedfinanciallandscapeandearnedMertonandScholestheNobelMemorialPrizeinEconomicSciencesin1997.InputsrequiredforBSMThemodelutilizesthefollowingfiveinputstopredictthepriceofoption(C):i.Currentprice(Spotprice)oftheAsset(St)ii.Strike/Exerciseprice(K)iii.RiskFreeRate(r)iv.Timetoexpiration(t)v.Volatility(σ)Black-ScholesModelforEuropeanCall(ImagebyAuthor)Nintheaboveequationdenotesstandardnormaldistribution.Theaboveistheequationforcalloptionpricing,putoptionformulaisslightlydifferentfromtheabove.Black-ScholesModelforEuropeanPut(ImagebyAuthor)NotethatBlack-ScholesModelisonlyusedtopriceEuropeanoptionsasitdoesnottakeintoaccountthatU.S.optionscouldbeexercisedbeforetheexpirationdate.Themodelalsodoesnottakeintoaccounttheeffectofdividendonpricing.ImplementBlack-ScholesModelusingOpstratOpstratisapythonpackagewhichdealswithoptions.Thispackagecanbeusedtodetermineoptionpricingaswellasvisualizeoptionpayoffs.Ifyouarenewtooptions,visualizingoptionpayoffscanbeagoodstartingpoint.Youcancheckoutthebelowarticleonhowtovisualizeoptionpayoffsusingopstrat.VisualizingOptionTradingStrategiesinPythonAwalk-throughofhowtoplotoptionpayoffdiagramsusingopstratpackageinpythonmedium.datadriveninvestor.comOptionvaluescanbecalculatedbyusingtheblack_scholes()functionfromopstrat.Allinputsrequiredforthemodelhavetobepassedinasarguments.Inadditiontotheaboveinputs,typeofoptionhastobespecifiedusingtypeparameter-‘c’forcalloptionand‘p’forputoption.#ImportLibrariesimportopstratasop#DeclareparametersK=200#spotpriceSt=208#currentstockpricer=4#4%riskfreeratet=30#timetoexpiry,30daysv=20#volatilitytype='c'#Optiontypecall#BlackScholesModelbsm=op.black_scholes(K=K,St=St,r=r,t=t,v=v,type='c')Thefunctionreturnsadictionarywithvalueandgreeksaskeys.Optionvaluecanbeaccessedbyusingvalueaskey.bsm['value']Output:{'optionvalue':10.210518559926442,'intrinsicvalue':8,'timevalue':2.2105185599264416}Theoutputisadictionarycontainingoptionvalueanditscomponents-timevalueandintrinsicvalue.Therequiredvaluecanbeaccessedbyusingtherespectivekey.bsm['value']['optionvalue']Output:10.210518559926442WhatareOptionGreeks?OptionGreeksareasetofriskmeasuressonamedaftertheGreeklettersthatdenotethem.ThesefiveprimaryGreekriskmeasuresareknownasanoption’stheta,vega,delta,gammaandrho.Greeksindicatehowsensitiveanoptionistotime-valuedecay,changesinimpliedvolatility,riskfreerate,andmovementsinthepriceitsunderlyingsecurity.Delta:MeasuresImpactofaChangeinthePriceofUnderlyingGamma:MeasurestheRateofChangeofDeltaTheta:MeasuresImpactofaChangeinTimeRemainingVega:MeasuresImpactofaChangeinVolatilityRho:MeasurestheimpactofchangesinInterestratesGreekscanbeobtainedfromtheoutputofblack_scholesfunctionbyusing‘greeks’key.bsm['greeks']Output:{'delta':0.7793593241701937,'gamma':0.024868265088898882,'theta':-0.07559961986526405,'vega':0.17686037602292404,'rho':0.12484620893217029}Individualgreekcanbeobtainedbypassingthegreeknameaskeytotheabovedictionary.bsm['greeks']['theta']Output:-0.07559961986526405Resources:NotebookforthearticleandmoreexamplescanbeobtainedfrommyGitHubrepo.BecomeaMemberIhopeyoulikethearticle,IwouldhighlyrecommendsigningupforMediumMembershiptoreadmorearticlesbymeorstoriesbythousandsofotherauthorsonvarietyoftopics.Yourmembershipfeedirectlysupportsmeandotherwritersyouread.You’llalsogetfullaccesstoeverystoryonMedium.Otherarticlesbytheauthoryoumayfindinteresting:StockMarketDataVisualizationUsingMplfinanceHowtoobtainstockmarketdataandcreatevisualizations(candlestick,OHLC,PnFetc.)inPythonusingmplfinance…medium.comAllyouneedtoknowaboutyfinance:Yahoo!FinanceLibraryAcompletestep-by-steptutorialonhowtouseYahooFinancePackageforpython-yfinance,toobtainsharepriceand…medium.comPhotobyScottGrahamonUnsplashDataDrivenInvestorempowermentthroughdata,knowledge,andexpertise.Follow73ThankstoTDSEditors. BlackScholesPythonOptionsGreeksPricing73 claps73WrittenbyAbhijithChandradasFollowDataAnalyst|Hacker|FinancialAnalyst|Freelancer|IIMMBA|Opensource|DemocratizeKnowledge|https://www.youtube.com/channel/UCLpBd4gzfIBXm2BPpdHOWdQFollowDataDrivenInvestorFollowempowermentthroughdata,knowledge,andexpertise.subscribetoDDIntelathttps://ddintel.datadriveninvestor.comFollowWrittenbyAbhijithChandradasFollowDataAnalyst|Hacker|FinancialAnalyst|Freelancer|IIMMBA|Opensource|DemocratizeKnowledge|https://www.youtube.com/channel/UCLpBd4gzfIBXm2BPpdHOWdQDataDrivenInvestorFollowempowermentthroughdata,knowledge,andexpertise.subscribetoDDIntelathttps://ddintel.datadriveninvestor.comMoreFromMedium3.3LsmallformfactorcaseSFFMykolaLytvynchukPayFacasaService:13QuestionsYouMustHaveAnswersToWayneAkeyWhyCleanCodeisEmpatheticCodeKarenWhiteinBigCommerceDeveloperBlogGoogleHasaSecretHiringChallengeCalledFoobarFabianBoslerinBetterProgrammingLifeShatteredasCovidsecondWavehitstheWorldBreakoleeDecreaseaDiskSizeonAzureVMPauloNunesDeveloponKubernetesSeries — OperatorDev — UnderstandingandDissectingKubebuilderYashvardhanKukrejaGameDevDigestIssue#77 — ModellingandmoreGameDevDigest



請為這篇文章評分?