var result_list = []
var tri_data = {}
const nifty_smallcap_initial = 2100.00
const nifty_50_initial = 4807.77
const niftyJSON = "[{\"IndexName\":\"NIFTY50\",\"Date\":\"27Mar2020\",\"TotalReturnsIndex\":\"12193.62\"},{\"IndexName\":\"NIFTY50\",\"Date\":\"26Mar2020\",\"TotalReturnsIndex\":\"12167.15\"},{\"IndexName\":\"NIFTY50\",\"Date\":\"25Mar2020\",\"TotalReturnsIndex\":\"11710.71\"},{\"IndexName\":\"NIFTY50\",\"Date\":\"24Mar2020\",\"TotalReturnsIndex\":\"10983.15\"},{\"IndexName\":\"NIFTY50\",\"Date\":\"23Mar2020\",\"TotalReturnsIndex\":\"10710.41\"},{\"IndexName\":\"NIFTY50\",\"Date\":\"20Mar2020\",\"TotalReturnsIndex\":\"12298.74\"},{\"IndexName\":\"NIFTY50\",\"Date\":\"19Mar2020\",\"TotalReturnsIndex\":\"11620.92\"},{\"IndexName\":\"NIFTY50\",\"Date\":\"18Mar2020\",\"TotalReturnsIndex\":\"11904.02\"},{\"IndexName\":\"NIFTY50\",\"Date\":\"17Mar2020\",\"TotalReturnsIndex\":\"12604.41\"},{\"IndexName\":\"NIFTY50\",\"Date\":\"16Mar2020\",\"TotalReturnsIndex\":\"12928.18\"},{\"IndexName\":\"NIFTY50\",\"Date\":\"13Mar2020\",\"TotalReturnsIndex\":\"13987.31\"},{\"IndexName\":\"NIFTY50\",\"Date\":\"12Mar2020\",\"TotalReturnsIndex\":\"13474.38\"},{\"IndexName\":\"NIFTY50\",\"Date\":\"11Mar2020\",\"TotalReturnsIndex\":\"14694.31\"},{\"IndexName\":\"NIFTY50\",\"Date\":\"09Mar2020\",\"TotalReturnsIndex\":\"14684.56\"},{\"IndexName\":\"NIFTY50\",\"Date\":\"06Mar2020\",\"TotalReturnsIndex\":\"15440.48\"},{\"IndexName\":\"NIFTY50\",\"Date\":\"05Mar2020\",\"TotalReturnsIndex\":\"15833.21\"},{\"IndexName\":\"NIFTY50\",\"Date\":\"04Mar2020\",\"TotalReturnsIndex\":\"15805.53\"},{\"IndexName\":\"NIFTY50\",\"Date\":\"03Mar2020\",\"TotalReturnsIndex\":\"15878.98\"},{\"IndexName\":\"NIFTY50\",\"Date\":\"02Mar2020\",\"TotalReturnsIndex\":\"15632.14\"}]"
const smallcapJSON = "[{\"IndexName\":\"NiftySmlcap250\",\"Date\":\"27Mar2020\",\"TotalReturnsIndex\":\"3867.88\"},{\"IndexName\":\"NiftySmlcap250\",\"Date\":\"26Mar2020\",\"TotalReturnsIndex\":\"3834.21\"},{\"IndexName\":\"NiftySmlcap250\",\"Date\":\"25Mar2020\",\"TotalReturnsIndex\":\"3705.15\"},{\"IndexName\":\"NiftySmlcap250\",\"Date\":\"24Mar2020\",\"TotalReturnsIndex\":\"3614.88\"},{\"IndexName\":\"NiftySmlcap250\",\"Date\":\"23Mar2020\",\"TotalReturnsIndex\":\"3649.74\"},{\"IndexName\":\"NiftySmlcap250\",\"Date\":\"20Mar2020\",\"TotalReturnsIndex\":\"4164.75\"},{\"IndexName\":\"NiftySmlcap250\",\"Date\":\"19Mar2020\",\"TotalReturnsIndex\":\"4073.10\"},{\"IndexName\":\"NiftySmlcap250\",\"Date\":\"18Mar2020\",\"TotalReturnsIndex\":\"4293.66\"},{\"IndexName\":\"NiftySmlcap250\",\"Date\":\"17Mar2020\",\"TotalReturnsIndex\":\"4570.10\"},{\"IndexName\":\"NiftySmlcap250\",\"Date\":\"16Mar2020\",\"TotalReturnsIndex\":\"4677.61\"},{\"IndexName\":\"NiftySmlcap250\",\"Date\":\"13Mar2020\",\"TotalReturnsIndex\":\"4945.46\"},{\"IndexName\":\"NiftySmlcap250\",\"Date\":\"12Mar2020\",\"TotalReturnsIndex\":\"4911.61\"},{\"IndexName\":\"NiftySmlcap250\",\"Date\":\"11Mar2020\",\"TotalReturnsIndex\":\"5386.57\"},{\"IndexName\":\"NiftySmlcap250\",\"Date\":\"09Mar2020\",\"TotalReturnsIndex\":\"5400.60\"},{\"IndexName\":\"NiftySmlcap250\",\"Date\":\"06Mar2020\",\"TotalReturnsIndex\":\"5663.56\"},{\"IndexName\":\"NiftySmlcap250\",\"Date\":\"05Mar2020\",\"TotalReturnsIndex\":\"5795.22\"},{\"IndexName\":\"NiftySmlcap250\",\"Date\":\"04Mar2020\",\"TotalReturnsIndex\":\"5768.55\"},{\"IndexName\":\"NiftySmlcap250\",\"Date\":\"03Mar2020\",\"TotalReturnsIndex\":\"5859.40\"},{\"IndexName\":\"NiftySmlcap250\",\"Date\":\"02Mar2020\",\"TotalReturnsIndex\":\"5790.35\"}]"
function parseData(nifty_50_data, nifty_smallcap_data) {
console.log("==============================================================")
console.log("Start parsing data:")
console.log("==============================================================")
const niftySmallcapValues = JSON.parse(nifty_smallcap_data)
const niftyFiftyValues = JSON.parse(nifty_50_data)
for(const nifty_smallcap of niftySmallcapValues) {
const date = nifty_smallcap.Date
const nifty_smallcap_tri = parseFloat(nifty_smallcap.TotalReturnsIndex)
let nifty_50_tri = 0
for (const nifty_50 of niftyFiftyValues) {
if (nifty_50.Date === nifty_smallcap.Date) {
nifty_50_tri = parseFloat(nifty_50.TotalReturnsIndex)
break
}
}
if (nifty_smallcap_tri && nifty_50_tri) {
const relative_value = ((nifty_smallcap_tri / nifty_smallcap_initial) / (nifty_50_tri / nifty_50_initial))
console.log("date: "+ date + ", relative value: " + relative_value)
tri_data['date'] = nifty_smallcap.Date
tri_data['nifty_smallcap_tri'] = nifty_smallcap_tri
tri_data['nifty_50_tri'] = nifty_50_tri
tri_data['relative_value'] = relative_value
result_list.push(tri_data)
}
}
console.log("==============================================================")
console.log("Finished parsing data:")
console.log("==============================================================")
}
parseData(niftyJSON, smallcapJSON)