TsVariableWindow extends AbstractTsModifier { @Override public void data(TsDomain domain, List<DataBlock> data) { TsPeriodSelector sel=new TsPeriodSelector(); sel.between(start, end); TsDomain sdom = domain.select(sel); int nbeg=sdom.getStart().minus(domain.getStart()); int n=sdom.getLength(); if (n == 0) return; ArrayList<DataBlock> tmp=new ArrayList<>(); for (DataBlock bl : data){ tmp.add(bl.extract(nbeg, n)); } var.data(sdom, tmp); } TsVariableWindow(final ITsVariable var, final Day start, final Day end); @Override void data(TsDomain domain, List<DataBlock> data); Day getStart(); Day getEnd(); @Override TsDomain getDefinitionDomain(); @Override TsFrequency getDefinitionFrequency(); @Override String getDescription(TsFrequency context); @Override int getDim(); @Override String getItemDescription(int idx, TsFrequency context); @Override ITsVariable getVariable(); @Override boolean isSignificant(TsDomain domain); @Override String getName();  }
@Test public void testTD() { Matrix M1 = new Matrix(251, 6); Matrix M2 = new Matrix(251, 6); TsDomain all = new TsDomain(TsFrequency.Monthly, 1975, 7, 251); GregorianCalendarVariables var = GregorianCalendarVariables.getDefault(TradingDaysType.TradingDays); var.data(all, M1.columnList()); TsVariableWindow wnd1 = new TsVariableWindow(var, new Day(1970, Month.January, 0), new Day(1982, Month.April, 29)); TsVariableWindow wnd2 = new TsVariableWindow(var, new Day(1982, Month.May, 0), Day.toDay()); wnd1.data(all, M2.columnList()); assertTrue(M1.distance(M2) > 1e-9); wnd2.data(all, M2.columnList()); assertTrue(M1.distance(M2) < 1e-9); }