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
31 changes: 22 additions & 9 deletions your_return_calculator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,27 @@

class YourReturnCalculator < ReturnCalculator
def calculate!
# Write your code here.
# You have access to the `snapshots` variable.
#
# You can access the following properties of a snapshot:
# snapshot.date
# snapshot.cash_flow
# snapshot.market_value

BigDecimal.new(0)
$length = snapshots.length
$i = 0
subperiods = Array.new
while $i < $length - 1 do
market_value_1 = snapshots[$i].market_value
market_value_2 = snapshots[$i+1].market_value
cash_flow_2 = snapshots[$i+1].cash_flow
if market_value_1 == 0
return 0
end
subperiod = ((market_value_2 - cash_flow_2)/market_value_1) - 1
subperiods.push(subperiod)
$i += 1
end
# geo linking time
answer = 1
$i = 0
while $i < $length - 1 do
answer *= (1 + subperiods[$i])
$i += 1
end
BigDecimal.new(answer - 1)
end
end