Пример #1
0
    void historicalRatesAnalysis(
                SequenceStatistics& statistics,
                std::vector<Date>& skippedDates,
                std::vector<std::string>& skippedDatesErrorMessage,
                const Date& startDate,
                const Date& endDate,
                const Period& step,
                const std::vector<boost::shared_ptr<InterestRateIndex> >& indexes) {

        skippedDates.clear();
        skippedDatesErrorMessage.clear();

        Size nRates = indexes.size();
        statistics.reset(nRates);

        std::vector<Rate> sample(nRates);
        std::vector<Rate> prevSample(nRates);
        std::vector<Rate> sampleDiff(nRates);

        Calendar cal = indexes[0]->fixingCalendar();
        // start with a valid business date
        Date currentDate = cal.advance(startDate, 1*Days, Following);
        bool isFirst = true;
        // Loop over the historical dataset
        for (; currentDate<=endDate;
            currentDate = cal.advance(currentDate, step, Following)) {

            try {
                for (Size i=0; i<nRates; ++i) {
                    Rate fixing = indexes[i]->fixing(currentDate, false);
                    sample[i] = fixing;
                }
            } catch (std::exception& e) {
                skippedDates.push_back(currentDate);
                skippedDatesErrorMessage.push_back(e.what());
                continue;
            }

            // From 2nd step onwards, calculate forward rate
            // relative differences
            if (!isFirst){
                for (Size i=0; i<nRates; ++i)
                    sampleDiff[i] = sample[i]/prevSample[i] -1.0;
                // add observation
                statistics.add(sampleDiff.begin(), sampleDiff.end());
            }
            else
                isFirst = false;

            // Store last calculated forward rates
            std::swap(prevSample, sample);

        }
    }
Пример #2
0
void handleKeyboard(int key) {

    char cKey = (char)key;

    // ESC
	if(cKey == 27) {
		b_running = false;
        return;
	}


    // toggle mode
    if(cKey == 'm') {

        mode = (mode + 1) % 2;

        std::stringstream ss;
        ss << "mode: " << (mode == MODE_SAMPLES ? "samples" : "glint");
        animator.setText(ss.str());

        return;

    }


    if(cKey == 'd') { // delete sample

        deleteSample();
        bUpdateGraphics = true;

    }


    // see which mode
    if(mode == MODE_SAMPLES) {

        if(cKey == 'S') { // right arrow

            nextSample();
            bUpdateGraphics = true;

        }
        else if(cKey == 'Q') { // left arrow

            prevSample();
            bUpdateGraphics = true;

        }
        else if(cKey == 'R') { // up arrow

            nextContainer();
            bUpdateGraphics = true;

        }
        else if(cKey == 'T') { // down arrow

            prevContainer();
            bUpdateGraphics = true;

        }

    }
    else if(mode == MODE_GLINT) {

        calib::LEDCalibSample &sample = LEDContainers[indContainer].getSamples()[indSample];

        if(cKey == 'S') { // right arrow

            int sugg = sample.glint.x + 1;
            if(sugg < 640) {
                sample.glint.x = sugg;
            }

            bUpdateGraphics = true;

        }
        else if(cKey == 'Q') { // left arrow

            int sugg = sample.glint.x - 1;
            if(sugg >= 0) {
                sample.glint.x = sugg;
            }

            bUpdateGraphics = true;

        }
        else if(cKey == 'R') { // up arrow

            int sugg = sample.glint.y - 1;
            if(sugg >= 0) {
                sample.glint.y = sugg;
            }

            bUpdateGraphics = true;

        }
        else if(cKey == 'T') { // down arrow

            int sugg = sample.glint.y + 1;
            if(sugg < 480) {
                sample.glint.y = sugg;
            }

            bUpdateGraphics = true;

        }


    }

}