Exemple #1
0
        //! Calibrate to a set of market instruments (caps/swaptions)

        /*! An additional constraint can be passed which must be
         *  satisfied in addition to the constraints of the model.
         */
        //public void calibrate(List<CalibrationHelper> instruments, OptimizationMethod method, EndCriteria endCriteria,
        //           Constraint constraint = new Constraint(), List<double> weights = new List<double>()) {
        public void calibrate(List <CalibrationHelper> instruments, OptimizationMethod method, EndCriteria endCriteria,
                              Constraint additionalConstraint, List <double> weights)
        {
            if (!(weights.Count == 0 || weights.Count == instruments.Count))
            {
                throw new ApplicationException("mismatch between number of instruments and weights");
            }

            Constraint c;

            if (additionalConstraint.empty())
            {
                c = constraint_;
            }
            else
            {
                c = new CompositeConstraint(constraint_, additionalConstraint);
            }
            List <double>       w = weights.Count == 0 ? new InitializedList <double>(instruments.Count, 1.0): weights;
            CalibrationFunction f = new CalibrationFunction(this, instruments, w);

            Problem prob = new Problem(f, c, parameters());

            shortRateEndCriteria_ = method.minimize(prob, endCriteria);
            Vector result = new Vector(prob.currentValue());

            setParams(result);
            // recheck
            Vector shortRateProblemValues_ = prob.values(result);

            notifyObservers();
        }
Exemple #2
0
        public double value(Vector p, List <CalibrationHelper> instruments)
        {
            List <double>       w = new InitializedList <double>(instruments.Count, 1.0);
            CalibrationFunction f = new CalibrationFunction(this, instruments, w);

            return(f.value(p));
        }
        public ProcessData()
        {
            InitializeComponent();


            this.cbMacro.Items.Add("Default");
            this.cbMacro.SelectedIndex = 0;
            this.cbCalFunctions.Items.Add("None");
            this.cbCalFunctions.Items.Add("S. cerevisiae");
            this.cbCalFunctions.Items.Add("S. pombe");
            this.cbCalFunctions.Items.Add("C. albicans");
            this.cbCalFunctions.Items.Add("P. pastoris");
            this.cbCalFunctions.Items.Add("E. coli");
            this.cbCalFunctions.Items.Add("Custom");
            this.cbCalFunctions.SelectedIndex = 1;
            this.txBlank.Text          = "0";
            BlankValue                 = 0;
            txtCoeffA.Text             = "1";
            txtCoeffB.Text             = "0";
            txtCoeffC.Text             = "0.8324057";
            TrueODCalibarationFunction = new CalibrationFunction();
            TrueODCalibarationFunction.AddTerm(0, 1);
            TrueODCalibarationFunction.AddTerm(1, 0);
            TrueODCalibarationFunction.AddTerm(2, (float)0.8324057);
        }
Exemple #4
0
        public double value(Vector parameters, List <CalibrationHelper> instruments)
        {
            List <double>       w = new InitializedList <double>(instruments.Count, 1.0);
            Projection          p = new Projection(parameters);
            CalibrationFunction f = new CalibrationFunction(this, instruments, w, p);

            return(f.value(parameters));
        }
Exemple #5
0
        //! Calibrate to a set of market instruments (caps/swaptions)

        /*! An additional constraint can be passed which must be
         *  satisfied in addition to the constraints of the model.
         */
        //public void calibrate(List<CalibrationHelper> instruments, OptimizationMethod method, EndCriteria endCriteria,
        //           Constraint constraint = new Constraint(), List<double> weights = new List<double>()) {
        public void calibrate(List <CalibrationHelper> instruments,
                              OptimizationMethod method,
                              EndCriteria endCriteria,
                              Constraint additionalConstraint = null,
                              List <double> weights           = null,
                              List <bool> fixParameters       = null)
        {
            if (weights == null)
            {
                weights = new List <double>();
            }
            if (additionalConstraint == null)
            {
                additionalConstraint = new Constraint();
            }
            Utils.QL_REQUIRE(weights.empty() || weights.Count == instruments.Count, () =>
                             "mismatch between number of instruments (" +
                             instruments.Count + ") and weights(" +
                             weights.Count + ")");

            Constraint c;

            if (additionalConstraint.empty())
            {
                c = constraint_;
            }
            else
            {
                c = new CompositeConstraint(constraint_, additionalConstraint);
            }
            List <double> w = weights.Count == 0 ? new InitializedList <double>(instruments.Count, 1.0): weights;

            Vector              prms = parameters();
            List <bool>         all  = new InitializedList <bool>(prms.size(), false);
            Projection          proj = new Projection(prms, fixParameters ?? all);
            CalibrationFunction f    = new CalibrationFunction(this, instruments, w, proj);
            ProjectedConstraint pc   = new ProjectedConstraint(c, proj);
            Problem             prob = new Problem(f, pc, proj.project(prms));

            shortRateEndCriteria_ = method.minimize(prob, endCriteria);
            Vector result = new Vector(prob.currentValue());

            setParams(proj.include(result));
            Vector shortRateProblemValues_ = prob.values(result);

            notifyObservers();

            //CalibrationFunction f = new CalibrationFunction(this, instruments, w);

            //Problem prob = new Problem(f, c, parameters());
            //shortRateEndCriteria_ = method.minimize(prob, endCriteria);
            //Vector result = new Vector(prob.currentValue());
            //setParams(result);
            //// recheck
            //Vector shortRateProblemValues_ = prob.values(result);

            //notifyObservers();
        }
