Example #1
0
        public void Finish(IFeatureCollection collection)
        {
            if (!_timesteps.IsComplete)
            {
                return;
            }

            //drifts and vols...
            _drifts = new double[_timesteps.TimeStepCount];
            _vols   = new double[_timesteps.TimeStepCount];

            var prevSpot = _forwardCurve(0);

            for (var t = 1; t < _drifts.Length; t++)
            {
                var atmVol      = _surface.GetForwardATMVol(0, _timesteps.Times[t]);
                var fxAtmVol    = _adjSurface == null ? 0.0 : _adjSurface.GetForwardATMVol(0, _timesteps.Times[t]);
                var driftAdj    = _adjSurface == null ? 1.0 : Exp(atmVol * fxAtmVol * _timesteps.Times[t] * _correlation);
                var spot        = _forwardCurve(_timesteps.Times[t]) * driftAdj;
                var varStart    = Pow(_surface.GetForwardATMVol(0, _timesteps.Times[t - 1]), 2) * _timesteps.Times[t - 1];
                var varEnd      = Pow(atmVol, 2) * _timesteps.Times[t];
                var fwdVariance = Max(0, varEnd - varStart);
                _vols[t]   = Sqrt(fwdVariance / _timesteps.TimeSteps[t]);
                _drifts[t] = Log(spot / prevSpot) / _timesteps.TimeSteps[t];

                prevSpot = spot;
            }
            _isComplete = true;
        }
Example #2
0
        public void Finish(FeatureCollection collection)
        {
            if (!_timesteps.IsComplete)
            {
                return;
            }

            //drifts and vols...
            _drifts = new double[_timesteps.TimeStepCount];
            _vols   = new double[_timesteps.TimeStepCount];

            var prevSpot = _forwardCurve(0);

            for (var t = 1; t < _drifts.Length; t++)
            {
                var spot        = _forwardCurve(_timesteps.Times[t]);
                var varStart    = System.Math.Pow(_surface.GetForwardATMVol(0, _timesteps.Times[t - 1]), 2) * _timesteps.Times[t - 1];
                var varEnd      = System.Math.Pow(_surface.GetForwardATMVol(0, _timesteps.Times[t]), 2) * _timesteps.Times[t];
                var fwdVariance = (varEnd - varStart);
                _vols[t]   = System.Math.Sqrt(fwdVariance / _timesteps.TimeSteps[t]);
                _drifts[t] = System.Math.Log(spot / prevSpot) / _timesteps.TimeSteps[t];

                prevSpot = spot;
            }
            _isComplete = true;
        }
Example #3
0
        public void Finish(IFeatureCollection collection)
        {
            if (!_timesteps.IsComplete)
            {
                return;
            }

            //drifts and vols...
            _drifts    = new Vector <double> [_timesteps.TimeStepCount];
            _lvInterps = new IInterpolator1D[_timesteps.TimeStepCount - 1];

            var strikes = new double[_timesteps.TimeStepCount][];
            var atmVols = new double[_timesteps.TimeStepCount];

            for (var t = 0; t < strikes.Length; t++)
            {
                var fwd = _forwardCurve(_timesteps.Times[t]);
                atmVols[t] = _surface.GetVolForDeltaStrike(0.5, _timesteps.Times[t], fwd);

                if (_timesteps.Times[t] == 0)
                {
                    strikes[t] = new double[] { fwd };
                    continue;
                }
                else
                {
                    var nStrikes   = 200;
                    var strikeStep = 1.0 / nStrikes;
                    strikes[t] = new double[nStrikes];
                    for (var k = 0; k < strikes[t].Length; k++)
                    {
                        var deltaK = -(strikeStep + strikeStep * k);
                        strikes[t][k] = Options.BlackFunctions.AbsoluteStrikefromDeltaKAnalytic(fwd, deltaK, 0, _timesteps.Times[t], atmVols[t]);
                    }
                }
            }

            var lvSurface = Options.LocalVol.ComputeLocalVarianceOnGridFromCalls(_surface, strikes, _timesteps.Times, _forwardCurve);

            for (var t = 0; t < _lvInterps.Length; t++)
            {
                _lvInterps[t] = InterpolatorFactory.GetInterpolator(strikes[t], lvSurface[t], t == 0 ? Interpolator1DType.DummyPoint : Interpolator1DType.LinearFlatExtrap);
            }

            var prevSpot = _forwardCurve(0);

            for (var t = 1; t < _drifts.Length; t++)
            {
                var fxAtmVol = _adjSurface == null ? 0.0 : _adjSurface.GetForwardATMVol(0, _timesteps.Times[t]);
                var driftAdj = _adjSurface == null ? 1.0 : Exp(atmVols[t] * fxAtmVol * _timesteps.Times[t] * _correlation);
                var spot     = _forwardCurve(_timesteps.Times[t]) * driftAdj;

                _drifts[t] = new Vector <double>(Log(spot / prevSpot) / _timesteps.TimeSteps[t]);

                prevSpot = spot;
            }
            _isComplete = true;
        }
