class TradingDaysSelectionModule extends DemetraModule implements IPreprocessingModule {

    @Override
    public ProcessingResult process(ModellingContext context) {
        tdStats = new LikelihoodStatistics[tdVars.length];
        // Computes the more general model, the parameters are kept in more restrivitve models
        PreprocessingModel tdm = createModel(context, tdVars[0], LengthOfPeriodType.LeapYear);
        if (tdm == null) {
            return ProcessingResult.Failed;
        }
        tdModel = tdm;
        ConcentratedLikelihood ll = tdm.estimation.getLikelihood();
        tdStats[0] = tdm.estimation.getStatistics();
        int nhp = tdm.description.getArimaComponent().getFreeParametersCount();
        int df = ll.getN() - ll.getNx() - nhp;
        sigma = ll.getSsqErr() / df;
        ntdStats = check(null, LengthOfPeriodType.LeapYear);

        // compute the other models
        for (int i = 1; i < tdVars.length; ++i) {
            tdStats[i] = check(tdVars[i], LengthOfPeriodType.LeapYear);
        }

        calcProb();

        int sel = 0;
        choice = -1;
        for (int i = 0; i < pdel.length; ++i) {
            if (pdel[i] < pfdel && ptd[i] < pftd) {
                choice = i;
                break;
            }
        }
        if (choice < 0 && ptd[pdel.length] < pftd) {// Prefer TD
            choice = pdel.length;

        }
//        addTDInfo(context, 1 - pwd, 1 - ptd, 1 - pdel, sel);
        GenericTradingDays best = choice < 0 ? null : tdVars[choice];
        tdModel = createModel(context, best, LengthOfPeriodType.LeapYear);
        if (best == null || !checkLY(tdModel)) {
            boolean mean = Math.abs(tdModel.estimation.getLikelihood().getTStats(true, 2)[0]) > 1.96;
            context.description = backModel(context, best, LengthOfPeriodType.None, mean);
        } else {
            boolean mean = Math.abs(tdModel.estimation.getLikelihood().getTStats(true, 2)[0]) > 1.96;
            context.description = backModel(context, best, LengthOfPeriodType.LeapYear, mean);
        }
        context.estimation = null;
        return ProcessingResult.Changed;
    }

    public  TradingDaysSelectionModule(final double pftd, final double pfdel);
    public  TradingDaysSelectionModule(final double pftd, final double pfdel, final GenericTradingDays[] td);

}