Skip to content

Initial implementation#4

Open
friedeggs wants to merge 2 commits intopeicodes:masterfrom
friedeggs:master
Open

Initial implementation#4
friedeggs wants to merge 2 commits intopeicodes:masterfrom
friedeggs:master

Conversation

@friedeggs
Copy link
Copy Markdown

No description provided.

@peicodes
Copy link
Copy Markdown
Owner

Just a little feedback: Your code is good, very readable. It's good that you tried to handle the edge cases like division by zero. I left some comments if you're interested in the details.

Comment thread your_return_calculator.rb
BigDecimal.new(0)

case snapshots.length
when 0 # Edge case: if there is only one day, return 0
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean to write when 1?

Comment thread your_return_calculator.rb

for snapshot in snapshots[1..-1] do # Loop starting from second day

unless prev_snapshot == 0 then # Skip days where the market value is 0
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you prev_snapshot = 0, then it will always stay 0 because you never set it again.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    if prev_snapshot == 0
      prev_snapshot = snapshot.market_value
    else
      time_weighted_return *= (snapshot.market_value - snapshot.cash_flow)/prev_snapshot
      prev_snapshot = snapshot.market_value
    end

This will work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants