コード例 #1
0
      public override void fetchResults(IPricingEngineResults r)
      {
         // copy from VanillaSwap
         // works because similarly simple instrument
         // that we always expect to be priced with a swap engine

         base.fetchResults(r);

         YearOnYearInflationSwap.Results results = r as YearOnYearInflationSwap.Results;
         if (results != null)
         {
            // might be a swap engine, so no error is thrown
            fairRate_ = results.fairRate;
            fairSpread_ = results.fairSpread;
         }
         else
         {
            fairRate_ = null;
            fairSpread_ = null;
         }

         if (fairRate_ == null)
         {
            // calculate it from other results
            if (legBPS_[0] != null)
               fairRate_ = fixedRate_ - NPV_ / (legBPS_[0] / Const.BASIS_POINT);
         }
         if (fairSpread_ == null)
         {
            // ditto
            if (legBPS_[1] != null)
               fairSpread_ = spread_ - NPV_ / (legBPS_[1] / Const.BASIS_POINT);
         }

      }
コード例 #2
0
ファイル: Loan.cs プロジェクト: jmptrader/QLNet-1
        public override void fetchResults(IPricingEngineResults r)
        {
            base.fetchResults(r);

            LoanPricingEngineResults results = r as LoanPricingEngineResults;

            if (results == null)
            {
                throw new ArgumentException("wrong result type");
            }

            if (results.legNPV.Count != 0)
            {
                if (results.legNPV.Count != legNPV_.Count)
                {
                    throw new ArgumentException("wrong number of leg NPV returned");
                }

                legNPV_ = results.legNPV;
            }
            else
            {
                legNPV_ = new InitializedList <double?>(legNPV_.Count);
            }
        }
コード例 #3
0
ファイル: VanillaSwap.cs プロジェクト: ykim-otcfin/QLNet
        public override void fetchResults(IPricingEngineResults r)
        {
            base.fetchResults(r);
            VanillaSwap.Results results = r as VanillaSwap.Results;

            if (results != null)
            {
                // might be a swap engine, so no error is thrown
                fairRate_   = results.fairRate;
                fairSpread_ = results.fairSpread;
            }
            else
            {
                fairRate_   = null;
                fairSpread_ = null;
            }

            if (fairRate_ == null)
            {
                // calculate it from other results
                if (legBPS_[0] != null)
                {
                    fairRate_ = fixedRate_ - NPV_.GetValueOrDefault() / (legBPS_[0] / Const.BASIS_POINT);
                }
            }
            if (fairSpread_ == null)
            {
                // ditto
                if (legBPS_[1] != null)
                {
                    fairSpread_ = spread_ - NPV_.GetValueOrDefault() / (legBPS_[1] / Const.BASIS_POINT);
                }
            }
        }
コード例 #4
0
ファイル: BasisSwap.cs プロジェクト: zhangz/QLNet
        public override void fetchResults(IPricingEngineResults r)
        {
            const double basisPoint = 1.0e-4;

            base.fetchResults(r);
            BasisSwap.Results results = r as BasisSwap.Results;

            if (results != null)
            {
                fairLongSpread_  = results.fairLongSpread;
                fairShortSpread_ = results.fairShortSpread;
            }
            else
            {
                fairLongSpread_  = null;
                fairShortSpread_ = null;
            }

            // Long fair spread should be fine - no averaging or compounding
            if (fairLongSpread_ == null && legBPS_[longNo_] != null)
            {
                fairLongSpread_ = longSpread_ - NPV_ / (legBPS_[longNo_] / basisPoint);
            }

            /* Short fair spread calculation ok if no averaging/compounding OR
            *  if there is averaging/compounding and the spread is added after */
            if (fairShortSpread_ == null && legBPS_[shortNo_] != null)
            {
                fairShortSpread_ = shortSpread_ - NPV_ / (legBPS_[shortNo_] / basisPoint);
            }
        }
コード例 #5
0
ファイル: Instrument.cs プロジェクト: spolnik/NQuantLib
 /*! When a derived result structure is defined for an instrument,
  * this method should be overridden to read from it.
  * This is mandatory in case a pricing engine is used.  */
 public virtual void fetchResults(IPricingEngineResults r)
 {
     var results = r as Results;
     if (results == null) throw new ArgumentException("no results returned from pricing engine");
     NPV = results.value;
     errorEstimateValue = results.errorEstimate;
     additionalResultsMap = results.additionalResults;
 }
