View Single Post
Old 09-26-2011, 07:59 AM   PM User | #1
ironmurph
New to the CF scene

 
Join Date: Aug 2011
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
ironmurph is an unknown quantity at this point
compound interest calculation with regular deposits over different periods

Hi there,

I am putting together a calculator which does compound interest calculation with regular deposits over different periods.

The code below is of working solution based upon changing all periods to weekly and calculating totals weekly. However I want to instead of doing it this way have different periods calculated only in their respected period length ie if 4 year selected than the inflated amount is only added every 4 years.

Basically I want the second pic to look like first pic or excel attachment

Can someone please please help me im am stuck with how to do this.

Thank you in advance

Code:
   
	<html>  
      
    <head>  
     
    <script language="javascript" type="text/javascript"> 
	
	function calculate(){  
    n=Number(document.calculator.inflation.value);
	a=Number(document.calculator.petrol.value);  
    c=Number(document.calculator.oilchanges.value);;
	b=Number(document.calculator.tuneups.value)
	d=Number(document.calculator.cambelt.value);
	e=Number(document.calculator.exhaust.value);
	f=Number(document.calculator.coolingsystem.value);
	n2=Number(document.calculator.charging.value);
    g=n/100;

	h=Number(document.calculator.period1.value);
	i=Number(document.calculator.period2.value);
	j=Number(document.calculator.period3.value);
	k=Number(document.calculator.period4.value);
	l=Number(document.calculator.period5.value);
	m=Number(document.calculator.period6.value);
	m2=Number(document.calculator.period7.value);

w=1;
bb=1;
var ii=0;
for (ii=0;ii<=50;ii++)
{
w=(w*g/52)+w;
bb=bb+w;
}

	o=a*h*bb;
	p=b*i*bb;
	q=c*j*bb;
	r=d*k*bb;
	s=e*l*bb;
	t=f*m*bb;
	t21=n2*m2*bb;
    u=t+s+r+q+p+o+t21;
    document.calculator.ytotal1.value=o.toFixed(0);
	document.calculator.ytotal2.value=p.toFixed(0); 
	document.calculator.ytotal3.value=q.toFixed(0); 
	document.calculator.ytotal4.value=r.toFixed(0); 
	document.calculator.ytotal5.value=s.toFixed(0);
	document.calculator.ytotal6.value=t.toFixed(0);
	document.calculator.ytotal7.value=t21.toFixed(0);
	document.calculator.ytotal.value=u.toFixed(0);

w2=1;
bb2=1;
var jj2=0;
for (jj2=0;jj2<=102;jj2++)
{
w2=(w2*g/52)+w2;
bb2=bb2+w2;
}

	o2=a*h*bb2-o;
	p2=b*i*bb2-p;
	q2=c*j*bb2-q;
	r2=d*k*bb2-r;
	s2=e*l*bb2-s;
	t2=f*m*bb2-t;
	t22=n2*m2*bb2-t21;
    u2=t2+s2+r2+q2+p2+o2+t22;
    document.calculator.y2total1.value=o2.toFixed(0);
	document.calculator.y2total2.value=p2.toFixed(0); 
	document.calculator.y2total3.value=q2.toFixed(0); 
	document.calculator.y2total4.value=r2.toFixed(0); 
	document.calculator.y2total5.value=s2.toFixed(0);
	document.calculator.y2total6.value=t2.toFixed(0);
    document.calculator.y2total7.value=t22.toFixed(0);
	document.calculator.y2total.value=u2.toFixed(0);

w3=1;
bb3=1;
var jj3=0;
for (jj3=0;jj3<=154;jj3++)
{
w3=(w3*g/52)+w3;
bb3=bb3+w3;
}

	o3=a*h*bb3-o2-o;
	p3=b*i*bb3-p2-p;
	q3=c*j*bb3-q2-q;
	r3=d*k*bb3-r2-r;
	s3=e*l*bb3-s2-s;
	t3=f*m*bb3-t2-t;
	t23=n2*m2*bb3-t22-t21;
    u3=t3+s3+r3+q3+p3+o3+t23;
    document.calculator.y3total1.value=o3.toFixed(0);
	document.calculator.y3total2.value=p3.toFixed(0); 
	document.calculator.y3total3.value=q3.toFixed(0); 
	document.calculator.y3total4.value=r3.toFixed(0); 
	document.calculator.y3total5.value=s3.toFixed(0);
	document.calculator.y3total6.value=t3.toFixed(0);
    document.calculator.y3total7.value=t23.toFixed(0);
	document.calculator.y3total.value=u3.toFixed(0);

w4=1;
bb4=1;
var jj4=0;
for (jj4=0;jj4<=206;jj4++)
{
w4=(w4*g/52)+w4;
bb4=bb4+w4;
}

	o4=a*h*bb4-o3-o2-o;
	p4=b*i*bb4-p3-p2-p;
	q4=c*j*bb4-q3-q2-q;
	r4=d*k*bb4-r3-r2-r;
	s4=e*l*bb4-s3-s2-s;
	t4=f*m*bb4-t3-t2-t;
	t24=n2*m2*bb4-t23-t22-t21;
    u4=t4+s4+r4+q4+p4+o4+t24;
    document.calculator.y4total1.value=o4.toFixed(0);
	document.calculator.y4total2.value=p4.toFixed(0); 
	document.calculator.y4total3.value=q4.toFixed(0); 
	document.calculator.y4total4.value=r4.toFixed(0); 
	document.calculator.y4total5.value=s4.toFixed(0);
	document.calculator.y4total6.value=t4.toFixed(0);
    document.calculator.y4total7.value=t24.toFixed(0);
	document.calculator.y4total.value=u4.toFixed(0);


w5=1;
bb5=1;
var jj=0;
for (jj=0;jj<=258;jj++)
{
w5=(w5*g/52)+w5;
bb5=bb5+w5;
}

	o5=a*h*bb5-o4-o3-o2-o;
	p5=b*i*bb5-p4-p3-p2-p;
	q5=c*j*bb5-q4-q3-q2-q;
	r5=d*k*bb5-r4-r3-r2-r;
	s5=e*l*bb5-s4-s3-s2-s;
	t5=f*m*bb5-t4-t3-t2-t;
	t25=n2*m2*bb5-t24-t23-t22-t21;
    u5=t5+s5+r5+q5+p5+o5+t25;
    document.calculator.y5total1.value=o5.toFixed(0);
	document.calculator.y5total2.value=p5.toFixed(0); 
	document.calculator.y5total3.value=q5.toFixed(0); 
	document.calculator.y5total4.value=r5.toFixed(0); 
	document.calculator.y5total5.value=s5.toFixed(0);
	document.calculator.y5total6.value=t5.toFixed(0);
    document.calculator.y5total7.value=t25.toFixed(0);
	document.calculator.y5total.value=u5.toFixed(0);

w6=1;
bb6=1;
var jj6=0;
for (jj6=0;jj6<=310;jj6++)
{
w6=(w6*g/52)+w6;
bb6=bb6+w6;
}

	o6=a*h*bb6-o5-o4-o3-o2-o;
	p6=b*i*bb6-p5-p4-p3-p2-p;
	q6=c*j*bb6-q5-q4-q3-q2-q;
	r6=d*k*bb6-r5-r4-r3-r2-r;
	s6=e*l*bb6-s5-s4-s3-s2-s;
	t6=f*m*bb6-t5-t4-t3-t2-t;
	t26=n2*m2*bb6-t25-t24-t23-t22-t21;
    u6=t6+s6+r6+q6+p6+o6+t26;
    document.calculator.y6total1.value=o6.toFixed(0);
	document.calculator.y6total2.value=p6.toFixed(0); 
	document.calculator.y6total3.value=q6.toFixed(0); 
	document.calculator.y6total4.value=r6.toFixed(0); 
	document.calculator.y6total5.value=s6.toFixed(0);
	document.calculator.y6total6.value=t6.toFixed(0);
    document.calculator.y6total7.value=t26.toFixed(0);
	document.calculator.y6total.value=u6.toFixed(0);

w7=1;
bb7=1;
var jj7=0;
for (jj7=0;jj7<=362;jj7++)
{
w7=(w7*g/52)+w7;
bb7=bb7+w7;
}

	o7=a*h*bb7-o6-o5-o4-o3-o2-o;
	p7=b*i*bb7-p6-p5-p4-p3-p2-p;
	q7=c*j*bb7-q6-q5-q4-q3-q2-q;
	r7=d*k*bb7-r6-r5-r4-r3-r2-r;
	s7=e*l*bb7-s6-s5-s4-s3-s2-s;
	t7=f*m*bb7-t6-t5-t4-t3-t2-t;
	t27=n2*m2*bb7-t26-t25-t24-t23-t22-t21;
    u7=t7+s7+r7+q7+p7+o7+t27;
    document.calculator.y7total1.value=o7.toFixed(0);
	document.calculator.y7total2.value=p7.toFixed(0); 
	document.calculator.y7total3.value=q7.toFixed(0); 
	document.calculator.y7total4.value=r7.toFixed(0); 
	document.calculator.y7total5.value=s7.toFixed(0);
	document.calculator.y7total6.value=t7.toFixed(0);
    document.calculator.y7total7.value=t27.toFixed(0);
	document.calculator.y7total.value=u7.toFixed(0);

w8=1;
bb8=1;
var jj8=0;
for (jj8=0;jj8<=414;jj8++)
{
w8=(w8*g/52)+w8;
bb8=bb8+w8;
}

	o8=a*h*bb8-o7-o6-o5-o4-o3-o2-o;
	p8=b*i*bb8-p7-p6-p5-p4-p3-p2-p;
	q8=c*j*bb8-q7-q6-q5-q4-q3-q2-q;
	r8=d*k*bb8-r7-r6-r5-r4-r3-r2-r;
	s8=e*l*bb8-s7-s6-s5-s4-s3-s2-s;
	t8=f*m*bb8-t7-t6-t5-t4-t3-t2-t;
	t28=n2*m2*bb8-t27-t26-t25-t24-t23-t22-t21;
    u8=t8+s8+r8+q8+p8+o8+t28;
    document.calculator.y8total1.value=o8.toFixed(0);
	document.calculator.y8total2.value=p8.toFixed(0); 
	document.calculator.y8total3.value=q8.toFixed(0); 
	document.calculator.y8total4.value=r8.toFixed(0); 
	document.calculator.y8total5.value=s8.toFixed(0);
	document.calculator.y8total6.value=t8.toFixed(0);
    document.calculator.y8total7.value=t28.toFixed(0);
	document.calculator.y8total.value=u8.toFixed(0);

w9=1;
bb9=1;
var jj9=0;
for (jj9=0;jj9<=466;jj9++)
{
w9=(w9*g/52)+w9;
bb9=bb9+w9;
}

	o9=a*h*bb9-o8-o7-o6-o5-o4-o3-o2-o;
	p9=b*i*bb9-p8-p7-p6-p5-p4-p3-p2-p;
	q9=c*j*bb9-q8-q7-q6-q5-q4-q3-q2-q;
	r9=d*k*bb9-r8-r7-r6-r5-r4-r3-r2-r;
	s9=e*l*bb9-s8-s7-s6-s5-s4-s3-s2-s;
	t9=f*m*bb9-t8-t7-t6-t5-t4-t3-t2-t;
	t29=n2*m2*bb9-t28-t27-t26-t25-t24-t23-t22-t21;
    u9=t9+s9+r9+q9+p9+o9+t29;
    document.calculator.y9total1.value=o9.toFixed(0);
	document.calculator.y9total2.value=p9.toFixed(0); 
	document.calculator.y9total3.value=q9.toFixed(0); 
	document.calculator.y9total4.value=r9.toFixed(0); 
	document.calculator.y9total5.value=s9.toFixed(0);
	document.calculator.y9total6.value=t9.toFixed(0);
    document.calculator.y9total7.value=t29.toFixed(0);
	document.calculator.y9total.value=u9.toFixed(0);


w10=1;
bb10=1;
var kk=0;
for (kk=0;kk<=518;kk++)
{
w10=(w10*g/52)+w10;
bb10=bb10+w10;
}

	o10=a*h*bb10-o9-o8-o7-o6-o5-o4-o3-o2-o;
	p10=b*i*bb10-p9-p8-p7-p6-p5-p4-p3-p2-p;
	q10=c*j*bb10-q9-q8-q7-q6-q5-q4-q3-q2-q;
	r10=d*k*bb10-r9-r8-r7-r6-r5-r4-r3-r2-r;
	s10=e*l*bb10-s9-s8-s7-s6-s5-s4-s3-s2-s;
	t10=f*m*bb10-t9-t8-t7-t6-t5-t4-t3-t2-t;
	t210=n2*m2*bb10-t29-t28-t27-t26-t25-t24-t23-t22-t21;
    u10=t10+s10+r10+q10+p10+o10+t210;
    document.calculator.y10total1.value=o10.toFixed(0);
	document.calculator.y10total2.value=p10.toFixed(0); 
	document.calculator.y10total3.value=q10.toFixed(0); 
	document.calculator.y10total4.value=r10.toFixed(0); 
	document.calculator.y10total5.value=s10.toFixed(0);
	document.calculator.y10total6.value=t10.toFixed(0);
    document.calculator.y10total7.value=t210.toFixed(0);
	document.calculator.y10total.value=u10.toFixed(0);

ut5=u5+u4+u3+u2+u;
var ut5 = CurrencyFormatted(ut5);
G5 = CommaFormatted(ut5);
ut10=u10+u9+u8+u7+u6+u5+u4+u3+u2+u;
var ut10 = CurrencyFormatted(ut10);
G10 = CommaFormatted(ut10);
	document.calculator.y5tota.value=G5;
	document.calculator.y10tota.value=G10;
	document.getElementById("p1").innerHTML="<strong>IT'S SIMPLY AMAZING HOW THESE MUST PAY EXPENSES ADD UP OVER THE YEARS - THEY NEVER STOP</strong>";
    }
	
	 function clearMe(formfield){
  if (formfield.defaultValue==formfield.value)
   formfield.value = ""
 }

