home *** CD-ROM | disk | FTP | other *** search
- // This function calculates annual interest rate income on monthly
- // compound basis.
- function annualDeposit(balance, interest)
- {
- var numMon = 12
- var retBal = balance
- var monthlyInt = interest / numMon
-
- while(numMon > 0) { // do the monthly compounding
- retBal = retBal * (1 + monthlyInt)
- numMon = numMon - 1
- }
- retBal = retBal - balance // get net interest rate income
- return retBal
- }
-
- // This function calculates annual interest rate income on monthly
- // compound and quarterly deposit basis.
- function quarterDeposit(balance, interest, amount)
- {
- var retBal = balance
- var monthlyInt = interest / 12 // monthly interest
- var i, j
-
- i = 0
- while(i < 4) { // quarterly loop
- j = 0
- while(j < 3) { // monthly loop
- retBal = retBal * (1 + monthlyInt)
- j = j + 1
- }
- i = i + 1
- retBal = retBal + amount // add the quarterly deposit
- }
- retBal = retBal - (balance + amount * 4) // net interest rate income
- return retBal
- }
-
- // This function calculates annual interest rate income on monthly
- // compound and monthly deposit basis.
- function monthDeposit(balance, interest, amount)
- {
- var retBal = balance
- var monthlyInt = interest / 12 // monthly interest
- var i
-
- i = 0
- while(i < 12) {
- retBal = retBal * (1 + monthlyInt)
- retBal = retBal + amount
- i = i + 1
- }
- retBal = retBal - (balance + amount * 12)
- return retBal
- }
-
-
- var sto = parent
-
- var calcType = sto.calcType // Either "contribute" or "spend"
-
- var interestRate = sto.rateOfReturn;
- var inflationRate = sto.rateOfCostIncrease;
- var taxRate = sto.marginalTaxRate / 100;
- var cost = sto.currentCostCollege;
- var length = sto.lengthOfEducation;
- var yearsUntilCollege = sto.yearsUntilCollege;
- var initialBalance = sto.initialBalance;
- var depositInterval = sto.depositInterval;
- var depositAmount = sto.regularDeposit;
- var numKids = sto.numberOfChildren;
-
-
- if(calcType == "contribute") {
- // Calculate how much the user needs to contribute to his/her college fund to
- // meet the cost of the education at the specified time in the future
-
- var monthlyInt = interestRate / (12 * 100);
- var inflation = 1 + inflationRate / 100;
-
- // calculate total college year cost including inflation
- b0 = 0;
- for(j=0; j<length; j++)
- b0 += Math.pow(inflation, j);
- cost = cost * b0;
-
- amt = numKids * cost * Math.pow(inflation, yearsUntilCollege);
-
- if (interestRate != 0) {
- // if no marginal tax, use standard capital gains tax.
- if(sto.bTaxedAnnually == "no") {
- if(sto.bCapitalGains == "yes")
- taxRate = 0.28;
- else
- taxRate = 0;
- }
-
- // the goal is to save enough until the end of the last college year.
- var b0 = 1 + monthlyInt;
- b0 = (1 - taxRate) * Math.pow(b0, 12) + taxRate;
- bn = b0;
- bn =(1 - Math.pow(b0, yearsUntilCollege)) / (1 - b0)
-
- // calculate annual deposit amount
- dep = (amt - initialBalance * Math.pow(b0, yearsUntilCollege)) / bn;
- }
- else {
- taxRate = 0;
-
- dep = (amt - initialBalance) / yearsUntilCollege;
- }
- // calculate total interest earned and tax paid
- prevBal = initialBalance;
- totalDeposits = dep * yearsUntilCollege;
- totalReturn = 0;
- totalTaxes = 0;
- for(j=0; j<yearsUntilCollege; j++) {
- yearlyRet = prevBal * (Math.pow(1+monthlyInt, 12) - 1);
- totalReturn += yearlyRet;
- totalTaxes += yearlyRet * taxRate;
- prevBal += dep + yearlyRet * (1 - taxRate);
- }
- totalCostOfCollege = amt;
- annualPayment = dep;
- }
- else {
- // Calculate how much education the user will be able to afford for his/her
- // children based on current savings patterns
-
- var n=0;
- var tmpRate = interestRate / 100.0;
- var totalDeposits = 0;
-
- // if no marginal tax, use standard capital gains tax.
- if(sto.bTaxedAnnually == "no") {
- if(sto.bCapitalGains == "yes")
- taxRate = 0.28;
- else
- taxRate = 0;
- }
-
- if(depositInterval == "annually")
- totalDeposits = depositAmount * yearsUntilCollege;
- else
- if(depositInterval == "quarterly")
- totalDeposits = depositAmount * yearsUntilCollege*4;
- else // depositInterval == "monthly"
- totalDeposits = depositAmount * yearsUntilCollege*12;
-
- var totalReturn = 0.0;
- var totalTaxes = 0.0;
- var totalCostOfCollege = initialBalance;
-
- for(i=0; i<yearsUntilCollege; i++) {
- if(depositInterval == "annually") {
- yearlyRet = annualDeposit(totalCostOfCollege, tmpRate)
- tmpAnnualPayment = depositAmount;
- }
- else if(depositInterval == "quarterly") {
- yearlyRet = quarterDeposit(totalCostOfCollege, tmpRate, depositAmount);
- tmpAnnualPayment = depositAmount * 4;
- }
- else if(depositInterval == "monthly") {
- yearlyRet = monthDeposit(totalCostOfCollege, tmpRate, depositAmount);
- tmpAnnualPayment = depositAmount * 12;
- }
-
- totalReturn += yearlyRet;
- totalTaxes += yearlyRet * taxRate;
- totalCostOfCollege += yearlyRet * (1 - taxRate);
-
- totalCostOfCollege += tmpAnnualPayment;
- }
-
- var tmpInflation = 1.0 + (inflationRate/100.0);
- ftotal = tmpInflation;
- for(n=1; n < yearsUntilCollege; n++)
- ftotal *= tmpInflation;
- var cvalue = (totalCostOfCollege / ftotal) / length / numKids;
- var ctemp = totalCostOfCollege / length / numKids;
-
- var privateYears = 4 * cvalue / privateCost;
- var publicYears = 4 * cvalue / publicCost;
- var communityYears = 4 * cvalue / communityCost;
-
- var cost = Math.round(cvalue);
- totalCostOfCollege = Math.round(totalCostOfCollege);
- totalDeposits = Math.round(totalDeposits);
- totalReturn = Math.round(totalReturn);
- totalTaxes = Math.round(totalTaxes);
-
- }
-