Exemple #6
0
        private static CalibrationFunction SetCalibrationFunction(float calibrationCoefA, float calibrationCoefB, float calibrationCoefC)
        {
            var trueODCalibartionFunction = new CalibrationFunction();

            trueODCalibartionFunction.AddTerm(0, calibrationCoefA);
            trueODCalibartionFunction.AddTerm(1, calibrationCoefB);
            trueODCalibartionFunction.AddTerm(2, calibrationCoefC);
            return(trueODCalibartionFunction);
        }
Exemple #7
0
 public double value(Vector p, List<CalibrationHelper> instruments)
 {
     List<double> w = new InitializedList<double>(instruments.Count, 1.0);
     CalibrationFunction f = new CalibrationFunction(this, instruments, w);
     return f.value(p);
 }
Exemple #8
0
        //! Calibrate to a set of market instruments (caps/swaptions)
        /*! An additional constraint can be passed which must be
            satisfied in addition to the constraints of the model.
        */
        //public void calibrate(List<CalibrationHelper> instruments, OptimizationMethod method, EndCriteria endCriteria,
        //           Constraint constraint = new Constraint(), List<double> weights = new List<double>()) {
        public void calibrate(List<CalibrationHelper> instruments, OptimizationMethod method, EndCriteria endCriteria,
            Constraint additionalConstraint, List<double> weights)
        {
            if (!(weights.Count == 0 || weights.Count == instruments.Count))
                throw new ApplicationException("mismatch between number of instruments and weights");

            Constraint c;
            if (additionalConstraint.empty())
                c = constraint_;
            else
                c = new CompositeConstraint(constraint_,additionalConstraint);
            List<double> w = weights.Count == 0 ? new InitializedList<double>(instruments.Count, 1.0): weights;
            CalibrationFunction f = new CalibrationFunction(this, instruments, w);

            Problem prob = new Problem(f, c, parameters());
            shortRateEndCriteria_ = method.minimize(prob, endCriteria);
            Vector result = new Vector(prob.currentValue());
            setParams(result);
            // recheck
            Vector shortRateProblemValues_ = prob.values(result);

            notifyObservers();
        }
        private void SetCalibrationFunction()
        {
            Single coeffA;
            Single coeffB;
            Single coeffC;

            if (cbCalFunctions.SelectedIndex != 6)
            {
                TrueODCalibarationFunction = new CalibrationFunction();
                var x = cbCalFunctions.SelectedIndex;
                switch (x)
                {
                case 0:
                    //None
                    TrueODCalibarationFunction.AddTerm(0, 1);
                    TrueODCalibarationFunction.AddTerm(1, 0);
                    TrueODCalibarationFunction.AddTerm(2, 0);
                    break;

                case 1:
                    //S. cerevisiae
                    TrueODCalibarationFunction.AddTerm(0, 1);
                    TrueODCalibarationFunction.AddTerm(1, 0);
                    TrueODCalibarationFunction.AddTerm(2, (float)0.8324057);
                    break;

                case 2:
                    //S. pombe
                    TrueODCalibarationFunction.AddTerm(0, 1);
                    TrueODCalibarationFunction.AddTerm(1, 0);
                    TrueODCalibarationFunction.AddTerm(2, (float)0.64672463774234579);
                    break;

                case 3:
                    //C. albicans
                    TrueODCalibarationFunction.AddTerm(0, 1);
                    TrueODCalibarationFunction.AddTerm(1, 0);
                    TrueODCalibarationFunction.AddTerm(2, (float)0.5790256635480614);
                    break;

                case 4:
                    //P. pastoris
                    TrueODCalibarationFunction.AddTerm(0, 1);
                    TrueODCalibarationFunction.AddTerm(1, 0);
                    TrueODCalibarationFunction.AddTerm(2, (float)0.5653284345804932);
                    break;

                case 5:
                    //E.coli
                    TrueODCalibarationFunction.AddTerm(0, 1);
                    TrueODCalibarationFunction.AddTerm(1, 0);
                    TrueODCalibarationFunction.AddTerm(2, (float)0.75389848795692815);
                    break;
                }
            }
            else
            {
                var isCoeefAValid = ValidateTextBoxEntry(txtCoeffA, out coeffA);
                var isCoeefBValid = ValidateTextBoxEntry(txtCoeffB, out coeffB);
                var isCoeefCValid = ValidateTextBoxEntry(txtCoeffC, out coeffC);

                if (!isCoeefAValid || !isCoeefBValid || !isCoeefCValid)
                {
                    return;
                }

                TrueODCalibarationFunction = new CalibrationFunction();
                TrueODCalibarationFunction.AddTerm(0, coeffA);
                TrueODCalibarationFunction.AddTerm(1, coeffB);
                TrueODCalibarationFunction.AddTerm(2, coeffC);
            }
        }