コード例 #6
0
ファイル: Instrument.cs プロジェクト: StreetConnect/QLNet
 /*! When a derived result structure is defined for an instrument,
  * this method should be overridden to read from it.
  * This is mandatory in case a pricing engine is used.  */
 public virtual void fetchResults(IPricingEngineResults r)
 {
     Instrument.Results results = r as Instrument.Results;
     if (results == null) throw new ArgumentException("no results returned from pricing engine");
     NPV_ = results.value;
     CASH_ = results.cash;
     errorEstimate_ = results.errorEstimate;
     additionalResults_ = results.additionalResults;
 }
コード例 #7
0
        public override void fetchResults(IPricingEngineResults r)
        {
            base.fetchResults(r);

            Bond.Results results = r as Bond.Results;
            Utils.QL_REQUIRE(results != null, () => "wrong result type");

            settlementValue_ = results.settlementValue;
        }
コード例 #8
0
        public override void fetchResults(IPricingEngineResults r)
        {
            base.fetchResults(r);

            Swap.Results results = r as Swap.Results;
            Utils.QL_REQUIRE(results != null, () => "wrong result type");

            if (!results.legNPV.empty())
            {
                Utils.QL_REQUIRE(results.legNPV.Count == legNPV_.Count, () => "wrong number of leg NPV returned");
                legNPV_ = new List <double?>(results.legNPV);
            }
            else
            {
                legNPV_ = new InitializedList <double?>(legNPV_.Count);
            }

            if (!results.legBPS.empty())
            {
                Utils.QL_REQUIRE(results.legBPS.Count == legBPS_.Count, () => "wrong number of leg BPS returned");
                legBPS_ = new List <double?>(results.legBPS);
            }
            else
            {
                legBPS_ = new InitializedList <double?>(legBPS_.Count);
            }

            if (!results.startDiscounts.empty())
            {
                Utils.QL_REQUIRE(results.startDiscounts.Count == startDiscounts_.Count, () => "wrong number of leg start discounts returned");
                startDiscounts_ = new List <double?>(results.startDiscounts);
            }
            else
            {
                startDiscounts_ = new InitializedList <double?>(startDiscounts_.Count);
            }

            if (!results.endDiscounts.empty())
            {
                Utils.QL_REQUIRE(results.endDiscounts.Count == endDiscounts_.Count, () => "wrong number of leg end discounts returned");
                endDiscounts_ = new List <double?>(results.endDiscounts);
            }
            else
            {
                endDiscounts_ = new InitializedList <double?>(endDiscounts_.Count);
            }

            if (results.npvDateDiscount != null)
            {
                npvDateDiscount_ = results.npvDateDiscount;
            }
            else
            {
                npvDateDiscount_ = null;
            }
        }
コード例 #9
0
        public override void fetchResults(IPricingEngineResults r)
        {
            base.fetchResults(r);
            CatBond.Results results = r as CatBond.Results;
            Utils.QL_REQUIRE(results != null, () => "wrong result type");

            lossProbability_       = results.lossProbability;
            expectedLoss_          = results.expectedLoss;
            exhaustionProbability_ = results.exhaustionProbability;
        }
コード例 #10
0
ファイル: Instrument.cs プロジェクト: jmptrader/QLNet-1
 /*! When a derived result structure is defined for an instrument,
  * this method should be overridden to read from it.
  * This is mandatory in case a pricing engine is used.  */
 public virtual void fetchResults(IPricingEngineResults r)
 {
     Instrument.Results results = r as Instrument.Results;
     if (results == null)
     {
         throw new ArgumentException("no results returned from pricing engine");
     }
     NPV_               = results.value;
     CASH_              = results.cash;
     errorEstimate_     = results.errorEstimate;
     additionalResults_ = results.additionalResults;
 }
コード例 #11
0
        public override void fetchResults(IPricingEngineResults r)
        {
            base.fetchResults(r);

            Bond.Results results = r as Bond.Results;
            if (results == null)
            {
                throw new ApplicationException("wrong result type");
            }

            settlementValue_ = results.settlementValue;
        }
