/// <summary>
        /// Prepare for valuation anything that is not dependent upon the scenario.
        /// </summary>
        public override void PreCloneInitialize(PriceFactorList factors, BaseTimeGrid baseTimes, RequiredResults requiredResults)
        {
            base.PreCloneInitialize(factors, baseTimes, requiredResults);

            IInflationCashflowListDeal deal = (IInflationCashflowListDeal)Deal;

            // Set up cashflow list
            IInflationRate inflationRate = deal.NeedInflationRate() ? factors.GetInterface <IInflationRate>(deal.Index) : null;

            deal.GetCashflows().PreCloneInitialize(factors.BaseDate, inflationRate, deal.GetHolidayCalendar());

            // Add to valuation time grid
            deal.AddPayDates(fT);

            if (deal.Investment_Horizon > 0.0)
            {
                fT.AddPayDate(deal.Investment_Horizon, requiredResults.CashRequired());
            }

            if (deal.Settlement_Date > 0.0)
            {
                fT.AddPayDate(deal.Settlement_Date, requiredResults.CashRequired());
            }

            // Recovery cashflows are created on the fly to respect customized cashflows
            if (NeedRecoveryCashflows())
            {
                fRecoveryCashflowList = new CFRecoveryInflationList();
                fRecoveryCashflowList.PopulateRecoveryCashflowList(factors.BaseDate, deal.Settlement_Date, deal.GetCashflows());
            }
        }
示例#2
0
        private static void Main(string[] args)
        {
            ServiceProvider serviceProvider = startup();

            _inflation = serviceProvider.GetService <IInflationRate>();

            // _inflation = new InflationRate();

            var result = _inflation.GetInflationRateByYear(2030);

            Console.WriteLine($"{result}");
        }
        /// <summary>
        /// Prepare for valuation anything that is dependent upon the scenario.
        /// </summary>
        /// <param name="factors">Price factors.</param>
        public override void PreValue(PriceFactorList factors)
        {
            base.PreValue(factors);

            IInflationCashflowListDeal deal = (IInflationCashflowListDeal)Deal;

            fIsDefaultNever  = !NeedCreditRating();
            fCreditRating    = NeedCreditRating()                      ? factors.Get <CreditRating>(deal.Issuer)                       : null;
            fRecoveryRate    = NeedRecoveryRate()                      ? factors.Get <RecoveryRate>(GetRecoveryRateID())               : null;
            fSurvivalProb    = NeedSurvivalProb()                      ? factors.GetInterface <ISurvivalProb>(GetSurvivalProbID())     : null;
            fInflationRate   = !string.IsNullOrEmpty(deal.Index)       ? factors.GetInterface <IInflationRate>(deal.Index)             : null;
            fRepoRate        = !string.IsNullOrEmpty(deal.Repo_Rate)   ? factors.GetInterface <IInterestRate>(deal.Repo_Rate)          : fDiscountRate;
            fIndexVolatility = deal is InflationOptionCashflowListDeal?factors.GetInterface <IPriceIndexVolatility>(GetPriceIndexVolatility()) : null;
        }