Exemple #10
0
 public CalibrationFunctionOption(CalibrationFunction func)
 {
     TF = func;
 }
Exemple #11
0
        private static void SetThinRawData(bool apply, ref Culture culture, float blankValue, CalibrationFunction trueODCalibartionFunction, int pointsToSkip = 0)
        {
            if (!apply)
            {
                return;
            }
            AddRawThinned(ref culture, pointsToSkip, false, trueODCalibartionFunction);
            var thinRaw          = culture.GrowthMeasurements.GetMeasurements(DataType.RawThinned);
            var processesThinned = Modules.ProccessedDatapoints(thinRaw, blankValue, trueODCalibartionFunction);

            culture.GrowthMeasurements.SetMeasurements(processesThinned, DataType.ProcessedThinned);
        }
Exemple #12
0
        private static List <GrowthMeasurement> NNSmoothProcessedData(bool apply, List <GrowthMeasurement> raw, List <GrowthMeasurement> smooth, float blankValue, CalibrationFunction trueODCalibartionFunction, int count, float maxPeak)
        {
            if (!apply)
            {
                return(smooth);
            }
            var neuroD    = new Neural();
            var fittedRaw = neuroD.GetFittedData(raw);

            return(Modules.ProccessedDatapoints(fittedRaw, blankValue, trueODCalibartionFunction, out count, out maxPeak, true));
        }
Exemple #13
0
        private static void ProcessData(Culture culture, float blankValue, bool doFit, CalibrationFunction trueODCalibartionFunction, bool skipMonotonicFilter = false)
        {
            var raw = culture.GrowthMeasurements.GetMeasurements(DataType.Raw);

            var   count   = 0;
            float maxPeak = 0;
            var   treated = Modules.ProccessedDatapoints(raw, blankValue, trueODCalibartionFunction, out count, out maxPeak, false, false, skipMonotonicFilter);

            treated = NNSmoothProcessedData(false, raw, treated, blankValue, trueODCalibartionFunction, count, maxPeak);

            SetRawFilteredData(false, raw, ref culture);
            SetRawUnFilteredData(false, raw, ref culture, blankValue);

            var uncalibrated = Modules.ProccessedDatapoints(raw, blankValue, trueODCalibartionFunction, out count, out maxPeak, false, true);

            culture.GrowthMeasurements.SetMeasurements(uncalibrated, DataType.ProcessedUncalibrated);

            if (count > 0)
            {
                SessionVariables.Peaks.Add(new Peak {
                    Well = culture.Container, MaxPeak = maxPeak, Number = count
                });
            }

            culture.GrowthMeasurements.SetMeasurements(treated, DataType.Processed);

            var firstDeriv = Modules.CalculateFirstDerivative(treated, FirstDerivWindow);

            culture.GrowthMeasurements.SetMeasurements(firstDeriv, DataType.FirstDerivative);
            SetNNSmoothFirstDeriv(false, firstDeriv, ref culture);

            culture.GrowthMeasurements.SetMeasurements(Modules.ConvertBioScreenTimeToHrs(raw), DataType.Raw);

            if (doFit)
            {
                SetNNSmoothProcessed(culture, treated);
            }
        }
Exemple #14
0
        public static void AddRawThinned(ref Culture culture, int skip = 0, bool isFirstDeriv = false, CalibrationFunction calibrationFunction = null)
        {
            var raw     = culture.GrowthMeasurements.GetMeasurements(DataType.Raw);
            var thinRaw = new List <GrowthMeasurement>();

            for (int i = 0; i < raw.Count; i += skip + 1)
            {
                var measurement = raw[i];
                thinRaw.Add(measurement);
            }
            culture.GrowthMeasurements.SetMeasurements(thinRaw, DataType.RawThinned);
            var processesThinned = Modules.ReProccessedDatapoints(thinRaw, BlankValue, calibrationFunction);

            if (isFirstDeriv)
            {
                var firstDeriv = Modules.CalculateFirstDerivative(processesThinned, FirstDerivWindow);
                culture.GrowthMeasurements.SetMeasurements(firstDeriv, DataType.FirstDerivative);
            }
            culture.GrowthMeasurements.SetMeasurements(processesThinned, DataType.ProcessedThinned);

            if (Modules.NoGrowth(processesThinned))
            {
                return;
            }
            var metaDataThinned = new GrowthVariableMetaData();
            var macroLagData    = Modules.GetLag(processesThinned);

            metaDataThinned.Lag = macroLagData.InterceptStretchs;
            var macroYieldData = Modules.GetYield(processesThinned);

            metaDataThinned.Yield = macroYieldData.YieldAnchors;
            var macroRateData = Modules.GetGT(processesThinned);

            metaDataThinned.Rate = macroRateData.RateSlopeAnchors;
            culture.GrowthMeasurements.SetMetaData(DataType.ProcessedThinned, metaDataThinned);
        }