@@ -79,7 +79,6 @@ public static void main(String args[]) throws Exception {
7979 double accrualFactor , valueCurrent , valueChange , cappedValueChange , gapAmount ;
8080 double gapAccount = 0.0 ;
8181 double realizedCashFlows = 0.0 ;
82- double fundingCosts = 0.0 ;
8382 // If trade has initially a non-zero value -> collateral needs to be set up by an up-front payment
8483 double collateralAccount = valuePrevious ;
8584
@@ -115,10 +114,7 @@ public static void main(String args[]) throws Exception {
115114 collateralAccount = collateralAccount + accrualFactor * cappedValueChange ;
116115 // D_i = D_{i-1}*(1+rt) + Z_i
117116 gapAccount = gapAccount * accrualFactor + gapAmount ;
118- }
119-
120- // Sum up funding costs. Margin buffer and funding spread can be time dependent
121- fundingCosts += marginFloor * fundingSpread * FloatingpointDate .getFloatingPointDateFromDate (valuationDatePrevious , valuationDateCurrent );
117+ }
122118 // Reuse current values as previous ones for next iteration
123119 valuationDatePrevious = valuationDateCurrent ;
124120 valuePrevious = valueCurrent ;
@@ -130,6 +126,8 @@ public static void main(String args[]) throws Exception {
130126 // Add increment results to result array
131127 margin .add (marginFloor );
132128 cashFlow .add (realizedCashFlows );
129+ // Constant Margin buffer and funding spread, but can be time dependent
130+ double fundingCosts = marginFloor * (1.0 - Math .exp (-fundingSpread * FloatingpointDate .getFloatingPointDateFromDate (startDate , forwardCurveSnapshots .get (valuationEndIndex - 1 ).getValuationDate ())));
133131 funding .add (fundingCosts );
134132 }
135133
0 commit comments