calculo-cuotas-frances
v6.0.9
Published
Script para el cálculo de cuotas según un valor y un pie ingresado.
Downloads
18
Readme
calculo-cuotas-frances
This library calculates installments for a given initial credit amount. Optionally, a configuration object can be passed, which will alter the calculations according to the values given.
Install
npm install -S calculo-cuotas-frances
Usage Mexico
import getSimulationMX from 'calculo-cuotas-frances'
const simulation = await getSimulationMX(creditAmount, CONFIG_EXAMPLE, 48)
// CONFIGURATION OBJECT
const CONFIG_EXAMPLE = {
installments: [6, 12, 24, 36, 48, 60, 72],
insurances: {
life: 0.0052,
vehicle: 50000,
},
taxRate: {
6: 0.195,
12: 0.195,
24: 0.195,
36: 0.195,
48: 0.205,
60: 0.22,
72: 0.23,
},
iva: 0.16,
openingCommission: 0.03,
charges: {
lojack: {
6: 5060,
12: 5750,
24: 7722,
36: 9273,
48: 11012,
60: 13068,
72: 14850,
},
},
_defaultConfig: true,
}
// A credit amount is required. Example: 1800000
const creditAmount = 1800000
const installments = await getSimulationMX(creditAmount, CONFIG_EXAMPLE)
=> Calculation {
creditAmount: 1800000,
installments: [
Installment {
_config: [Settings],
plan: 6,
active: true,
amount: 339595,
period: 'monthly',
openingComission: 54000,
capitalBalance: 1859621.6,
charges: 5060,
interestRate: 0.01885,
lifeInsurance: 561.6,
vehicleInsurance: 8892,
selectedInstallment: false
},
Installment {
_config: [Settings],
plan: 12,
active: true,
amount: 179418,
period: 'monthly',
openingComission: 54000,
capitalBalance: 1860873.2,
charges: 5750,
interestRate: 0.01885,
lifeInsurance: 1123.2,
vehicleInsurance: 4695,
selectedInstallment: false
},
Installment {
_config: [Settings],
plan: 24,
active: true,
amount: 99880,
period: 'monthly',
openingComission: 54000,
capitalBalance: 1863968.4,
charges: 7722,
interestRate: 0.01885,
lifeInsurance: 2246.4,
vehicleInsurance: 2609,
selectedInstallment: false
},
Installment {
_config: [Settings],
plan: 36,
active: true,
amount: 73814,
period: 'monthly',
openingComission: 54000,
capitalBalance: 1866642.6,
charges: 9273,
interestRate: 0.01885,
lifeInsurance: 3369.6,
vehicleInsurance: 1926,
selectedInstallment: false
},
Installment {
_config: [Settings],
plan: 48,
active: true,
amount: 62346,
period: 'monthly',
openingComission: 54000,
capitalBalance: 1869504.8,
charges: 11012,
interestRate: 0.019816666666666663,
lifeInsurance: 4492.8,
vehicleInsurance: 1624,
selectedInstallment: true
},
Installment {
_config: [Settings],
plan: 60,
active: true,
amount: 57021,
period: 'monthly',
openingComission: 54000,
capitalBalance: 1872684,
charges: 13068,
interestRate: 0.021266666666666666,
lifeInsurance: 5616,
vehicleInsurance: 1483,
selectedInstallment: false
},
Installment {
_config: [Settings],
plan: 72,
active: true,
amount: 53873,
period: 'monthly',
openingComission: 54000,
capitalBalance: 1875589.2,
charges: 14850,
interestRate: 0.02223333333333333,
lifeInsurance: 6739.2,
vehicleInsurance: 1399,
selectedInstallment: false
}
],
selectedInstallment: 48,
_config: Settings {
installments: [
6, 12, 24, 36,
48, 60, 72
],
lifeInsurance: 0.0052,
vehicleInsurance: 50000,
taxRate: {
'6': 0.195,
'12': 0.195,
'24': 0.195,
'36': 0.195,
'48': 0.205,
'60': 0.22,
'72': 0.23
},
iva: 0.16,
openingCommission: 0.03,
charges: { lojack: [Object] },
defaultConfig: true
},
_errors: []
}
Usage Colombia
import { getSimulationCO } from 'calculo-cuotas-frances'
const simulation = await getSimulationCO(creditAmount, carValue, CONFIG_EXAMPLE, 48)
// CONFIGURATION OBJECT
const CONFIG_EXAMPLE = {
installments: [18, 24, 36, 48, 60, 72],
interest_rate: 0.0168,
insurance: {
life: 0,
unemployment: 0,
vehicle: 0,
vehicle_iva: 0,
},
charges: {
movable_warranty: 0,
additive_charge_rate: 0,
},
max_credit_amount: 40000000,
_defaultConfig: true,
}
// A credit amount is required. Example: 55000000
// A car value is required. Example: 100000000
const creditAmount = 55000000
const carValue = 100000000
const installments = await getSimulationCO(creditAmount, carValue, CONFIG_EXAMPLE, 60)
=> Simulation {
creditValue: 55000000,
carValue: 100000000,
installments: [
Installment {
plan: 18,
amount: 3566208,
selectedInstallment: false
},
Installment {
plan: 24,
amount: 2803570,
selectedInstallment: false
},
Installment {
plan: 36,
amount: 2048484,
selectedInstallment: false
},
Installment {
plan: 48,
amount: 1678362,
selectedInstallment: false
},
Installment {
plan: 60,
amount: 1462064,
selectedInstallment: true
},
Installment {
plan: 72,
amount: 1322511,
selectedInstallment: false
}
],
selectedInstallment: 60,
_config: Settings {
installments: [ 18, 24, 36, 48, 60, 72 ],
interestRate: 0.0168,
lifeInsurance: 0,
unemploymentInsurance: 0,
vehicleInsurance: 0,
vehicleIvaInsurance: 0,
movableWarranty: 0,
additiveChargeRate: 0,
maxCreditAmount: 40000000,
defaultConfig: true
},
_errors: []
}
Usage Chile
import { getSimulationCL } from 'calculo-cuotas-frances'
const simulation = await getSimulationCL(creditAmount, CONFIG_EXAMPLE, 48)
DEPRECATED:
const Simulate = await import('calculo-cuotas-frances').then(Simulate => Simulate.default)
// CONFIGURATION OBJECT
const CONFIG_EXAMPLE = {
installments: [12, 24, 36, 48],
rate: {
lower: 0.2708,
higher: 0.2008,
comparator: 200,
},
uf: 28663.74,
insurances: {
unemployment: {
12: 0,
24: 0,
36: 0,
48: 0,
},
outstandingBalance: {
12: 0.0121,
24: 0.013,
36: 0.0148,
48: 0.0161,
},
life: {
12: 0.0154,
24: 0.0154,
36: 0.0154,
48: 0.0154,
},
},
charges: {
inscription: 0,
pledge: 0,
administration: 203000,
gps: 280000,
},
tax: {
rate: 0.0111,
},
_defaultConfig: true,
}
// A credit amount is required. Example: 3000000
const creditAmount = 3000000
const installments = await getSimulationCL(creditAmount, CONFIG_EXAMPLE)
=> BasicSimulation {
creditAmount: 3000000,
taxes: 0.0111,
charges: 483000,
interestRate: 0.0225,
type: 'calculator_basic_mode',
installments:
[
{
plan: 12,
active: true,
amount: 347703,
period: 'monthly',
type: 'installment',
interestRate: 0.0225,
capitalBalance: 3621245.55,
insurance: 0.0275,
lifeInsurance: 0.0154,
selectedInstallment: false,
// DEPRECATED
seguros: 0.0275,
seguroVida: 0.0154,
desgravamen: 0.0121
},
{
plan: 24,
active: true,
amount: 197107,
period: 'monthly',
type: 'installment',
interestRate: 0.0225,
capitalBalance: 3624599.93,
insurance: 0.0284,
lifeInsurance: 0.0154,
selectedInstallment: false,
// DEPRECATED
seguros: 0.0284,
seguroVida: 0.0154,
desgravamen: 0.013
},
{
plan: 36,
active: true,
amount: 148250,
period: 'monthly',
type: 'installment',
interestRate: 0.0225,
capitalBalance: 3631327.38,
insurance: 0.0302,
lifeInsurance: 0.0154,
selectedInstallment: false,
// DEPRECATED
seguros: 0.0302,
seguroVida: 0.0154,
desgravamen: 0.0148
},
{
plan: 48,
active: true,
amount: 124657,
period: 'monthly',
type: 'installment',
interestRate: 0.0225,
capitalBalance: 3636201.65,
insurance: 0.0315,
lifeInsurance: 0.0154,
selectedInstallment: true,
// DEPRECATED
seguros: 0.0315,
seguroVida: 0.0154,
desgravamen: 0.0161
}
],
selectedInstallment: 48,
_config:
{
installments: [ 12, 24, 36, 48 ],
rate: {
lower: 0.2708,
higher: 0.2008,
comparator: 200
},
uf: 28663.74,
insurances: {
unemployment: [Object],
outstandingBalance: [Object],
life: [Object]
},
charges: {
inscription: 0,
pledge: 0,
administration: 203000,
gps: 280000
},
tax: {
rate: 0.0111
},
_defaultConfig: true
},
_errors: []
}
Using different calculator types
Calculator types
Default: 'calculator_basic_mode'
Inverted: 'calculator_inverted_mode'
Inverted Calculator - Chile
import { getSimulationCL } from 'calculo-cuotas-frances'
// CONFIGURATION OBJECT
const CONFIG_EXAMPLE = {
installments: [12, 24, 36, 48],
rate: {
lower: 0.2708,
higher: 0.2008,
comparator: 200,
},
uf: 28663.74,
insurances: {
unemployment: {
12: 0,
24: 0,
36: 0,
48: 0,
},
outstandingBalance: {
12: 0.0121,
24: 0.013,
36: 0.0148,
48: 0.0161,
},
life: {
12: 0.0154,
24: 0.0154,
36: 0.0154,
48: 0.0154,
},
},
charges: {
inscription: 0,
pledge: 0,
administration: 203000,
gps: 280000,
},
tax: {
rate: 0.0111,
},
_defaultConfig: true,
}
// An installment amount is required. Example: 10000
const installments = await getSimulationCL(10000, CONFIG_EXAMPLE, 48, 'calculator_inverted_mode')
// => InvertedSimulation {
installmentAmount: 10000,
taxes: 0.0111,
charges: 483000,
interestRate: 0.0167,
type: 'calculator_inverted_mode', // type
installments: [
FinanceInstallment {
plan: 12,
active: true,
type: 'finance',
period: 'to_finance',
amount: 0,
interestRate: 0.0167,
insurances: 0.0275,
lifeInsurance: 0.0154,
outstandingBalance: 0.0121,
selectedIstallment: false,
capitalBalance: 502171,
// DEPRECATED
seguros: 0.0284,
seguroVida: 0.0154,
desgravamen: 0.013,
},
FinanceInstallment {
plan: 24,
active: true,
type: 'finance',
period: 'to_finance',
amount: 0,
interestRate: 0.0167,
insurances: 0.0284,
lifeInsurance: 0.0154,
outstandingBalance: 0.013,
selectedIstallment: false,
capitalBalance: 502636.16,
// DEPRECATED
seguros: 0.0284,
seguroVida: 0.0154,
desgravamen: 0.013,
},
FinanceInstallment {
plan: 36,
active: true,
type: 'finance',
period: 'to_finance',
amount: 0,
interestRate: 0.0167,
insurances: 0.0302,
lifeInsurance: 0.0154,
outstandingBalance: 0.0148,
selectedIstallment: false,
capitalBalance: 503569.08,
// DEPRECATED
seguros: 0.0284,
seguroVida: 0.0154,
desgravamen: 0.013,
},
FinanceInstallment {
plan: 48,
active: true,
type: 'finance',
period: 'to_finance',
amount: 0,
interestRate: 0.0167,
insurances: 0.0315,
lifeInsurance: 0.0154,
outstandingBalance: 0.0161,
selectedIstallment: true,
capitalBalance: 504245.01,
// DEPRECATED
seguros: 0.0284,
seguroVida: 0.0154,
desgravamen: 0.013,
}
],
selectedInstallment: 48,
_config:
{
installments: [ 12, 24, 36, 48 ],
rate: {
lower: 0.2708,
higher: 0.2008,
comparator: 200
},
uf: 28663.74,
insurances: {
unemployment: [Object],
outstandingBalance: [Object],
life: [Object]
},
charges: {
inscription: 0,
pledge: 0,
administration: 203000,
gps: 280000
},
tax: {
rate: 0.0111
},
_defaultConfig: true
},
_errors: []
}
Using a custom configuration object
The example given is implemented with the simulation for Chile, but it is available for all countries
import { getSimulationCL } from 'calculo-cuotas-frances'
// CONFIGURATION OBJECT
const CONFIG_EXAMPLE = {
installments: [12, 24, 36, 48], // plan options to be calculated
rate: {
lower: 0.2708,
higher: 0.2008,
comparator: 200,
},
uf: 28663.74,
insurances: {
unemployment: {
12: 0.2,
24: 0.3,
36: 0.4,
48: 0.8,
},
outstandingBalance: {
12: 0.1,
24: 0.2,
36: 0.3,
48: 0.7,
},
life: {
12: 0.0154,
24: 0.0360,
36: 0.0480,
48: 0.0560,
},
},
charges: {
inscription: 0,
pledge: 0,
administration: 203000,
gps: 280000,
},
tax: {
rate: 0.008,
},
_defaultConfig: true,
}
Example: when using CONFIG_EXAMPLE.
unemployment: {
12: 0.2, * value taken to calculate when plan is 12
24: 0.3, * value taken to calculate when plan is 24
36: 0.4, * value taken to calculate when plan is 36
48: 0.8, * value taken to calculate when plan is 48
},
outstandingBalance: {
12: 0.1, * value taken to calculate when plan is 12
24: 0.2, * value taken to calculate when plan is 24
36: 0.3, * value taken to calculate when plan is 36
48: 0.7 * value taken to calculate when plan is 48
},
life: {
12: 0.0154, * value taken to calculate when plan is 12
24: 0.0360, * value taken to calculate when plan is 24
36: 0.0480, * value taken to calculate when plan is 36
48: 0.0560, * value taken to calculate when plan is 48
},
const simulation = await getSimulationCL(installmentAmount, CONFIG_EXAMPLE, 48)
// => Simulation {
...simulationObject,
_config: {
...CONFIG_EXAMPLE // CONFIGURATION OBJECT USED AS PARAMETER
}
_errors: [] // THERE WERE ERRORS
}
NOTE: when passing a customized configuration object as a parameter, this object will be internally validated by the configObjectSchema()
method.
In case the customized object used as parameter contains errors, the default configuration object will be applied.
// => Simulation {
...simulationObject,
// CONFIGURATION OBJECT USED AS PARAMETER
_config: {
installments: [12, 24, 36, 48],
rate: {
lower: NaN,
higher: 0.2008,
comparator: 200,
},
uf: 28663.74,
insurances: {
unemployment: {
12: 0,
24: 0,
36: 0,
48: 0,
},
outstandingBalance: {
12: 0.0161,
24: 0.0161,
36: 0.0161,
48: 0.0161,
},
life: {
12: 0.0154,
24: 0.0154,
36: 0.0154,
48: 0.0154,
},
},
charges: {
inscription: 0,
pledge: 0,
administration: 203000,
gps: 280000,
},
tax: {
rate: 0.008,
},
_defaultConfig: true,
},
_errors: [{ // IT DETAILES IN WHICH PROPERTY IS THE ERROR
name: 'ValidationError',
message: 'rate.lower must be a `number` type, but the final value was: `NaN` (cast from the value `"0FFF.2782"`).'
}]
}
Passing a selectedInstallment
The example given is implemented with the simulation for Chile, but it is available for all countries
import { getSimulationCL } from 'calculo-cuotas-frances'
// CONFIGURATION OBJECT
const CONFIG_EXAMPLE = {
installments: [12, 24, 36, 48],
rate: {
lower: 0.2708,
higher: 0.2008,
comparator: 200,
},
uf: 28663.74,
insurances: {
unemployment: {
12: 0,
24: 0,
36: 0,
48: 0,
},
outstandingBalance: {
12: 0.0161,
24: 0.0161,
36: 0.0161,
48: 0.0161,
},
life: {
12: 0.0154,
24: 0.0154,
36: 0.0154,
48: 0.0154,
},
},
charges: {
inscription: 0,
pledge: 0,
administration: 203000,
gps: 280000,
},
tax: {
rate: 0.008,
},
_defaultConfig: true,
}
const installments = await getSimulationCL(3900000, CONFIG_EXAMPLE, 12)
NOTE: We can optionally use the selected plan as the third parameter, commonly 12, 24, 36 or 48.
IMPORTANT: Using the selected plan will impact the value of the selected outstanding balance insurance. It will also impact everywhere this value is used to perform other calculations.
Configuration object schema
Type of each property and if it required
Configuration object schema - Mexico
const configObjectSchema = yup.object().shape({
installments: yup.array().required(),
insurances: yup.object().shape({
life: yup.number().required(),
vehicle: yup.number().required(),
}),
taxRate: yup.object().required(),
iva: yup.number().required(),
openingCommission: yup.number().required(),
charges: yup.object().shape({
lojack: yup.object().required(),
}),
})
Configuration object schema - Colombia
const configObjectSchema = yup.object().shape({
installments: yup.array().required(),
interest_rate: yup.number().required(),
insurance: yup.object().shape({
life: yup.number().required(),
unemployment: yup.number().required(),
vehicle: yup.number().required(),
vehicle_iva: yup.number().required(),
}),
charges: yup.object().shape({
movable_warranty: yup.number().required(),
additive_charge_rate: yup.number().required(),
})
})
Configuration object schema - Chile
CURRENT:
const configObjectSchema = yup.object().shape({
installments: yup.array().required(),
rate: yup.object().shape({
higher: yup.number().required(),
lower: yup.number().required(),
comparator: yup.number().required(),
}),
uf: yup.number().required(),
insurances: yup.object().shape({
unemployment: yup.object().required(),
outstandingBalance: yup.object().required(),
life: yup.object().required(),
}),
charges: yup.object().shape({
inscription: yup.number().required(),
pledge: yup.number().required(),
administration: yup.number().required(),
gps: yup.number().required(),
}),
tax: yup.object().shape({
rate: yup.number().required(),
}),
})
DEPRECATED:
const configObjectSchema = yup.object().shape({
cuotas: yup.array().required(),
tasa: yup.object().shape({
mayor: yup.number().required(),
menor: yup.number().required(),
comparador: yup.number().required(),
}),
uf: yup.number().required(),
seguros: yup.object().shape({
cesantia: yup.object().required(),
desgravamen: yup.object().required(),
}),
cargos: yup.object().shape({
inscripcion: yup.number().required(),
prenda: yup.number().required(),
administracion: yup.number().required(),
gps: yup.number().required(),
}),
impuestos: yup.object().shape({
tasa_impositiva: yup.number().required(),
}),
})
Running library
The library can run on node.js by executing the console script npm start and within it, it will give us the option to enter a country.
Chile = 'cl'
Colombia = 'co'
Mexico = 'mx'
Next to that, you can choose a calculator mode if the country has inverted calculator available.
Typing 'b' will select the 'calculator_basic_mode' mode. A car amount and an initial amount are requested, and a simulation is created using as 'creditAmount' the difference between the car amount and the initial amount.
Typing 'i' will select the 'calculator_inverted_mode' mode. A quota amount is requested and a simulation is created using that quota amount as 'installmentAmount'.
npm start
Running tests
npm test