コード例 #1
0
        private void StartCalibration()
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-US");
            ss.K = Double.Parse(this.labelk.Text, NumberStyles.AllowDecimalPoint | NumberStyles.Float);
            ss.Lambda_X = Double.Parse(this.labellambdax.Text, NumberStyles.AllowDecimalPoint | NumberStyles.Float);
            ss.Sigma_x = Double.Parse(this.labelsigma_x.Text, NumberStyles.AllowDecimalPoint | NumberStyles.Float);
            ss.Mu_e = Double.Parse(this.labelmu_e.Text, NumberStyles.AllowDecimalPoint | NumberStyles.Float);
            ss.Sigma_e = Double.Parse(this.labelsigma_e.Text, NumberStyles.AllowDecimalPoint | NumberStyles.Float);
            ss.Lambda_e = Double.Parse(this.labellambdae.Text, NumberStyles.AllowDecimalPoint | NumberStyles.Float);
            ss.P_xe = Double.Parse(this.labelpxe.Text, NumberStyles.AllowDecimalPoint | NumberStyles.Float);
            ss.e0 = Double.Parse(this.labele0.Text, NumberStyles.AllowDecimalPoint | NumberStyles.Float);
            ss.x0 = Double.Parse(this.labelx0.Text, NumberStyles.AllowDecimalPoint | NumberStyles.Float);
            ss.MaxIter = Int32.Parse(this.labelMaxIter.Text);
            try
            {
            MWNumericArray maxitera = new MWNumericArray(ss.MaxIter);
            MWNumericArray e0a = new MWNumericArray(ss.e0);
            MWNumericArray x0a = new MWNumericArray(ss.x0);
            MWNumericArray maturity = new MWNumericArray(maturities.ToArray());
            MWNumericArray futures = new MWNumericArray(pcount, lcount - 1, futureList.ToArray());
            MWNumericArray k = new MWNumericArray(ss.K);
            MWNumericArray lambdax = new MWNumericArray(ss.Lambda_X);
            MWNumericArray lambdae = new MWNumericArray(ss.Lambda_e);
            MWNumericArray sigmax = new MWNumericArray(ss.Sigma_x);
            MWNumericArray sigmae = new MWNumericArray(ss.Sigma_e);
            MWNumericArray p_xe = new MWNumericArray(ss.P_xe);
            MWNumericArray mu_e = new MWNumericArray(ss.Mu_e);
            Schwartz.Schwartz s = null;

                 s = new Schwartz.Schwartz();

            MWArray[] Results;
            try
            {
                /** Call matlab */
                Results = (MWArray[])s.SchwartzAndSmith(12,maxitera, x0a, e0a, maturity, futures, k, mu_e, sigmax, sigmae, p_xe, lambdae, lambdax);
            }
            catch
            {
                MessageBox.Show("Calibration aborted!");
                return;
            }

            /** Spot vector */
            double[,] ret = (double[,])Results[0].ToArray();
            this.generatedSpot = new double[ret.Length];
            for (int i = 0; i < ret.Length; i++)
                this.generatedSpot[i] = ret[0, i];

            ss.K = (double)((MWNumericArray)Results[1]).ToVector(MWArrayComponent.Real).GetValue(0);
            ss.Mu_e = (double)((MWNumericArray)Results[2]).ToVector(MWArrayComponent.Real).GetValue(0);
            ss.Sigma_x = (double)((MWNumericArray)Results[3]).ToVector(MWArrayComponent.Real).GetValue(0);
            ss.Sigma_e = (double)((MWNumericArray)Results[4]).ToVector(MWArrayComponent.Real).GetValue(0);
            ss.P_xe = (double)((MWNumericArray)Results[5]).ToVector(MWArrayComponent.Real).GetValue(0);
            ss.Lambda_e = (double)((MWNumericArray)Results[6]).ToVector(MWArrayComponent.Real).GetValue(0);
            ss.Lambda_X = (double)((MWNumericArray)Results[7]).ToVector(MWArrayComponent.Real).GetValue(0);
            ss.x0 = (double)((MWNumericArray)Results[8]).ToVector(MWArrayComponent.Real).GetValue(0);
            ss.e0 = (double)((MWNumericArray)Results[9]).ToVector(MWArrayComponent.Real).GetValue(0);
            likelihood = (double)((MWNumericArray)Results[10]).ToVector(MWArrayComponent.Real).GetValue(0);
            nbiter = (int)((double)((MWNumericArray)Results[11]).ToVector(MWArrayComponent.Real).GetValue(0));
            }
            catch (Exception)
            {
                MessageBox.Show("It seems your computer does not have a working copy of the Matlab Compiler Runtime\n Calibration cannot be done without, but you can still use the rest of the program.");
                this.Invoke(new CalibrationDoneCallback(CalibrationDone), this);
                return;

            }
            this.Invoke(new CalibrationDoneCallback(CalibrationDone), this);
        }
