Skip to content

Commit

Permalink
Features:
Browse files Browse the repository at this point in the history
	- Composite Floating Unit Period #1 (2, 3)
	- Composite Floating Unit Period #2 (4, 5)
	- Discrete Period Discount Factor #1 (12, 13)
	- Discrete Period Discount Factor #2 (14, 15)
	- Native Flat Forward Discount #1 (20, 21)
	- Native Flat Forward Discount #2 (22, 23)
	- Native Flat Forward Discount #3 (24, 25)
	- Native Flat Forward Discount #4 (26, 27)


Bug Fixes/Clean-up:

	- Latent Market State Builder #1 (28, 29)
	- Latent Market State Builder #2 (30, 31)
	- Latent Market State Builder #3 (32, 33)
	- Latent Market State Builder #4 (34, 35)
	- Latent Market State Builder #5 (36, 37)
	- Latent Market State Builder #6 (38)


Samples:

	- Kakinada Bond Metrics Curve Up (1)
	- Kakinada Bond Metrics #1 (6, 7)
	- Kakinada Bond Metrics #2 (8, 9)
	- Kakinada Bond Metrics #3 (10, 11)
	- Kakinada Bond Metrics #4 (16, 17)
	- Kakinada Bond Metrics #5 (18, 19)
	- Kakinada Bond Metrics #6 (39, 40)
	- Kakinada Bond Metrics #7 (41, 42)
	- Kakinada Bond Metrics #8 (43, 44)
	- Kakinada Bond Metrics #9 (45, 46)
	- Kakinada Bond Metrics #10 (47, 48)
	- Kakinada Bond Metrics #11 (51, 52)
	- Kakinada Bond Metrics #12 (53, 54)
	- Kakinada Bond Metrics #13 (55, 56)
	- Kakinada Bond Metrics #14 (57, 58)
	- Kakinada Bond Metrics #15 (59, 60)
	- Kakinada Bond Metrics #16 (61, 62)
	- Kakinada Bond Metrics #17 (63, 64)
	- Kakinada Bond Metrics #18 (65, 66)
	- Kakinada Bond Metrics #19 (67, 68)
	- Kakinada Bond Metrics #20 (69, 70)
	- Kakinada Bond Metrics #21 (71, 72)
	- Kakinada Bond Metrics #22 (73, 74)
	- Kakinada Bond Metrics #23 (75, 76)
	- Kakinada Bond Metrics #24 (77, 78)
	- Kakinada Bond Metrics #25 (79, 80)
  • Loading branch information
lakshmiDRIP committed Feb 10, 2018
1 parent 95d8cdd commit fcf3327
Show file tree
Hide file tree
Showing 8 changed files with 526 additions and 203 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,20 @@ private double baseForwardRate (

int iReferencePeriodStartDate = _rip.startDate();

if (iEpochDate > iReferencePeriodStartDate)
iReferencePeriodEndDate = new org.drip.analytics.date.JulianDate (iReferencePeriodStartDate =
iEpochDate).addTenor (forwardLabel.tenor()).julian();
iReferencePeriodStartDate = iReferencePeriodStartDate > iEpochDate ? iReferencePeriodStartDate :
iEpochDate;

return dcFunding.libor (
iReferencePeriodStartDate,
iReferencePeriodEndDate,
_rip.dcf()
org.drip.analytics.daycount.Convention.YearFraction (
iReferencePeriodStartDate,
iReferencePeriodEndDate,
floaterIndex.dayCount(),
false,
null,
floaterIndex.calendar()
)
);
}

Expand Down
227 changes: 108 additions & 119 deletions src/main/java/org/drip/sample/loan/Kakinada.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@

import org.drip.analytics.cashflow.*;
import org.drip.analytics.date.*;
import org.drip.market.definition.FloaterIndex;
import org.drip.param.market.CurveSurfaceQuoteContainer;
import org.drip.param.valuation.ValuationParams;
import org.drip.product.creator.BondBuilder;
import org.drip.product.credit.BondComponent;
import org.drip.quant.common.FormatUtil;
import org.drip.service.env.EnvManager;
import org.drip.service.scenario.*;
import org.drip.service.template.LatentMarketStateBuilder;
import org.drip.state.discount.MergedDiscountForwardCurve;
import org.drip.state.identifier.FloaterLabel;

