BOND AMORTIZATION

Hello

I am trying to create a Bond Amortization Schedule to be generated once a report is executed for a particular period or a day.

Output of the schedule will serve as an input into the main report.

I want to develop a script that can carry the value of field in a previous row as an input into the output of the next row.

Attached is a sample of what I am trying to achieve.
EE-SAMPLE.xlsx
barkomeAsked:
Who is Participating?
 
Vitor MontalvãoMSSQL Senior EngineerCommented:
Hi barkome,

sorry for the delay but this was quite challenging.
Here's the solution that I think you'll need:
;WITH CTE_FIRST (ROWNUM, FAIRVALUE, INTEREST, COUPON, AMORTIZATION, CLOSINGVALUE, INCOME) 
AS 
	(SELECT A.ROWNUM, A.VLN_CST_AMT, A.VLN_CST_AMT*(B.YTM_YLD_RT/365/100), A.INV_FV_AMT*(A.INT_RT/100/365), (A.VLN_CST_AMT*(B.YTM_YLD_RT/365/100))-(A.INV_FV_AMT*(A.INT_RT/100/365)),
			A.VLN_CST_AMT+(A.VLN_CST_AMT*(B.YTM_YLD_RT/365/100))+(A.INV_FV_AMT*(A.INT_RT/100/365)),A.VLN_CST_AMT*(B.YTM_YLD_RT/365/100)
	FROM TABLE_A A, TABLE_B B
	WHERE A.ROWNUM=1
	UNION ALL
	SELECT A.ROWNUM, F.CLOSINGVALUE, F.CLOSINGVALUE*(B.YTM_YLD_RT/365/100), A.INV_FV_AMT*(A.INT_RT/100/365), 
		(F.CLOSINGVALUE*(B.YTM_YLD_RT/365/100))-(A.INV_FV_AMT*(A.INT_RT/100/365)), F.CLOSINGVALUE+(F.CLOSINGVALUE*(B.YTM_YLD_RT/365/100))+(A.INV_FV_AMT*(A.INT_RT/100/365)),
		F.INCOME+(A.VLN_CST_AMT*(B.YTM_YLD_RT/365/100))
	FROM TABLE_A A
		INNER JOIN CTE_FIRST F ON F.ROWNUM=A.ROWNUM-1
	, TABLE_B B)
	
SELECT *
FROM CTE_FIRST

Open in new window

0
 
Vitor MontalvãoMSSQL Senior EngineerCommented:
No one commented yet on this question.
Maybe because the information is not enough?

Can you give some sample data?
Those one from the Excel isn't enough. Try to give some rows from TableA and TableB.
0
 
barkomeAuthor Commented:
Hi Vitor

Thanks for responding, please see the attached spreadsheet.
EE-SAMPLE-2.xlsx
0
 
barkomeAuthor Commented:
Fantastic, this is great and simple to understand. I guess this explains the power of CTE's
0
 
Vitor MontalvãoMSSQL Senior EngineerCommented:
I guess this explains the power of CTE's
Sure. Very good for recursive stuffs ;)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.