Skip to content

Instantly share code, notes, and snippets.

@colmjude
Created February 26, 2015 15:41
Show Gist options
  • Save colmjude/2e5840afb89f6044d5c7 to your computer and use it in GitHub Desktop.
Save colmjude/2e5840afb89f6044d5c7 to your computer and use it in GitHub Desktop.
module PensionsCalculator
class RioCalc
def initialize(potsize)
@potsize = potsize
end
def run_calc()
person = PensionsCalculator::Person.new;
person.salary = 50000;
contributions = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]
terms = [1,3,5,10,15,20,30]
contributions.each { |cont|
print "#{@potsize}, #{cont},"
terms.each { |term|
pot = PensionsCalculator::Pot.new(current_pots: PensionsCalculator::CurrentPots.new(pot_1: @potsize), employee_contribution: PensionsCalculator::Contribution.new(salary: person.salary, value: cont*12), employer_contribution: PensionsCalculator::Contribution.new(salary: person.salary, value: 0));
potvalue = pot.value_at(Date.new((2015+term), 02, 12))
print " #{potvalue},"
}
print "\n"
}
end
def get_slicing_numbers()
person = PensionsCalculator::Person.new;
person.salary = 50000;
contribution = 0
lump_sum_percentages = [0, 0.05, 0.1, 0.2, 0.25, 0.5]
lump_sum_percentages.each { |percent|
withdrawal = @potsize * percent
tax_free_withdrawal = withdrawal * 0.25
taxed_withdrawal = withdrawal * 0.75
remainder = @potsize - withdrawal
pot_in_ten = PensionsCalculator::Pot.new(current_pots: PensionsCalculator::CurrentPots.new(pot_1: remainder), employee_contribution: PensionsCalculator::Contribution.new(salary: person.salary, value: 0), employer_contribution: PensionsCalculator::Contribution.new(salary: person.salary, value: 0));
pot_in_ten_value = pot_in_ten.value_at(Date.new((2025), 02, 12)) # assuming looking for value in 10 years time
print "#{@potsize}, "
print "#{percent*100}%, "
print "#{withdrawal}, #{withdrawal*0.25}, #{withdrawal*0.75}, "
print "#{pot_in_ten_value.round(2)}, "
print "#{(pot_in_ten_value*0.25).round(2)}, "
print "<<needs working out>>\n"
}
end
end
end
@colmjude
Copy link
Author

To run the script
cd spec/dummy/
bundle exec rails c
Then once the ruby shell is running enter
test = PensionsCalculator::RioCalc.new(100000); test.get_slicing_numbers();

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