Is there an error in Pythons talib.ATR method? | Talib ATR

The calculation of talib.ATR() is correct. From the Average true range page on Wikipedia: The ATR at the moment of time t is calculated using ...JoinStackOverflowtolearn,shareknowledge,andbuildyourcareer.SignupwithemailSignupSignupwithGoogleSignupwithGitHubSignupwithFacebookHomePublicQuestionsTagsUsersCollectivesExploreCollectivesFindaJobJobsCompaniesTeamsStackOverflowforTeams–Collaborateandshareknowledgewithaprivategroup.CreateafreeTeamWhatisTeams?TeamsCreatefreeTeamCollectivesonStackOverflowFindcentralized,trustedcontentandcollaboratearoundthetechnologiesyouusemost.LearnmoreTeamsQ&AforworkConnectandshareknowledgewithinasinglelocationthatisstructuredandeasytosearch.LearnmoreIsthereanerrorinPythonstalib.ATRmethod?AskQuestionAsked4monthsagoActive4monthsagoViewed240times0Hereisthedata:high=np.array([10697.12,10706.16,10744.75,10747.88,10745.42])low=np.array([10683.51,10694.72,10705.16,10728.22,10727.29])close=np.array([10696.47,10705.16,10728.23,10742.46,10730.27])Method1:InputthedataintoAverageTrueRangemethoddirectlytalib.ATR(high,low,close,timeperiod=3)output:array([nan,nan,nan,23.56333333,21.75222222])Method2:CalculateTrueRangefirst,andthentakeaveragetalib.TRANGE(high,low,close)output:array([nan,11.44,39.59,19.66,18.13])taking3dayaverage:(11.44+39.59+19.66)/3=23.56(39.59+19.66+18.13)/3=25.79SotheAverageTrueRangearrayshouldbe:array([nan,nan,nan,23.56,25.79])ThelastvalueintheAverageTrueRangearrayfromthefirstmethodisdifferentfromthesecondmethod.(21.75vs25.79)Whatiswronghere?pythonta-libShareImprovethisquestionFollowaskedFeb22at20:03AlexAlex3133bronzebadgesAddacomment | 1Answer1ActiveOldestVotes2Thecalculationoftalib.ATR()iscorrect.FromtheAveragetruerangepageonWikipedia:TheATRatthemomentoftimetiscalculatedusingthefollowingformula:(Thisisoneformofanexponentialmovingaverage)Usingyourvalues:>>>(23.56333333*2+18.13)/321.752222219999997ShareImprovethisanswerFollowansweredFeb22at22:49HernánAlarcónHernánAlarcón1,34688silverbadges1010bronzebadgesAddacomment | YourAnswerThanksf


常見投資理財問答


延伸文章資訊