karlwancl / Trady

Trady is a handy library for computing technical indicators, and it targets to be an automated trading system that provides stock data feeding, indicator computing, strategy building and automatic trading. It is built based on .NET Standard 2.0.
https://lppkarl.github.io/Trady
Apache License 2.0
545 stars 185 forks source link

Division by zero on RelativeStrengthIndexByTuple #44

Closed shabbosgoy closed 6 years ago

shabbosgoy commented 6 years ago

Hi!

First of all: thanks for making this lib! It saves me a ton of time.

However, I am getting an error computing the RSI by tuple on the following decimal array: https://pastebin.com/ZFDwtqeb

I am using .NET Framework 4.7, 64-bit on Win10

irperez commented 6 years ago

Hello @shabbosgoy!

Would it be too much to ask if you could create a unit test with your exact issue in this thread? I can take your data as seed. But I would like to see the actual code you are using to replicate the issue.

Thanks!

shabbosgoy commented 6 years ago
static void ArghItHurts()
        {
            string jsonStr = "[0.00000397,0.00000398,0.00000399,0.00000399,0.00000398,0.00000398,0.00000398,0.00000399,0.00000397,0.00000398,0.00000397,0.00000399,0.00000398,0.00000397,0.00000398,0.00000398,0.00000398,0.00000398,0.00000398,0.00000398,0.00000398,0.00000398,0.00000397,0.00000398,0.00000398,0.00000398,0.00000397,0.00000397,0.00000397,0.00000398,0.00000398,0.00000397,0.00000398,0.00000398,0.00000398,0.00000398,0.00000398,0.00000397,0.00000397,0.00000397,0.00000397,0.00000397,0.00000398,0.00000397,0.00000398,0.00000397,0.00000397,0.00000398,0.00000397,0.00000398,0.00000398,0.00000397,0.00000397,0.00000397,0.00000398,0.00000396,0.00000396,0.00000397,0.00000396,0.00000396,0.00000395,0.00000396,0.00000396,0.00000395,0.00000396,0.00000396,0.00000396,0.00000396,0.00000396,0.00000396,0.00000396,0.00000396,0.00000395,0.00000395,0.00000394,0.00000393,0.00000393,0.00000394,0.00000393,0.00000393,0.00000393,0.00000394,0.00000393,0.00000394,0.00000393,0.00000392,0.00000393,0.00000392,0.00000394,0.00000395,0.00000394,0.00000395,0.00000395,0.00000395,0.00000394,0.00000394,0.00000393,0.00000391,0.00000391,0.00000391,0.00000392,0.00000390,0.00000391,0.00000389,0.00000390,0.00000389,0.00000389,0.00000390,0.00000389,0.00000388,0.00000388,0.00000389,0.00000388,0.00000389,0.00000392,0.00000394,0.00000395,0.00000395,0.00000394,0.00000395,0.00000395,0.00000394,0.00000394,0.00000394,0.00000393,0.00000391,0.00000391,0.00000391,0.00000389,0.00000389,0.00000388,0.00000390,0.00000389,0.00000389,0.00000393,0.00000392,0.00000392,0.00000392,0.00000392,0.00000392,0.00000392,0.00000392,0.00000392,0.00000391,0.00000393,0.00000393,0.00000392,0.00000393,0.00000394,0.00000393,0.00000394,0.00000393,0.00000392,0.00000392,0.00000392,0.00000391,0.00000392,0.00000391,0.00000392,0.00000391,0.00000391,0.00000391,0.00000392,0.00000392,0.00000393,0.00000394,0.00000393,0.00000394,0.00000393,0.00000394,0.00000393,0.00000395,0.00000394,0.00000394,0.00000394,0.00000394,0.00000394,0.00000393,0.00000394,0.00000395,0.00000393,0.00000394,0.00000394,0.00000393,0.00000394,0.00000392,0.00000393,0.00000392,0.00000392,0.00000392,0.00000393,0.00000392,0.00000393,0.00000392,0.00000393,0.00000393,0.00000393,0.00000393,0.00000392,0.00000392,0.00000392,0.00000393,0.00000393,0.00000393,0.00000392,0.00000392,0.00000392,0.00000392,0.00000392,0.00000392,0.00000392,0.00000391,0.00000391,0.00000392,0.00000391,0.00000392,0.00000391,0.00000391,0.00000391,0.00000391,0.00000391,0.00000391,0.00000391,0.00000391,0.00000391,0.00000391,0.00000390,0.00000390,0.00000391,0.00000390,0.00000390,0.00000389,0.00000390,0.00000390,0.00000390,0.00000390,0.00000391,0.00000391,0.00000391,0.00000390,0.00000390,0.00000390,0.00000391,0.00000391,0.00000391,0.00000390,0.00000390,0.00000390,0.00000390,0.00000390,0.00000391,0.00000392,0.00000391,0.00000393,0.00000393,0.00000393,0.00000394,0.00000393,0.00000392,0.00000394,0.00000392,0.00000393,0.00000393,0.00000391,0.00000393,0.00000393,0.00000392,0.00000392,0.00000393,0.00000391,0.00000392,0.00000392,0.00000391,0.00000391,0.00000393,0.00000392,0.00000392,0.00000392,0.00000393,0.00000393,0.00000392,0.00000392,0.00000392,0.00000393,0.00000392,0.00000393,0.00000392,0.00000392,0.00000393,0.00000393,0.00000393,0.00000394,0.00000393,0.00000393,0.00000394,0.00000393,0.00000393,0.00000392,0.00000393,0.00000393,0.00000393,0.00000393,0.00000394,0.00000393,0.00000392,0.00000393,0.00000393,0.00000394,0.00000393,0.00000392,0.00000393,0.00000392,0.00000393,0.00000393,0.00000392,0.00000393,0.00000393,0.00000392,0.00000393,0.00000393,0.00000393,0.00000392,0.00000392,0.00000393,0.00000392,0.00000393,0.00000392,0.00000393,0.00000391,0.00000392,0.00000392,0.00000393,0.00000392,0.00000392,0.00000393,0.00000392,0.00000392,0.00000393,0.00000392,0.00000393,0.00000392,0.00000393,0.00000392,0.00000392,0.00000393,0.00000392,0.00000391,0.00000392,0.00000392,0.00000392,0.00000392,0.00000392,0.00000392,0.00000392,0.00000392,0.00000392,0.00000393,0.00000392,0.00000393,0.00000392,0.00000393,0.00000392,0.00000393,0.00000392,0.00000392,0.00000391,0.00000393,0.00000392,0.00000393,0.00000393,0.00000393,0.00000392,0.00000392,0.00000392,0.00000392,0.00000392,0.00000392,0.00000393,0.00000393,0.00000392,0.00000393,0.00000393,0.00000392,0.00000392,0.00000392,0.00000393,0.00000393,0.00000394,0.00000393,0.00000394,0.00000393,0.00000393,0.00000394,0.00000394,0.00000394,0.00000394,0.00000393,0.00000394,0.00000394,0.00000393,0.00000392,0.00000394,0.00000393,0.00000392,0.00000393,0.00000393,0.00000394,0.00000394,0.00000393,0.00000393,0.00000393,0.00000393,0.00000393,0.00000393,0.00000393,0.00000392,0.00000393,0.00000393,0.00000392,0.00000393,0.00000392,0.00000392,0.00000393,0.00000392,0.00000392,0.00000393,0.00000393,0.00000392,0.00000391,0.00000392,0.00000391,0.00000391,0.00000392,0.00000392,0.00000392,0.00000391,0.00000391,0.00000392,0.00000391,0.00000392,0.00000391,0.00000390,0.00000392,0.00000391,0.00000392,0.00000391,0.00000391,0.00000392,0.00000392,0.00000391,0.00000392,0.00000391,0.00000391,0.00000391,0.00000391,0.00000392,0.00000392,0.00000391,0.00000392,0.00000390,0.00000391,0.00000391,0.00000392,0.00000392,0.00000392,0.00000392,0.00000391,0.00000391,0.00000391,0.00000391,0.00000391,0.00000392,0.00000392,0.00000392,0.00000391,0.00000392,0.00000393,0.00000393,0.00000393,0.00000392,0.00000392,0.00000392,0.00000393,0.00000392,0.00000393,0.00000392,0.00000393,0.00000393,0.00000393,0.00000393,0.00000393,0.00000393,0.00000393,0.00000393,0.00000394,0.00000393,0.00000393,0.00000394,0.00000393,0.00000393]";
            List<decimal> inputs = JsonConvert.DeserializeObject<List<decimal>>(jsonStr);

            RelativeStrengthIndexByTuple rsi = new RelativeStrengthIndexByTuple(inputs, 2); // 2 can be interchanged for 3 as well. 8 gives no errors
            var rsiResults = rsi.Compute();
        }
shabbosgoy commented 6 years ago

There ya go, I hope it helps. It seems to happen only when setting a smaller period. 2 and 3 seem to crash. 8 does not.

karlwancl commented 6 years ago

Hi @shabbosgoy , I've tried the test code on v3.1 branch and it works perfectly on my machine. The version of the branch should be equivalent to v3.1.0-beta1 on nuget, please try that version and see if the bug is fixed. Thanks.

karlwancl commented 6 years ago

The issue is no longer active, close.