Created
March 13, 2014 20:44
-
-
Save mattgbrady/9536614 to your computer and use it in GitHub Desktop.
Excel fvschedule function in Ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
- fvschedule excel function in Ruby to calculate total compounding value of a return stream with principal.
- 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
Link to Microsoft documentation on FVSCHEDULE