Option pricing using the Black-Scholes model, without the ...
文章推薦指數: 80 %
Black-Scholes PDE. We will solve this equation numerically, using Python. The main advantage of this method is that it bypasses very complicated analytical ... GetstartedOpeninappSigninGetstartedFollow604KFollowers·Editors'PicksFeaturesDeepDivesGrowContributeAboutGetstartedOpeninappOptionpricingusingtheBlack-Scholesmodel,withouttheformulaAnalternativeperspectiveonthebasicsofquantitativefinance,theBlack-Scholesformula.DanielRetiJan12·7minreadEveryuniversitystudenttakingamoduleonfinancehasseentheBlack-Scholes-Mertonoptionpricingformula.Itislong,ugly,andconfusing.Itdoesn’tevengiveanintuitionforpricingoptions.ThederivationofitissodifficultthatScholesandMertonreceivedaNobelprizeforitin1997(Blackdiedin1995).ItreliesontheFeynman-Kactheoremandrisk-neutralmeasures,butIwillnotgetintoit.(https://en.wikipedia.org/wiki/Black%E2%80%93Scholes_equation).Black-ScholesPDEPricinganoptioncanbedoneusingtheBlack-Scholespartialdifferentialequation(BSPDE).TheBSPDEcanbederivedbyapplyingIto’sLemmatogeometricBrownianmotionandthensettingthenecessaryconditionstosatisfythecontinuous-timedeltahedging.Black-ScholesPDE.Wewillsolvethisequationnumerically,usingPython.Themainadvantageofthismethodisthatitbypassesverycomplicatedanalyticalcalculationswithnumericalmethods,whicharedonebyourcomputer.NumericalsolutionstothePDEAswearetryingtosolvethePDEnumerically,weneedtoestablishafewthingsbefore.Firstly,wewilluseittovalueaEuropeancalloptionwithstrikepriceK.ThemethodIwillbeusingiscalledthefinitedifferencemethodanditinvolvessettingupagridofpoints.ThisgridwillbeusedtosimulatethePDEfrompointtopoint.Thegridonthex-axiswillrepresentthesimulatedtimes,whichrangesfrom[0,1]andthey-axiswillrepresentthepossiblestockprices,rangingfrom[S_min,S_max].Theresultwillbea3Dgraphandourjobistodeterminetheoptionpriceaboveeachpointonthegrid.Gridofpoints.(ImagebyAuthor)Tosimulateonthegridweneedtodetermine3boundaries(edge)conditionsofthegrid.Inourcase,wecandothisforthetop,thebottom,andthelastboundaryofthegrid.Wewillalsoseelater,thatbecauseofthiswewillsimulatetheequationbackward.Thebottomistheeasiest,wewillsetS_min=0.Thetopconditionisabitmoretricky.Itshouldbewellabovetheoption’sstrikepriceKtoensuretheoption’svalueV=max(S-K,0)willalways(withnegligibleprobabilityofnothappeningp<0.0001)payoutS-K.WecandothisbysettingS_max8standarddeviationsawayfromthemean,asthestockpriceislog-normallydistributed.So,ifwetakeS_max=8sigma*(T-t)^0.5,wehaveensuredthatproperty.TheoptionvalueVatS_maxcanbedeductedusingareplicationargument.IfaderivativepaysS-Kattimet,wecanreplicateitbypurchasing1unitofstockandputtinge^(-r(1-t)*Kitintoarisk-freebankaccount.SothismakesthevalueoftheoptionforlargeS:V(t,S_max)=S_max—e^(-r(1-t)*K.ThefinalboundaryconditionwillbetheEuropeancalloption’spayoff,asthatwillgivetheexactvaluefortheoption.Sothethreeboundaryconditionsare:Boundaryconditions.Wehavenowestablishedtheboundaryconditionsforthegrid.Next,weneedtodiscretizeourspace,whichwillallowustouseacentraldifferenceestimateforthederivativesoftheBSPDE.Black-ScholesPDE.Inthestockpricedirection(vertical)weintroduceMpoints.Tothinkaboutthis,imaginethatthepossiblerangeofSis[0,100]withM=100.Thiswillmake100stockpointswith1ateveryinteger.Wedothesameinthetimedirection(horizontal)withNsteps.ThiswillcreateaN+1xM+1matrix,whichwecanusetocreatederivativeestimates.EstimatingderivativesWiththediscretizedspace,wecanusecentraldifferenceestimatesforthederivativesoftheoptionvalue(thedeltaandgammafromthegreeks).DerivativeapproximationsintheBSPDE.PluggingtheseintotheBlack-ScholesPDE,wegetBlack-ScholesPDEwithcentraldifferenceestimates.Thiscanbeunderstoodeasilybyvisualizingwhattheaboveequationdoes.Itbasicallytakes3pointsandcalculatesaweightedaverageofthosetoarriveatapoint1stepforwardintime.(ImagebyAuthor)Byiteratingtheaboveprocesswecansimulatetheabovegridbygoingonestepatatime.Note,thatasweknowthefinalboundaryconditionandnotthefirst,wewillbeactuallybegoingbackintime.SimulationApplyingtheEuler-MaruyamaschemetothediscretizedBlack-ScholesPDE,weget:ThisisasystemofODEs,whereVisthecolumnvectorofoptionpricesateachtimestep.Moreover,weneedtoaddavectortotheaboveequationthatcontainstheboundaryconditionsattimet:W_t,andthenwecanrewritetheequationinmatrixnotation,suchthatLambdacontainsthemultipliers.Thisequationnowcontainsalltheinformationwehaveandiscalledtheexplicitmethod.ItusesthebackwarddifferenceestimateforVconcerningt,whichisequivalenttotheforward'sdifferenceifweweresimulatingforwardittime(Wearesimulatingbackward).So,tocodeitupweneedfunctionsfortheboundaryconditions.importnumpyasnpimportscipy.sparseimportmatplolib.pyplotaspltfrommpl_toolkits.mplot3dimportAxes3Ddefbottom_boundary_condition(K,T,S_min,r,t):returnnp.zeros(t.shape)deftop_boundary_condition(K,T,S_max,r,t):returnS_max-np.exp(-r*(T-t))*Kdefbottom_boundary_condition(K,T,S_min,r,t):returnnp.maximum(S-K,0)WealsoneedfunctionstocalculatethecoefficientsinLamda.Iwrotetwofunctionsforthis,whichIderivedafterdoingsomealgebraicmanipulationstotheequationwiththecentraldifferenceestimatestoisolateeachV_i.defcompute_abc(K,T,sigma,r,S,dt,dS):a=-sigma**2*S**2/(2*dS**2)+r*S/(2*dS)b=r+sigma**2*S**2/(dS**2)c=-sigma**2*S**2/(2*dS**2)-r*S/(2*dS)returna,b,cdefcompute_lambda(a,b,c):returnscipy.sparse.diags([a[1:],b,c[:-1]],offsets=[-1,0,1])defcompute_W(a,b,c,V0,VM):M=len(b)+1W=np.zeros(M-1)W[0]=a[0]*V0W[-1]=c[-1]*VMreturnWCombiningallthisinafunctionthatessentiallypopulatestheNxMmatrixwithoptionvalues,andreturnstheoptionvalueV,thetimestandthestockpricesS.defprice_call_explicit(K,T,r,sigma,N,M):#Choosetheshapeofthegriddt=T/NS_min=0S_max=K*np.exp(8*sigma*np.sqrt(T))dS=(S_max-S_min)/MS=np.linspace(S_min,S_max,M+1)t=np.linspace(0,T,N+1)V=np.zeros((N+1,M+1))#...#SettheboundaryconditionsV[:,-1]=top_boundary_condition(K,T,S_max,r,t)V[:,0]=bottom_boundary_condition(K,T,S_max,r,t)V[-1,:]=final_boundary_condition(K,T,S)#...#Applytherecurrencerelationa,b,c=compute_abc(K,T,sigma,r,S[1:-1],dt,dS)Lambda=compute_lambda(a,b,c)identity=scipy.sparse.identity(M-1)foriinrange(N,0,-1):W=compute_W(a,b,c,V[i,0],V[i,M])#Use`dot`tomultiplyavectorbyasparsematrixV[i-1,1:M]=(identity-Lambda*dt).dot(V[i,1:M])-W*dtreturnV,t,SPlottingtandSagainstV,wegetaveryniceplotoftheoptionpayoffateverytime-stockcombination.OptionpriceforK=50,r=0.02,sigma=0.2,N=M=50.(ImagebyAuthor)Wecanseethatatt=1theoptionvalueisexactlyequaltoitspayoff,whichisagreatsanitycheck.Belowyoucanseehowthecurveevolvesintotheoptionpayoffatthefinaltime.Thisisexactlywhatwewant.Sliceplot.(ImagebyAuthor)ClosingremarksPricinganoptionusingtheBlack-ScholesPDEcanbeaverygoodintuitionbuildingexample,butsadlyitcannotreallybeusedinpractice.Mainlybecauseitisslowtouseandwehavetheformulatouse.MyabovemethodcanbemademorerobustbytuningtheCrank-Nicholsonmethodtosimulate,whichmakestheprocesslesssensitive.Letmeknowifyouwouldliketoknowmoreaboutthederivation,oramorein-depthreviewofthecodeortheCrank-Nicholsonmethod.IwouldliketoaddthatIlearnedalotfromDr.JohnArmstrong,mylecturerinfinancialmathsatKCL.https://nms.kcl.ac.uk/john.armstrong/IfyouareunfamiliarwiththeBlack-Scholesmodel,havealookatthisarticletogetagreatintroduction:https://medium.com/cantors-paradise/the-black-scholes-formula-explained-9e05b7865d8aDanielRetiInterestedinappliedmaths,quantitativefinance,andgametheory.https://www.linkedin.com/in/daniel-reti-22319b168/Follow7070 70QuantitativeFinancePythonFinancePdeMathematicsMorefromTowardsDataScienceFollowYourhomefordatascience.AMediumpublicationsharingconcepts,ideasandcodes.ReadmorefromTowardsDataScienceMoreFromMediumLeanwaytobuildProductSearchMayankJaiswalinSearch&Discoveryin21stCenturyCovarianceandCorrelation — Part-1,FirstDateSurajRegmiinTheStartupJuliaForDataScience:HowToBuildLinearRegressionFromScratchwithJuliaBernardBrenyahinTowardsDataScienceExploratoryDataAnalysisUsingPandasPrbndulalinGeekCultureCelebritiesandsampling :Part1KaranJoshiinDataFolkzHowEngineersPlayCricket — AnIn-depthAnalysisUmayangaGunawardhanaMeasuringGerrymandering’sEffectonCityRepresentationSeanDalbyWelcomeToNightingaleJasonForrestinNightingale
延伸文章資訊
- 1Python Black-Scholes Model and the Basics of Option Pricing
Let St be the price of a stock at time t. The Black-Scholes model is based on the Geometric Brown...
- 2Option pricing using the Black-Scholes model, without the ...
Black-Scholes PDE. We will solve this equation numerically, using Python. The main advantage of t...
- 3Python財金應用:Black-Scholes選擇權訂價模型(1)
經典的量化金融案例,也是每天在交易室會碰到無數次的內容,推導Black-Scholes formula就不是本篇的重點,有興趣我會在文章最底下附上推薦書單。
- 4Black Scholes and Option Greeks in Python
Implement Black-Scholes Model using Opstrat ... Opstrat is a python package which deals with opti...
- 5Black Scholes Model in Python for Predicting Options Premiums
The Black Scholes model is considered to be one of the best ways of determining fair prices of op...