@@ -652,17 +652,53 @@ public static int accruedDays(Leg leg, bool includeSettlementDateFlows, Date set
652652 }
653653 return 0 ;
654654 }
655- public static double accruedAmount ( Leg leg , bool includeSettlementDateFlows , Date settlementDate = null )
655+ public static double accruedAmount ( Leg leg , bool includeSettlementDateFlows , Date settlementDate = null , Date accrualStartDate = null )
656656 {
657+ double result = 0.0 ;
658+
657659 if ( settlementDate == null )
658660 settlementDate = Settings . evaluationDate ( ) ;
659661
660662 CashFlow cf = nextCashFlow ( leg , includeSettlementDateFlows , settlementDate ) ;
661663 if ( cf == null )
662664 return 0 ;
665+
663666 Date paymentDate = cf . date ( ) ;
664- double result = 0.0 ;
665667
668+ CashFlow cfStart = null ;
669+ Date endDate = paymentDate ;
670+
671+ if ( accrualStartDate != null )
672+ {
673+ cfStart = nextCashFlow ( leg , includeSettlementDateFlows , accrualStartDate ) ;
674+
675+ if ( cfStart != null )
676+ endDate = cfStart . date ( ) ;
677+ }
678+
679+ // More periods
680+ if ( endDate != paymentDate )
681+ {
682+ // First period
683+ Coupon cp = cfStart as Coupon ;
684+ if ( cp != null )
685+ result += cp . accruedAmount ( cp . accrualEndDate ( ) ) - cp . accruedAmount ( accrualStartDate ) ;
686+
687+
688+ foreach ( CashFlow x in leg . Where ( x => x . date ( ) <= paymentDate &&
689+ x . date ( ) > endDate ) )
690+ {
691+ cp = x as Coupon ;
692+ if ( cp != null )
693+ if ( x . date ( ) < paymentDate )
694+ result += cp . accruedAmount ( cp . accrualEndDate ( ) ) ;
695+ else
696+ result += cp . accruedAmount ( settlementDate ) ;
697+ }
698+ return result ;
699+ }
700+
701+ // One period
666702 foreach ( CashFlow x in leg . Where ( x => x . date ( ) == paymentDate ) )
667703 {
668704 Coupon cp = x as Coupon ;
0 commit comments