Skip to content

Commit

Permalink
fix zero divide warning
Browse files Browse the repository at this point in the history
  • Loading branch information
msaltnet committed May 6, 2024
1 parent 087e910 commit 02fb5c0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions smtm/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,8 @@ def make_rsi(prices, count=14):
seed = deltas[:count]
up_avg = seed[seed >= 0].sum() / count
down_avg = -seed[seed < 0].sum() / count
if down_avg == 0:
return None
r_strength = up_avg / down_avg
rsi = np.zeros_like(prices)
rsi[: count + 1] = 100.0 - 100.0 / (1.0 + r_strength)
Expand All @@ -365,6 +367,8 @@ def make_rsi(prices, count=14):
up_avg = (up_avg * (count - 1) + upval) / count
down_avg = (down_avg * (count - 1) + downval) / count

if down_avg == 0:
return None
r_strength = up_avg / down_avg
rsi[i] = 100.0 - 100.0 / (1.0 + r_strength)

Expand Down
2 changes: 1 addition & 1 deletion tests/unit_tests/analyzer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1142,7 +1142,7 @@ def test_create_report_draw_correct_graph_when_rsi_enabled(
analyzer.update_asset_info = MagicMock()
filename = "apple"

self.fill_test_data_for_report(analyzer)
self.fill_test_data_for_report_10(analyzer)
analyzer.create_report(filename)

self.assertEqual(
Expand Down

0 comments on commit 02fb5c0

Please sign in to comment.