/*
* -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
Expand Down Expand Up @@ -68,6 +66,94 @@

public class Kakinada {

private static final void PrintCashFlows (
final BondComponent bond,
final ValuationParams valParams,
final CurveSurfaceQuoteContainer csqc)
throws Exception
{
double dirtyPV = 0.;
double startDF = 1.;

FloaterIndex floaterIndex = bond.floaterSetting().fri().floaterIndex();

System.out.println ("\t||----------------------------------------------------------------------------------------------------------------------||");

System.out.println ("\t|| PERIOD LABELS AND CURVE FACTORS ||");

System.out.println ("\t||----------------------------------------------------------------------------------------------------------------------||");

System.out.println ("\t|| L -> R: ||");

System.out.println ("\t|| - Period Start Date ||");

System.out.println ("\t|| - Period End Date ||");

System.out.println ("\t|| - Period Coupon Rate (%) ||");

System.out.println ("\t|| - Period Coupon Year Fraction ||");

System.out.println ("\t|| - Period Start DF ||");

System.out.println ("\t|| - Period End DF ||");

System.out.println ("\t|| - Recalculated Rate ||");

System.out.println ("\t||----------------------------------------------------------------------------------------------------------------------||");

for (CompositePeriod p : bond.couponPeriods()) {
int iEndDate = p.endDate();

int iPayDate = p.payDate();

int iStartDate = p.startDate() > valParams.valueDate() ? p.startDate() : valParams.valueDate();

double dblCouponRate = bond.couponMetrics (
iPayDate,
valParams,
csqc
).rate();

double dblCouponDCF = p.couponDCF();

double dblDCF = org.drip.analytics.daycount.Convention.YearFraction (
iStartDate,
iEndDate,
floaterIndex.dayCount(),
false,
null,
floaterIndex.calendar()
);

double endDF = p.df (csqc);

double dblCouponPV = dblCouponRate * dblDCF * endDF;

System.out.println ("\t|| " +
DateUtil.YYYYMMDD (iStartDate) + " => " +
DateUtil.YYYYMMDD (iEndDate) + " | " +
FormatUtil.FormatDouble (dblCouponRate, 1, 4, 100.) + "% | " +
FormatUtil.FormatDouble (dblCouponDCF, 1, 4, 1.) + " | " +
FormatUtil.FormatDouble (startDF, 1, 6, 1.) + " | " +
FormatUtil.FormatDouble (endDF, 1, 6, 1.) + " | " +
FormatUtil.FormatDouble (dblDCF, 1, 4, 1.) + " | " +
FormatUtil.FormatDouble (dblCouponPV, 1, 6, 1.) + " | " +
FormatUtil.FormatDouble (((startDF / endDF) - 1.) / dblDCF, 1, 4, 100.) + "% | "
);

dirtyPV += dblCouponPV;
startDF = endDF;
}

System.out.println ("\t||----------------------------------------------------------------------------------------------------------------------||");

System.out.println ("\t|| PV : " + FormatUtil.FormatDouble (dirtyPV + startDF, 1, 6, 1.));

System.out.println ("\t||----------------------------------------------------------------------------------------------------------------------||");

System.out.println();
}

public static final void main (
final String[] astArgs)
throws Exception
Expand All @@ -81,20 +167,20 @@ public static final void main (
);

String[] astrDepositTenor = new String[] {
"2D"
"1D"
};

double[] adblDepositQuote = new double[] {
0.0130411 // 2D
0.01304 // 1D
};

double[] adblFuturesQuote = new double[] {
0.01345, // 98.655
0.01470, // 98.530
0.01575, // 98.425
0.01660, // 98.340
0.01745, // 98.255
0.01845 // 98.155
0.01345, // 98.655
0.01470, // 98.530
0.01575, // 98.425
0.01660, // 98.340
0.01745, // 98.255
0.01845 // 98.155
};

String[] astrFixFloatTenor = new String[] {
Expand Down Expand Up @@ -183,20 +269,19 @@ public static final void main (

double dblFX = 1;
int iSettleLag = 3;
double dblSpread = 0.0450;
String strCurrency = "USD";
double dblSpread = 0.00; // 0.0450;
double dblCleanPrice = 1.0;
double dblIssuePrice = 0.995;
double dblSpreadBump = 20.;
double dblSpreadBump = 1.;
String strTreasuryCode = "UST";
double dblIssueAmount = 321500000.;
double dblSpreadDurationMultiplier = 5.;
double dblResetRate = adblDepositQuote[0];

JulianDate dtEffective = DateUtil.CreateFromYMD (
2016,
1,
27
2017,
7,
26
);

JulianDate dtMaturity = DateUtil.CreateFromYMD (
Expand All @@ -219,24 +304,6 @@ public static final void main (
null
);

CompositeFloatingPeriod cfp = (CompositeFloatingPeriod) bond.stream().containingPeriod (dtSpot.julian());

int iResetDate = ((org.drip.analytics.cashflow.ComposableUnitFloatingPeriod) (cfp.periods().get
(0))).referenceIndexPeriod().fixingDate();

MergedDiscountForwardCurve mdfc = LatentMarketStateBuilder.SmoothFundingCurve (
dtSpot,
strCurrency,
astrDepositTenor,
adblDepositQuote,
"ForwardRate",
adblFuturesQuote,
"ForwardRate",
astrFixFloatTenor,
adblFixFloatQuote,
"SwapRate"
);

BondReplicator abr = BondReplicator.CorporateLoan (
dblCleanPrice,
dblIssuePrice,
Expand Down Expand Up @@ -268,11 +335,7 @@ public static final void main (

System.out.println();

CurveSurfaceQuoteContainer csqc = abr.creditBaseCSQC();

FloaterLabel fl = bond.floaterSetting().fri();

csqc.setFixing (iResetDate, fl, dblResetRate);
CurveSurfaceQuoteContainer csqc = abr.fundingBaseCSQC();

ValuationParams valParams = ValuationParams.Spot (dtSpot.julian());

Expand All @@ -289,91 +352,17 @@ public static final void main (

System.out.println ("Price Out : " +
bond.priceFromYield (
ValuationParams.Spot (dtSpot.julian()),
valParams,
csqc,
null,
dblYield
)
);

System.out.println ("\t||----------------------------------------------------------------------------------------------------------------------||");

System.out.println ("\t|| PERIOD LABELS AND CURVE FACTORS ||");

System.out.println ("\t||----------------------------------------------------------------------------------------------------------------------||");

System.out.println ("\t|| L -> R: ||");

System.out.println ("\t|| - Period Start Date ||");

System.out.println ("\t|| - Period End Date ||");

System.out.println ("\t|| - Period Credit Label ||");

System.out.println ("\t|| - Period Funding Label ||");

System.out.println ("\t|| - Period Coupon Rate (%) ||");

System.out.println ("\t|| - Period Coupon Year Fraction ||");

System.out.println ("\t|| - Period Coupon Amount ||");

System.out.println ("\t|| - Period Principal Amount ||");

System.out.println ("\t|| - Period Discount Factor ||");

System.out.println ("\t|| - Period Survival Probability ||");

System.out.println ("\t|| - Period Recovery ||");

System.out.println ("\t||----------------------------------------------------------------------------------------------------------------------||");

for (CompositePeriod p : bond.couponPeriods()) {
int iEndDate = p.endDate();

int iPayDate = p.payDate();

int iStartDate = p.startDate();

double dblCouponRate = bond.couponMetrics (
iPayDate,
valParams,
csqc
).rate();

double dblCouponDCF = p.couponDCF();

System.out.println ("\t|| " +
DateUtil.YYYYMMDD (iStartDate) + " => " +
DateUtil.YYYYMMDD (iEndDate) + " | ? | " +
p.fundingLabel().fullyQualifiedName() + " | " +
p.floaterLabel().fullyQualifiedName() + " | " +
FormatUtil.FormatDouble (dblCouponRate, 1, 2, 100.) + "% | " +
FormatUtil.FormatDouble (dblCouponDCF, 1, 4, 1.) + " | " +
FormatUtil.FormatDouble (dblCouponRate * dblCouponDCF * p.notional (iEndDate) * p.couponFactor (iEndDate), 1, 4, 1.) + " | " +
FormatUtil.FormatDouble (p.notional (iStartDate) - p.notional (iEndDate), 1, 4, 1.) + " | " +
FormatUtil.FormatDouble (p.df (csqc), 1, 4, 1.) + " | " +
FormatUtil.FormatDouble (p.survival (csqc), 1, 4, 1.) + " | " +
FormatUtil.FormatDouble (p.recovery (csqc), 2, 0, 100.) + "% ||"
);
}

System.out.println ("\t|| " +
DateUtil.YYYYMMDD (dtEffective.julian()) + " => " +
DateUtil.YYYYMMDD (dtMaturity.julian()) + " | ? | " +
bond.fundingLabel().fullyQualifiedName() + " | " +
bond.forwardLabel().get (bond.name()).fullyQualifiedName() + " | " +
FormatUtil.FormatDouble (0., 1, 2, 100.) + "% | " +
FormatUtil.FormatDouble (0., 1, 4, 1.) + " | " +
FormatUtil.FormatDouble (0., 1, 4, 1.) + " | " +
FormatUtil.FormatDouble (bond.notional (dtMaturity.julian()), 1, 4, 1.) + " | " +
FormatUtil.FormatDouble (mdfc.df (dtMaturity), 1, 4, 1.) + " | " +
FormatUtil.FormatDouble (1., 1, 4, 1.) + " | " +
FormatUtil.FormatDouble (1., 2, 0, 100.) + "% ||"
PrintCashFlows (
bond,
valParams,
csqc
);

System.out.println ("\t||----------------------------------------------------------------------------------------------------------------------||");

System.out.println();
}
}
5 changes: 5 additions & 0 deletions src/main/java/org/drip/service/env/BuildManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ public static final boolean Init()

try {
s_aBuildRecord = new org.drip.service.env.BuildRecord[] {
new org.drip.service.env.BuildRecord (
"3.31.0",
"1.8.0_112",
"Tue Feb 06 01:10:47 EST 2018"
),
new org.drip.service.env.BuildRecord (
"3.30.0",
"1.8.0_112",
Expand Down
Loading

0 comments on commit fcf3327

Please sign in to comment.