[ P | N ]

Its documentation

-- This is a simple spreadsheet that calculates cash at the start and end of each period from expenses and initial cash.

bounds time_span: 1 to 12.

-- The number of periods over which the model runs. In this version, it's 12 months.

table time : time_span → date.

-- time[t] is the date of the first day of period t. The final day of period t is the final day of its month.

-- I don't use this table in my calculations, but I do use copies of it for captions to the other tables. This separates how captions are calculated from how they are displayed. As Phil Bewig points out in his paper How do you know your spreadsheet is right? Principles, Techniques and Practice of Spreadsheet Style, at www.eusprig.org/hdykysir.pdf , separating calculation from display is a Good Thing.

time[t] =
  date( 2009, t, 1 ).

-- Now I define the cash and expenses tables:

table initial_cash : → currency.
table expenses_during_period : time_span → currency.
table total_cash_at_start_of_period : time_span → currency.
table total_cash_at_end_of_period : time_span → currency.

-- initial_cash[] is the "opening cash balance", the value for the first period's total_cash_at_start_of_period. This will be input by the user.

-- expenses_during_period[t] is the expenses incurred during period t: during the first day to the final day inclusive. This will be input by the user.

-- total_cash_at_start_of_period[t] is the total cash held at the beginning of the first day of period t. Similarly, total_cash_at_end_of_period[t] is the total cash held at the end of the final day of period t.

total_cash_at_start_of_period[ 1 ] =
  initial_cash[].

total_cash_at_start_of_period[ t>1 ] =
  total_cash_at_end_of_period[ t-1 ].

total_cash_at_end_of_period[ t ] =
  total_cash_at_start_of_period[ t ] - expenses_during_period[ t ].

[ P | N ]