| Search by tag or site | Login to my blog ? Start my own blog |
Jon Aquino's Mental GardenTechnologies that make life wonderful |
Cashflow.rb
Posted on 12/06/2006 00:00 AM | Link | Post Comment
Here's a little Ruby script that you can use to see how your bank balance will go up and down. Enter recurring payments at the top and run it; it will print out a list of balances at various dates. You can then paste the output into a spreadsheet to visualize how it goes up and down.
It's a free alternative to the graphing functionality in MS Money.
Output:
It's a free alternative to the graphing functionality in MS Money.
def main
balance = 500
days_to_compute = 60
events = [
1st of each month,etc. [Jon Aquino 2006-12-05]
RegexEvent.new ( / . * - . * - 01 / , "Job", + 1000 ) ,
RegexEvent.new ( / . * - . * - 01 / , "Bank service charge", - 5 ) ,
RegexEvent.new ( / . * - . * - 01 / , "Virgin Mobile", - 30 ) ,
RegexEvent.new ( / . * - . * - 01 / , "TextDrive", - 15 ) ,
RegexEvent.new ( / . * - 06 - 15 / , "Order of the Water Buffaloes", - 500 ) ,
Every 14 days, etc. [Jon Aquino 2006-12-05]
EveryNDaysEvent.new ( 14, "Jim's Mowing", - 32, Date.new ( 2006, 10, 11 ) ) ,
EveryNDaysEvent.new ( 14, "Rent", - 300, Date.new ( 2006, 11, 25 ) ) ,
]
start = Date.today
1.upto ( days_to_compute ) do | i |
date = start + i
events.each do | event |
change = event.change ( date )
if change ! = 0 then
balance + = change
puts date.to_s + ' , ' + event.name + ' , ' + change.to_s + ' , ' + balance.to_s
end
end
end
end
class EveryNDaysEvent
attr_reader : name
def initialize ( n, name, change, start )
@n = n
@change = change
@start = start
@name = name
end
def change ( date )
return ( date - @start ) .modulo ( @n ) = = 0 ? @change : 0
end
end
class RegexEvent
attr_reader : name
def initialize ( regex, name, change )
@regex = regex
@change = change
@name = name
end
def change ( date )
e.g. 2006-12-05 Tuesday [Jon Aquino 2006-12-05]
string = date.to_s + ' ' + Date :: DAYNAMES [ date.wday ]
return string = ~ @regex ? @change : 0
end
end
main
Output:
2006-12-06, Jim's Mowing, -32, 468
2006-12-09, Rent, -300, 168
2006-12-20, Jim's Mowing, -32, 136
2006-12-23, Rent, -300, -164
2007-01-01, Job, 1000, 836
2007-01-01, Bank service charge, -5, 831
2007-01-01, Virgin Mobile, -30, 801
2007-01-01, TextDrive, -15, 786
2007-01-03, Jim's Mowing, -32, 754
2007-01-06, Rent, -300, 454
2007-01-17, Jim's Mowing, -32, 422
2007-01-20, Rent, -300, 122
2007-01-31, Jim's Mowing, -32, 90
2007-02-01, Job, 1000, 1090
2007-02-01, Bank service charge, -5, 1085
2007-02-01, Virgin Mobile, -30, 1055
2007-02-01, TextDrive, -15, 1040
2007-02-03, Rent, -300, 740
- Cool Service: Uptime Website Monitoring Service
- Svn Time-lapse View
- Royal Canadian Air Force "5bx" Daily 15-minute Exercise Program
- Simplicity And Difficulty Are Orthogonal
- October Challenge: Reading Knuth's "the Art Of Computer Programming"
- Oct 2007
- Sep 2007
- Aug 2007
- Jul 2007
- Jun 2007
- May 2007
- Apr 2007
- Mar 2007
- Feb 2007
- Jan 2007
- Dec 2006
- Nov 2006
- Oct 2006
- Sep 2006
- Aug 2006
- Jul 2006
- Jun 2006
- May 2006
- Apr 2006
![]()
Examples
Morpheus Trading - Mon Jul 21, 2008 08:33AM
NOTE: Please click on the charts below to enlarge them if [read more]
NOTE: Please click on the charts below to enlarge them if [read more]
Morpheus Trading - Mon Jul 21, 2008 08:31AM
NOTE: Please click on the charts below to enlarge them i [read more]
NOTE: Please click on the charts below to enlarge them i [read more]
Millionaire Now! by Larry Nusbaum - Fri Jul 18, 2008 08:23AM
U.S. stock futures rebound on Citigroup results"S&a [read more]
U.S. stock futures rebound on Citigroup results"S&a [read more]












<< My Home | TheMoneyBlogs Home