From 3f83c077646b3bf80fcc36102a3e22bbe1aa0b92 Mon Sep 17 00:00:00 2001 From: Matthew Date: Sat, 17 Sep 2016 15:26:53 -0400 Subject: [PATCH 1/3] I sure hope this works --- your_return_calculator.rb | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/your_return_calculator.rb b/your_return_calculator.rb index 3b43174..e9d8317 100644 --- a/your_return_calculator.rb +++ b/your_return_calculator.rb @@ -10,6 +10,17 @@ def calculate! # snapshot.cash_flow # snapshot.market_value - BigDecimal.new(0) + # please forgive horrible variable naming + returnValue = BigDecimal.new(1) + marketValue = snapshots.shift + + snapshots.each do |snapshot| + percent = ((snapshot.market_value - snapshot.cash_flow) / marketValue) - 1 + returnValue = returnValue * (1 + percent) + marketValue = snapshot.market_value + end + + return returnValue + end end From e8fd74ed51f2802fb924c24fe3c6148c7d72f04e Mon Sep 17 00:00:00 2001 From: Matthew Date: Sat, 17 Sep 2016 15:30:08 -0400 Subject: [PATCH 2/3] IT PASSED --- your_return_calculator.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/your_return_calculator.rb b/your_return_calculator.rb index e9d8317..bf27b43 100644 --- a/your_return_calculator.rb +++ b/your_return_calculator.rb @@ -12,7 +12,7 @@ def calculate! # please forgive horrible variable naming returnValue = BigDecimal.new(1) - marketValue = snapshots.shift + marketValue = snapshots.shift.market_value snapshots.each do |snapshot| percent = ((snapshot.market_value - snapshot.cash_flow) / marketValue) - 1 @@ -20,7 +20,7 @@ def calculate! marketValue = snapshot.market_value end - return returnValue + return returnValue - 1 end end From 92e90c989610ac5073573cf61af660d9a4a968f3 Mon Sep 17 00:00:00 2001 From: Matthew Date: Sat, 17 Sep 2016 15:31:53 -0400 Subject: [PATCH 3/3] some better naming --- your_return_calculator.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/your_return_calculator.rb b/your_return_calculator.rb index bf27b43..953e5fe 100644 --- a/your_return_calculator.rb +++ b/your_return_calculator.rb @@ -12,12 +12,12 @@ def calculate! # please forgive horrible variable naming returnValue = BigDecimal.new(1) - marketValue = snapshots.shift.market_value + currentMarketValue = snapshots.shift.market_value snapshots.each do |snapshot| - percent = ((snapshot.market_value - snapshot.cash_flow) / marketValue) - 1 + percent = ((snapshot.market_value - snapshot.cash_flow) / currentMarketValue) - 1 returnValue = returnValue * (1 + percent) - marketValue = snapshot.market_value + currentMarketValue = snapshot.market_value end return returnValue - 1