コード例 #12
0
ファイル: ForwardVanillaOption.cs プロジェクト: zkhvan/QLNet
 public override void fetchResults(IPricingEngineResults r)
 {
     base.fetchResults(r);
     ForwardVanillaOption.Results results = r as ForwardVanillaOption.Results;
     Utils.QL_REQUIRE(results != null, () => "no results returned from pricing engine");
     delta_       = results.delta;
     gamma_       = results.gamma;
     theta_       = results.theta;
     vega_        = results.vega;
     rho_         = results.rho;
     dividendRho_ = results.dividendRho;
 }
コード例 #13
0
        public override void fetchResults(IPricingEngineResults r)
        {
            base.fetchResults(r);
            CreditDefaultSwap.Results results = r as CreditDefaultSwap.Results;
            Utils.QL_REQUIRE(results != null, () => "wrong result type");

            fairSpread_    = results.fairSpread;
            fairUpfront_   = results.fairUpfront;
            couponLegBPS_  = results.couponLegBPS;
            couponLegNPV_  = results.couponLegNPV;
            defaultLegNPV_ = results.defaultLegNPV;
            upfrontNPV_    = results.upfrontNPV;
            upfrontBPS_    = results.upfrontBPS;
        }
コード例 #14
0
        /// <summary>
        ///  Sets the pricing results locally.
        /// </summary>
        public override void fetchResults(IPricingEngineResults r)
        {
            base.fetchResults(r);

            Results results = r as Results;

            if (results == null)
            {
                throw new ApplicationException("No greeks returned from pricing engine");
            }

            delta_ = results.delta;
            gamma_ = results.gamma;
            theta_ = results.theta;
            vega_  = results.vega;
            rho_   = results.rho;
        }
コード例 #15
0
ファイル: AssetSwap.cs プロジェクト: igitur/qlnet
 public override void fetchResults(IPricingEngineResults r)
 {
     base.fetchResults(r);
     AssetSwap.Results results = r as AssetSwap.Results;
     if (results != null)
     {
         fairSpread_          = results.fairSpread;
         fairCleanPrice_      = results.fairCleanPrice;
         fairNonParRepayment_ = results.fairNonParRepayment;
     }
     else
     {
         fairSpread_          = null;
         fairCleanPrice_      = null;
         fairNonParRepayment_ = null;
     }
 }
コード例 #16
0
        public override void fetchResults(IPricingEngineResults r)
        {
            base.fetchResults(r);

            Results results = r as Results;

            if (results == null)
            {
                throw new ApplicationException("no greeks returned from pricing engine");
            }

            /* no check on null values - just copy.
             * this allows:
             * a) to decide in derived options what to do when null
             * results are returned (throw? numerical calculation?)
             * b) to implement slim engines which only calculate the
             * value---of course care must be taken not to call
             * the greeks methods when using these.
             */
            delta_       = results.delta;
            gamma_       = results.gamma;
            theta_       = results.theta;
            vega_        = results.vega;
            rho_         = results.rho;
            dividendRho_ = results.dividendRho;

            // QL_ENSURE(moreResults != 0, "no more greeks returned from pricing engine");

            /* no check on null values - just copy.
             * this allows:
             * a) to decide in derived options what to do when null
             * results are returned (throw? numerical calculation?)
             * b) to implement slim engines which only calculate the
             * value---of course care must be taken not to call
             * the greeks methods when using these.
             */
            deltaForward_       = results.deltaForward;
            elasticity_         = results.elasticity;
            thetaPerDay_        = results.thetaPerDay;
            strikeSensitivity_  = results.strikeSensitivity;
            itmCashProbability_ = results.itmCashProbability;
        }
