//-------------------------------------------------------------------------
        public virtual void explainPresentValue(KnownAmountSwapPaymentPeriod period, RatesProvider provider, ExplainMapBuilder builder)
        {
            Currency  currency    = period.Currency;
            LocalDate paymentDate = period.PaymentDate;

            builder.put(ExplainKey.ENTRY_TYPE, "KnownAmountPaymentPeriod");
            builder.put(ExplainKey.PAYMENT_DATE, paymentDate);
            builder.put(ExplainKey.PAYMENT_CURRENCY, currency);
            builder.put(ExplainKey.START_DATE, period.StartDate);
            builder.put(ExplainKey.UNADJUSTED_START_DATE, period.UnadjustedStartDate);
            builder.put(ExplainKey.END_DATE, period.EndDate);
            builder.put(ExplainKey.UNADJUSTED_END_DATE, period.UnadjustedEndDate);
            builder.put(ExplainKey.DAYS, (int)DAYS.between(period.StartDate, period.EndDate));
            if (paymentDate.isBefore(provider.ValuationDate))
            {
                builder.put(ExplainKey.COMPLETED, true);
                builder.put(ExplainKey.FORECAST_VALUE, CurrencyAmount.zero(currency));
                builder.put(ExplainKey.PRESENT_VALUE, CurrencyAmount.zero(currency));
            }
            else
            {
                builder.put(ExplainKey.DISCOUNT_FACTOR, provider.discountFactor(currency, paymentDate));
                builder.put(ExplainKey.FORECAST_VALUE, CurrencyAmount.of(currency, forecastValue(period, provider)));
                builder.put(ExplainKey.PRESENT_VALUE, CurrencyAmount.of(currency, presentValue(period, provider)));
            }
        }
        public virtual void test_before()
        {
            LocalDate startDate = date(2018, 2, 1);
            LocalDate endDate   = date(2018, 2, 28);
            OvernightAveragedDailyRateComputation cmp = OvernightAveragedDailyRateComputation.of(USD_FED_FUND, startDate, endDate, REF_DATA);
            ImmutableRatesProvider rates          = getRatesProvider(date(2018, 1, 24));
            double computedRate                   = FUNCTION.rate(cmp, DUMMY_ACCRUAL_START_DATE, DUMMY_ACCRUAL_END_DATE, rates);
            PointSensitivityBuilder sensiComputed = FUNCTION.rateSensitivity(cmp, startDate, endDate, rates);
            ExplainMapBuilder       builder       = ExplainMap.builder();
            double explainRate  = FUNCTION.explainRate(cmp, startDate, endDate, rates, builder);
            double expectedRate = 0d;
            PointSensitivityBuilder sensiExpected = PointSensitivityBuilder.none();
            LocalDate date = startDate;

            while (!date.isAfter(endDate))
            {
                OvernightIndexObservation obs = OvernightIndexObservation.of(USD_FED_FUND, date, REF_DATA);
                double rate = rates.overnightIndexRates(USD_FED_FUND).rate(obs);
                PointSensitivityBuilder rateSensi = rates.overnightIndexRates(USD_FED_FUND).ratePointSensitivity(obs);
                LocalDate nextDate = cmp.FixingCalendar.next(date);
                long      days     = DAYS.between(date, nextDate);
                expectedRate += rate * days;
                sensiExpected = sensiComputed.combinedWith(rateSensi.multipliedBy(days));
                date          = nextDate;
            }
            double nDays = 28d;

            expectedRate /= nDays;
            sensiExpected = sensiExpected.multipliedBy(1d / nDays);
            assertEquals(computedRate, expectedRate, TOL);
            assertTrue(sensiComputed.build().equalWithTolerance(sensiExpected.build(), TOL));
            assertEquals(explainRate, computedRate, TOL);
            assertEquals(builder.build().get(ExplainKey.COMBINED_RATE).Value, expectedRate, TOL);
        }
Esempio n. 3
0
        public virtual void test_explainPresentValue_inPast()
        {
            RatesProvider prov = createProvider(VAL_DATE);

            ExplainMapBuilder builder = ExplainMap.builder();

            PRICER.explainPresentValue(PERIOD_PAST, prov, builder);
            ExplainMap explain = builder.build();

            assertEquals(explain.get(ExplainKey.ENTRY_TYPE).get(), "KnownAmountPaymentPeriod");
            assertEquals(explain.get(ExplainKey.PAYMENT_DATE).get(), PERIOD_PAST.PaymentDate);
            assertEquals(explain.get(ExplainKey.PAYMENT_CURRENCY).get(), PERIOD_PAST.Currency);

            int daysBetween = (int)DAYS.between(DATE_1, DATE_2);

            assertEquals(explain.get(ExplainKey.START_DATE).get(), PERIOD_PAST.StartDate);
            assertEquals(explain.get(ExplainKey.UNADJUSTED_START_DATE).get(), PERIOD_PAST.UnadjustedStartDate);
            assertEquals(explain.get(ExplainKey.END_DATE).get(), PERIOD_PAST.EndDate);
            assertEquals(explain.get(ExplainKey.UNADJUSTED_END_DATE).get(), PERIOD_PAST.UnadjustedEndDate);
            assertEquals(explain.get(ExplainKey.DAYS).Value, (int?)daysBetween);

            assertEquals(explain.get(ExplainKey.FORECAST_VALUE).get().Currency, PERIOD_PAST.Currency);
            assertEquals(explain.get(ExplainKey.FORECAST_VALUE).get().Amount, 0, TOLERANCE_PV);
            assertEquals(explain.get(ExplainKey.PRESENT_VALUE).get().Currency, PERIOD_PAST.Currency);
            assertEquals(explain.get(ExplainKey.PRESENT_VALUE).get().Amount, 0 * DISCOUNT_FACTOR, TOLERANCE_PV);
        }