示例#4
0
 public AmountService(IInflationRate inflationRate, ILogger logger)
 {
     this.inflationRate = inflationRate;
     this.logger        = logger;
 }
 public InflationService(IInflationRate inflationRate, IMyLogger myLogger)
 {
     this._inflationRate = inflationRate;
     this._myLogger      = myLogger;
 }
 public SalaryService(IInflationRate inflationRate, ILog log)
 {
     this._inflationRate = inflationRate;
     this._log           = log;
 }
 public AmountService(ILogger logger, IInflationRate inflationRate)
 {
     _logger             = logger;
     this._inflationRate = inflationRate;
 }
        /// <summary>
        /// Returns the payment amount on settlement date based on the cashflowlist.
        /// </summary>
        /// <remarks>
        /// The payment amount on settlement date will be either the dirty price of the bond or the clean price of the bond plus
        /// the accrued interest (two cashflows). Note that for a long position in a bond forward, this value is negative
        /// (indicating outgoing cashflow).
        /// </remarks>
        protected virtual void GetSettlementAmount(Vector amount, double valueDate, double baseDate, IInflationRate inflationRate, IPriceIndexVolatility indexVolatility)
        {
            amount.Clear();
            using (var cache = Vector.CacheLike(amount))
            {
                var    deal          = (IInflationCashflowListDeal)Deal;
                var    cashflows     = deal.GetCashflows();
                Vector settlementPay = cache.Get();

                for (int i = 0; i < cashflows.Count(); ++i)
                {
                    if (cashflows.GetCashflow(i).Payment_Date < deal.Settlement_Date)
                    {
                        continue;
                    }
                    else if (cashflows.GetCashflow(i).Payment_Date == deal.Settlement_Date)
                    {
                        cashflows.GetCashflow(i).ExpectedAmount(settlementPay, CalcUtils.DaysToYears(valueDate - baseDate), inflationRate, indexVolatility,
                                                                IntraValuationDiagnosticsWriterFactory.GetOrCreate(IntraValuationDiagnosticsLevel.None));
                        amount.Add(settlementPay);
                    }
                    else
                    {
                        break;
                    }
                }
            }
        }
        /// <summary>
        /// Returns the current exposure amount in nominal dollars based on the recovery cashflowlist
        /// </summary>
        protected void GetCurrentExposure(Vector exposure, double t, double valueDate, IInflationRate inflationRate)
        {
            if (fRecoveryCashflowList != null)
            {
                for (int i = 0; i < fRecoveryCashflowList.Count(); i++)
                {
                    if (fRecoveryCashflowList[i].Payment_Date >= valueDate)
                    {
                        var cashflow = fRecoveryCashflowList[i];
                        cashflow.GetExposure(exposure, t, valueDate, inflationRate);
                        return;
                    }
                }
            }

            exposure.Assign(0.0);
        }
        /// <summary>
        /// Modify the pv and cash taking the date of default into account.
        /// </summary>
        protected void GetDefaultValue(double baseDate, double valueDate, Vector defaultDate, IInflationRate inflationRate, IPriceIndexVolatility indexVolatility, IInterestRate repo, Vector pv, Vector cash)
        {
            IInflationCashflowListDeal deal = (IInflationCashflowListDeal)Deal;

            double settlementDate = deal.Settlement_Date;
            double t           = CalcUtils.DaysToYears(valueDate - baseDate);
            double buySellSign = deal.Buy_Sell == BuySell.Buy ? 1.0 : -1.0;

            if (repo == null)
            {
                repo = fDiscountRate;
            }

            using (var cache = Vector.CacheLike(pv))
            {
                Vector principal = cache.Get();
                GetCurrentExposure(principal, t, valueDate, inflationRate);

                // Approximation: recover only principal, neglecting accrued interest.
                Vector recovery = cache.Get(buySellSign * principal * fRecoveryRate.Get(t));

                if (valueDate <= settlementDate)
                {
                    // Set the pv to (recovery - |settlementAmount|) * df when defaultDate <= valueDate <= settlementDate.
                    // Set cash to (recovery - |settlementAmount|) when defaultDate <= valueDate = settlementDate (cash is always zero before settlementDate).
                    // Note that GetSettlementAmount(...) will return a negative value for a long bond position, indicating an outgoing cashflow.
                    double tSettle          = CalcUtils.DaysToYears(settlementDate - baseDate);
                    Vector settlementAmount = cache.Get();
                    GetSettlementAmount(settlementAmount, valueDate, baseDate, inflationRate, indexVolatility);
                    settlementAmount.MultiplyBy(buySellSign);

                    Vector hasDefaulted = cache.Get(defaultDate <= valueDate);

                    pv.AssignConditional(hasDefaulted, repo.Get(t, tSettle) * (recovery + settlementAmount), pv);

                    if (cash != null && valueDate == settlementDate)
                    {
                        cash.AssignConditional(hasDefaulted, pv, cash);
                    }
                }
                else
                {
                    // after settlement date
                    recovery.MultiplyBy(defaultDate >= valueDate); // set to zero if already defaulted
                    Vector notDefaulted = cache.Get(defaultDate > valueDate);

                    pv.AssignConditional(notDefaulted, pv, recovery);

                    if (cash != null)
                    {
                        cash.AssignConditional(notDefaulted, cash, recovery);
                    }
                }
            }
        }
 public AmountService(IInflationRate object1, ILogger object2)
 {
     this._rate = object1;
     this._log  = object2;
 }