I'm trying to figure out if it's possible to value structured products, mainly loans, in quantlib. The idea is to build a bond class with different cash flows. For example, a loan could have coupons that only pay interest, could be only-amortizing or even the coupons can increase the nominal amount.
Also, for FTP purposes, one could be interested in the yield that returns the par value of the loan. Is there a native function for that?
It's possible to do this with the current release in python or c++?
Being more precise, imagine these two examples:
First, I have a loan that is issued with a face value of 2000 and has two redemptions of 1000:
I've been successful building the cashflows with the Bond class with a simple code:
def bond_from_table(df,notional, outlay_date, day_counter, r=0.03):
eval_date = ql.Settings.instance().evaluationDate
coupons = []
redemptions = []
redem = 0
for i in range(df.shape[0]):
start_date = df.at[i,'Start']
end_date = df.at[i,'End']
notional -= redem
redem = df.at[i,'Capital']
redemptions.append(ql.Redemption(redem,end_date))
coupons.append(ql.FixedRateCoupon(end_date,notional,r,day_counter,start_date,end_date))
leg = ql.Leg(coupons)
loan = ql.Bond(0,calendar,eval_date,leg)
return loan
As it seems that the Bond class constructs the redemptions from the nominals that are being paid. The good thing is that using the bond class we can access all the bond functions and other things as callability and so on.
But! if I try to build something like this:
Where after the initial 2000 payment to the client, another 400 are paid in the next coming dates (that's why the - sign) -at the end, you receive the total lend- I would get an error saying the nominal is increasing, which is true. I guess there might be another route for this, but I think I'll be losing the functionalities of the bond class.
Any ideas? Thanks in advance,