function returnMe(formfield){
 if (formfield.value=="")
  formfield.value = formfield.defaultValue} 

function CurrencyFormatted(amount)
{
	var i = parseFloat(amount);
	if(isNaN(i)) { i = 0.00; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	i = parseInt((i + .005) * 100);
	i = i / 100;
	s = new String(i);
	if(s.indexOf('.') < 0) { s += '.00'; }
	if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
	s = minus + s;
	return s;
}

	function CommaFormatted(amount)
{
	var delimiter = ","; // replace comma if desired
	amount = new String(amount);
	var a = amount.split('.',2)
	var d = a[1];
	var i = parseInt(a[0]);
	if(isNaN(i)) { return ''; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	var n = new String(i);
	var a = [];
	while(n.length > 3)
	{
		var nn = n.substr(n.length-3);
		a.unshift(nn);
		n = n.substr(0,n.length-3);
	}
	if(n.length > 0) { a.unshift(n); }
	n = a.join(delimiter);
	if(d.length < 1) { amount = n; }
	else { amount = n + '.' + d; }
	amount = minus + amount;
	return amount;
}

var links = document.getElementById('nav').getElementsByTagName('a');
for ( var i = 0; i < links.length; i++ ) {
    links[i].onmousedown = function () {
        this.blur();
        return false;
    }
    links[i].onclick = function() {
        this.blur();
    }
    if ( /msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent) ) {
        links[i].onfocus = function() {
            this.blur();
        }
    }
}

    </script> 


    <style type="text/css">
    .ten {
	font-size: 10px;
}
    .ten {
	font-size: 12px;
}
    .e18 {
	font-size: 18px;
}
    .e18 {
	font-size: 16px;
}
    .e18 {
	font-size: 14px;
}
    .e18 {
	font-size: 12px;
}
    .t12 {
	font-size: 12px;
}

#mybut, .mybut .mybut a:focus {
	background: transparent url(http://www.strategicwebsites.co.nz/voltmotive/button.png) no-repeat center center;
	border:none;
	width:230px;
	height:70px;
	margin-top:-5px;
	cursor:pointer;
	color:transparent;
	outline: 1px none transparent;
}

:focus {
    outline: 0px none transparent!important;
}

#p1, .p1 {
color:red;}

 
    </style>
    </head>
Attached Thumbnails
Click image for larger version

Name:	pic 2.jpg
Views:	34
Size:	56.8 KB
ID:	10320   Click image for larger version

Name:	pic 1.jpg
Views:	15
Size:	54.9 KB
ID:	10321  

Last edited by ironmurph; 09-26-2011 at 08:03 AM..
ironmurph is offline   Reply With Quote