public static final void main(final java.lang.String[] astrArgs) throws java.lang.Exception { FloatingStream fs = new org.drip.product.rates.FloatingStream( org.drip.analytics.date.JulianDate.Today().getJulian(), org.drip.analytics.date.JulianDate.Today().addTenor("4Y").getJulian(), 0.03, org.drip.product.params.FloatingRateIndex.Create("JPY-LIBOR-6M"), 2, "30/360", "30/360", false, null, null, null, null, null, null, null, null, null, 100., "JPY", "JPY"); byte[] abFS = fs.serialize(); System.out.println(new java.lang.String(abFS)); FloatingStream fsDeser = new FloatingStream(abFS); System.out.println(new java.lang.String(fsDeser.serialize())); }
@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; }
@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; }
@Override public java.lang.String getForwardCurveName() { return _fri.fullyQualifiedName(); }