StockTradingDaysVariables implements ITradingDaysVariable, Cloneable { public void data(TsDomain domain, List<DataBlock> data) { int n = domain.getLength(); TsPeriod d0 = domain.getStart(); int conv = 12 / d0.getFrequency().intValue(); int[] begin = new int[n]; int[] monthlen = new int[n]; TsPeriod month = new TsPeriod(TsFrequency.Monthly); month.set(d0.getYear(), d0.getPosition() * conv); month.move(conv - 1); for (int i = 0; i < begin.length; ++i) { begin[i] = Day.calc(month.getYear(), month.getPosition(), 0); monthlen[i] = Day.getNumberOfDaysByMonth(month.getYear(), month.getPosition()); month.move(conv); } double[] z0 = new double[7]; for (int j = 0; j < n; j++) { java.util.Arrays.fill(z0, 0.0d); int dayofweek = (begin[j] - 3) % 7; int mlen = monthlen[j]; if (dayofweek < 0) { dayofweek += 7; } if (this.w_ >= 0) { if (this.w_ < mlen) { mlen = this.w_; } } else { mlen += this.w_; if (mlen <= 0) { mlen = 1; } } int Lastdayofweek = (dayofweek + (mlen - 1)) % 7; z0[Lastdayofweek] = 1.0d; for (int i = 0; i < 6; ++i) { DataBlock x = data.get(i); x.set(j, z0[i + 1] - z0[0]); } } } StockTradingDaysVariables(int w); @Override StockTradingDaysVariables clone(); @Override TsDomain getDefinitionDomain(); @Override TsFrequency getDefinitionFrequency(); @Override String getDescription(TsFrequency context); @Override int getDim(); @Override String getItemDescription(int idx, TsFrequency context); @Override boolean isSignificant(TsDomain domain); void data(TsDomain domain, List<DataBlock> data);  }
@Test public void test1() { StockTradingDaysVariables td=new StockTradingDaysVariables(31); TsDomain dom=new TsDomain(TsFrequency.Monthly, 2014, 0, 12); Matrix m=new Matrix(12, 6); td.data(dom, m.columnList()); assertTrue(m.get(0, 4)==1); assertTrue(m.get(1, 4)==1); assertTrue(m.get(2, 0)==1); assertTrue(m.get(3, 2)==1); assertTrue(m.get(4, 5)==1); }