コード例 #1
0
        /// <summary>
        /// Prepare for valuation anything that will be shared between scenarios.
        /// </summary>
        public override void PreCloneInitialize(PriceFactorList factors, BaseTimeGrid baseTimes, RequiredResults requiredResults)
        {
            base.PreCloneInitialize(factors, baseTimes, requiredResults);

            CommodityForwardDealBase deal = (CommodityForwardDealBase)fDeal;

            // Add to valuation time grid
            fT.AddPayDate(deal.Maturity_Date, requiredResults.CashRequired());
        }
コード例 #2
0
        /// <summary>
        /// Calculate valuation profiles.
        /// </summary>
        public override void Value(ValuationResults valuationResults, PriceFactorList factors, BaseTimeGrid baseTimes)
        {
            base.PreValue(factors);

            IAssetPrice     commodityPrice;
            ISpotProcessVol dummyAssetPriceVol;

            ((BaseAssetFxDealHelper)GetDealHelper()).PreValueAsset(out commodityPrice, out dummyAssetPriceVol, out fBasketPricer, ref fQuantoCompo, factors);

            CommodityForwardDealBase deal = (CommodityForwardDealBase)fDeal;

            double scale     = (deal.Buy_Sell == BuySell.Buy ? +1 : -1) * deal.Units;
            double tMaturity = CalcUtils.DaysToYears(deal.Maturity_Date - factors.BaseDate);

            TimeGridIterator tgi    = new TimeGridIterator(fT);
            CashAccumulators cash   = valuationResults.Cash;
            PVProfiles       result = valuationResults.Profile;

            VectorEngine.For(tgi, () =>
            {
                using (var cache = Vector.Cache(factors.NumScenarios))
                {
                    Vector pv = cache.Get();

                    if (tgi.Date <= deal.Maturity_Date)
                    {
                        pv.Assign(commodityPrice.ForwardFactor(tgi.T, tMaturity, fFxRate) * commodityPrice.Get(tgi.T));     // assign forward * fxRate to pv
                        pv.Assign((pv - deal.Forward_Price * fFxRate.Get(tgi.T)) * fDiscountRate.Get(tgi.T, tMaturity) * scale);
                    }
                    else
                    {
                        pv.Clear();
                    }

                    result.AppendVector(tgi.Date, pv);

                    if (tgi.Date == deal.Maturity_Date)
                    {
                        cash.Accumulate(fFxRate, deal.Maturity_Date, (commodityPrice.Get(tMaturity) / fFxRate.Get(tMaturity) - deal.Forward_Price) * scale);
                    }
                }
            });

            result.Complete(fT);
        }