コード例 #2
0
        private void StartCalibration()
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-US");
            ss.K        = Double.Parse(this.labelk.Text, NumberStyles.AllowDecimalPoint | NumberStyles.Float);
            ss.Lambda_X = Double.Parse(this.labellambdax.Text, NumberStyles.AllowDecimalPoint | NumberStyles.Float);
            ss.Sigma_x  = Double.Parse(this.labelsigma_x.Text, NumberStyles.AllowDecimalPoint | NumberStyles.Float);
            ss.Mu_e     = Double.Parse(this.labelmu_e.Text, NumberStyles.AllowDecimalPoint | NumberStyles.Float);
            ss.Sigma_e  = Double.Parse(this.labelsigma_e.Text, NumberStyles.AllowDecimalPoint | NumberStyles.Float);
            ss.Lambda_e = Double.Parse(this.labellambdae.Text, NumberStyles.AllowDecimalPoint | NumberStyles.Float);
            ss.P_xe     = Double.Parse(this.labelpxe.Text, NumberStyles.AllowDecimalPoint | NumberStyles.Float);
            ss.e0       = Double.Parse(this.labele0.Text, NumberStyles.AllowDecimalPoint | NumberStyles.Float);
            ss.x0       = Double.Parse(this.labelx0.Text, NumberStyles.AllowDecimalPoint | NumberStyles.Float);
            ss.MaxIter  = Int32.Parse(this.labelMaxIter.Text);
            try
            {
                MWNumericArray    maxitera = new MWNumericArray(ss.MaxIter);
                MWNumericArray    e0a      = new MWNumericArray(ss.e0);
                MWNumericArray    x0a      = new MWNumericArray(ss.x0);
                MWNumericArray    maturity = new MWNumericArray(maturities.ToArray());
                MWNumericArray    futures  = new MWNumericArray(pcount, lcount - 1, futureList.ToArray());
                MWNumericArray    k        = new MWNumericArray(ss.K);
                MWNumericArray    lambdax  = new MWNumericArray(ss.Lambda_X);
                MWNumericArray    lambdae  = new MWNumericArray(ss.Lambda_e);
                MWNumericArray    sigmax   = new MWNumericArray(ss.Sigma_x);
                MWNumericArray    sigmae   = new MWNumericArray(ss.Sigma_e);
                MWNumericArray    p_xe     = new MWNumericArray(ss.P_xe);
                MWNumericArray    mu_e     = new MWNumericArray(ss.Mu_e);
                Schwartz.Schwartz s        = null;

                s = new Schwartz.Schwartz();

                MWArray[] Results;
                try
                {
                    /** Call matlab */
                    Results = (MWArray[])s.SchwartzAndSmith(12, maxitera, x0a, e0a, maturity, futures, k, mu_e, sigmax, sigmae, p_xe, lambdae, lambdax);
                }
                catch
                {
                    MessageBox.Show("Calibration aborted!");
                    return;
                }

                /** Spot vector */
                double[,] ret      = (double[, ])Results[0].ToArray();
                this.generatedSpot = new double[ret.Length];
                for (int i = 0; i < ret.Length; i++)
                {
                    this.generatedSpot[i] = ret[0, i];
                }


                ss.K        = (double)((MWNumericArray)Results[1]).ToVector(MWArrayComponent.Real).GetValue(0);
                ss.Mu_e     = (double)((MWNumericArray)Results[2]).ToVector(MWArrayComponent.Real).GetValue(0);
                ss.Sigma_x  = (double)((MWNumericArray)Results[3]).ToVector(MWArrayComponent.Real).GetValue(0);
                ss.Sigma_e  = (double)((MWNumericArray)Results[4]).ToVector(MWArrayComponent.Real).GetValue(0);
                ss.P_xe     = (double)((MWNumericArray)Results[5]).ToVector(MWArrayComponent.Real).GetValue(0);
                ss.Lambda_e = (double)((MWNumericArray)Results[6]).ToVector(MWArrayComponent.Real).GetValue(0);
                ss.Lambda_X = (double)((MWNumericArray)Results[7]).ToVector(MWArrayComponent.Real).GetValue(0);
                ss.x0       = (double)((MWNumericArray)Results[8]).ToVector(MWArrayComponent.Real).GetValue(0);
                ss.e0       = (double)((MWNumericArray)Results[9]).ToVector(MWArrayComponent.Real).GetValue(0);
                likelihood  = (double)((MWNumericArray)Results[10]).ToVector(MWArrayComponent.Real).GetValue(0);
                nbiter      = (int)((double)((MWNumericArray)Results[11]).ToVector(MWArrayComponent.Real).GetValue(0));
            }
            catch (Exception)
            {
                MessageBox.Show("It seems your computer does not have a working copy of the Matlab Compiler Runtime\n Calibration cannot be done without, but you can still use the rest of the program.");
                this.Invoke(new CalibrationDoneCallback(CalibrationDone), this);
                return;
            }
            this.Invoke(new CalibrationDoneCallback(CalibrationDone), this);
        }