Example #4
0
        public void Finish(IFeatureCollection collection)
        {
            if (!_timesteps.IsComplete)
            {
                return;
            }

            //drifts and vols...
            _drifts     = new double[_timesteps.TimeStepCount];
            _vols       = new double[_timesteps.TimeStepCount];
            _spotDrifts = new double[_timesteps.TimeStepCount];
            _spotVols   = new double[_timesteps.TimeStepCount];
            _invCdfs    = new IInterpolator1D[_timesteps.TimeStepCount];

            _spot0 = _forwardCurve(0);
            var prevSpot = _spot0;

            for (var t = 1; t < _drifts.Length; t++)
            {
                var atmVol      = _surface.GetForwardATMVol(0, _timesteps.Times[t]);
                var fxAtmVol    = _adjSurface == null ? 0.0 : _adjSurface.GetForwardATMVol(0, _timesteps.Times[t]);
                var driftAdj    = _adjSurface == null ? 1.0 : Exp(atmVol * fxAtmVol * _timesteps.Times[t] * _correlation);
                var spot        = _forwardCurve(_timesteps.Times[t]) * driftAdj;
                var varStart    = Pow(_surface.GetForwardATMVol(0, _timesteps.Times[t - 1]), 2) * _timesteps.Times[t - 1];
                var varEnd      = Pow(atmVol, 2) * _timesteps.Times[t];
                var fwdVariance = Max(0, varEnd - varStart);
                _vols[t]    = Sqrt(fwdVariance / _timesteps.TimeSteps[t]);
                _drifts[t]  = Log(spot / prevSpot) / _timesteps.TimeSteps[t];
                _invCdfs[t] = _surface.GenerateCDF2(500, _timesteps.Dates[t], spot, true, driftAdj);

                _spotVols[t]   = atmVol;
                _spotDrifts[t] = Log(spot / _spot0) / _timesteps.Times[t];

                prevSpot = spot;
            }

            _spotTimesSqrt = _timesteps.Times.Select(x => Sqrt(x)).ToArray();

            _isComplete = true;
        }
        public void Finish(IFeatureCollection collection)
        {
            if (!_timesteps.IsComplete)
            {
                return;
            }

            _fwds = new double[_timesteps.TimeStepCount];

            for (var t = 0; t < _fwds.Length; t++)
            {
                var atmVol   = _surface.GetForwardATMVol(0, _timesteps.Times[t]);
                var fxAtmVol = _adjSurface == null ? 0.0 : _adjSurface.GetForwardATMVol(0, _timesteps.Times[t]);
                var driftAdj = _adjSurface == null ? 1.0 : Exp(atmVol * fxAtmVol * _timesteps.Times[t] * _correlation);
                var spot     = _forwardCurve(_timesteps.Times[t]) * driftAdj;
                _fwds[t] = spot;
            }
            _isComplete = true;
        }