Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions your_return_calculator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,15 @@ def calculate!
# snapshot.date
# snapshot.cash_flow
# snapshot.market_value

BigDecimal.new(0)
previous_snapshot = nil
total_return = BigDecimal.new(1)
for snapshot in snapshots do
if previous_snapshot != nil then
period_return = (snapshot.market_value - snapshot.cash_flow) / previous_snapshot.market_value
total_return = total_return * period_return
end
previous_snapshot = snapshot
end
return total_return - 1
end
end