コード例 #17
0
ファイル: CPISwap.cs プロジェクト: igitur/qlnet
        // other
        public override void fetchResults(IPricingEngineResults r)
        {
            const double basisPoint = 1.0e-4;

            // copy from VanillaSwap
            // works because similarly simple instrument
            // that we always expect to be priced with a swap engine

            base.fetchResults(r);

            CPISwap.Results results = r as CPISwap.Results;

            if (results != null)
            {
                // might be a swap engine, so no error is thrown
                fairRate_   = results.fairRate;
                fairSpread_ = results.fairSpread;
            }
            else
            {
                fairRate_   = null;
                fairSpread_ = null;
            }

            if (fairRate_ == null)
            {
                // calculate it from other results
                if (legBPS_[0] != null)
                {
                    fairRate_ = fixedRate_ - NPV_ / (legBPS_[0] / basisPoint);
                }
            }
            if (fairSpread_ == null)
            {
                // ditto
                if (legBPS_[1] != null)
                {
                    fairSpread_ = spread_ - NPV_ / (legBPS_[1] / basisPoint);
                }
            }
        }
コード例 #18
0
ファイル: Loan.cs プロジェクト: ariesy/QLNet
        public override void fetchResults(IPricingEngineResults r)
        {
            base.fetchResults(r);

            LoanPricingEngineResults results = r as LoanPricingEngineResults;
            if (results == null) throw new ArgumentException("wrong result type");

            if (results.legNPV.Count != 0)
            {
                if (results.legNPV.Count != legNPV_.Count)
                {
                    throw new ArgumentException("wrong number of leg NPV returned");
                }

                legNPV_ = results.legNPV;
            }
            else
            {
                legNPV_ = new InitializedList<double?>(legNPV_.Count);
            }
        }
コード例 #19
0
ファイル: FloatFloatSwap.cs プロジェクト: igitur/qlnet
 public override void fetchResults(IPricingEngineResults res)
 {
     base.fetchResults(res);
 }
コード例 #20
0
 public virtual void calculate(IPricingEngineResults r)
 {
     throw new NotSupportedException();
 }
コード例 #21
0
 public override void fetchResults(IPricingEngineResults r)
 {
     // you don't actually need to do anything else because it is so simple
     base.fetchResults(r);
 }
コード例 #22
0
 public override void calculate(IPricingEngineResults r)
 {
     engine_.calculate(r);
 }
コード例 #23
0
        public override void calculate(IPricingEngineResults r)
        {
            OneAssetOption.Results results = r as OneAssetOption.Results;
            Utils.QL_REQUIRE(results != null, () => "incorrect results type");

            double beginDate, endDate;
            int    dateNumber        = stoppingTimes_.Count;
            bool   lastDateIsResTime = false;
            int    firstIndex        = -1;
            int    lastIndex         = dateNumber - 1;
            bool   firstDateIsZero   = false;
            double firstNonZeroDate  = getResidualTime();

            double dateTolerance = 1e-6;
            int    j;

            if (dateNumber > 0)
            {
                Utils.QL_REQUIRE(getDividendTime(0) >= 0, () => "first date (" + getDividendTime(0) + ") cannot be negative");
                if (getDividendTime(0) < getResidualTime() * dateTolerance)
                {
                    firstDateIsZero = true;
                    firstIndex      = 0;
                    if (dateNumber >= 2)
                    {
                        firstNonZeroDate = getDividendTime(1);
                    }
                }

                if (Math.Abs(getDividendTime(lastIndex) - getResidualTime()) < dateTolerance)
                {
                    lastDateIsResTime = true;
                    lastIndex         = dateNumber - 2;
                }

                if (!firstDateIsZero)
                {
                    firstNonZeroDate = getDividendTime(0);
                }

                if (dateNumber >= 2)
                {
                    for (j = 1; j < dateNumber; j++)
                    {
                        Utils.QL_REQUIRE(getDividendTime(j - 1) < getDividendTime(j), () =>
                                         "dates must be in increasing order: " + getDividendTime(j - 1) +
                                         " is not strictly smaller than " + getDividendTime(j));
                    }
                }
            }

            double dt = getResidualTime() / (timeStepPerPeriod_ * (dateNumber + 1));

            // Ensure that dt is always smaller than the first non-zero date
            if (firstNonZeroDate <= dt)
            {
                dt = firstNonZeroDate / 2.0;
            }

            setGridLimits();
            initializeInitialCondition();
            initializeOperator();
            initializeBoundaryConditions();
            initializeModel();
            initializeStepCondition();

            prices_ = (SampledCurve)intrinsicValues_.Clone();
            if (lastDateIsResTime)
            {
                executeIntermediateStep(dateNumber - 1);
            }

            j = lastIndex;
            object temp;

            do
            {
                if (j == dateNumber - 1)
                {
                    beginDate = getResidualTime();
                }
                else
                {
                    beginDate = getDividendTime(j + 1);
                }

                if (j >= 0)
                {
                    endDate = getDividendTime(j);
                }
                else
                {
                    endDate = dt;
                }

                temp = prices_.values();
                model_.rollback(ref temp, beginDate, endDate, timeStepPerPeriod_, stepCondition_);
                prices_.setValues((Vector)temp);

                if (j >= 0)
                {
                    executeIntermediateStep(j);
                }
            } while (--j >= firstIndex);

            temp = prices_.values();
            model_.rollback(ref temp, dt, 0, 1, stepCondition_);
            prices_.setValues((Vector)temp);

            if (firstDateIsZero)
            {
                executeIntermediateStep(0);
            }

            results.value = prices_.valueAtCenter();
            results.delta = prices_.firstDerivativeAtCenter();
            results.gamma = prices_.secondDerivativeAtCenter();
            results.additionalResults["priceCurve"] = prices_;
        }
