Exemplo n.º 1
0
 public static double GetSurvivalProb(
     [QuantSAExcelArgument(Description = "The hazard rate curve or other source of default probabilities.")]
     SurvivalProbabilitySource survivalProbabilitySource,
     [QuantSAExcelArgument(Description =
                               "If date2 is omitted the date until which survival is calculated.  If date2 is provided the date from which survival is calculated.")]
     Date date1,
     [QuantSAExcelArgument(
          Description =
              "Optional: If provided then the survival probability is calculated from date1 until date2.",
          Default = null)]
     Date date2)
 {
     return(date2 == null
         ? survivalProbabilitySource.GetSP(date1)
         : survivalProbabilitySource.GetSP(date1, date2));
 }
        /// <summary>
        /// Run a simulation and store the results for later use by <see cref="GetIndices(MarketObservable, List{Date})"/>
        /// </summary>
        /// <param name="simNumber"></param>
        public override void RunSimulation(int simNumber)
        {
            _simulation = new Dictionary <int, double>();
            var    spot     = _fxSource.GetRate(_anchorDate);
            var    simRate  = spot;
            var    oldFxFwd = spot;
            double newFXfwd;


            var hazEst = _survivalProbSource.GetSP(_survivalProbSource.GetAnchorDate().AddTenor(Tenor.FromYears(1)));

            hazEst = -Math.Log(hazEst);
            // Simulate the default
            var tau = _uniform.Generate();

            tau             = Math.Log(tau) / -hazEst;
            _simDefaultTime = _anchorDate.value + tau * 365;

            for (var timeCounter = 0; timeCounter < _allRequiredDates.Count; timeCounter++)
            {
                double dt = timeCounter > 0
                    ? _allRequiredDates[timeCounter] - _allRequiredDates[timeCounter - 1]
                    : _allRequiredDates[timeCounter] - _anchorDate.value;
                newFXfwd = _fxSource.GetRate(new Date(_anchorDate.value + dt));

                dt = dt / 365.0;
                var sdt = Math.Sqrt(dt);
                var dW  = _normal.Generate();
                // TODO: drift needs to be adjusted for default rate * jump size
                simRate = simRate * newFXfwd / oldFxFwd * Math.Exp(-0.5 * _fxVol * _fxVol * dt + _fxVol * sdt * dW);
                if (_simDefaultTime < _allRequiredDates[timeCounter])
                {
                    _simulation[_allRequiredDates[timeCounter]] = simRate * (1 + _relJumpSizeInDefault);
                }
                else
                {
                    _simulation[_allRequiredDates[timeCounter]] = simRate;
                }
            }
        }