finmath / finmath-lib

Mathematical Finance Library: Algorithms and methodologies related to mathematical finance.
Apache License 2.0
488 stars 168 forks source link

Integration of SwapLegWithResetting into SwapLeg #28

Closed NiklasRodi closed 7 years ago

NiklasRodi commented 7 years ago

What is this PR for?

What type of PR is it?

Refactoring, Bug Fix

cfries commented 7 years ago

Is this

        double firstPeriodStartDate = legSchedule.getPeriodStart(0);
        for(int periodIndex=0; periodIndex<legSchedule.getNumberOfPeriods(); periodIndex++) {

(...)

            double notional = (discountCurveForNotionalReset.getDiscountFactor(model,periodStart)/discountCurveForNotionalReset.getDiscountFactor(model,firstPeriodStartDate)) / (discountCurve.getDiscountFactor(model,periodStart)/discountCurve.getDiscountFactor(model,firstPeriodStartDate));

really what we want? Note that the lib supports running swaps. So firstPeriodStartDate < 0 and firstPeriodStartDate < evaluationTime.

I have to think a bit about this, but I assume that firstPeriodStartDate should be replaced by either evaluationTime or the largest periodStart smaller than evaluationTime.

NiklasRodi commented 7 years ago

Yes your are right. Using firstPeriodStartDate only works in a special case (standard CCY swap that was traded in t=0). I think one should replace firstPeriodStartDate with the spotOffset of the corresponding FX which is usually t+2bd using the union of the businessday calendars of the 2 involved currencies and further rolled Forward if this is a USD holiday. There are also exceptions to that, e.g. USD/CAD settles t+1bd. As I do not have that information available (at on point one may have to think about adding an fxSpot object to the model and a currency to every SwapLeg and other product) I would use t+2bd using the calendar of the SwapLeg as an Approximation.

What do you think about that?

NiklasRodi commented 7 years ago

Are you ok with using t+2bd using the calendar of the SwapLeg as an approximation of the spotDate of the FX? However, this would leave me with the issue of identifying the date that corresponds to the given evaluationTime which is imO impossible in the current set-up.

NiklasRodi commented 7 years ago

I (still) think that an AnalyticalModel should have a referenceDate which is the common (!) referenceDate of all curves and volatilitySurfaces it contains. In that case I could calculate the

NiklasRodi commented 7 years ago

See Integration of SwapLegWithResetting into SwapLeg v2