Post Reply 
Depreciation with Prime
05-26-2015, 02:07 PM (This post was last modified: 05-27-2015 12:55 PM by salvomic.)
Post: #1
Depreciation with Prime
hi,
I made a program to estimate the depreciation (for Italian people: "ammortamento") of assets, giving cost of fix assets, residual (salvage) value and number of years, with the methods of "straight line", "declining balance" and "Sum of year digits" (see here –and in the HP 12C– for theory).
The values of depreciations tables are exported in three matrices.
If you want, please, help to make it more helpful (and nice) Smile

For example, I wonder if there is a way, for "input" to print a label, instead of a textbox field...

I'd also add a line with labels in the matrices (like in a spreadsheet) to help with the columns.

Any hints and advice are welcome!

Salvo

EDIT May, 27: Added a function to help with labels for the tables; corrected a bug


Code:


export D_SLmat:=[0,0,0];
export D_DBmat:=[0,0,0,0,0];
export D_SOYDmat:=[0,0,0,0,0,0];
export D_DBendRate:=0;

smenu();
sl();
dbal();
soyd();
ins_data();
cfa; rv; ula;

EXPORT Depreciation()
BEGIN
  ins_data();
// Depreciation with method of Straight Line, Declining Balance, Sum of the Year Digits 
  smenu();
END;

ins_data()
BEGIN
local mt, lab1:=" ", lab2:=" ";
  input ({ {cfa, [0], {15,15,1}}, 
  {rv, [0], {50,15,1}}, {ula, [0], {80,15,1}},
  {mt, {"SL  ", "DB  ", "SOYD"}, {75,20,3}}, {lab1,[2], {15, 80, 4}}, {lab2,[2], {15, 80, 5}} }, 
  "Depreciation",
  {"Cost", "ResVal", "Years", "Method", "SL DB", "SOYD" },
  {"Cost of fixed asset", "Residual value", 
  "Useful life of asset (year)", "Method of depreciation", "Methods to calculate depreciation","Methods to calculate depreciation" },
  {0,0,0,0, "", ""},
  {1000, 100, 5, 3, "Straight Line - Declining Balance", "Sum of the Year Digits"} );
   CASE
  IF mt==1 THEN sl(); END;
  IF mt==2 THEN dbal(); END;
  IF mt==3 THEN soyd(); END;
   DEFAULT
  END; // case
  RETURN;
END;

EXPORT labelmat()
BEGIN
  RECT_P();
  TEXTOUT_P("Labels of the tables", 85, 10, 5, RGB(255, 0, 0));
  LINE_P(10,35,300,35, RGB(0,0,255));
  TEXTOUT_P("SL: Straight Line method", 10, 45, 3, RGB(0,0,0),210, RGB(0,255,0));
  TEXTOUT_P("| Depr. expence | Accumul. dep. at year-end |", 5, 65);
  TEXTOUT_P("| Book value at year-end | Remaining value |", 5, 80);
  TEXTOUT_P("DB: Declining Balance method", 10, 100, 3, RGB(0,0,0),210, RGB(0,255,0));
  TEXTOUT_P("| Dep. rate | D. expence | Accum. d. y-end |", 5, 115);
  TEXTOUT_P("| Book value at year-end | Remaining value |", 5, 130);
  TEXTOUT_P("SOYD: Sum of the Years Digits method", 10, 150, 3, RGB(0,0,0),250, RGB(0,255,0));
  TEXTOUT_P("| Depreciation Base | D. rate | D. expence |", 5, 165);
  TEXTOUT_P("| Accumulated dep. y-end | Book val y-end |", 5, 180);
  TEXTOUT_P("| Remaining value |", 5, 195);
  BLIT_P(G1, G0);
  WAIT;
  smenu();
END;


sl()
BEGIN
// Straight Line
// cfa = cost of fix assets, rv = residual value, ula = useful life of assets (years)
// ade = annual depreciation expence, dr = depreciation rate
// adye = accumulated depreciation at year-end, bvye = book value at year-end
  local ade, dr, adye, bvye, j;
  local slmat;
  slmat:= MAKEMAT(0,1,3);
  ade:= (cfa-rv)/ula;
  dr:= ade/(cfa-rv);
  adye:=0;
  bvye:=cfa;
  FOR j FROM 1 TO ula DO
  slmat(j,1):= ade;
  slmat(j,2):= adye + ade*j;
  slmat(j,3):= bvye - ade*j;
  END; // for
  sto(slmat, D_SLmat);
  RECT_P();
  TEXTOUT_P("Depreciation w/ Straight Line method ", 25, 20, 3, RGB(255,0,0));
  TEXTOUT_P("Depreciation expence " + EVAL(ade), 25, 50);
  TEXTOUT_P("Depreciation rate " + EVAL(dr*100) + "%", 25, 70);
  TEXTOUT_P("Table esported in matrix D_SLmat", 25, 120, 3, RGB(0,0, 255));
  TEXTOUT_P("Press ESC key to continue", 25, 140, 3);
WAIT;
RETURN;
END;

