Finished porting formulas

I do not guarantee that these work, BUT I did at least test on a
simple case and got the same answer as the spreadsheet....