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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.