コード例 #24
0
ファイル: FDStepConditionEngine.cs プロジェクト: igitur/qlnet
        public override void calculate(IPricingEngineResults r)
        {
            OneAssetOption.Results results = r as OneAssetOption.Results;
            setGridLimits();
            initializeInitialCondition();
            initializeOperator();
            initializeBoundaryConditions();
            initializeStepCondition();

            List <IOperator>          operatorSet  = new List <IOperator>();
            List <Vector>             arraySet     = new List <Vector>();
            BoundaryConditionSet      bcSet        = new BoundaryConditionSet();
            StepConditionSet <Vector> conditionSet = new StepConditionSet <Vector>();

            prices_ = (SampledCurve)intrinsicValues_.Clone();

            controlPrices_   = (SampledCurve)intrinsicValues_.Clone();
            controlOperator_ = (TridiagonalOperator)finiteDifferenceOperator_.Clone();
            controlBCs_[0]   = BCs_[0];
            controlBCs_[1]   = BCs_[1];

            operatorSet.Add(finiteDifferenceOperator_);
            operatorSet.Add(controlOperator_);

            arraySet.Add(prices_.values());
            arraySet.Add(controlPrices_.values());

            bcSet.Add(BCs_);
            bcSet.Add(controlBCs_);

            conditionSet.Add(stepCondition_);
            conditionSet.Add(new NullCondition <Vector>());

            var model = new FiniteDifferenceModel <ParallelEvolver <CrankNicolson <TridiagonalOperator> > >(operatorSet, bcSet);

            object temp = arraySet;

            model.rollback(ref temp, getResidualTime(), 0.0, timeSteps_, conditionSet);
            arraySet = (List <Vector>)temp;

            prices_.setValues(arraySet[0]);
            controlPrices_.setValues(arraySet[1]);

            StrikedTypePayoff striked_payoff = payoff_ as StrikedTypePayoff;

            Utils.QL_REQUIRE(striked_payoff != null, () => "non-striked payoff given");

            double variance         = process_.blackVolatility().link.blackVariance(exerciseDate_, striked_payoff.strike());
            double dividendDiscount = process_.dividendYield().link.discount(exerciseDate_);
            double riskFreeDiscount = process_.riskFreeRate().link.discount(exerciseDate_);
            double spot             = process_.stateVariable().link.value();
            double forwardPrice     = spot * dividendDiscount / riskFreeDiscount;

            BlackCalculator black = new BlackCalculator(striked_payoff, forwardPrice, Math.Sqrt(variance), riskFreeDiscount);

            results.value = prices_.valueAtCenter()
                            - controlPrices_.valueAtCenter()
                            + black.value();
            results.delta = prices_.firstDerivativeAtCenter()
                            - controlPrices_.firstDerivativeAtCenter()
                            + black.delta(spot);
            results.gamma = prices_.secondDerivativeAtCenter()
                            - controlPrices_.secondDerivativeAtCenter()
                            + black.gamma(spot);
            results.additionalResults["priceCurve"] = prices_;
        }
