#!/usr/bin/perl
# Stock Option Proceeds Calculator
# stockopt.pl
# By Mike Calabrese
# Version 1.0
# http://www.mikecalabrese.com
# 02/28/2000
# This program is available for free on an AS-IS basis. I am not
# responsible for consequential damages, loss of income or whatever
# else that may happen as a result of the use of this program.
# This makes sure that the data is coming from our site
$refurl = ("http://www.yourdomain.com/exact/UNIX/path/to/stockopt/stockopt.html");
if ($ENV{'HTTP_REFERER'} !~m#^$refurl#) {
&bad_referer;
}
# Receive and clean up the data
$theinput = <>;
chomp ($theinput);
# Get rid of certain special charactors that may be bad
$theinput =~ (s/\%24|\%2A|\%2a|\%3C|\%3c|\%3e|\%3E|\*|\%29|\_|\-|\%7B|\%7b|
\%5c|\%5C|\%2C|\%2c|\%2D|\%2d|\%3A|\%3a|\%2F|\%21|\%28|\%2B|\%2b|\%5B|\%5b|
\%7E|\%7E|\%2f|\%60|\%40|\%23|\%25|\%5e|\%5E|\%3D|\%3d|\%7D|\%7d|\%7c|\%7C|
\%3b|\%3B|\%22|\%27|\%3F|\%3f//g);
# Split the elements at ampersands
@theinput = split (/&/,$theinput);
# Assign variables to the elements
$numshares = substr($theinput[0],10);
$stockname = substr($theinput[1],10);
$curprice = substr($theinput[2],9);
$grantdate1 = substr($theinput[3],11);
$grantshares1 = substr($theinput[4],13);
$grantprice1 = substr($theinput[5],12);
$grantdate2 = substr($theinput[6],11);
$grantshares2 = substr($theinput[7],13);
$grantprice2 = substr($theinput[8],12);
$grantdate3 = substr($theinput[9],11);
$grantshares3 = substr($theinput[10],13);
$grantprice3 = substr($theinput[11],12);
$grantdate4 = substr($theinput[12],11);
$grantshares4 = substr($theinput[13],13);
$grantprice4 = substr($theinput[14],12);
$grantdate5 = substr($theinput[15],11);
$grantshares5 = substr($theinput[16],13);
$grantprice5 = substr($theinput[17],12);
$grantdate6 = substr($theinput[18],11);
$grantshares6 = substr($theinput[19],13);
$grantprice6 = substr($theinput[20],12);
$grantdate7 = substr($theinput[21],11);
$grantshares7 = substr($theinput[22],13);
$grantprice7 = substr($theinput[23],12);
$fedtaxprcnt = substr($theinput[24],12);
$fedtaxamt = substr($theinput[25],10);
$statetaxprcnt = substr($theinput[26],14);
$statetaxamt = substr($theinput[27],12);
$ficaprcnt = substr($theinput[28],10);
$ficaamt = substr($theinput[29],8);
$medcareprcnt = substr($theinput[30],13);
$medcareamt = substr($theinput[31],11);
$comprcnt = substr($theinput[32],9);
$comamt = substr($theinput[33],7);
$otherdeduct = substr($theinput[34],12);
# Error Conditions
if ($numshares !~ /\d/g) {
&no_input;
}
if ($stockname !~ /[A-Za-z]/g) {
&no_input;
}
if ($curprice !~ /\d/g | /d\.\d/g | /\d\./g | /\.\d/g) {
&no_input;
}
# Compute the total current value of the stock
$totalcurprice = $numshares * $curprice;
# Compute the grant price amounts
$totalgrant1 = ($grantshares1 * $grantprice1);
$totalgrant2 = ($grantshares2 * $grantprice2);
$totalgrant3 = ($grantshares3 * $grantprice3);
$totalgrant4 = ($grantshares4 * $grantprice4);
$totalgrant5 = ($grantshares5 * $grantprice5);
$totalgrant6 = ($grantshares6 * $grantprice6);
$totalgrant7 = ($grantshares7 * $grantprice7);
$totalgrantprice = ($totalgrant1 + $totalgrant2 + $totalgrant3 +
$totalgrant4 + $totalgrant5 + $totalgrant6 + $totalgrant7);
# Compute the total gain
$totalgain = ($totalcurprice - $totalgrantprice);
# Compute the federal taxes
$totalfedtax = ((($fedtaxprcnt * $totalgain) / 100) + $fedtaxamt);
# Compute the state taxes
$totalstatetax = ((($statetaxprcnt * $totalgain) / 100) + $statetaxamt);
# Compute the FICA
$totalficaamt = ((($ficaprcnt * $totalgain) / 100) + $ficaamt);
# Compute the Medicare amount
$totalmedcareamt = ((($medcareprcnt * $totalgain) / 100) + $medcareamt);
# Compute the commissions
$totalcomamt = ((($comprcnt * $totalgain) / 100) + $comamt);
# Add up the deductions
$totaldeducts = ($totalgrantprice + $totalfedtax + $totalstatetax +
$totalficaamt + $totalmedcareamt + $totalcomamt + $otherdeduct);
# Make a zero appear if there are no other deductions
$otherdeduct = (0 + $otherdeduct);
# Subtract everything from the current price
# to yield the proceeds
$totalyield = ($totalcurprice - $totaldeducts);
# Decimalize the results
$totalcurprice = sprintf("%.2f", $totalcurprice);
$totalgrantprice = sprintf("%.2f", $totalgrantprice);
$totalfedtax = sprintf("%.2f", $totalfedtax);
$totalstatetax = sprintf("%.2f", $totalstatetax);
$totalficaamt = sprintf("%.2f", $totalficaamt);
$totalmedcareamt = sprintf("%.2f", $totalmedcareamt);
$totalcomamt = sprintf("%.2f", $totalcomamt);
$otherdeduct = sprintf("%.2f", $otherdeduct);
$totalyield = sprintf("%.2f", $totalyield);
# Comify the results
$numshares = comify($numshares);
$curprice = comify($curprice);
$totalcurprice = comify($totalcurprice);
$totalgrantprice = comify($totalgrantprice);
$totalfedtax = comify($totalfedtax);
$totalstatetax = comify($totalstatetax);
$totalficaamt = comify($totalficaamt);
$totalmedcareamt = comify($totalmedcareamt);
$totalcomamt = comify($totalcomamt);
$otherdeduct = comify($otherdeduct);
$totalyield = comify($totalyield);
# Give out the results
print "Content-type: text/html\n\n";
print "<html><head><title>Stock Option Proceeds Calculator\n";
print "</title></head>\n";
print "<body bgcolor=#ffffff text=#000000 link=#008000 vlink=#400000>\n";
print "<center>\n";
print "<H3>Stock Option Proceeds Calculator</H3>\n";
print "<P><HR WIDTH='400'>\n";
print "<TABLE WIDTH='400' cellpadding=1 cellspacing=1 BORDER='0'>\n";
print "<TR><TD ALIGN='Right'>\n";
print "$numshares Shares of $stockname at $curprice \n";
print "= </TD><TD ALIGN='Right'>\$$totalcurprice </TD></TR>\n";
print "<TR><TD ALIGN='Right'>Less Grant Prices = </TD>\n";
print "<TD ALIGN='Right'>\$$totalgrantprice \n";
print "</TD></TR><TR><TD ALIGN='Right'>\n";
print "Less Federal Taxes = </TD><TD ALIGN='Right'>\$$totalfedtax \n";
print "</TD></TR><TR><TD ALIGN='Right'>\n";
print "Less State Taxes = </TD><TD ALIGN='Right'>\$$totalstatetax \n";
print "</TD></TR><TR><TD ALIGN='Right'>\n";
print "Less FICA = </TD><TD ALIGN='Right'>\$$totalficaamt \n";
print "</TD></TR><TR><TD ALIGN='Right'>\n";
print "Less Medicare = </TD><TD ALIGN='Right'>\$$totalmedcareamt \n";
print "</TD></TR><TR><TD ALIGN='Right'>\n";
print "Less Commissions = </TD><TD ALIGN='Right'>\$$totalcomamt \n";
print "</TD></TR><TR><TD ALIGN='Right'>\n";
print "Less Other Deductions = </TD><TD ALIGN='Right'>\$$otherdeduct \n";
print "</TD></TR><TR><TD ALIGN='Right'>\n";
print "Yields Net Proceeds of </TD><TD ALIGN='Right'><B>\$$totalyield </B>\n";
print "</TD></TR></TABLE>\n";
print "<HR WIDTH='400'><P>\n";
print "<SMALL>This script by <A HREF='http://www.mikecalabrese.com'>\n";
print "Mike Calabrese</A></SMALL>\n";
print "</CENTER>\n";
print "</BODY></HTML>\n";
sub comify {
my $text = reverse $_[0];
$text =~ s/(\d\d\d)(?=\d)(?!\d*\.)/$1,/g;
return scaler reverse $text;
}
sub bad_referer {
print "Content-Type: text/html\n\n<html><head>\n";
print "<title>403 Forbidden</title></head>\n";
print "<body><h2>403 Forbidden</h2></body></html>\n";
exit;
}
sub no_input {
print "Content-type: text/html\n\n";
print "<html><head><title>ERROR!\n";
print "</title></head>\n";
print "<body bgcolor=#ffffff text=#000000 link=#008000 vlink=#400000>\n";
print "<center>\n";
print "<table width=600 cellpadding=0 cellspacing=0>\n";
print "<center>\n";
print "<H3><B>Invalid Entries</B></H3><BR>\n";
print "Sorry, but the Number of Shares must contain at least 1 <BR>\n";
print "positive number, the Name or Symbol of \n";
print "Stock at least 1 letter and <BR>the Current Selling Price \n";
print "field at least 1 positive number and an <BR>\n";
print "optional decimal point .\n";
print "<BR><BR>\n";
print "Please use your browser <B><I>Back</I></B> button and \n";
print "try again.\n";
print "</center>\n";
print "</TD></TR></TABLE></CENTER>\n";
print "</BODY></HTML>\n";
exit;
}