@Override public byte[] serialize() { java.lang.StringBuffer sb = new java.lang.StringBuffer(); sb.append(org.drip.service.stream.Serializer.VERSION + getFieldDelimiter()); sb.append(_dblNotional + getFieldDelimiter()); sb.append(_dblSpread + getFieldDelimiter()); if (null == _strIR || _strIR.isEmpty()) sb.append(org.drip.service.stream.Serializer.NULL_SER_STRING + getFieldDelimiter()); else sb.append(_strIR + getFieldDelimiter()); if (null == _strCode || _strCode.isEmpty()) sb.append(org.drip.service.stream.Serializer.NULL_SER_STRING + getFieldDelimiter()); else sb.append(_strCode + getFieldDelimiter()); sb.append(_bApplyAccEOMAdj + getFieldDelimiter()); sb.append(_bApplyCpnEOMAdj + getFieldDelimiter()); sb.append(_dblMaturity + getFieldDelimiter()); sb.append(_dblEffective + getFieldDelimiter()); if (null == _fri) sb.append(org.drip.service.stream.Serializer.NULL_SER_STRING + getFieldDelimiter()); else sb.append(new java.lang.String(_fri.serialize()) + getFieldDelimiter()); if (null == _notlSchedule) sb.append(org.drip.service.stream.Serializer.NULL_SER_STRING + getFieldDelimiter()); else sb.append(new java.lang.String(_notlSchedule.serialize()) + getFieldDelimiter()); if (null == _settleParams) sb.append(org.drip.service.stream.Serializer.NULL_SER_STRING + getFieldDelimiter()); else sb.append(new java.lang.String(_settleParams.serialize()) + getFieldDelimiter()); if (null == _lsCouponPeriod) sb.append(org.drip.service.stream.Serializer.NULL_SER_STRING); else { boolean bFirstEntry = true; java.lang.StringBuffer sbPeriods = new java.lang.StringBuffer(); for (org.drip.analytics.period.CashflowPeriod p : _lsCouponPeriod) { if (null == p) continue; if (bFirstEntry) bFirstEntry = false; else sbPeriods.append(getCollectionRecordDelimiter()); sbPeriods.append(new java.lang.String(p.serialize())); } if (sbPeriods.toString().isEmpty()) sb.append(org.drip.service.stream.Serializer.NULL_SER_STRING); else sb.append(sbPeriods.toString()); } return sb.append(getObjectTrailer()).toString().getBytes(); }
@Override public double getCoupon( final double dblValueDate, final org.drip.param.definition.ComponentMarketParams mktParams) throws java.lang.Exception { if (!org.drip.quant.common.NumberUtil.IsValid(dblValueDate) || null == mktParams) throw new java.lang.Exception("FloatingStream::getCoupon => Invalid Inputs"); org.drip.analytics.period.Period currentPeriod = null; for (org.drip.analytics.period.CashflowPeriod period : _lsCouponPeriod) { if (null == period) continue; if (dblValueDate >= period.getStartDate() && dblValueDate < period.getEndDate()) { currentPeriod = period; break; } } if (null == currentPeriod) throw new java.lang.Exception("FloatingStream::getCoupon => Invalid Inputs"); java.util.Map< org.drip.analytics.date.JulianDate, org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>> mapFixings = mktParams.getFixings(); if (null != mapFixings) { double dblCurrentResetDate = currentPeriod.getResetDate(); if (org.drip.quant.common.NumberUtil.IsValid(dblCurrentResetDate)) { org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> mapIndexFixing = mapFixings.get(new org.drip.analytics.date.JulianDate(dblCurrentResetDate)); if (null != mapIndexFixing) { java.lang.Double dblFixing = mapIndexFixing.get(_fri.fullyQualifiedName()); if (null != dblFixing) return dblFixing + _dblSpread; } } } org.drip.analytics.rates.DiscountCurve dc = mktParams.getDiscountCurve(); if (null == dc) throw new java.lang.Exception("FloatingStream::getCoupon => cant determine index"); return dc.libor(currentPeriod.getStartDate(), currentPeriod.getEndDate()) + _dblSpread; }
/** * FloatingStream constructor * * @param dblEffective Effective Date * @param dblMaturity Maturity Date * @param dblSpread Spread * @param fri Floating Rate Index * @param iFreq Frequency * @param strCouponDC Coupon Day Count * @param strAccrualDC Accrual Day Count * @param bFullStub TRUE => Generate full first-stub * @param dapEffective Effective DAP * @param dapMaturity Maturity DAP * @param dapPeriodStart Period Start DAP * @param dapPeriodEnd Period End DAP * @param dapAccrualStart Accrual Start DAP * @param dapAccrualEnd Accrual End DAP * @param dapPay Pay DAP * @param dapReset Reset DAP * @param notlSchedule Notional Schedule * @param dblNotional Initial Notional Amount * @param strIR IR Curve * @param strCalendar Calendar * @throws java.lang.Exception Thrown if inputs are invalid */ public FloatingStream( final double dblEffective, final double dblMaturity, final double dblSpread, final org.drip.product.params.FloatingRateIndex fri, final int iFreq, final java.lang.String strCouponDC, final java.lang.String strAccrualDC, final boolean bFullStub, final org.drip.analytics.daycount.DateAdjustParams dapEffective, final org.drip.analytics.daycount.DateAdjustParams dapMaturity, final org.drip.analytics.daycount.DateAdjustParams dapPeriodStart, final org.drip.analytics.daycount.DateAdjustParams dapPeriodEnd, final org.drip.analytics.daycount.DateAdjustParams dapAccrualStart, final org.drip.analytics.daycount.DateAdjustParams dapAccrualEnd, final org.drip.analytics.daycount.DateAdjustParams dapPay, final org.drip.analytics.daycount.DateAdjustParams dapReset, final org.drip.product.params.FactorSchedule notlSchedule, final double dblNotional, final java.lang.String strIR, final java.lang.String strCalendar) throws java.lang.Exception { if (null == (_strIR = strIR) || _strIR.isEmpty() || !org.drip.quant.common.NumberUtil.IsValid(_dblEffective = dblEffective) || !org.drip.quant.common.NumberUtil.IsValid(_dblMaturity = dblMaturity) || !org.drip.quant.common.NumberUtil.IsValid(_dblSpread = dblSpread) || null == (_fri = fri) || !org.drip.quant.common.NumberUtil.IsValid(_dblNotional = dblNotional)) throw new java.lang.Exception("FloatingStream ctr => Invalid Input params! " + _fri); if (null == (_notlSchedule = notlSchedule)) _notlSchedule = org.drip.product.params.FactorSchedule.CreateBulletSchedule(); if (null == (_lsCouponPeriod = org.drip.analytics.period.CashflowPeriod.GeneratePeriodsBackward( dblEffective, // Effective dblMaturity, // Maturity dapEffective, // Effective DAP dapMaturity, // Maturity DAP dapPeriodStart, // Period Start DAP dapPeriodEnd, // Period End DAP dapAccrualStart, // Accrual Start DAP dapAccrualEnd, // Accrual End DAP dapPay, // Pay DAP dapReset, // Reset DAP iFreq, // Coupon Freq strCouponDC, // Coupon Day Count _bApplyCpnEOMAdj, strAccrualDC, // Accrual Day Count _bApplyAccEOMAdj, bFullStub, // Full First Coupon Period? false, // Merge the first 2 Periods - create a long stub? true, strCalendar)) || 0 == _lsCouponPeriod.size()) throw new java.lang.Exception("FloatingStream ctr: Cannot generate Period Schedule"); }
@Override public org.drip.state.estimator.PredictorResponseWeightConstraint generateCalibPRLC( final org.drip.param.valuation.ValuationParams valParams, final org.drip.param.pricer.PricerParams pricerParams, final org.drip.param.definition.ComponentMarketParams mktParams, final org.drip.param.valuation.QuotingParams quotingParams, final org.drip.state.representation.LatentStateMetricMeasure lsmm) { if (null == valParams || valParams.valueDate() >= getMaturityDate().getJulian() || null == lsmm || !(lsmm instanceof org.drip.analytics.rates.RatesLSMM) || !org.drip.analytics.rates.DiscountCurve.LATENT_STATE_DISCOUNT.equalsIgnoreCase( lsmm.getID())) return null; if (org.drip.analytics.rates.DiscountCurve.QUANTIFICATION_METRIC_FORWARD_RATE.equalsIgnoreCase( lsmm.getQuantificationMetric()) || org.drip.analytics.rates.DiscountCurve.QUANTIFICATION_METRIC_DISCOUNT_FACTOR .equalsIgnoreCase(lsmm.getQuantificationMetric())) { if (null == mktParams) return null; org.drip.analytics.rates.DiscountCurve dc = mktParams.getDiscountCurve(); if (null == dc) return null; org.drip.state.estimator.PredictorResponseWeightConstraint prwc = new org.drip.state.estimator.PredictorResponseWeightConstraint(); double dblDirtyCV100 = 0.; boolean bFirstPeriod = true; try { for (org.drip.analytics.period.CashflowPeriod period : _lsCouponPeriod) { if (null == period) continue; double dblPayDate = period.getPayDate(); if (valParams.valueDate() > dblPayDate) continue; double dblPeriodDCF = period.getCouponDCF(); if (bFirstPeriod) { bFirstPeriod = false; dblPeriodDCF -= period.getAccrualDCF(valParams.valueDate()); } double dblPeriodCV100 = dblPeriodDCF * dc.df(dblPayDate) * getNotional(dblPayDate); dblDirtyCV100 += dblPeriodCV100; if (!prwc.addPredictorResponseWeight(dblPayDate, dblPeriodCV100 * _dblNotional)) return null; } return prwc.updateValue(-1. * dblDirtyCV100 * _dblNotional * lsmm.getMeasureQuoteValue()) ? prwc : null; } catch (java.lang.Exception e) { e.printStackTrace(); return null; } } return null; }
@Override public org.drip.quant.calculus.WengertJacobian calcQuoteDFMicroJack( final java.lang.String strQuote, final org.drip.param.valuation.ValuationParams valParams, final org.drip.param.pricer.PricerParams pricerParams, final org.drip.param.definition.ComponentMarketParams mktParams, final org.drip.param.valuation.QuotingParams quotingParams) { if (null == valParams || valParams.valueDate() >= _dblMaturity || null == strQuote || null == mktParams || null == mktParams.getDiscountCurve()) return null; if ("Rate".equalsIgnoreCase(strQuote) || "SwapRate".equalsIgnoreCase(strQuote)) { org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> mapMeasures = value(valParams, pricerParams, mktParams, quotingParams); if (null == mapMeasures) return null; double dblDirtyDV01 = mapMeasures.get("DirtyDV01"); double dblParSwapRate = mapMeasures.get("SwapRate"); try { org.drip.quant.calculus.WengertJacobian wjSwapRateDFMicroJack = null; org.drip.analytics.rates.DiscountCurve dc = mktParams.getDiscountCurve(); for (org.drip.analytics.period.CashflowPeriod p : _lsCouponPeriod) { double dblPeriodPayDate = p.getPayDate(); if (dblPeriodPayDate < valParams.valueDate()) continue; org.drip.quant.calculus.WengertJacobian wjPeriodFwdRateDF = dc.getForwardRateJack(p.getStartDate(), p.getEndDate()); org.drip.quant.calculus.WengertJacobian wjPeriodPayDFDF = dc.jackDDFDQuote(dblPeriodPayDate); if (null == wjPeriodFwdRateDF || null == wjPeriodPayDFDF) continue; double dblForwardRate = dc.libor(p.getStartDate(), p.getEndDate()); double dblPeriodPayDF = dc.df(dblPeriodPayDate); if (null == wjSwapRateDFMicroJack) wjSwapRateDFMicroJack = new org.drip.quant.calculus.WengertJacobian(1, wjPeriodFwdRateDF.numParameters()); double dblPeriodNotional = getNotional(p.getStartDate(), p.getEndDate()); double dblPeriodDCF = p.getCouponDCF(); for (int k = 0; k < wjPeriodFwdRateDF.numParameters(); ++k) { double dblPeriodMicroJack = (dblForwardRate - dblParSwapRate) * wjPeriodPayDFDF.getFirstDerivative(0, k) + dblPeriodPayDF * wjPeriodFwdRateDF.getFirstDerivative(0, k); if (!wjSwapRateDFMicroJack.accumulatePartialFirstDerivative( 0, k, dblPeriodNotional * dblPeriodDCF * dblPeriodMicroJack / dblDirtyDV01)) return null; } } return wjSwapRateDFMicroJack; } catch (java.lang.Exception e) { e.printStackTrace(); } } return null; }
@Override public org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> value( final org.drip.param.valuation.ValuationParams valParams, final org.drip.param.pricer.PricerParams pricerParams, final org.drip.param.definition.ComponentMarketParams mktParams, final org.drip.param.valuation.QuotingParams quotingParams) { if (null == valParams || null == mktParams) return null; org.drip.analytics.rates.DiscountCurve dc = mktParams.getDiscountCurve(); if (null == dc) return null; long lStart = System.nanoTime(); double dblFixing01 = 0.; double dblAccrued01 = 0.; double dblDirtyDV01 = 0.; boolean bFirstPeriod = true; double dblDirtyFloatingPV = 0.; double dblCashPayDF = java.lang.Double.NaN; double dblResetDate = java.lang.Double.NaN; double dblResetRate = java.lang.Double.NaN; java.lang.String strFRI = _fri.fullyQualifiedName(); org.drip.analytics.rates.ForwardRateEstimator fc = mktParams.getForwardCurve(); if (null != fc && !_fri.match(fc.index())) fc = null; for (org.drip.analytics.period.CashflowPeriod period : _lsCouponPeriod) { double dblFloatingRate = 0.; double dblDirtyPeriodDV01 = java.lang.Double.NaN; double dblPeriodPayDate = period.getPayDate(); if (dblPeriodPayDate < valParams.valueDate()) continue; if (null == fc) fc = dc.forwardRateEstimator(dblPeriodPayDate, _fri); try { if (bFirstPeriod) { bFirstPeriod = false; if (null == mktParams.getFixings() || null == mktParams .getFixings() .get(new org.drip.analytics.date.JulianDate(period.getResetDate())) || null == mktParams .getFixings() .get(new org.drip.analytics.date.JulianDate(period.getResetDate())) .get(strFRI)) dblResetRate = dblFloatingRate = null == fc ? dc.libor(_fri.tenor()) : fc.forward(period.getPayDate()); else dblResetRate = dblFloatingRate = mktParams .getFixings() .get(new org.drip.analytics.date.JulianDate(period.getResetDate())) .get(strFRI); dblFixing01 = period.getAccrualDCF(valParams.valueDate()) * 0.0001 * getNotional(period.getAccrualStartDate(), valParams.valueDate()); if (period.getStartDate() < valParams.valueDate()) dblAccrued01 = dblFixing01; dblResetDate = period.getResetDate(); } else dblFloatingRate = null == fc ? dc.libor(period.getStartDate(), period.getEndDate()) : fc.forward(period.getPayDate()); dblDirtyPeriodDV01 = 0.0001 * period.getCouponDCF() * mktParams.getDiscountCurve().df(dblPeriodPayDate) * getNotional(period.getAccrualStartDate(), period.getEndDate()); } catch (java.lang.Exception e) { e.printStackTrace(); return null; } if (s_bBlog) { try { System.out.println( new org.drip.analytics.date.JulianDate(period.getResetDate()) + " [" + new org.drip.analytics.date.JulianDate(period.getStartDate()) + "->" + new org.drip.analytics.date.JulianDate(period.getEndDate()) + "] => " + org.drip.quant.common.FormatUtil.FormatDouble(dblFloatingRate, 1, 4, 100.)); } catch (java.lang.Exception e) { e.printStackTrace(); } } dblDirtyDV01 += dblDirtyPeriodDV01; dblDirtyFloatingPV += dblDirtyPeriodDV01 * 10000. * dblFloatingRate; } try { double dblCashSettle = valParams.cashPayDate(); if (null != _settleParams) dblCashSettle = _settleParams.cashSettleDate(valParams.valueDate()); dblCashPayDF = mktParams.getDiscountCurve().df(dblCashSettle); } catch (java.lang.Exception e) { e.printStackTrace(); return null; } dblDirtyDV01 /= dblCashPayDF; dblDirtyFloatingPV /= dblCashPayDF; double dblCleanDV01 = dblDirtyDV01 - dblAccrued01; double dblCleanFloatingPV = dblDirtyFloatingPV - dblAccrued01 * (dblResetRate + _dblSpread); org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> mapResult = new org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>(); mapResult.put("ResetDate", dblResetDate); mapResult.put("ResetRate", dblResetRate); mapResult.put("Accrued01", dblAccrued01 * _dblNotional); mapResult.put("Fixing01", dblFixing01 * _dblNotional); mapResult.put( "FloatAccrued", dblAccrued01 * 10000. * (dblResetRate + _dblSpread) * _dblNotional); mapResult.put("DV01", dblCleanDV01 * _dblNotional); mapResult.put("CleanDV01", dblCleanDV01 * _dblNotional); mapResult.put("DirtyDV01", dblDirtyDV01 * _dblNotional); mapResult.put("CleanFloatingPV", dblCleanFloatingPV * _dblNotional); mapResult.put("DirtyFloatingPV", dblDirtyFloatingPV * _dblNotional); mapResult.put("PV", dblCleanFloatingPV * _dblNotional); mapResult.put("CleanPV", dblCleanFloatingPV * _dblNotional); mapResult.put("DirtyPV", dblDirtyFloatingPV * _dblNotional); mapResult.put("Upfront", dblCleanFloatingPV * _dblNotional); mapResult.put("FairPremium", dblCleanFloatingPV / dblCleanDV01); mapResult.put("Rate", dblCleanFloatingPV / dblCleanDV01); mapResult.put("ParRate", dblCleanFloatingPV / dblCleanDV01); double dblValueNotional = java.lang.Double.NaN; try { dblValueNotional = getNotional(valParams.valueDate()); } catch (java.lang.Exception e) { e.printStackTrace(); } if (org.drip.quant.common.NumberUtil.IsValid(dblValueNotional)) { double dblPrice = 100. * (1. + (dblCleanFloatingPV / _dblNotional / dblValueNotional)); mapResult.put("Price", dblPrice); mapResult.put("CleanPrice", dblPrice); } mapResult.put("CalcTime", (System.nanoTime() - lStart) * 1.e-09); return mapResult; }