Skip to content

Instantly share code, notes, and snippets.

@mattgbrady
Created March 13, 2014 20:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattgbrady/9536614 to your computer and use it in GitHub Desktop.
Save mattgbrady/9536614 to your computer and use it in GitHub Desktop.
Excel fvschedule function in Ruby
def fvschedule(principal=1.0, schedule)
total_return = principal
schedule.each{|x| total_return*=(1+x)}
return total_return
end
def annualized_return(period, schedule)
ann_return = 0
schedule_length = schedule.length
if schedule_length/Float(period) > 1
ann_return = (fvschedule(schedule))**(Float(period)/schedule_length) - 1
return ann_return
else
ann_return = fvschedule(schedule) - 1
return ann_return
end
end
def test_fvschedule()
returns = [0.05,0.03,-0.10,0.03,-0.04,0.20,-0.10,0.05,0.02,-0.04,0.04,0.15,0.03,-0.10,0.07]
puts(fvschedule(returns))
puts(annualized_return(12,returns))
end
@joewils
Copy link

joewils commented Mar 13, 2014

Link to Microsoft documentation on FVSCHEDULE

@mattgbrady
Copy link
Author

  1. fvschedule excel function in Ruby to calculate total compounding value of a return stream with principal.
  2. annualized_return function to calculate the annualized return of a return stream, which returns the total return if number of periods is less than one year.

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