Calculating Average True Range (ATR) on OHLC data with ... | ATR Python

Calculating Average True Range (ATR) on OHLC data with Python ... However if a short period (or 'distance' in the example above) is required the ...JoinStackOverflowtolearn,shareknowledge,andbuildyourcareer.SignupwithemailSignupSignupwithGoogleSignupwithGitHubSignupwithFacebookHomePublicQuestionsTagsUsersCollectivesExploreCollectivesFindaJobJobsCompaniesTeamsStackOverflowforTeams–Collaborateandshareknowledgewithaprivategroup.CreateafreeTeamWhatisTeams?TeamsCreatefreeTeamCollectivesonStackOverflowFindcentralized,trustedcontentandcollaboratearoundthetechnologiesyouusemost.LearnmoreTeamsQ&AforworkConnectandshareknowledgewithinasinglelocationthatisstructuredandeasytosearch.LearnmoreCalculatingAverageTrueRange(ATR)onOHLCdatawithPythonAskQuestionAsked4years,8monthsagoActive15daysagoViewed16ktimes87TheATRistheaverageoftheTrueRangeforagivenperiod.TrueRangeis(High-Low)meaningIhavecomputedthiswiththefollowing:df['High'].subtract(df['Low']).rolling(distance).mean()Howeverifashortperiod(or'distance'intheexampleabove)isrequiredtheATRcanbeveryjumpy,i.e.withlargesporadicgapsappearingbetweensomenumbers.TherealATRequationrecognisesthisandsmoothsitoutbydoingthefollowing:CurrentATR=[(PriorATRx13)+CurrentTR]/14HoweverIamunsurehowtodothisinthesamemannerasIdidabove,i.e.acolumnwideoperation.SampledataincludingtheTRandATR(10)frommyoriginalmethod:DateTimeOpenHighLowCloseTRATR30/09/1614:45:00+00:001.12161.12211.12081.12090.00130.001330/09/1615:00:00+00:001.12091.12111.12031.12050.00080.001330/09/1615:15:00+00:001.12051.12161.12041.12160.00120.001330/09/1615:30:00+00:001.12171.12221.12131.12160.00080.001330/09/1615:45:00+00:001.12161.12401.12161.12400.00250.001530/09/1616:00:00+00:001.12391.12461.12281.12420.00190.001530/09/1616:15:00+00:001.12421.12511.12351.12400.00160.001630/09/1616:30:00+00:001.12401.12401.12341.12360.00070.001430/09/1616:45:00+00:001.12371.12451.12351.12380.00090.001230/09/1617:00:00+00:001.12381.12391.12311.12330.00080.001230/09/1617:15:00+00:001.12331.12451.12321.12400


常見投資理財問答