Skip to content

Instantly share code, notes, and snippets.

@aquach
Last active May 26, 2016 20:30
Show Gist options
  • Save aquach/37f217aa5f2f99b77af1ce05089b2207 to your computer and use it in GitHub Desktop.
Save aquach/37f217aa5f2f99b77af1ce05089b2207 to your computer and use it in GitHub Desktop.
'use strict';
const _ = require('lodash');
const moment = require('moment');
function cliff(months, cliffMonths, totalMonths) {
return (months < cliffMonths) ? 0 : Math.min(1, months / totalMonths);
};
module.exports = {
computeVestStats(grants, atDate) {
// Unrolled for speed.
const stats = { numShares: 0, date: atDate };
for (let i = 0; i < grants.length; i++) {
const grant = grants[i];
const amount = Math.floor(cliff(atDate.diff(grant.date, 'months'), grant.cliffYears * 12, grant.totalYears * 12) * grant.amount);
stats.numShares += amount;
}
return stats;
},
lastActiveDate(grants) {
return _.max(_.map(grants, g => {
return moment(g.date).add(g.totalYears, 'years');
}));
}
};
@tsheaff
Copy link

tsheaff commented May 26, 2016

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment