def g(yieldCurve, zeroRates,n, verbose):
    '''
        generates recursively the zero curve 
        expressions eval('(0.06/1.05)+(1.06/(1+x)**2)-1')
        solves these expressions to get the new rate
        for that period
    
    '''
    if len(zeroRates) >= len(yieldCurve):
        print "\n\n\t+zero curve boot strapped [%d iterations]" % (n)
        return
    else:
        legn = ''
        for i in range(0,len(zeroRates),1):
            if i == 0:
                legn = '%2.6f/(1+%2.6f)**%d'%(yieldCurve[n], zeroRates[i],i+1)
            else:
                legn = legn + ' +%2.6f/(1+%2.6f)**%d'%(yieldCurve[n], zeroRates[i],i+1)
        legn = legn + '+ (1+%2.6f)/(1+x)**%d-1'%(yieldCurve[n], n+1)
        # solve the expression for this iteration
        if verbose:
            print "-[%d] %s" % (n, legn.strip())
        rate1 = solve(eval(legn), x)
        # Abs here since some solutions can be complex
        rate1 = min([Real(abs(r)) for r in rate1])
        if verbose:
            print "-[%d] solution %2.6f" % (n, float(rate1))
        # stuff the new rate in the results, will be 
        # used by the next iteration
        zeroRates.append(rate1)
        g(yieldCurve, zeroRates,n+1, verbose)

        generates recursively the zero curve 
        expressions eval('(0.06/1.05)+(1.06/(1+x)**2)-1')
        solves these expressions to get the new rate
        for that period
    
    
recipes/Python/578257_zero_curve_bootstrapping_forward_curve/recipe-578257.py