Last active
May 26, 2016 20:30
-
-
Save aquach/37f217aa5f2f99b77af1ce05089b2207 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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'); | |
})); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
👍