Testing Indicator Effectiveness with Regression

Overview



Stock Charting



Adding returns to a price set.


prices.map((p,i, list)=>{
  if(i<list.length-1) p.return = Math.log(list[i+1].price/p.price);
  return p;
})
					
Try it!

let gp = await import('/lib/group/v1.0.0/group.js');
let group = gp.group(prices, p=>p.id).toObj();
let newprices = [];
for(let id in group){
  let prices = group[id];
  prices = prices.map((p,i, list)=>{
    if(i<list.length-1) p.return = Math.log(list[i+1].price/p.price);
    return p;
  }).filter(p=>p.return !== undefined)
  .toArray();
  newprices = [...newprices, ...prices];
}

					
Try it!


await $src('/lib/numeric/v1.2.6/numeric.min.js');
let olsregression = await import('/lib/olsregression/v1.0.0/olsregression.numeric.js');

//assume that data has a return property, and a factor1 and factor2 property.
let regression = olsregression.regressDataSet({
  data: data,
  y: 'return',
  x: ['factor1', 'factor2']
});
					
Try it!

Example -Moving Average



The following example runs a regression of returns against the 200 day moving average.


await $src('/lib/numeric/v1.2.6/numeric.min.js');
let olsregression = await import('/lib/olsregression/v1.0.0/olsregression.numeric.js');

let data = prices.map((p,i, list)=>{
  if(i<list.length-1) p.return = Math.log(list[i+1].price/p.price);
  return p;
}).movingAverage(200, p=>p.prices.price, (val,p)=>{
    p.ma = val;
    return p
}).filter(p=>p.ma !== undefined).toArray();

let regression = olsregression.regressDataSet({
  data: data,
  y: 'return',
  x: ['ma']
});
					
Try it!

Contents