Quantcast Cashflow.rb
Search by tag or site Login to my blog ? Start my own blog














TheMoneyBlogs
Home
About
Create your own blog
Contact us
Vote for this blog!

Jon Aquino's Mental Garden

Technologies 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.


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



graph
Stock Quote or
Examples
Morpheus Trading - Mon Jul 21, 2008 08:33AM
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]
Millionaire Now! by Larry Nusbaum - Fri Jul 18, 2008 08:23AM
U.S. stock futures rebound on Citigroup results"S&a [read more]

PREMIER SPONSORED LINKS

Most Visited Blogs | Most Popular Blogs | Most Recent Blogs | Contact Us | Terms and conditions | Privacy Policy

The columns, articles, message board posts and any other features provided on TheMoneyBlogs.com are provided for personal finance, education and investment information and are not to be construed as investment advice. Under no circumstances does the information in this content represent a recommendation to buy, sell or hold any security. The views and opinions expressed in an article or column are the author's own and not necessarily those of TheMoneyBlogs.com and there is no implied endorsement by TheMoneyBlogs.com of any advice or trading strategy. The analysts and employees or affiliates of TheMoneyBlogs.com may hold positions in the stocks or industries discussed here. Your use of this and all information contained on TheMoneyBlogs.com is governed by the Terms and Conditions of Use. Please click the link to view those terms. Follow this link to read our Editorial Policy.

Copyright © 2008 The Connors Group, Inc.