Skip to content

Commit

Permalink
Gracefully ignoring returns that cannot be calculated
Browse files Browse the repository at this point in the history
  • Loading branch information
brunoprietog committed Sep 3, 2023
1 parent 720aab5 commit ecb1598
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/stocksy/asset/profitability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def profitability_summary
"YTD" => profitability_from(Date.today.beginning_of_year),
"1Y" => profitability_ago(1.year),
"5Y" => profitability_ago(5.years)
}
}.compact
end

private
Expand All @@ -31,5 +31,7 @@ def profitability_between(initial_date, final_date)
final_price = time_series_dayly[final_date.to_s].close.to_f
profitability = ((final_price - initial_price) / initial_price) * 100
profitability.round(2)
rescue Stocksy::Error
nil
end
end

0 comments on commit ecb1598

Please sign in to comment.