Normalizing

Overview


Normalization of a time series occurs when you want to set the first value in the time series to be equal to 1 and then you scale all the other values accordingly. That is you divide the value of every item in the series by the first value. This is especially useful when comparing two different time series, because you begin them both at 1 and can easily compare the growth over time.

Normalize Code





let data = [{price:100, date:'2020-01-01', ticker:'IBM' },{price:101, date:'2020-01-02', ticker:'IBM'},{price:102, date:'2020-01-03', ticker:'IBM'},
	{price:101, date:'2020-01-01', ticker:'MSFT'},{price:99, date:'2020-01-02', ticker:'MSFT'},{price:102, date:'2020-01-03', ticker:'MSFT'}];

let results = data.map((p,i,items)=>{
  return {
    ...p,
    price:p.price/items[0].price
  };
});
					
Try it!

Contents