QLNet.LmLinearExponentialVolatilityModel.volatility C# (CSharp) Method

volatility() public method

public volatility ( double t ) : Vector
t double
return Vector
        public override Vector volatility(double t)
        {
            return volatility(t, null);
        }

Same methods

LmLinearExponentialVolatilityModel::volatility ( double t, Vector x ) : Vector
LmLinearExponentialVolatilityModel::volatility ( int i, double t ) : double
LmLinearExponentialVolatilityModel::volatility ( int i, double t, Vector x ) : double

Usage Example

Example #1
0
        public void testSimpleCovarianceModels()
        {
            //"Testing simple covariance models...";

            //SavedSettings backup;

            const int size = 10;
            const double tolerance = 1e-14;
            int i;

            LmCorrelationModel corrModel=new LmExponentialCorrelationModel(size, 0.1);

            Matrix recon = corrModel.correlation(0.0,null)
                - corrModel.pseudoSqrt(0.0,null)*Matrix.transpose(corrModel.pseudoSqrt(0.0,null));

            for (i=0; i<size; ++i) {
                for (int j=0; j<size; ++j) {
                    if (Math.Abs(recon[i,j]) > tolerance)
                        Assert.Fail("Failed to reproduce correlation matrix"
                                    + "\n    calculated: " + recon[i,j]
                                    + "\n    expected:   " + 0);
                }
            }

            List<double> fixingTimes=new InitializedList<double>(size);
            for (i=0; i<size; ++i) {
                fixingTimes[i] = 0.5*i;
            }

            const double a=0.2;
            const double b=0.1;
            const double c=2.1;
            const double d=0.3;

            LmVolatilityModel volaModel=new LmLinearExponentialVolatilityModel(fixingTimes, a, b, c, d);

            LfmCovarianceProxy covarProxy=new LfmCovarianceProxy(volaModel, corrModel);

            LiborForwardModelProcess process=new LiborForwardModelProcess(size, makeIndex());

            LiborForwardModel liborModel=new LiborForwardModel(process, volaModel, corrModel);

            for (double t=0; t<4.6; t+=0.31) {
                recon = covarProxy.covariance(t,null)
                    - covarProxy.diffusion(t,null)*Matrix.transpose(covarProxy.diffusion(t,null));

                for (int k=0; k<size; ++k) {
                    for (int j=0; j<size; ++j) {
                        if (Math.Abs(recon[k,j]) > tolerance)
                            Assert.Fail("Failed to reproduce correlation matrix"
                                        + "\n    calculated: " + recon[k,j]
                                        + "\n    expected:   " + 0);
                    }
                }

                Vector volatility = volaModel.volatility(t,null);

                for (int k=0; k<size; ++k) {
                    double expected = 0;
                    if (k>2*t) {
                        double T = fixingTimes[k];
                        expected=(a*(T-t)+d)*Math.Exp(-b*(T-t)) + c;
                    }

                    if (Math.Abs(expected - volatility[k]) > tolerance)
                        Assert.Fail("Failed to reproduce volatities"
                                    + "\n    calculated: " + volatility[k]
                                    + "\n    expected:   " + expected);
                }
            }
        }