Esempio n. 4
0
        /// <summary>
        /// Explains the present value of a single payment period with z-spread.
        /// <para>
        /// This adds information to the <seealso cref="ExplainMapBuilder"/> to aid understanding of the calculation.
        ///
        /// </para>
        /// </summary>
        /// <param name="period">  the period to price </param>
        /// <param name="ratesProvider">  the rates provider, used to determine price index values </param>
        /// <param name="issuerDiscountFactors">  the discount factor provider </param>
        /// <param name="zSpread">  the z-spread </param>
        /// <param name="compoundedRateType">  the compounded rate type </param>
        /// <param name="periodsPerYear">  the number of periods per year </param>
        /// <param name="builder">  the builder to populate </param>
        public virtual void explainPresentValueWithZSpread(CapitalIndexedBondPaymentPeriod period, RatesProvider ratesProvider, IssuerCurveDiscountFactors issuerDiscountFactors, ExplainMapBuilder builder, double zSpread, CompoundedRateType compoundedRateType, int periodsPerYear)
        {
            Currency  currency    = period.Currency;
            LocalDate paymentDate = period.PaymentDate;

            builder.put(ExplainKey.ENTRY_TYPE, "CapitalIndexedBondPaymentPeriod");
            builder.put(ExplainKey.PAYMENT_DATE, paymentDate);
            builder.put(ExplainKey.PAYMENT_CURRENCY, currency);
            builder.put(ExplainKey.START_DATE, period.StartDate);
            builder.put(ExplainKey.UNADJUSTED_START_DATE, period.UnadjustedStartDate);
            builder.put(ExplainKey.END_DATE, period.EndDate);
            builder.put(ExplainKey.UNADJUSTED_END_DATE, period.UnadjustedEndDate);
            builder.put(ExplainKey.DAYS, (int)DAYS.between(period.UnadjustedStartDate, period.UnadjustedEndDate));
            if (paymentDate.isBefore(ratesProvider.ValuationDate))
            {
                builder.put(ExplainKey.COMPLETED, true);
                builder.put(ExplainKey.FORECAST_VALUE, CurrencyAmount.zero(currency));
                builder.put(ExplainKey.PRESENT_VALUE, CurrencyAmount.zero(currency));
            }
            else
            {
                builder.put(ExplainKey.DISCOUNT_FACTOR, issuerDiscountFactors.discountFactor(paymentDate));
                builder.put(ExplainKey.FORECAST_VALUE, CurrencyAmount.of(currency, forecastValue(period, ratesProvider)));
                builder.put(ExplainKey.PRESENT_VALUE, CurrencyAmount.of(currency, presentValueWithZSpread(period, ratesProvider, issuerDiscountFactors, zSpread, compoundedRateType, periodsPerYear)));
            }
        }
Esempio n. 5
0
        private void LoadDayUnregistered()
        {
            DAYS dia = DaysDao.getDay(int.Parse(Request["Day"]));

            if (dia != null)
            {
                int contador2 = 1;
                int contador3 = 0;
                //if (diaReported != null && diaReported.REPORT_DAY != null && diaReported.REPORT_DAY.Count > 0)
                //{
                //    contador3 += diaReported.REPORT_DAY.Count;
                //    contador2 += diaReported.REPORT_DAY.Count;
                //}
                List <DAYS_CONFIG> listado = dia.DAYS_CONFIG.ToList();
                if (contador2 <= listado.Count)
                {
                    for (int i = contador3; i < listado.Count; i++)
                    {
                        Label lbl = (Label)FindControl("lblReport" + contador2);
                        lbl.Text = listado[i].name;

                        HtmlGenericControl divPanel = (HtmlGenericControl)FindControl("div" + contador2);
                        divPanel.Style.Remove("display");

                        DropDownList ddl = (DropDownList)FindControl("ddlDataTypeReport" + contador2);
                        ddl.Items.Insert(0, listado[i].dataType);

                        TextBox txt = (TextBox)FindControl("txtReport" + contador2);
                        switch (listado[i].dataType)
                        {
                        case "Time":
                            txt.CssClass = "validateTime";
                            break;

                        case "Integer":
                            txt.CssClass  = "validateOnlyNumber";
                            txt.MaxLength = 4;
                            break;

                        case "Broken/Unbroken":
                            txt.CssClass  = "validateOnlyBOrU";
                            txt.MaxLength = 1;
                            break;
                        }
                        contador2++;
                    }
                }
                int otroCont = 1;
                for (int k = 0; k < listado.Count; k++)
                {
                    Label lblDesc = (Label)FindControl("lblDescReport" + otroCont);
                    lblDesc.Text = listado[k].description;
                    otroCont++;
                }
                //foreach (DAYS_CONFIG confDay in dia.DAYS_CONFIG)
                //{

                //}
            }
        }
        //-------------------------------------------------------------------------
        /// <summary>
        /// Explains the present value of the FRA product.
        /// <para>
        /// This returns explanatory information about the calculation.
        ///
        /// </para>
        /// </summary>
        /// <param name="fra">  the FRA product for which present value should be computed </param>
        /// <param name="provider">  the rates provider </param>
        /// <returns> the explanatory information </returns>
        public virtual ExplainMap explainPresentValue(ResolvedFra fra, RatesProvider provider)
        {
            ExplainMapBuilder builder  = ExplainMap.builder();
            Currency          currency = fra.Currency;

            builder.put(ExplainKey.ENTRY_TYPE, "FRA");
            builder.put(ExplainKey.PAYMENT_DATE, fra.PaymentDate);
            builder.put(ExplainKey.START_DATE, fra.StartDate);
            builder.put(ExplainKey.END_DATE, fra.EndDate);
            builder.put(ExplainKey.ACCRUAL_YEAR_FRACTION, fra.YearFraction);
            builder.put(ExplainKey.DAYS, (int)DAYS.between(fra.StartDate, fra.EndDate));
            builder.put(ExplainKey.PAYMENT_CURRENCY, currency);
            builder.put(ExplainKey.NOTIONAL, CurrencyAmount.of(currency, fra.Notional));
            builder.put(ExplainKey.TRADE_NOTIONAL, CurrencyAmount.of(currency, fra.Notional));
            if (fra.PaymentDate.isBefore(provider.ValuationDate))
            {
                builder.put(ExplainKey.COMPLETED, true);
                builder.put(ExplainKey.FORECAST_VALUE, CurrencyAmount.zero(currency));
                builder.put(ExplainKey.PRESENT_VALUE, CurrencyAmount.zero(currency));
            }
            else
            {
                double rate = rateComputationFn.explainRate(fra.FloatingRate, fra.StartDate, fra.EndDate, provider, builder);
                builder.put(ExplainKey.FIXED_RATE, fra.FixedRate);
                builder.put(ExplainKey.DISCOUNT_FACTOR, provider.discountFactor(currency, fra.PaymentDate));
                builder.put(ExplainKey.PAY_OFF_RATE, rate);
                builder.put(ExplainKey.UNIT_AMOUNT, unitAmount(fra, provider));
                builder.put(ExplainKey.FORECAST_VALUE, forecastValue(fra, provider));
                builder.put(ExplainKey.PRESENT_VALUE, presentValue(fra, provider));
            }
            return(builder.build());
        }
        static void Main7(string[] args)
        {

            DAYS d = DAYS.SATURDAY;

            PrintDay(d);

            Console.Read();
        }
