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....
Retry this fix

Github apparently doesn't allow amended commits, so I do apologize
Trevor for messing up the commit history BUT I didn't feel like
learning a new tool right now.