コード例 #25
0
ファイル: VanillaSwap.cs プロジェクト: Yenyenx/qlnet
        public override void fetchResults(IPricingEngineResults r)
        {
            const double basisPoint = 1.0e-4;

             base.fetchResults(r);
             VanillaSwap.Results results = r as VanillaSwap.Results;

             if (results != null)
             { // might be a swap engine, so no error is thrown
            fairRate_ = results.fairRate;
            fairSpread_ = results.fairSpread;
             }
             else
             {
            fairRate_ = null;
            fairSpread_ = null;
             }

             if (fairRate_ == null)
             {
            // calculate it from other results
            if (legBPS_[0] != null)
               fairRate_ = fixedRate_ - NPV_.GetValueOrDefault() / (legBPS_[0] / basisPoint);
             }
             if (fairSpread_ == null)
             {
            // ditto
            if (legBPS_[1] != null)
               fairSpread_ = spread_ - NPV_.GetValueOrDefault() / (legBPS_[1] / basisPoint);
             }
        }
コード例 #26
0
ファイル: FDMultiPeriodEngine.cs プロジェクト: Yenyenx/qlnet
        public override void calculate(IPricingEngineResults r)
        {
            OneAssetOption.Results results = r as OneAssetOption.Results;
            if (results == null) throw new ApplicationException("incorrect results type");

            double beginDate, endDate;
            int dateNumber = stoppingTimes_.Count;
            bool lastDateIsResTime = false;
            int firstIndex = -1;
            int lastIndex = dateNumber - 1;
            bool firstDateIsZero = false;
            double firstNonZeroDate = getResidualTime();

            double dateTolerance = 1e-6;
            int j;

            if (dateNumber > 0) {
                if (!(getDividendTime(0) >= 0))
                    throw new ApplicationException("first date (" + getDividendTime(0) + ") cannot be negative");
                if (getDividendTime(0) < getResidualTime() * dateTolerance) {
                    firstDateIsZero = true;
                    firstIndex = 0;
                    if (dateNumber >= 2)
                        firstNonZeroDate = getDividendTime(1);
                }

                if (Math.Abs(getDividendTime(lastIndex) - getResidualTime()) < dateTolerance) {
                    lastDateIsResTime = true;
                    lastIndex = dateNumber - 2;
                }

                if (!firstDateIsZero)
                    firstNonZeroDate = getDividendTime(0);

                if (dateNumber >= 2) {
                    for (j = 1; j < dateNumber; j++)
                        if (!(getDividendTime(j - 1) < getDividendTime(j)))
                            throw new ApplicationException("dates must be in increasing order: "
                                   + getDividendTime(j - 1) + " is not strictly smaller than " + getDividendTime(j));
                }
            }

            double dt = getResidualTime() / (timeStepPerPeriod_ * (dateNumber + 1));

            // Ensure that dt is always smaller than the first non-zero date
            if (firstNonZeroDate <= dt)
                dt = firstNonZeroDate / 2.0;

            setGridLimits();
            initializeInitialCondition();
            initializeOperator();
            initializeBoundaryConditions();
            initializeModel();
            initializeStepCondition();

            prices_ = (SampledCurve)intrinsicValues_.Clone();
            if (lastDateIsResTime)
                executeIntermediateStep(dateNumber - 1);

            j = lastIndex;
            object temp;
            do {
                if (j == dateNumber - 1)
                    beginDate = getResidualTime();
                else
                    beginDate = getDividendTime(j + 1);

                if (j >= 0)
                    endDate = getDividendTime(j);
                else
                    endDate = dt;

                temp = prices_.values();
                model_.rollback(ref temp, beginDate, endDate, timeStepPerPeriod_, stepCondition_);
                prices_.setValues((Vector)temp);

                if (j >= 0)
                    executeIntermediateStep(j);
            } while (--j >= firstIndex);

            temp = prices_.values();
            model_.rollback(ref temp, dt, 0, 1, stepCondition_);
            prices_.setValues((Vector)temp);

            if (firstDateIsZero)
                executeIntermediateStep(0);

            results.value = prices_.valueAtCenter();
            results.delta = prices_.firstDerivativeAtCenter();
            results.gamma = prices_.secondDerivativeAtCenter();
            results.additionalResults["priceCurve"] = prices_;
        }