Esempio n. 8
0
        public static string NanosToString(long nanos)
        {
            Debug.Assert(nanos >= 0);
            long          nanoSeconds = nanos;
            StringBuilder timeString  = new StringBuilder();

            long days = DAYS.convert(nanoSeconds, NANOSECONDS);

            if (days > 0)
            {
                nanoSeconds -= DAYS.toNanos(days);
                timeString.Append(days).Append('d');
            }
            long hours = HOURS.convert(nanoSeconds, NANOSECONDS);

            if (hours > 0)
            {
                nanoSeconds -= HOURS.toNanos(hours);
                timeString.Append(hours).Append('h');
            }
            long minutes = MINUTES.convert(nanoSeconds, NANOSECONDS);

            if (minutes > 0)
            {
                nanoSeconds -= MINUTES.toNanos(minutes);
                timeString.Append(minutes).Append('m');
            }
            long seconds = SECONDS.convert(nanoSeconds, NANOSECONDS);

            if (seconds > 0)
            {
                nanoSeconds -= SECONDS.toNanos(seconds);
                timeString.Append(seconds).Append('s');
            }
            long milliseconds = MILLISECONDS.convert(nanoSeconds, NANOSECONDS);

            if (milliseconds > 0)
            {
                nanoSeconds -= MILLISECONDS.toNanos(milliseconds);
                timeString.Append(milliseconds).Append("ms");
            }
            long microseconds = MICROSECONDS.convert(nanoSeconds, NANOSECONDS);

            if (microseconds > 0)
            {
                nanoSeconds -= MICROSECONDS.toNanos(microseconds);
                timeString.Append(microseconds).Append("μs");
            }
            if (nanoSeconds > 0 || timeString.Length == 0)
            {
                timeString.Append(nanoSeconds).Append("ns");
            }
            return(timeString.ToString());
        }
 // common parts of explain
 private void explainBasics(FixedCouponBondPaymentPeriod period, ExplainMapBuilder builder, Currency currency, LocalDate paymentDate)
 {
     builder.put(ExplainKey.ENTRY_TYPE, "FixedCouponBondPaymentPeriod");
     builder.put(ExplainKey.PAYMENT_DATE, paymentDate);
     builder.put(ExplainKey.PAYMENT_CURRENCY, currency);
     builder.put(ExplainKey.START_DATE, period.StartDate);
     builder.put(ExplainKey.UNADJUSTED_START_DATE, period.UnadjustedStartDate);
     builder.put(ExplainKey.END_DATE, period.EndDate);
     builder.put(ExplainKey.UNADJUSTED_END_DATE, period.UnadjustedEndDate);
     builder.put(ExplainKey.ACCRUAL_YEAR_FRACTION, period.YearFraction);
     builder.put(ExplainKey.DAYS, (int)DAYS.between(period.StartDate, period.EndDate));
 }
Esempio n. 10
0
        public static bool SaveConfigForDay(int day, int idDay, string date, string state, int[] idDiasConfigurados, string[] names, string[] dataTypes, string[] descriptions)
        {
            bool resp = false;

            try
            {
                goliazco_FWEntities entity = new goliazco_FWEntities();
                if (idDay > 0)
                {
                    DAYS dayConfig = (from t in entity.DAYS where t.idDay == idDay select t).FirstOrDefault();
                    if (dayConfig != null)
                    {
                        string[] formats = { "dd/MM/yyyy" };
                        dayConfig.completeDay = DateTime.ParseExact(date, formats, new CultureInfo("en-US"), DateTimeStyles.None);
                        dayConfig.state       = state;
                        int i = 0;
                        if (dayConfig.DAYS_CONFIG != null && dayConfig.DAYS_CONFIG.Count > 0)
                        {
                            for (i = 0; i < idDiasConfigurados.Length; i++)
                            {
                                DAYS_CONFIG diaYaConfigurado = (from t in dayConfig.DAYS_CONFIG where t.idReportNum == idDiasConfigurados[i] select t).FirstOrDefault();
                                diaYaConfigurado.name        = names[i];
                                diaYaConfigurado.dataType    = dataTypes[i];
                                diaYaConfigurado.description = descriptions[i];
                            }
                        }
                        if (names.Length > idDiasConfigurados.Length)
                        {
                            for (int j = i; j < names.Length; j++)
                            {
                                DAYS_CONFIG newConfigForDay = new DAYS_CONFIG();
                                newConfigForDay.name        = names[j];
                                newConfigForDay.dataType    = dataTypes[j];
                                newConfigForDay.description = descriptions[j];
                                dayConfig.DAYS_CONFIG.Add(newConfigForDay);
                            }
                        }
                    }
                    entity.SaveChanges();
                    resp = true;
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            return(resp);
        }
Esempio n. 11
0
        public static DAYS getDay(int day)
        {
            DAYS getDay = null;
            goliazco_FWEntities entity = null;

            try
            {
                entity = new goliazco_FWEntities();
                //getDay = (from t in entity.DAYS where t.Day == day select t).FirstOrDefault();
                getDay             = (from t in entity.DAYS where t.idDay == day select t).FirstOrDefault();
                getDay.DAYS_CONFIG = (from t in entity.DAYS_CONFIG where t.idDay == getDay.idDay select t).ToList();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            return(getDay);
        }
Esempio n. 12
0
        public virtual void test_explainPresentValueWithZSpread_past()
        {
            ExplainMapBuilder builder = ExplainMap.builder();

            PRICER.explainPresentValueWithZSpread(PERIOD_INTERP, IRP_AFTER_PAY, ICDF_AFTER_PAY, builder, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR);
            ExplainMap explain = builder.build();

            assertEquals(explain.get(ExplainKey.ENTRY_TYPE).get(), "CapitalIndexedBondPaymentPeriod");
            assertEquals(explain.get(ExplainKey.PAYMENT_DATE).get(), PERIOD_INTERP.PaymentDate);
            assertEquals(explain.get(ExplainKey.PAYMENT_CURRENCY).get(), PERIOD_INTERP.Currency);
            assertEquals(explain.get(ExplainKey.START_DATE).get(), START);
            assertEquals(explain.get(ExplainKey.UNADJUSTED_START_DATE).get(), START_UNADJ);
            assertEquals(explain.get(ExplainKey.END_DATE).get(), END);
            assertEquals(explain.get(ExplainKey.UNADJUSTED_END_DATE).get(), END_UNADJ);
            assertEquals(explain.get(ExplainKey.DAYS).Value.intValue(), (int)DAYS.between(START_UNADJ, END_UNADJ));
            assertEquals(explain.get(ExplainKey.FORECAST_VALUE).get().Amount, 0d, NOTIONAL * TOL);
            assertEquals(explain.get(ExplainKey.PRESENT_VALUE).get().Amount, 0d, NOTIONAL * TOL);
        }
Esempio n. 13
0
        //-------------------------------------------------------------------------
        public virtual void test_explainPresentValue()
        {
            ExplainMapBuilder builder = ExplainMap.builder();

            PRICER.explainPresentValue(PERIOD_INTERP, IRP_BEFORE_START, ICDF_BEFORE_START, builder);
            ExplainMap explain = builder.build();

            assertEquals(explain.get(ExplainKey.ENTRY_TYPE).get(), "CapitalIndexedBondPaymentPeriod");
            assertEquals(explain.get(ExplainKey.PAYMENT_DATE).get(), PERIOD_INTERP.PaymentDate);
            assertEquals(explain.get(ExplainKey.PAYMENT_CURRENCY).get(), PERIOD_INTERP.Currency);
            assertEquals(explain.get(ExplainKey.START_DATE).get(), START);
            assertEquals(explain.get(ExplainKey.UNADJUSTED_START_DATE).get(), START_UNADJ);
            assertEquals(explain.get(ExplainKey.END_DATE).get(), END);
            assertEquals(explain.get(ExplainKey.UNADJUSTED_END_DATE).get(), END_UNADJ);
            assertEquals(explain.get(ExplainKey.DAYS).Value.intValue(), (int)DAYS.between(START_UNADJ, END_UNADJ));
            assertEquals(explain.get(ExplainKey.DISCOUNT_FACTOR).Value, ICDF_BEFORE_START.discountFactor(END));
            assertEquals(explain.get(ExplainKey.FORECAST_VALUE).get().Amount, PRICER.forecastValue(PERIOD_INTERP, IRP_BEFORE_START), NOTIONAL * TOL);
            assertEquals(explain.get(ExplainKey.PRESENT_VALUE).get().Amount, PRICER.presentValue(PERIOD_INTERP, IRP_BEFORE_START, ICDF_BEFORE_START), NOTIONAL * TOL);
        }
	  //-------------------------------------------------------------------------
	  /// <summary>
	  /// Test explain.
	  /// </summary>
	  public virtual void test_explainPresentValue_ISDA()
	  {
		ResolvedFra fraExp = RFRA;
		SimpleRatesProvider prov = createProvider(fraExp);

		DiscountingFraProductPricer test = DiscountingFraProductPricer.DEFAULT;
		CurrencyAmount fvExpected = test.forecastValue(fraExp, prov);
		CurrencyAmount pvExpected = test.presentValue(fraExp, prov);

		ExplainMap explain = test.explainPresentValue(fraExp, prov);
		Currency currency = fraExp.Currency;
		int daysBetween = (int) DAYS.between(fraExp.StartDate, fraExp.EndDate);
		assertEquals(explain.get(ExplainKey.ENTRY_TYPE).get(), "FRA");
		assertEquals(explain.get(ExplainKey.PAYMENT_DATE).get(), fraExp.PaymentDate);
		assertEquals(explain.get(ExplainKey.START_DATE).get(), fraExp.StartDate);
		assertEquals(explain.get(ExplainKey.END_DATE).get(), fraExp.EndDate);
		assertEquals(explain.get(ExplainKey.ACCRUAL_YEAR_FRACTION).Value, fraExp.YearFraction);
		assertEquals(explain.get(ExplainKey.DAYS).Value, (int?)(int) daysBetween);
		assertEquals(explain.get(ExplainKey.PAYMENT_CURRENCY).get(), currency);
		assertEquals(explain.get(ExplainKey.NOTIONAL).get().Amount, fraExp.Notional, TOLERANCE);
		assertEquals(explain.get(ExplainKey.TRADE_NOTIONAL).get().Amount, fraExp.Notional, TOLERANCE);

		assertEquals(explain.get(ExplainKey.OBSERVATIONS).get().size(), 1);
		ExplainMap explainObs = explain.get(ExplainKey.OBSERVATIONS).get().get(0);
		IborRateComputation floatingRate = (IborRateComputation) fraExp.FloatingRate;
		assertEquals(explainObs.get(ExplainKey.INDEX).get(), floatingRate.Index);
		assertEquals(explainObs.get(ExplainKey.FIXING_DATE).get(), floatingRate.FixingDate);
		assertEquals(explainObs.get(ExplainKey.INDEX_VALUE).Value, FORWARD_RATE, TOLERANCE);
		assertEquals(explainObs.get(ExplainKey.FROM_FIXING_SERIES).HasValue, false);
		assertEquals(explain.get(ExplainKey.DISCOUNT_FACTOR).Value, DISCOUNT_FACTOR, TOLERANCE);
		assertEquals(explain.get(ExplainKey.FIXED_RATE).Value, fraExp.FixedRate, TOLERANCE);
		assertEquals(explain.get(ExplainKey.PAY_OFF_RATE).Value, FORWARD_RATE, TOLERANCE);
		assertEquals(explain.get(ExplainKey.COMBINED_RATE).Value, FORWARD_RATE, TOLERANCE);
		assertEquals(explain.get(ExplainKey.UNIT_AMOUNT).Value, fvExpected.Amount / fraExp.Notional, TOLERANCE);
		assertEquals(explain.get(ExplainKey.FORECAST_VALUE).get().Currency, currency);
		assertEquals(explain.get(ExplainKey.FORECAST_VALUE).get().Amount, fvExpected.Amount, TOLERANCE);
		assertEquals(explain.get(ExplainKey.PRESENT_VALUE).get().Currency, currency);
		assertEquals(explain.get(ExplainKey.PRESENT_VALUE).get().Amount, pvExpected.Amount, TOLERANCE);

		// test via FraTrade
		DiscountingFraTradePricer testTrade = new DiscountingFraTradePricer(test);
		assertEquals(testTrade.explainPresentValue(RFRA_TRADE, prov), test.explainPresentValue(RFRA, prov));
	  }
Esempio n. 15
0
        private void LoadDayRegisteredToBeModified()
        {
            DAYS diaReported = DaysDao.getDay(int.Parse(Request["Day"]));

            if (diaReported != null)
            {
                hdIdDayConfigured.Value   = diaReported.idDay.ToString();
                txtDateOfDay.Text         = ((DateTime)diaReported.completeDay).ToString("dd/MM/yyyy");
                ddlStateDay.SelectedValue = diaReported.state;
                int cont = 1;
                if (diaReported.DAYS_CONFIG != null && diaReported.DAYS_CONFIG.Count > 0)
                {
                    foreach (DAYS_CONFIG confDay in diaReported.DAYS_CONFIG)
                    {
                        HiddenField hdField = (HiddenField)FindControl("hdReport" + cont);
                        hdField.Value = confDay.idReportNum.ToString();

                        CheckBox cbField = (CheckBox)FindControl("CheckBox" + cont);
                        cbField.Checked = true;
                        cbField.Enabled = false;

                        TextBox lbl = (TextBox)FindControl("txtReport" + cont);
                        lbl.Text = confDay.name;

                        DropDownList ddl = (DropDownList)FindControl("ddlDataTypeReport" + cont);
                        ddl.SelectedValue = confDay.dataType;

                        TextBox txtDesc = (TextBox)FindControl("txtDescription" + cont);
                        txtDesc.Text = confDay.description;

                        HtmlAnchor anchorDel = (HtmlAnchor)FindControl("anchorDelete" + cont);
                        anchorDel.Visible = true;
                        anchorDel.HRef    = "javascript:DeleteExercise(" + confDay.idReportNum.ToString() + ");";

                        cont++;
                    }
                }
            }
        }
Esempio n. 16
0
        // explain PV for an accrual period, ignoring compounding
        private void explainPresentValue(RateAccrualPeriod accrualPeriod, DayCount dayCount, Currency currency, double notional, RatesProvider provider, ExplainMapBuilder builder)
        {
            double rawRate    = rateComputationFn.explainRate(accrualPeriod.RateComputation, accrualPeriod.StartDate, accrualPeriod.EndDate, provider, builder);
            double payOffRate = rawRate * accrualPeriod.Gearing + accrualPeriod.Spread;
            double ua         = unitNotionalAccrual(accrualPeriod, accrualPeriod.Spread, provider);

            // Note that the forecast value is not published since this is potentially misleading when
            // compounding is being applied, and when it isn't then it's the same as the forecast
            // value of the payment period.

            builder.put(ExplainKey.ENTRY_TYPE, "AccrualPeriod");
            builder.put(ExplainKey.START_DATE, accrualPeriod.StartDate);
            builder.put(ExplainKey.UNADJUSTED_START_DATE, accrualPeriod.UnadjustedStartDate);
            builder.put(ExplainKey.END_DATE, accrualPeriod.EndDate);
            builder.put(ExplainKey.UNADJUSTED_END_DATE, accrualPeriod.UnadjustedEndDate);
            builder.put(ExplainKey.ACCRUAL_YEAR_FRACTION, accrualPeriod.YearFraction);
            builder.put(ExplainKey.ACCRUAL_DAYS, dayCount.days(accrualPeriod.StartDate, accrualPeriod.EndDate));
            builder.put(ExplainKey.DAYS, (int)DAYS.between(accrualPeriod.StartDate, accrualPeriod.EndDate));
            builder.put(ExplainKey.GEARING, accrualPeriod.Gearing);
            builder.put(ExplainKey.SPREAD, accrualPeriod.Spread);
            builder.put(ExplainKey.PAY_OFF_RATE, accrualPeriod.NegativeRateMethod.adjust(payOffRate));
            builder.put(ExplainKey.UNIT_AMOUNT, ua);
        }
Esempio n. 17
0
        public static bool saveNewDay(int day, string date, string state)
        {
            bool resp = false;

            try
            {
                using (goliazco_FWEntities entity = new goliazco_FWEntities())
                {
                    DAYS     newDay  = new DAYS();
                    string[] formats = { "dd/MM/yyyy" };
                    newDay.Day         = day;
                    newDay.completeDay = DateTime.ParseExact(date, formats, new CultureInfo("en-US"), DateTimeStyles.None);
                    newDay.state       = state;
                    entity.DAYS.Add(newDay);
                    entity.SaveChanges();
                    resp = true;
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            return(resp);
        }
            /// <summary>
            /// Data is not held for weekends.
            /// </summary>
//JAVA TO C# CONVERTER TODO TASK: Enum value-specific class bodies are not converted by Java to C# Converter:
            public static readonly DenseTimeSeriesCalculation SKIP_WEEKENDS = new DenseTimeSeriesCalculation()
            {
                int calculatePosition(java.time.LocalDate startDate, java.time.LocalDate date)
                {
                    int unadjusted        = (int)DAYS.between(startDate, date);
                    int weekendAdjustment = startDate.getDayOfWeek().compareTo(date.getDayOfWeek()) > 0 ? 1 : 0;
                    int numWeekends       = (unadjusted / 7) + weekendAdjustment;

                    return(unadjusted - (2 * numWeekends));
                }

                java.time.LocalDate calculateDateFromPosition(java.time.LocalDate startDate, int position)
                {
                    int numWeekends        = position / 5;
                    int remaining          = position % 5;
                    int endPointAdjustment = (remaining < (6 - startDate.get(DAY_OF_WEEK))) ? 0 : 2;

                    return(startDate.plusDays((7 * numWeekends) + remaining + endPointAdjustment));
                }

                boolean allowsDate(java.time.LocalDate date)
                {
                    return(!isWeekend(date));
                }
        /// <summary> 转换成_historyproduction.dat </summary>
        public List <NAME> ConvertToHistoryProduction(List <string> wells, List <TIME> times)
        {
            List <NAME> names = new List <NAME>();

            //  初始化名称
            wells.ForEach(l => names.Add(new NAME("NAME")
            {
                WellName = l
            }));

            foreach (var n in names)
            {
                //  查找包含井名的时间步
                var findTimes = times.FindAll(l => l.Find <WELLCTRL>() != null && l.Find <WELLCTRL>().WellName0 == n.WellName);

                DAYS days = new DAYS("DAYS");
                n.Add(days);

                foreach (var item in findTimes)
                {
                    DAYS.Item it = new DAYS.Item();
                    it.Time0 = item.Date;
                    days.Items.Add(it);

                    WELLCTRL well = item.Find <WELLCTRL>();

                    switch (well.ProType)
                    {
                    case SimONProductType.BHP:
                        break;

                    case SimONProductType.WRAT:
                        it.Csl1 = well.Jcyblxz2;
                        break;

                    case SimONProductType.GRAT:
                        it.Cql2 = well.Jcyblxz2;
                        break;

                    case SimONProductType.ORAT:
                        it.Cyl3 = well.Jcyblxz2;
                        break;

                    case SimONProductType.LRAT:
                        it.Cyl7 = well.Jcyblxz2;
                        break;

                    case SimONProductType.WIR:
                        it.Zsl4 = well.Jcyblxz2;
                        break;

                    case SimONProductType.GIR:
                        it.Zql5 = well.Jcyblxz2;
                        break;

                    case SimONProductType.WIBHP:
                        it.Zsl4 = well.Jcyblxz2;
                        break;

                    case SimONProductType.GIBHP:
                        it.Zql5 = well.Jcyblxz2;
                        break;

                    case SimONProductType.SHUT:                           // 关井
                        break;

                    default:
                        break;
                    }
                }
            }

            return(names);
        }
Esempio n. 20
0
        //-------------------------------------------------------------------------
        public InterpolatedNodalCurveDefinition filtered(LocalDate valuationDate, ReferenceData refData)
        {
            // mutable list of date-node pairs
//JAVA TO C# CONVERTER TODO TASK: Method reference constructor syntax is not converted by Java to C# Converter:
//JAVA TO C# CONVERTER TODO TASK: Most Java stream collectors are not converted by Java to C# Converter:
            List <Pair <LocalDate, CurveNode> > nodeDates = nodes.Select(node => Pair.of(node.date(valuationDate, refData), node)).collect(toCollection(List <object>::new));

            // delete nodes if clash, but don't throw exceptions yet
            for (int i = 0; i < nodeDates.Count; i++)
            {
                Pair <LocalDate, CurveNode> pair        = nodeDates[i];
                CurveNodeDateOrder          restriction = pair.Second.DateOrder;
                // compare node to previous node
                if (i > 0)
                {
                    Pair <LocalDate, CurveNode> pairBefore = nodeDates[i - 1];
                    if (DAYS.between(pairBefore.First, pair.First) < restriction.MinGapInDays)
                    {
                        switch (restriction.Action)
                        {
                        case DROP_THIS:
                            nodeDates.RemoveAt(i);
                            i = -1;       // restart loop
                            goto loopContinue;

                        case DROP_OTHER:
                            nodeDates.RemoveAt(i - 1);
                            i = -1;       // restart loop
                            goto loopContinue;

                        case EXCEPTION:
                            break;       // do nothing yet
                            break;
                        }
                    }
                }
                // compare node to next node
                if (i < nodeDates.Count - 1)
                {
                    Pair <LocalDate, CurveNode> pairAfter = nodeDates[i + 1];
                    if (DAYS.between(pair.First, pairAfter.First) < restriction.MinGapInDays)
                    {
                        switch (restriction.Action)
                        {
                        case DROP_THIS:
                            nodeDates.Remove(i);
                            i = -1;       // restart loop
                            goto loopContinue;

                        case DROP_OTHER:
                            nodeDates.Remove(i + 1);
                            i = -1;       // restart loop
                            goto loopContinue;

                        case EXCEPTION:
                            break;       // do nothing yet
                            break;
                        }
                    }
                }
                loopContinue :;
            }
            loopBreak :
            // throw exceptions if rules breached
            for (int i = 0; i < nodeDates.Count; i++)
            {
                Pair <LocalDate, CurveNode> pair        = nodeDates[i];
                CurveNodeDateOrder          restriction = pair.Second.DateOrder;
                // compare node to previous node
                if (i > 0)
                {
                    Pair <LocalDate, CurveNode> pairBefore = nodeDates[i - 1];
                    if (DAYS.between(pairBefore.First, pair.First) < restriction.MinGapInDays)
                    {
                        throw new System.ArgumentException(Messages.format("Curve node dates clash, node '{}' and '{}' resolved to dates '{}' and '{}' respectively", pairBefore.Second.Label, pair.Second.Label, pairBefore.First, pair.First));
                    }
                }
                // compare node to next node
                if (i < nodeDates.Count - 1)
                {
                    Pair <LocalDate, CurveNode> pairAfter = nodeDates[i + 1];
                    if (DAYS.between(pair.First, pairAfter.First) < restriction.MinGapInDays)
                    {
                        throw new System.ArgumentException(Messages.format("Curve node dates clash, node '{}' and '{}' resolved to dates '{}' and '{}' respectively", pair.Second.Label, pairAfter.Second.Label, pair.First, pairAfter.First));
                    }
                }
            }
            // return the resolved definition
//JAVA TO C# CONVERTER TODO TASK: Most Java stream collectors are not converted by Java to C# Converter:
            IList <CurveNode> filteredNodes = nodeDates.Select(p => p.Second).collect(toImmutableList());

            return(new InterpolatedNodalCurveDefinition(name, xValueType, yValueType, dayCount, filteredNodes, interpolator, extrapolatorLeft, extrapolatorRight));
        }
Esempio n. 21
0
        private void ArmarTable()
        {
            //DAYS excerciseForDay = DaysDao.getDay(int.Parse(ddlDay.SelectedValue));
            DAYS excerciseForDay = DaysDao.getDay(1);

            if (Users != null)
            {
                DataTable tabla = new DataTable("Usuarios");

                DataColumn dtColumnIdUser = new DataColumn("idUser");
                tabla.Columns.Add(dtColumnIdUser);

                DataColumn dtName = new DataColumn("name");
                tabla.Columns.Add(dtName);

                DataColumn dtAge = new DataColumn("age");
                tabla.Columns.Add(dtAge);
                DataColumn dtGender = new DataColumn("gender");
                tabla.Columns.Add(dtGender);
                DataColumn dtNationality = new DataColumn("nationality");
                tabla.Columns.Add(dtNationality);
                DataColumn dtEmail = new DataColumn("email");
                tabla.Columns.Add(dtEmail);
                DataColumn dtPass = new DataColumn("pass");
                tabla.Columns.Add(dtPass);
                DataColumn dtHades = new DataColumn("hades_pb");
                tabla.Columns.Add(dtHades);
                DataColumn dtPoseidon = new DataColumn("poseidon_pb");
                tabla.Columns.Add(dtPoseidon);
                DataColumn dtVenus = new DataColumn("venus_pb");
                tabla.Columns.Add(dtVenus);

                if (excerciseForDay != null && excerciseForDay.DAYS_CONFIG != null && excerciseForDay.DAYS_CONFIG.Count > 0)
                {
                    List <DAYS_CONFIG> excer = excerciseForDay.DAYS_CONFIG.ToList();
                    for (int i = 0; i < excer.Count; i++)
                    {
                        DataColumn column = new DataColumn(excer[i].name + " " + excer[i].dataType);

                        BoundField columna = new BoundField();
                        columna.DataField      = excer[i].name + " " + excer[i].dataType;
                        columna.HeaderText     = excer[i].name + " " + excer[i].dataType;
                        columna.SortExpression = excer[i].name + " " + excer[i].dataType;
                        gvUsuarios.Columns.Add(columna);

                        tabla.Columns.Add(column);
                    }
                }


                for (int j = 0; j < Users.Count; j++)
                {
                    DataRow dw = tabla.NewRow();
                    dw.SetField("idUser", Users[j].idUser);
                    dw.SetField("name", Users[j].name);
                    dw.SetField("age", Users[j].age);
                    dw.SetField("gender", Users[j].gender);
                    dw.SetField("nationality", Users[j].nationality);
                    dw.SetField("email", Users[j].email);
                    dw.SetField("pass", Users[j].pass);
                    dw.SetField("hades_pb", Users[j].hades_pb);
                    dw.SetField("poseidon_pb", Users[j].poseidon_pb);
                    dw.SetField("venus_pb", Users[j].venus_pb);
                    //if (Users[j].DAYS_REPORT != null && Users[j].DAYS_REPORT.Count > 0)
                    //{
                    DAYS_REPORT diaSolicitado = UserDao.getDiaReportado(Users[j].idUser, 1);
                    if (diaSolicitado != null)
                    {
                        List <REPORT_DAY> diasReportados = DaysDao.getDiasReportados(diaSolicitado.idRegister);
                        for (int i = 0; i < diasReportados.Count; i++)
                        {
                            dw.SetField(diasReportados[i].Name + " " + diasReportados[i].DataInform, diasReportados[i].Inform);
                        }
                    }
                    //}
                    tabla.Rows.Add(dw);
                }

                //TablaUsuarios = tabla;
                //gvUsuarios.DataSource = TablaUsuarios;
                //gvUsuarios.DataBind();
            }
        }
Esempio n. 22
0
        /// <summary> 转换成SimON格式的项 </summary>
        public WELLCTRL ConvertToSimON(OPT.Product.SimalorManager.Item item, DATES date, List <NAME> histNames)
        {
            WELLCTRL well = new WELLCTRL("WELLCTRL");

            if (item is WCONPROD.ItemHY)
            {
                WCONPROD.ItemHY nIt = item as WCONPROD.ItemHY;

                #region - 转换历史数据 -

                NAME name = histNames.Find(l => l.WellName == nIt.jm0);

                if (name == null)
                {
                    LogProviderHandler.Instance.OnRunLog("当前日期:" + date.DateTime + "井" + nIt.jm0 + "未找到对应的历史信息!");
                    return(null);
                }


                DAYS days = name.Find <DAYS>();

                if (days == null)
                {
                    days = new DAYS("DAYS");
                    name.Add(days);
                }
                DAYS.Item dayitem = new DAYS.Item();
                dayitem.Time0 = date.DateTime;
                dayitem.Csl1  = nIt.rcsl4;
                dayitem.Cql2  = nIt.rcql5;
                dayitem.Cyl3  = nIt.rcyl3;
                dayitem.Cyl7  = nIt.liqutPro6;
                days.Items.Add(dayitem);

                #endregion

                #region - 转换数模数据 -

                well.WellName0 = nIt.jm0;
                well.Jcyblxz2  = nIt.rcsl4;

                //  产水
                if (nIt.kzms2 == "WATER")
                {
                    well.Jcyblxz2 = nIt.rcsl4;
                    well.ProType  = SimONProductType.WRAT;
                }
                if (nIt.kzms2 == "GRAT")
                {
                    //  产气
                    well.Jcyblxz2 = nIt.rcql5;
                    well.ProType  = SimONProductType.GRAT;
                }
                if (nIt.kzms2 == "ORAT")
                {
                    //  产油
                    well.Jcyblxz2 = nIt.rcyl3;
                    well.ProType  = SimONProductType.ORAT;
                }

                if (nIt.kzms2 == "LRAT")
                {
                    //  产液
                    well.Jcyblxz2 = (nIt.rcyl3.ToDouble() + nIt.rcsl4.ToDouble()).ToString();
                    well.ProType  = SimONProductType.LRAT;
                }
                #endregion
            }
            else if (item is WCONHIST.Item)
            {
                WCONHIST.Item nIt = item as WCONHIST.Item;

                #region - 转换历史数据 -

                NAME name = histNames.Find(l => l.WellName == nIt.wellName0);

                if (name == null)
                {
                    LogProviderHandler.Instance.OnRunLog("当前日期:" + date.DateTime + "井" + nIt.wellName0 + "未找到对应的历史信息!");
                    return(well);
                }
                DAYS days = name.Find <DAYS>();

                if (days == null)
                {
                    days = new DAYS("DAYS");
                    name.Add(days);
                }
                DAYS.Item dayitem = new DAYS.Item();
                dayitem.Time0 = date.DateTime;
                dayitem.Csl1  = nIt.waterPro4;
                dayitem.Cql2  = nIt.gasPro5;
                dayitem.Cyl3  = nIt.oilPro3;
                dayitem.Cyl7  = (nIt.waterPro4.ToDouble() + nIt.oilPro3.ToDouble()).ToString();
                days.Items.Add(dayitem);

                #endregion

                #region - 转换数模数据 -

                well.WellName0 = nIt.wellName0;
                well.Jcyblxz2  = nIt.waterPro4;


                //  产水
                if (nIt.ctrlModel2 == "WATER")
                {
                    well.Jcyblxz2 = nIt.waterPro4;
                    well.ProType  = SimONProductType.WRAT;
                }
                if (nIt.ctrlModel2 == "GRAT")
                {
                    //  产气
                    well.Jcyblxz2 = nIt.gasPro5;
                    well.ProType  = SimONProductType.GRAT;
                }
                if (nIt.ctrlModel2 == "ORAT")
                {
                    //  产油
                    well.Jcyblxz2 = nIt.oilPro3;
                    well.ProType  = SimONProductType.ORAT;
                }

                if (nIt.ctrlModel2 == "LRAT")
                {
                    //  产液
                    well.Jcyblxz2 = (nIt.waterPro4.ToDouble() + nIt.oilPro3.ToDouble()).ToString();
                    well.ProType  = SimONProductType.LRAT;
                }
                #endregion
            }

            else if (item is WCONINJE.ItemHY)
            {
                WCONINJE.ItemHY nIt = item as WCONINJE.ItemHY;

                #region - 转换历史数据 -

                NAME name = histNames.Find(l => l.WellName == nIt.jm0);

                if (name == null)
                {
                    LogProviderHandler.Instance.OnRunLog("当前日期:" + date.DateTime + "井" + nIt.jm0 + "未找到对应的历史信息!");
                    return(well);
                }


                DAYS days = name.Find <DAYS>();

                if (days == null)
                {
                    days = new DAYS("DAYS");
                    name.Add(days);
                }
                DAYS.Item dayitem = new DAYS.Item();
                dayitem.Time0 = date.DateTime;

                if (nIt.zrltlx1 == "WATER")
                {
                    dayitem.Zsl4 = nIt.rzrl4;
                }
                else
                {
                    dayitem.Zql5 = nIt.rzrl4;
                }

                days.Items.Add(dayitem);

                #endregion

                #region - 转换数模数据 -

                well.WellName0 = nIt.jm0;


                if (nIt.zrltlx1 == "WATER")
                {
                    //well.Jcyblxz2 = nIt.rzrl4;
                    well.Jcyblxz2 = nIt.rzrl4;
                    well.ProType  = SimONProductType.WIR;
                }
                else
                {
                    //well.Jcyblxz2 = nIt.rzrl4;
                    //well.Jkkz1 = "6";

                    well.Jcyblxz2 = nIt.rzrl4;
                    well.ProType  = SimONProductType.GIR;
                }

                #endregion
            }
            else if (item is WCONINJH.Item)
            {
                WCONINJH.Item nIt = item as WCONINJH.Item;

                #region - 转换历史数据 -

                NAME name = histNames.Find(l => l.WellName == nIt.jm0);

                if (name == null)
                {
                    LogProviderHandler.Instance.OnRunLog("当前日期:" + date.DateTime + "井" + nIt.jm0 + "未找到对应的历史信息!");
                    return(well);
                }


                DAYS days = name.Find <DAYS>();

                if (days == null)
                {
                    days = new DAYS("DAYS");
                    name.Add(days);
                }
                DAYS.Item dayitem = new DAYS.Item();
                dayitem.Time0 = date.DateTime;

                if (nIt.zrltlx1 == "WATER")
                {
                    dayitem.Zsl4 = nIt.rzrl3;
                }
                else
                {
                    dayitem.Zql5 = nIt.rzrl3;
                }

                days.Items.Add(dayitem);

                #endregion

                #region - 转换数模数据 -

                well.WellName0 = nIt.jm0;

                if (nIt.zrltlx1 == "WATER")
                {
                    well.Jcyblxz2 = nIt.rzrl3;
                    //well.Jkkz1 = "7";
                    well.ProType = SimONProductType.WIBHP;
                }
                else
                {
                    well.Jcyblxz2 = nIt.rzrl3;
                    //well.Jkkz1 = "8";
                    well.ProType = SimONProductType.GIBHP;
                }

                #endregion
            }

            return(well);
        }
 static void PrintDay(DAYS d)
 {
     Console.WriteLine(d.ToString());
 }