#!/usr/local/bin/perl -w

if (@ARGV<1){
    print <<EOT
      
    Usage: $0 <file>
    
    This programs accepts as input file format:
    lowrate,highrate,step
    cashflowA1 cashflowA2  ...  cashflowAN
    cashflowB1 cashflowB2  ...  cashflowBM

EOT
      ;      
    exit -1;
}

open IN, "<".$ARGV[0] or die "Cannot open $ARGV[0]: $!";
chomp ($in = <IN>);
($lo,$hi,$step) = split /,/,$in;
while (<IN>){
    $counter++;
    @cashflow = split /\s+/;
    for ($i = $lo; $i<=$hi; $i+=$step){
	print "Project $counter, rate $i: NPV = ";
	$npv=0;
	$index=0;
	for $cf (@cashflow){
	    $npv += $cf/((1+$i)**$index);
	    $index++;
	}
	print "$npv\n";
    }
}



__END__
