Java Code Examples for java.time.LocalDate#isEqual()
The following examples show how to use
java.time.LocalDate#isEqual() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UpdateTime.java From iliasDownloaderTool with GNU General Public License v2.0 | 6 votes |
@Override public String toString() { if (this.lastUpdateTime == null) { return DEFAULT_VALUE; } final LocalDate today = LocalDate.now(); final LocalDate lastUpdateDay = LocalDate.from(this.lastUpdateTime); String prefix = ""; String pattern = "HH:mm"; final boolean lastUpdateWasToday = today.isEqual(lastUpdateDay); final boolean lastUpdateWasYesterday = today.minusDays(1).isEqual(lastUpdateDay); if (lastUpdateWasToday) { prefix = "Heute, "; } else if (lastUpdateWasYesterday) { prefix = "Gestern, "; } else { pattern = "EEEE d. MMMM, HH:mm"; } String formattedTime = this.lastUpdateTime.format(DateTimeFormatter.ofPattern(pattern)); return "Letzte Aktualisierung: " + prefix + formattedTime; }
Example 2
Source File: LeaveServiceImpl.java From axelor-open-suite with GNU Affero General Public License v3.0 | 6 votes |
public LeaveRequest getLeave(User user, LocalDate date) { List<LeaveRequest> leaves = JPA.all(LeaveRequest.class) .filter("self.user = :userId AND self.statusSelect IN (:awaitingValidation,:validated)") .bind("userId", user) .bind("awaitingValidation", LeaveRequestRepository.STATUS_AWAITING_VALIDATION) .bind("validated", LeaveRequestRepository.STATUS_VALIDATED) .fetch(); if (ObjectUtils.notEmpty(leaves)) { for (LeaveRequest leave : leaves) { LocalDate from = leave.getFromDateT().toLocalDate(); LocalDate to = leave.getToDateT().toLocalDate(); if ((from.isBefore(date) && to.isAfter(date)) || from.isEqual(date) || to.isEqual(date)) { return leave; } } } return null; }
Example 3
Source File: DateTimes.java From eas-ddd with Apache License 2.0 | 5 votes |
public static boolean isValidFormat(String dateString, LocalDate minDate, LocalDate maxDate) { DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyyMMdd"); try { LocalDate date = LocalDate.parse(dateString, dateFormatter); return date.isAfter(minDate) && (date.isBefore(maxDate) || date.isEqual(maxDate)); } catch (DateTimeParseException ex) { return false; } }
Example 4
Source File: DiscountingCapitalIndexedBondTradePricer.java From Strata with Apache License 2.0 | 5 votes |
/** * Calculates the present value sensitivity of the settlement of the bond trade from the real clean price. * <p> * The present value sensitivity of the settlement is the sensitivity of the present value to * the underlying curves. * * @param trade the trade * @param ratesProvider the rates provider, used to determine price index values * @param refData the reference data used to calculate the settlement date * @param discountingProvider the discount factors provider * @param cleanRealPrice the clean real price * @return the present value sensitivity of the settlement */ public PointSensitivities presentValueSensitivityFromCleanPrice( ResolvedCapitalIndexedBondTrade trade, RatesProvider ratesProvider, LegalEntityDiscountingProvider discountingProvider, ReferenceData refData, double cleanRealPrice) { validate(ratesProvider, discountingProvider); LocalDate valuationDate = ratesProvider.getValuationDate(); ResolvedCapitalIndexedBond bond = trade.getProduct(); LocalDate standardSettlementDate = bond.calculateSettlementDateFromValuation(valuationDate, refData); LocalDate tradeSettlementDate = settlementDate(trade, valuationDate); RepoCurveDiscountFactors repoDf = DiscountingCapitalIndexedBondProductPricer.repoCurveDf(bond, discountingProvider); double df = repoDf.discountFactor(standardSettlementDate); PointSensitivityBuilder dfSensi = repoDf.zeroRatePointSensitivity(standardSettlementDate); PointSensitivityBuilder pvSensiStandard = forecastValueSensitivityStandardFromCleanPrice(bond, ratesProvider, standardSettlementDate, cleanRealPrice).multipliedBy(df).combinedWith(dfSensi.multipliedBy( forecastValueStandardFromCleanPrice(bond, ratesProvider, standardSettlementDate, cleanRealPrice) .getAmount())); if (standardSettlementDate.isEqual(tradeSettlementDate)) { return presentValueSensitivityFromProductPresentValueSensitivity( trade, ratesProvider, discountingProvider, pvSensiStandard).build(); } // check coupon payment between two settlement dates IssuerCurveDiscountFactors issuerDf = DiscountingCapitalIndexedBondProductPricer.issuerCurveDf(bond, discountingProvider); PointSensitivityBuilder pvSensiDiff = PointSensitivityBuilder.none(); if (standardSettlementDate.isAfter(tradeSettlementDate)) { pvSensiDiff = pvSensiDiff.combinedWith(productPricer.presentValueSensitivityCoupon(bond, ratesProvider, issuerDf, tradeSettlementDate, standardSettlementDate).multipliedBy(-1d)); } else { pvSensiDiff = pvSensiDiff.combinedWith(productPricer.presentValueSensitivityCoupon(bond, ratesProvider, issuerDf, standardSettlementDate, tradeSettlementDate)); } return presentValueSensitivityFromProductPresentValueSensitivity( trade, ratesProvider, discountingProvider, pvSensiStandard.combinedWith(pvSensiDiff)).build(); }
Example 5
Source File: ProgramIncrementServiceImpl.java From mirrorgate with Apache License 2.0 | 5 votes |
private boolean findIfLocalDateIsInRange(final String date1, final String date2) { final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd"); final LocalDate dateTime1 = LocalDate.parse(date1, formatter); final LocalDate dateTime2 = LocalDate.parse(date2, formatter); final LocalDate now = LocalDate.now(); return (now.isEqual(dateTime1) || now.isEqual(dateTime2)) || (dateTime1.isBefore(now) && dateTime2.isAfter(now)); }
Example 6
Source File: CoverageComparator.java From elexis-3-core with Eclipse Public License 1.0 | 5 votes |
@Override public int compare(Object o1, Object o2) { int comp = 0; if (o1 instanceof ICoverage && o2 instanceof ICoverage) { ICoverage coverage1 = (ICoverage) o1; ICoverage coverage2 = (ICoverage) o2; // compare gesetz boolean is1Closed = !coverage1.isOpen(); boolean is2Closed = !coverage2.isOpen(); comp = ObjectUtils.compare(is1Closed, is2Closed); if (comp == 0) { String systemName1 = coverage1.getBillingSystem() != null ? coverage1.getBillingSystem().getName() : null; String systemName2 = coverage2.getBillingSystem() != null ? coverage2.getBillingSystem().getName() : null; comp = ObjectUtils.compare(systemName1, systemName2); if (comp == 0) { // compare beginn date LocalDate t1 = coverage1.getDateFrom(); LocalDate t2 = coverage2.getDateFrom(); if (t1 != null && t2 != null) { comp = t1.isEqual(t2) ? 0 : (t1.isBefore(t2) ? 1 : -1); if (comp == 0) { comp = ObjectUtils.compare(coverage1.getDescription(), coverage2.getDescription()); if (comp == 0) { comp = ObjectUtils.compare(coverage1.getId(), coverage2.getId()); } } } } } } return comp; }
Example 7
Source File: TreatmentMatcher.java From hmftools with GNU General Public License v3.0 | 5 votes |
private static boolean isPossibleMatch(@NotNull BiopsyData biopsy, @NotNull LocalDate treatmentStartDate) { LocalDate biopsyDate = biopsy.date(); return biopsyDate != null && (treatmentStartDate.isAfter(biopsyDate) || treatmentStartDate.isEqual(biopsyDate)) && Duration.between(biopsyDate.atStartOfDay(), treatmentStartDate.atStartOfDay()).toDays() < Config.MAX_DAYS_BETWEEN_TREATMENT_AND_BIOPSY; }
Example 8
Source File: DiscountingCapitalIndexedBondTradePricer.java From Strata with Apache License 2.0 | 5 votes |
/** * Calculates the present value of the bond trade from the clean price. * <p> * Since the sign of the settlement notional is opposite to that of the product, negative amount will be returned * for positive quantity of trade. * * @param trade the trade * @param ratesProvider the rates provider, used to determine price index values * @param refData the reference data used to calculate the settlement date * @param discountingProvider the discount factors provider * @param cleanRealPrice the clean real price * @return the present value of the settlement */ public CurrencyAmount presentValueFromCleanPrice( ResolvedCapitalIndexedBondTrade trade, RatesProvider ratesProvider, LegalEntityDiscountingProvider discountingProvider, ReferenceData refData, double cleanRealPrice) { validate(ratesProvider, discountingProvider); LocalDate valuationDate = ratesProvider.getValuationDate(); ResolvedCapitalIndexedBond bond = trade.getProduct(); LocalDate standardSettlementDate = bond.calculateSettlementDateFromValuation(valuationDate, refData); LocalDate tradeSettlementDate = settlementDate(trade, valuationDate); RepoCurveDiscountFactors repoDf = DiscountingCapitalIndexedBondProductPricer.repoCurveDf(bond, discountingProvider); double df = repoDf.discountFactor(standardSettlementDate); CurrencyAmount pvStandard = forecastValueStandardFromCleanPrice( bond, ratesProvider, standardSettlementDate, cleanRealPrice).multipliedBy(df); if (standardSettlementDate.isEqual(tradeSettlementDate)) { return presentValueFromProductPresentValue(trade, ratesProvider, discountingProvider, pvStandard); } // check coupon payment between two settlement dates IssuerCurveDiscountFactors issuerDf = DiscountingCapitalIndexedBondProductPricer.issuerCurveDf(bond, discountingProvider); double pvDiff = 0d; if (standardSettlementDate.isAfter(tradeSettlementDate)) { pvDiff = -productPricer.presentValueCoupon(bond, ratesProvider, issuerDf, tradeSettlementDate, standardSettlementDate); } else { pvDiff = productPricer.presentValueCoupon(bond, ratesProvider, issuerDf, standardSettlementDate, tradeSettlementDate); } return presentValueFromProductPresentValue( trade, ratesProvider, discountingProvider, pvStandard.plus(pvDiff)); }
Example 9
Source File: ExtractProjectCommitsAdapter.java From coderadar with MIT License | 5 votes |
/** * @param range Date range to test for * @param rc RevCommit to check * @return True if the commit was made within the date range, false otherwise. */ private boolean isInDateRange(DateRange range, RevCommit rc) { LocalDate commitTime = Instant.ofEpochSecond(rc.getCommitTime()).atZone(ZoneId.systemDefault()).toLocalDate(); return (commitTime.isBefore(range.getEndDate()) || commitTime.isEqual(range.getEndDate())) && (commitTime.isAfter(range.getStartDate()) || commitTime.isEqual(range.getStartDate())); }
Example 10
Source File: Qualifier.java From HubTurbo with GNU Lesser General Public License v3.0 | 5 votes |
private boolean satisfiesCreationDate(TurboIssue issue) { LocalDate creationDate = issue.getCreatedAt().toLocalDate(); if (date.isPresent()) { return creationDate.isEqual(date.get()); } else if (dateRange.isPresent()) { return dateRange.get().encloses(creationDate); } else { throw new SemanticException(type); } }
Example 11
Source File: VulnerabilityService.java From pacbot with Apache License 2.0 | 4 votes |
public void useRealTimeDataForLatestDate(List<Map<String, Object>> trendList, String ag, String trendCategory, String ruleId, String domain) throws ServiceException { Map<String, Object> latestDaysTrendData = new HashMap<>(trendList.get(trendList.size() - 1)); Map<String, Long> baseApiReturnMap = new HashMap<>(); Map<String, Object> overallCompliance = new HashMap<>(); long compliantQuantity = 0; long noncompliantQuantity = 0; long total = 0; double compliance; LocalDate today; try { switch (trendCategory) { case "vulncompliance": Map<String, Object> vulnSummary = getVulnerabilitySummary(ag, SEVERITY_LEVELS); total = Long.valueOf(vulnSummary.get("hosts").toString()); noncompliantQuantity = Long.valueOf(vulnSummary.get("totalVulnerableAssets").toString()); compliantQuantity = total - noncompliantQuantity; latestDaysTrendData.put(COMPLAINT, compliantQuantity); latestDaysTrendData.put(NON_COMPLIANT, noncompliantQuantity); latestDaysTrendData.put(TOTAL, total); if (total > 0) { compliance = Math.floor(compliantQuantity * HUNDRED / total); } else { compliance = INT_HUNDRED; } latestDaysTrendData.put(COMPLIANCE_PERCENT, compliance); break; default: // nothings } // Check if the trend already has todays data (Compare dates) // If yes, overwrite. If not, add at the end. LocalDate date = null; today = LocalDate.now(); date = LocalDate.parse(latestDaysTrendData.get("date").toString(), DateTimeFormatter.ISO_LOCAL_DATE); if (date.isEqual(today)) { logger.info("Latest days data available in trend data, so overwriting"); trendList.set(trendList.size() - 1, latestDaysTrendData); } else if (date.isEqual(today.minusDays(1))) { // Ideally we need to consider this case only else, we may // unnecessarily append wrong data. FOr eg. In case of patching // if any previous/ progress is requested. logger.info("Latest days data is NOT available in trend data, so adding at the end"); latestDaysTrendData.put("date", today.format(DateTimeFormatter.ISO_LOCAL_DATE)); trendList.add(latestDaysTrendData); } } catch (ServiceException e) { logger.error("Call to Base API to get todays data failed", e); return; } }
Example 12
Source File: DateTool.java From axelor-open-suite with GNU Affero General Public License v3.0 | 4 votes |
private static int days360Between(LocalDate startDate, LocalDate endDate) { int nbDayOfFirstMonth = 0; int nbDayOfOthersMonths = 0; int nbDayOfLastMonth = 0; LocalDate start = startDate; if (endDate.getMonthValue() != startDate.getMonthValue() || endDate.getYear() != startDate.getYear()) { // First month :: if the startDate is not the last day of the month if (!startDate.isEqual(startDate.withDayOfMonth(startDate.lengthOfMonth()))) { nbDayOfFirstMonth = 30 - startDate.getDayOfMonth(); } // The startDate is included nbDayOfFirstMonth = nbDayOfFirstMonth + 1; // Months between the first one and the last one LocalDate date1 = startDate.plusMonths(1).withDayOfMonth(1); while (endDate.getMonthValue() != date1.getMonthValue() || endDate.getYear() != date1.getYear()) { nbDayOfOthersMonths = nbDayOfOthersMonths + 30; date1 = date1.plusMonths(1); } // Last Month start = endDate.withDayOfMonth(1); } if (endDate.isEqual(endDate.withDayOfMonth(endDate.lengthOfMonth()))) { nbDayOfLastMonth = 30 - start.getDayOfMonth(); } else { nbDayOfLastMonth = endDate.getDayOfMonth() - start.getDayOfMonth(); } // The endDate is included nbDayOfLastMonth = nbDayOfLastMonth + 1; return nbDayOfFirstMonth + nbDayOfOthersMonths + nbDayOfLastMonth; }
Example 13
Source File: ForecastRecapService.java From axelor-open-suite with GNU Affero General Public License v3.0 | 4 votes |
public void populateWithSalaries(ForecastRecap forecastRecap) throws AxelorException { List<Employee> employeeList = new ArrayList<Employee>(); ForecastRecapLineType salaryForecastRecapLineType = this.getForecastRecapLineType(ForecastRecapLineTypeRepository.ELEMENT_SALARY); if (forecastRecap.getBankDetails() != null) { employeeList = Beans.get(EmployeeRepository.class) .all() .filter( "self.mainEmploymentContract.payCompany = ?1 AND self.bankDetails = ?2", forecastRecap.getCompany(), forecastRecap.getBankDetails()) .fetch(); } else { employeeList = Beans.get(EmployeeRepository.class) .all() .filter("self.mainEmploymentContract.payCompany = ?1", forecastRecap.getCompany()) .fetch(); } LocalDate itDate = LocalDate.parse(forecastRecap.getFromDate().toString(), DateTimeFormatter.ISO_DATE); while (!itDate.isAfter(forecastRecap.getToDate())) { LocalDate monthEnd = itDate.withDayOfMonth(itDate.lengthOfMonth()); if (itDate.isEqual(monthEnd)) { for (Employee employee : employeeList) { forecastRecap.addForecastRecapLineListItem( this.createForecastRecapLine( itDate, salaryForecastRecapLineType.getTypeSelect(), employee .getHourlyRate() .multiply(employee.getWeeklyWorkHours().multiply(new BigDecimal(4))), null, null, null, salaryForecastRecapLineType)); } itDate = itDate.plusMonths(1); } else { itDate = monthEnd; } } }
Example 14
Source File: LeaveServiceImpl.java From axelor-open-suite with GNU Affero General Public License v3.0 | 4 votes |
public BigDecimal computeLeaveDaysByLeaveRequest( LocalDate fromDate, LocalDate toDate, LeaveRequest leaveRequest, Employee employee) throws AxelorException { BigDecimal leaveDays = BigDecimal.ZERO; WeeklyPlanning weeklyPlanning = employee.getWeeklyPlanning(); LocalDate leaveFrom = leaveRequest.getFromDateT().toLocalDate(); LocalDate leaveTo = leaveRequest.getToDateT().toLocalDate(); LocalDate itDate = fromDate; if (fromDate.isBefore(leaveFrom) || fromDate.equals(leaveFrom)) { itDate = leaveFrom; } boolean morningHalf = false; boolean eveningHalf = false; BigDecimal daysToAdd = BigDecimal.ZERO; if (leaveTo.equals(leaveFrom) && leaveRequest.getStartOnSelect() == leaveRequest.getEndOnSelect()) { eveningHalf = leaveRequest.getStartOnSelect() == LeaveRequestRepository.SELECT_AFTERNOON; morningHalf = leaveRequest.getStartOnSelect() == LeaveRequestRepository.SELECT_MORNING; } while (!itDate.isEqual(leaveTo.plusDays(1)) && !itDate.isEqual(toDate.plusDays(1))) { if (itDate.equals(leaveFrom) && !morningHalf) { daysToAdd = BigDecimal.valueOf( computeStartDateWithSelect( itDate, leaveRequest.getStartOnSelect(), weeklyPlanning)); } else if (itDate.equals(leaveTo) && !eveningHalf) { daysToAdd = BigDecimal.valueOf( computeEndDateWithSelect(itDate, leaveRequest.getEndOnSelect(), weeklyPlanning)); } else { daysToAdd = BigDecimal.valueOf( weeklyPlanningService.getWorkingDayValueInDays(weeklyPlanning, itDate)); } if (!publicHolidayHrService.checkPublicHolidayDay(itDate, employee)) { leaveDays = leaveDays.add(daysToAdd); } itDate = itDate.plusDays(1); } return leaveDays; }
Example 15
Source File: LeaveServiceImpl.java From axelor-open-suite with GNU Affero General Public License v3.0 | 4 votes |
/** * Computes the duration in days of a leave, according to the input planning. * * @param leave * @param employee * @param fromDate * @param toDate * @param startOn * @param endOn * @return * @throws AxelorException */ protected BigDecimal computeDurationInDays( LeaveRequest leave, Employee employee, LocalDate fromDate, LocalDate toDate, int startOn, int endOn) throws AxelorException { BigDecimal duration = BigDecimal.ZERO; WeeklyPlanning weeklyPlanning = getWeeklyPlanning(leave, employee); EventsPlanning holidayPlanning = getPublicHolidayEventsPlanning(leave, employee); // If the leave request is only for 1 day if (fromDate.isEqual(toDate)) { if (startOn == endOn) { if (startOn == LeaveRequestRepository.SELECT_MORNING) { duration = duration.add( BigDecimal.valueOf( weeklyPlanningService.getWorkingDayValueInDaysWithSelect( weeklyPlanning, fromDate, true, false))); } else { duration = duration.add( BigDecimal.valueOf( weeklyPlanningService.getWorkingDayValueInDaysWithSelect( weeklyPlanning, fromDate, false, true))); } } else { duration = duration.add( BigDecimal.valueOf( weeklyPlanningService.getWorkingDayValueInDaysWithSelect( weeklyPlanning, fromDate, true, true))); } // Else if it's on several days } else { duration = duration.add( BigDecimal.valueOf(computeStartDateWithSelect(fromDate, startOn, weeklyPlanning))); LocalDate itDate = fromDate.plusDays(1); while (!itDate.isEqual(toDate) && !itDate.isAfter(toDate)) { duration = duration.add( BigDecimal.valueOf( weeklyPlanningService.getWorkingDayValueInDays(weeklyPlanning, itDate))); itDate = itDate.plusDays(1); } duration = duration.add(BigDecimal.valueOf(computeEndDateWithSelect(toDate, endOn, weeklyPlanning))); } if (holidayPlanning != null) { duration = duration.subtract( publicHolidayHrService.computePublicHolidayDays( fromDate, toDate, weeklyPlanning, holidayPlanning)); } return duration; }
Example 16
Source File: TestUpdateHighlightPolicy.java From LGoodDatePicker with MIT License | 4 votes |
@Override public boolean isDateAllowed(LocalDate someDate) { return someDate.isAfter(LocalDate.now()) || someDate.isEqual(LocalDate.now()); }
Example 17
Source File: DiscountingCapitalIndexedBondTradePricer.java From Strata with Apache License 2.0 | 4 votes |
/** * Calculates the present value of the settlement of the bond trade from the clean price with z-spread. * <p> * Since the sign of the settlement notional is opposite to that of the product, negative amount will be returned * for positive quantity of trade. * <p> * The z-spread is a parallel shift applied to continuously compounded rates or periodic * compounded rates of the discounting curve. * * @param trade the trade * @param ratesProvider the rates provider, used to determine price index values * @param discountingProvider the discount factors provider * @param refData the reference data used to calculate the settlement date * @param zSpread the z-spread * @param compoundedRateType the compounded rate type * @param periodsPerYear the number of periods per year * @param cleanRealPrice the clean real price * @return the present value of the settlement */ public CurrencyAmount presentValueFromCleanPriceWithZSpread( ResolvedCapitalIndexedBondTrade trade, RatesProvider ratesProvider, LegalEntityDiscountingProvider discountingProvider, ReferenceData refData, double cleanRealPrice, double zSpread, CompoundedRateType compoundedRateType, int periodsPerYear) { validate(ratesProvider, discountingProvider); LocalDate valuationDate = ratesProvider.getValuationDate(); ResolvedCapitalIndexedBond bond = trade.getProduct(); LocalDate standardSettlementDate = bond.calculateSettlementDateFromValuation(valuationDate, refData); LocalDate tradeSettlementDate = settlementDate(trade, valuationDate); RepoCurveDiscountFactors repoDf = DiscountingCapitalIndexedBondProductPricer.repoCurveDf(bond, discountingProvider); double df = repoDf.discountFactor(standardSettlementDate); CurrencyAmount pvStandard = forecastValueStandardFromCleanPrice( bond, ratesProvider, standardSettlementDate, cleanRealPrice).multipliedBy(df); if (standardSettlementDate.isEqual(tradeSettlementDate)) { return presentValueFromProductPresentValue(trade, ratesProvider, discountingProvider, pvStandard); } // check coupon payment between two settlement dates IssuerCurveDiscountFactors issuerDf = DiscountingCapitalIndexedBondProductPricer.issuerCurveDf(bond, discountingProvider); double pvDiff = 0d; if (standardSettlementDate.isAfter(tradeSettlementDate)) { pvDiff = -productPricer.presentValueCouponWithZSpread( bond, ratesProvider, issuerDf, tradeSettlementDate, standardSettlementDate, zSpread, compoundedRateType, periodsPerYear); } else { pvDiff = productPricer.presentValueCouponWithZSpread( bond, ratesProvider, issuerDf, standardSettlementDate, tradeSettlementDate, zSpread, compoundedRateType, periodsPerYear); } return presentValueFromProductPresentValue( trade, ratesProvider, discountingProvider, pvStandard.plus(pvDiff)); }
Example 18
Source File: FlutterSurvey.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 4 votes |
boolean isSurveyOpen() { final LocalDate now = LocalDate.now(); return (now.isEqual(startDate) || now.isAfter(startDate)) && now.isBefore(endDate); }
Example 19
Source File: DiscountingFixedCouponBondTradePricer.java From Strata with Apache License 2.0 | 4 votes |
/** * Calculates the present value of the fixed coupon bond trade with z-spread from the * clean price of the underlying product. * <p> * The present value of the trade is the value on the valuation date. * The result is expressed using the payment currency of the bond. * <p> * The z-spread is a parallel shift applied to continuously compounded rates or periodic * compounded rates of the discounting curve. * <p> * Coupon payments of the underlying product are considered based on the settlement date of the trade. * * @param trade the trade * @param provider the discounting provider * @param refData the reference data used to calculate the settlement date * @param cleanPrice the clean price * @param zSpread the z-spread * @param compoundedRateType the compounded rate type * @param periodsPerYear the number of periods per year * @return the present value of the fixed coupon bond trade */ public CurrencyAmount presentValueFromCleanPriceWithZSpread( ResolvedFixedCouponBondTrade trade, LegalEntityDiscountingProvider provider, ReferenceData refData, double cleanPrice, double zSpread, CompoundedRateType compoundedRateType, int periodsPerYear) { ResolvedFixedCouponBond product = trade.getProduct(); LocalDate standardSettlementDate = standardSettlementDate(product, provider, refData); LocalDate tradeSettlementDate = settlementDate(trade, provider.getValuationDate()); Currency currency = product.getCurrency(); RepoCurveDiscountFactors repoDf = DiscountingFixedCouponBondProductPricer.repoCurveDf(product, provider); double df = repoDf.discountFactor(standardSettlementDate); double pvStandard = (cleanPrice * product.getNotional() + productPricer.accruedInterest(product, standardSettlementDate)) * df; if (standardSettlementDate.isEqual(tradeSettlementDate)) { return presentValueFromProductPresentValue(trade, provider, CurrencyAmount.of(currency, pvStandard)); } // check coupon payment between two settlement dates IssuerCurveDiscountFactors issuerDf = DiscountingFixedCouponBondProductPricer.issuerCurveDf(product, provider); double pvDiff = 0d; if (standardSettlementDate.isAfter(tradeSettlementDate)) { pvDiff = productPricer.presentValueCouponWithZSpread( product, issuerDf, tradeSettlementDate, standardSettlementDate, zSpread, compoundedRateType, periodsPerYear); } else { pvDiff = -productPricer.presentValueCouponWithZSpread( product, issuerDf, standardSettlementDate, tradeSettlementDate, zSpread, compoundedRateType, periodsPerYear); } return presentValueFromProductPresentValue(trade, provider, CurrencyAmount.of(currency, pvStandard + pvDiff)); }
Example 20
Source File: DiscountingFxSingleProductPricer.java From Strata with Apache License 2.0 | 3 votes |
/** * Calculates the current cash. * * @param fx the product * @param valuationDate the valuation date * @return the current cash */ public MultiCurrencyAmount currentCash(ResolvedFxSingle fx, LocalDate valuationDate) { if (valuationDate.isEqual(fx.getPaymentDate())) { return MultiCurrencyAmount.of(fx.getBaseCurrencyPayment().getValue(), fx.getCounterCurrencyPayment().getValue()); } return MultiCurrencyAmount.empty(); }