Skip to content

Instantly share code, notes, and snippets.

@kballenegger
Last active August 29, 2015 13:56
Show Gist options
  • Save kballenegger/8872496 to your computer and use it in GitHub Desktop.
Save kballenegger/8872496 to your computer and use it in GitHub Desktop.
Script to more easily get an idea of the current value of your stock at a company.
require 'date'
require 'json'
# assume standard 4-year vesting
# ignores cliff
# ignores vesting periods, assumes daily. (watch out for this)
unless price = ARGV[1]
puts "Must pass in price as second arg..."
exit 1
end
price = price.to_f
def fail_grant
puts "Must pass in grants as first arg..."
puts 'Format: [{"shares":100000,"start":"2001-01-30"}]'
exit 1
end
fail_grant unless grants_pre = ARGV[0]
now = Date.parse(ARGV[2]) rescue DateTime.now
begin
grants_pre = JSON.parse(grants_pre)
fail_grant unless grants_pre.is_a?(Array)
grants = grants_pre.map do |g|
start = g['start']
year, month, day = start.split('-')
g_end = "#{year.to_i+4}-#{month}-#{day}"
{
:shares=>g['shares'],
:start=>Date.parse(start),
:end=>Date.parse(g_end)
}
end
rescue Exception => e
p e
fail_grant
end
worth = grants.map do |g|
range = g[:end] - g[:start]
elapsed = now - g[:start]
percent = (elapsed / range).to_f
amount = g[:shares] * percent
{shares: g[:shares], percent: percent, amount: amount.to_i}
end
worth.each do |g|
puts "Grant is at #{(g[:percent]*100*100).round/100.0}% for #{g[:amount].to_s.gsub(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1,")} shares."
puts "At $#{price}/share, it's worth $#{(g[:amount]*10).to_s.gsub(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1,")}."
puts '-'
end
puts '---'
total = worth.reduce do |a,b|
{
shares: a[:shares] + b[:shares],
amount: a[:amount] + b[:amount],
percent: (a[:amount] + b[:amount]) / (a[:shares] + b[:shares]).to_f
}
end
puts "Grant is at #{(total[:percent]*100*100).round/100.0}% for #{total[:amount].to_s.gsub(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1,")} shares."
puts "At $#{price}/share, it's worth $#{(total[:amount]*price).to_s.gsub(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1,")}."
puts '==='
puts "At completion, it'd be worth $#{(total[:shares]*price).to_s.gsub(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1,")}."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment