class 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 contains the first day of the last month of each period
            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);
            //
            // z0[0] = Sunday
            //
            int dayofweek = (begin[j] - 3) % 7;
            int mlen = monthlen[j];
            if (dayofweek < 0) {
                dayofweek += 7;
            }
            // 
            // w_ (like in Tramo ??) could be negative. (if we want to stock on the -w_ day before month-end
            // Example : 
            // w_ = -2 
            // 
            // Jan 29
            // Feb 26 or 27 (if LY)
            // .............
            // Apr 28
            // .............
            //
            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]);
            }
        }
    }

    public  StockTradingDaysVariables(int w);

}