コード例 #27
0
        public override void calculate(IPricingEngineResults r)
        {
            OneAssetOption.Results results = r as OneAssetOption.Results;
            setGridLimits();
            initializeInitialCondition();
            initializeOperator();
            initializeBoundaryConditions();
            initializeStepCondition();

            // typedef StandardSystemFiniteDifferenceModel model_type;

            List<IOperator> operatorSet = new List<IOperator>();
            List<Vector> arraySet = new List<Vector>();
            BoundaryConditionSet bcSet = new BoundaryConditionSet();
            StepConditionSet<Vector> conditionSet = new StepConditionSet<Vector>();

            prices_ = (SampledCurve)intrinsicValues_.Clone();

            controlPrices_ = (SampledCurve)intrinsicValues_.Clone();
            controlOperator_ = (TridiagonalOperator)finiteDifferenceOperator_.Clone();
            controlBCs_[0] = BCs_[0];
            controlBCs_[1] = BCs_[1];

            operatorSet.Add(finiteDifferenceOperator_);
            operatorSet.Add(controlOperator_);

            arraySet.Add(prices_.values());
            arraySet.Add(controlPrices_.values());

            bcSet.Add(BCs_);
            bcSet.Add(controlBCs_);

            conditionSet.Add(stepCondition_);
            conditionSet.Add(new NullCondition<Vector>());

            var model = new FiniteDifferenceModel<ParallelEvolver<CrankNicolson<TridiagonalOperator>>>(operatorSet, bcSet);

            object temp = arraySet;
            model.rollback(ref temp, getResidualTime(), 0.0, timeSteps_, conditionSet);
            arraySet = (List<Vector>)temp;

            prices_.setValues(arraySet[0]);
            controlPrices_.setValues(arraySet[1]);

            StrikedTypePayoff striked_payoff = payoff_ as StrikedTypePayoff;
            if (striked_payoff == null)
                throw new ApplicationException("non-striked payoff given");

            double variance = process_.blackVolatility().link.blackVariance(exerciseDate_, striked_payoff.strike());
            double dividendDiscount = process_.dividendYield().link.discount(exerciseDate_);
            double riskFreeDiscount = process_.riskFreeRate().link.discount(exerciseDate_);
            double spot = process_.stateVariable().link.value();
            double forwardPrice = spot * dividendDiscount / riskFreeDiscount;

            BlackCalculator black = new BlackCalculator(striked_payoff, forwardPrice, Math.Sqrt(variance), riskFreeDiscount);

            results.value = prices_.valueAtCenter()
                - controlPrices_.valueAtCenter()
                + black.value();
            results.delta = prices_.firstDerivativeAtCenter()
                - controlPrices_.firstDerivativeAtCenter()
                + black.delta(spot);
            results.gamma = prices_.secondDerivativeAtCenter()
                - controlPrices_.secondDerivativeAtCenter()
                + black.gamma(spot);
            results.additionalResults.Add("priceCurve", prices_);
        }
コード例 #28
0
ファイル: BasisSwap.cs プロジェクト: ariesy/QLNet
 public override void fetchResults(IPricingEngineResults r)
 {
     base.fetchResults(r);
      BasisSwap.Results results = r as BasisSwap.Results;
 }
コード例 #29
0
ファイル: BasisSwap.cs プロジェクト: zkhvan/QLNet
 public override void fetchResults(IPricingEngineResults r)
 {
     base.fetchResults(r);
     BasisSwap.Results results = r as BasisSwap.Results;
 }
コード例 #30
0
ファイル: AssetSwap.cs プロジェクト: Yenyenx/qlnet
 public override void fetchResults(IPricingEngineResults r)
 {
     base.fetchResults(r);
      AssetSwap.Results results = r as AssetSwap.Results;
      if (results != null)
      {
     fairSpread_ = results.fairSpread;
     fairCleanPrice_= results.fairCleanPrice;
     fairNonParRepayment_= results.fairNonParRepayment;
      }
      else
      {
     fairSpread_ = null;
     fairCleanPrice_ = null;
     fairNonParRepayment_ = null;
     }
 }