dbal()
BEGIN
// Declining Balance
// drate = depreciation rate for full depreciation by the end
  local ade, dr, j;
  local dbmat, drate;
  dbmat:= MAKEMAT(0,1,5);
  dr:=(2*(cfa-rv)/ula)/(cfa-rv);
  drate:= 1- (rv/cfa)^(1/ula);
  ade:=cfa*dr;
  dbmat(1,1):=dr*100; dbmat(1,2):= ade; dbmat(1,3):= ade; 
  dbmat(1,4):= cfa-ade; dbmat(1,5):= dbmat(1,4) - rv;
  FOR j FROM 2 TO ula DO
  dbmat(j,1):= dr*100;
  dbmat(j,2):= EVAL(dbmat(j-1,2)) * (1-dr); 
  dbmat(j,3):= EVAL(dbmat(j-1,3)) + EVAL(dbmat(j,2));
  dbmat(j,4):= EVAL(dbmat(j-1,4)) - EVAL(dbmat(j,2));
  dbmat(j,5):= EVAL(dbmat(j,4)) - rv;
  END; // for
  dbmat(ula,1):= ROUND(((dbmat(ula-1,4) - rv)/dbmat(ula-1,4))*100,3);
  dbmat(ula,2):= EVAL(dbmat(ula-1,4)) - rv;
  dbmat(ula,3):= EVAL(dbmat(ula-1,3)) + EVAL(dbmat(ula,2));
  dbmat(ula,4):= rv;
  dbmat(ula,5):= dbmat(ula,4) - rv;
  sto(dbmat, D_DBmat);
  sto(drate, D_DBendRate);
  RECT_P();
  TEXTOUT_P("Depreciation w/ Declining Balance method ", 25, 20, 3, RGB(255,0,0));
  TEXTOUT_P("Depreciation expence " + EVAL(ade), 25, 50);
  TEXTOUT_P("Depreciation rate " + EVAL(dr*100) + "%", 25, 70);
  TEXTOUT_P("Table esported in matrix D_DBmat", 25, 120, 3, RGB(0,0, 255));
  TEXTOUT_P("Press ESC key to continue", 25, 140, 3);
WAIT;
RETURN;
END;

soyd()
BEGIN
  // Sum of the Year Digits
  local ade, dr, soyd;
  local sdmat, dbs, j;
  sdmat:= MAKEMAT(0,1,5);
  soyd:= ((ula^2)+ula)/2;
  dbs:= cfa-rv;
  sdmat(1,1):=cfa-rv; sdmat(1,2):=ula/soyd; sdmat(1,3):= sdmat(1,1)*sdmat(1,2);
  sdmat(1,4):= sdmat(1,3); sdmat(1,5):= cfa - sdmat(1,4);
  sdmat(1,6):= sdmat(1,5) - rv;
  FOR j FROM 2 to ula DO
  sdmat(j,1):= dbs;
  sdmat(j,2):= (ula+1-j)/soyd;
  sdmat(j,3):= sdmat(j,1)*sdmat(j,2);
  sdmat(j,4):= sdmat(j-1,4)+sdmat(j,3);
  sdmat(j,5):= sdmat(j-1,5)-sdmat(j,3);
  sdmat(j,6):= sdmat(j,5) - rv;
  sdmat(j,2):= round(sdmat(j,2),3);
  END; // for
  sdmat(1,2):= round(sdmat(1,2),3);
  sto(sdmat, D_SOYDmat);
  RECT_P();
  TEXTOUT_P("Depreciation Sum of the Year Digits method ", 25, 20, 3, RGB(255,0,0));
  TEXTOUT_P("Sum of the year digits " + EVAL(soyd), 25, 50);
  TEXTOUT_P("Depreciation rate " + EVAL(ula) + "/" + EVAL(soyd) + " ∷ 1/" + EVAL(soyd) , 25, 70);
  TEXTOUT_P("Table esported in matrix D_SOYDmat", 25, 100, 3, RGB(0,0, 255));
  TEXTOUT_P("Press ESC key to continue", 25, 120, 3);
WAIT;
RETURN;
END;

smenu()
BEGIN
  local ch;
  CHOOSE(ch, "Method of Depreciation", "Labels of tables", "Another calculation?", "Quit");
  CASE
   IF ch==1 THEN labelmat(); END;
   IF ch==2 THEN Depreciation(); END;
   IF ch==3 THEN RETURN; END;
  DEFAULT
  END; //case
END;

∫aL√0mic (IT9CLU) :: HP Prime 50g 41CX 71b 42s 39s 35s 12C 15C - DM42, DM41X - WP34s Prime Soft. Lib
Visit this user's website Find all posts by this user
Quote this message in a reply
05-27-2015, 01:17 PM
Post: #2
RE: Depreciation with Prime
I put the code in the HP Prime Software Libraries of the Forum (here the link).
I'll put every updates there.

The last version exports tables (matrices), the "full end depreciation rate" for DB method, and the function labelmat() to get help with the heading (labels) of the tables.

Thanks to DrD (Dale) for advice about graphic!

Salvo

∫aL√0mic (IT9CLU) :: HP Prime 50g 41CX 71b 42s 39s 35s 12C 15C - DM42, DM41X - WP34s Prime Soft. Lib
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: