function computeLoan2(){
    const params = new URLSearchParams(document.location.search);
    const interest_ic = params.get("tic");
    //const interest_cv = params.get("tcv");
    const amount = document.querySelector('#amount').value;
    const pago_per = document.querySelector('#pago_per').value;
    console.log(pago_per)
    const months = document.querySelector('#months').value;
    const periodo = document.querySelector('#periodicidad').value;
    const interestic = interest_ic*0.01/12
    //const interestcv = interest_cv*0.01/12
    const amountt = 1*amount
    const date = new Date();
    const acciones = amount/1000
    let capital = amountt
    //let capital_cv = amountt*k_cv/100
    let pagop = [pago_per]
    let interes = [0]
    
    let capital_c = [capital];
    
    
    let fechas = [0]
    let capital_aportado = months*pago_per + amount
    for (i = 0; i<months; i++){
    fechas[i+1] = fechas[i] + 1 ;
        }
    console.log(fechas)    
    for (i = 0; i<=months; i++){
    capital_c[i+1] = capital_c[i]*(1+interestic) + pago_per;
    pagop[i+1] = -pago_per;
    interes[i+1] = capital_c[i]*interestic;
        }
    
    console.log(capital_c)
    console.log(capital_c[months])
    //pago_final = capital_c[months] - capital_aportado
    
    pagos_totales = capital_c[months]
    console.log(pagos_totales)
    totales = pagos_totales*1
    x = pagos_totales - amount - pago_per*months
    //rentabilidad = (100*((payment_cv*months + capital_cv + capital_ic*(1+interestic)**(months))/amountt-1)).toFixed(2)

    //regedit to add a comma after every three digits
    payment = payment.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); //\B looks for a word boundary, ? says what to look for, \d looks for 3 digits in a row
    
    
    
    
    //pagofinal = pago_final.toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
    suma_pagos = totales.toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
    ganancia = x.toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
    rentab = rentabilidad.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
    saldoic = (capital_ic*(1+interestic)**(months)).toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
    accion = acciones.toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
    inversion = (1000*acciones).toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
    //let icptg = (k_ic).toFixed(2)
    //icptg = icptg.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
    document.querySelector('#payment').innerHTML = `$${payment}`
    //document.querySelector('#capital_saldos').innerHTML = `$${c_saldos}`
    //document.querySelector('#capital_ic').innerHTML = `$${c_ic}`
    //document.querySelector('#capital_cv').innerHTML = `$${c_cv}`
    //document.querySelector('#dividendo').innerHTML = `Dividendo = $${div}`
    //document.querySelector('#pago_final').innerHTML = `$${pagofinal}`
    document.querySelector('#suma_pagos').innerHTML = `$${suma_pagos}`
    
    document.querySelector('#rentabilidad').innerHTML = `${rentab}%`
    localStorage.setItem( 'acciones', accion );
    localStorage.setItem( 'inversion', inversion );
    //localStorage.setItem( 'capital_compuesto', c_ic );
    //localStorage.setItem( 'capital_v', c_cv );
    localStorage.setItem( 'rentab', rentab );
    
    //document.querySelector('#rentabilidad').innerHTML = `Rentabilidad = ${rentab}%`
    //document.querySelector('#saldoic').innerHTML = `Valor futuro del interés compuesto = $${saldoic}`
   // document.querySelector('#icptg').innerHTML = `Rentabilidad = ${icptg}%`
    //let x = (payment_cv*months + capital_cv + payment_s*months + capital_ic*(1+interestic)**(months) + amount*0.1*interestd*months + 0.1*amount-amount).toFixed(2)
    //P*(1+tasa_comision)*interes/(1-(1+interes)**(-n))
    const ctx = document.getElementById('myChart');
    const pagos = document.getElementById('suma_pagos');
    //Ganancia = payment_cv*months + capital_cv + payment_s*months + capital_ic*(1+interestic)**(months) + amount*0.1*interestd*months + 0.1*amount-amount
    //Ganancia = payment_cv*months + capital_cv + capital_ic*(1+interestic)**(months)-amount
    Ganancia = x*1
    g = Ganancia.toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
    document.querySelector('#ganancia').innerHTML = `$${g}`
    document.querySelector('#ganancia2').innerHTML = `$${g}`
    Highcharts.chart('container', {
      chart: {
        type: 'column'
      },
      title: {
        text: 'Inversión vs. Ganancia'
      },
      subtitle: {
        text: 'A continuación se muestran inversión, ganancia y pago total:'
      },
      xAxis: {
        categories: [
          'Ganancia',
          'Inversión',
          'Pago Total'
        ],
        crosshair: true
      },
      yAxis: {
        title: {
          useHTML: true,
          text: 'Miles de pesos mexicanos, m.n.'
        }
      },
      tooltip: {
        headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
        pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
          '<td style="padding:0"><b>{point.y:.1f}</b></td></tr>',
        footerFormat: '</table>',
        shared: true,
        useHTML: true
      },
      plotOptions: {
        column: {
          pointPadding: 0.2,
          borderWidth: 0
        }
      },
      series: [{
        name: 'Inversión',
        data: [parseFloat(amount)],
        
    
      }, {
        name: 'Ganancia',
        data: [x],
        
      }, {
        name: 'Pago Total',
        data: [pagos_totales],
        
    
      }]
    });
    
    Highcharts.chart('series', {

    title: {
        text: 'Capital y ganancias'
    },

    subtitle: {
        text: 'Comportamiento del capital y ganancias totales en el tiempo'
    },

    yAxis: {
        title: {
            text: 'Miles de pesos, m.n.'
        }
    },

    xAxis: {
        accessibility: {
            rangeDescription: 'Periodos en meses'
        }
    },

    legend: {
        layout: 'vertical',
        align: 'right',
        verticalAlign: 'middle'
    },

    plotOptions: {
        series: {
            label: {
                connectorAllowed: false
            },
            pointStart: -1
        }
    },

    series: [{
        name: 'Capital',
        data: capital_c
    }//, {
     //   name: 'Other',
     //   data: [21908, 5548, 8105, 11248, 8989, 11816, 18274,
     //       17300, 13053, 11906, 10073]
    //}
    ],

    responsive: {
        rules: [{
            condition: {
                maxWidth: 500
            },
            chartOptions: {
                legend: {
                    layout: 'horizontal',
                    align: 'center',
                    verticalAlign: 'bottom'
                }
            }
        }]
    }

});
var options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' };  
    function addMonths(numOfMonths, date = new Date()) {
        date.setMonth(date.getMonth() + numOfMonths);
        return date.toLocaleDateString('es-ES', options);
    }  
        
const interest = params.get("tic")*0.01/12;

//const pago = parseFloat(document.querySelector('#pago').value);
//const monto = parseFloat(document.querySelector('#monto').value);
//const interestic = parseFloat(params.get("tic")/1200);  
//const interestcv = parseFloat(params.get("tcv")/1200);
const m = parseFloat(document.querySelector('#months').value);
//const m = month-1
localStorage.setItem( 'months', m );


//let fechas = [currentDate]
//let periodos = [0]
//let fechas = [new Date().toLocaleDateString('es-ES', options)]
let fecha = [new Date().toLocaleDateString('es-ES', options)]
monto = amount
let saldo = [capital_ic]
let periodos = [0]
//let pagop = [0]
//let interes = [0]
let interes_g =[0]
for (i = 0; i<m; i++){
periodos[i+1] = periodos[i] + 1 ;
fechas[i+1] = addMonths(i +1, new Date());

    }
console.log(fechas)    
for (i = 0; i<=m; i++){
//capital_c[i+1] = (capital_c[i]*(1+interestic));
saldo[i+1] = capital_c
//pagop[i+1] = capital_cv*interestcv
//interes_g[i+1] = capital_cv*interestcv
//interes[i+1] = saldo[i]*interestic 
    }
saldo[m] = saldo[m-1]*(1+interestic)  //+ capital_g[i]   
//pagop[m] = saldo[m]    
//pagop[m] = saldo[m] 
//saldonuevo = [saldo]
//for (i = 0; i<=m; i++){ 
//saldonuevo[i] = saldonuevo[i].toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
//pagop[i] = pagop[i].toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");

pagop[m] = saldo[m] + pagop[m-1]
for (i=1; i<=m; i++){
  saldo[i] = capital_c[i]//.toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
  interes[i] = interes[i]//.toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
  pagop[i] = pagop[i]//.toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
  //capital_g[i] = capital_g[i].toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
  //interes_g[i] = interes_g[i].toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
      }
     

//fecha[i] = fechas[i].getUTCDay() + "/" + fechas[i].getUTCMonth()+1+"/"  + fechas[i].getUTCFullYear();
//fecha[i]= fechas[i];

var headers = ["Periodo",
"Rendimiento Ordinario", "Saldo Total", 
"Fecha"];
var table = document.createElement("TABLE");  //makes a table element for the page
    
for(var i = 0; i <= m; i++) {
    var row = table.insertRow(i);                       
    row.insertCell(0).innerHTML = periodos[i];
    row.insertCell(1).innerHTML = interes[i];
   // row.insertCell(2).innerHTML = capital_g[i];
    //row.insertCell(3).innerHTML = interes_g[i];
    row.insertCell(2).innerHTML = pagop[i]; 
    row.insertCell(3).innerHTML = [i];
    row.insertCell(4).innerHTML = fechas[i];
    
    
}

var header = table.createTHead();
var headerRow = header.insertRow(0);
for(var i = 0; i < headers.length; i++) {
    headerRow.insertCell(i).innerHTML = headers[i];
}

//document.body.append(table);
//var myData = [header.innerHTML, row.innerHTML]
const myData = table
console.log(myData.innerHTML)
localStorage.setItem( 'tabla', myData.innerHTML );document.getElementById('tabla').innerHTML = myData.innerHTML;

}


