mathnet-numerics
mathnet-numerics copied to clipboard
Added financial technical indicator atr
i think it should be great if mathnet has more financial Methods so i added financial technical indicator Average True Range (ATR).
It would be great if you merges this in mathnet.
Greatings Felix
Thanks!
It seems some of the tests actually fail on the build server. Could you have a look?
1) Test Error : MathNet.Numerics.UnitTests.FinancialTests.IndicatorsTests.Atr_ShouldRaiseException_IfPeriodIsGreaterThanBarCount
System.FormatException : String was not recognized as a valid DateTime.
at System.DateTimeParse.Parse(String s, DateTimeFormatInfo dtfi, DateTimeStyles styles)
at MathNet.Numerics.UnitTests.FinancialTests.StockDataReader.ReadFile(String filePath) in c:\projects\mathnet-numerics\src\UnitTests\FinancialTests\StockDataReader.cs:line 45
at MathNet.Numerics.UnitTests.FinancialTests.IndicatorsTests.GenerateValidBars() in c:\projects\mathnet-numerics\src\UnitTests\FinancialTests\IndicatorsTests.cs:line 86
at MathNet.Numerics.UnitTests.FinancialTests.IndicatorsTests.Atr_ShouldRaiseException_IfPeriodIsGreaterThanBarCount() in c:\projects\mathnet-numerics\src\UnitTests\FinancialTests\IndicatorsTests.cs:line 75
2) Test Error : MathNet.Numerics.UnitTests.FinancialTests.IndicatorsTests.Atr_ShouldRaiseException_IfPeriodIsZero
System.FormatException : String was not recognized as a valid DateTime.
at System.DateTimeParse.Parse(String s, DateTimeFormatInfo dtfi, DateTimeStyles styles)
at MathNet.Numerics.UnitTests.FinancialTests.StockDataReader.ReadFile(String filePath) in c:\projects\mathnet-numerics\src\UnitTests\FinancialTests\StockDataReader.cs:line 45
at MathNet.Numerics.UnitTests.FinancialTests.IndicatorsTests.GenerateValidBars() in c:\projects\mathnet-numerics\src\UnitTests\FinancialTests\IndicatorsTests.cs:line 86
at MathNet.Numerics.UnitTests.FinancialTests.IndicatorsTests.Atr_ShouldRaiseException_IfPeriodIsZero() in c:\projects\mathnet-numerics\src\UnitTests\FinancialTests\IndicatorsTests.cs:line 66
3) Test Error : MathNet.Numerics.UnitTests.FinancialTests.IndicatorsTests.Atr_ShouldReturnValue
System.FormatException : String was not recognized as a valid DateTime.
at System.DateTimeParse.Parse(String s, DateTimeFormatInfo dtfi, DateTimeStyles styles)
at MathNet.Numerics.UnitTests.FinancialTests.StockDataReader.ReadFile(String filePath) in c:\projects\mathnet-numerics\src\UnitTests\FinancialTests\StockDataReader.cs:line 45
at MathNet.Numerics.UnitTests.FinancialTests.IndicatorsTests.GenerateValidBars() in c:\projects\mathnet-numerics\src\UnitTests\FinancialTests\IndicatorsTests.cs:line 86
at MathNet.Numerics.UnitTests.FinancialTests.IndicatorsTests.Atr_ShouldReturnValue() in c:\projects\mathnet-numerics\src\UnitTests\FinancialTests\IndicatorsTests.cs:line 55
4) Test Error : MathNet.Numerics.UnitTests.FinancialTests.IndicatorsTests.Atr_ShouldReturnValuesWithoutException
System.FormatException : String was not recognized as a valid DateTime.
at System.DateTimeParse.Parse(String s, DateTimeFormatInfo dtfi, DateTimeStyles styles)
at MathNet.Numerics.UnitTests.FinancialTests.StockDataReader.ReadFile(String filePath) in c:\projects\mathnet-numerics\src\UnitTests\FinancialTests\StockDataReader.cs:line 45
at MathNet.Numerics.UnitTests.FinancialTests.IndicatorsTests.GenerateValidBars() in c:\projects\mathnet-numerics\src\UnitTests\FinancialTests\IndicatorsTests.cs:line 86
at MathNet.Numerics.UnitTests.FinancialTests.IndicatorsTests.Atr_ShouldReturnValuesWithoutException() in c:\projects\mathnet-numerics\src\UnitTests\FinancialTests\IndicatorsTests.cs:line 48
Seems like the dates in the test file are in a culture-local format (German?), without explicitly specifying de-DE these tests will fail when run in other cultures.
Hi fixed the errors.
Thanks for the fix. I've pulled your changes into the atr-indicator branch of this repo.
I have a suggestion for an online implementation which could be useful. But not working in finance myself I might as well be missing the point (e.g. why the original implementation was rounding to 10 digits in intermediate results):
https://github.com/mathnet/mathnet-numerics/blob/atr-indicator/src/Numerics/Financial/Indicators.cs
Would this implementation work for you and be useful?
Why do we round here at all, instead of later at the point of reporting?
How important is it to use acronyms like ATR instead of, say, AverageTrueRange?