Exemple #1
0
def show_irs_vs_tenure(irs_threshold,
                       tenure,
                       no_banks,
                       threshold,
                       autocontinue=False):
    if not autocontinue:
        a = raw_input("Do you want to see IRS value vs tenure?[Y/n]")
    if (autocontinue or a != 'n'):
        for t in threshold:
            for b in no_banks:
                im_data = np.zeros((len(irs_threshold), len(tenure)))
                for i, irst in enumerate(irs_threshold):
                    for j, ten in enumerate(tenure):
                        agg_id = get_aggregate_id(b, t, irst, ten)
                        x, y, r, raw = get_aggregate_dist(agg_id)
                        err, alp = get_hump_error(x, y, raw)
                        im_data[i, j] = min(alp, 10)
                        if alp > 10:
                            print "Large value for alpha"
                            print alp

                #im = get_color_image(im_data)

                min_value = np.min(1)
                max_value = np.max(10)

                fig = pplot.figure()
                ax = fig.add_subplot(111)
                ax.set_ylabel("IRS Value")
                ax.set_yticklabels(np.arange(0, 9))
                ax.set_xlabel("Term to maturity")
                ax.set_xticklabels([0, 50, 100, 250, 400, 550, 700, 850])
                ax.set_title("Heatmap for %d banks, threshold %d" % (b, t))

                cax = ax.imshow(im_data,
                                origin='lower',
                                interpolation='nearest',
                                vmin=min_value,
                                vmax=max_value)

                cb = fig.colorbar(cax)
                cb.set_ticks([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
                cb.set_ticklabels([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
                cb.set_label('Alpha', rotation=270)

                # pplot.show()
                filename = 'alpha_irs_ten_%d_banks_%d_threshold.png' % (b, t)
                path = '/home/xxxxx/Programming/GitRepos/scriptie/figs/heatmaps/alpha/'
                fl = '%s%s' % (path, filename)

                pplot.savefig(fl, bbox_inches='tight')
                pplot.close(fig)

                if not autocontinue:
                    try:
                        a = raw_input("Do you want to continue [Y/n]")
                        if (a == 'n'):
                            return
                    except KeyboardInterrupt:
                        exit(0)
def run_svm(threshold, no_banks,irs_threshold,tenure):
    for t in threshold:
        for b in no_banks:

            points = np.dstack(np.meshgrid(irs_threshold, tenure)).reshape(-1, 2)
            alpha_class = np.zeros(len(points))
            for i,x in enumerate(points):
                irst = x[0]
                ten = x[1]
                agg_id = get_aggregate_id(b,t,irst,ten)
                x,y,r,raw = get_aggregate_dist(agg_id)
                _,alp = get_hump_error(x,y,raw)

                if alp <= 3:
                    alpha_class[i] = 1
                else:
                    alpha_class[i] = 0
            svc = svm.SVC(kernel='poly').fit(points,alpha_class)

            xx, yy = np.meshgrid(np.arange(min(irs_threshold),max(irs_threshold), 0.02),
                                 np.arange(min(tenure),max(tenure), 0.02))

            Z = svc.predict(np.c_[xx.ravel(), yy.ravel()])
            Z = Z.reshape(xx.shape)

            pplot.figure()
            pplot.contourf(xx, yy, Z, cmap=plt.cm.coolwarm, alpha=0.8)
            pplot.scatter(points[:,0],points[:,1], c=alpha_class)

            pplot.show()
Exemple #3
0
def show_irs_vs_threshold(irs_threshold,
                          tenure,
                          no_banks,
                          threshold,
                          autocontinue=False):
    if not autocontinue:
        a = raw_input("Do you want to see IRS value vs threshold?[Y/n]")
    if (autocontinue or a != 'n'):
        for ten in tenure:
            for b in no_banks:
                im_data = np.zeros((len(irs_threshold), len(threshold)))
                for i, irst in enumerate(irs_threshold):
                    for j, t in enumerate(threshold):
                        agg_id = get_aggregate_id(b, t, irst, ten)
                        x, y, r, raw = get_aggregate_dist(agg_id)
                        err, alp = get_hump_error(x, y, raw)
                        im_data[i, j] = round(alp, 2)

                #im = get_color_image(im_data)
                min_value = np.min(1)
                max_value = np.max(10)

                fig = pplot.figure()
                ax = fig.add_subplot(111)
                ax.set_ylabel("IRS Value")
                ax.set_yticklabels(np.arange(0, 9))
                ax.set_xlabel("Threshold")
                ax.set_xticklabels([0, 10, 15, 20, 25, 30])
                ax.set_title("Heatmap for %d banks, term to maturity %d" %
                             (b, ten))

                cax = ax.imshow(im_data,
                                origin='lower',
                                interpolation='nearest',
                                vmin=min_value,
                                vmax=max_value)
                cb = fig.colorbar(cax)
                cb.set_ticks([min_value, max_value])
                cb.set_ticklabels([min_value, max_value])
                cb.set_label('P(x > Last powerlaw point)', rotation=270)

                filename = 'alpha_irs_thresh_%d_banks_%d_tenure.png' % (b, ten)
                path = '/home/..../Programming/GitRepos/scriptie/figs/heatmaps/alpha/'
                fl = '%s%s' % (path, filename)
                pplot.savefig(fl, bbox_inches='tight')
                pplot.close(fig)

                if not autocontinue:
                    try:
                        a = raw_input("Do you want to continue [Y/n]")
                        if (a == 'n'):
                            return
                    except KeyboardInterrupt:
                        exit(0)
    irs_threshold = np.arange(1,9)
    tenure = [50,100,250,400,550,700,850]
    no_banks = [100, 200]#np.arange(100,600,100)
    threshold = np.arange(10,35,5)

    a = raw_input("Do you want to see IRS value vs tenure?[Y/n]")
    if(a != 'n'):
        for t in threshold:
            for b in no_banks:
                im_data = np.zeros((len(irs_threshold),len(tenure)))
                for i,irst in enumerate(irs_threshold):
                    for j,ten in enumerate(tenure):
                        agg_id = get_aggregate_id(b,t,irst,ten)
                        x,y,r,raw = get_aggregate_dist(agg_id)
                        err,alp = get_hump_error(x,y,raw)
                        im_data[i,j] = alp

                fig = pplot.figure()
                ax = fig.add_subplot(111)
                ax.set_ylabel("IRS Value")
                ax.set_yticklabels(np.arange(0,9))
                ax.set_xlabel("Tenure")
                ax.set_xticklabels([0,50,100,250,400,550,700,850])
                ax.set_title("Heatmap for %d banks, threshold %d:Alpha"%(b,t))

                cax = ax.imshow(im_data,origin='lower',interpolation='nearest',
                    vmin=np.min(im_data),vmax=np.max(im_data))

                pplot.colorbar(cax)
                pplot.show()
Exemple #5
0
def get_frequencies(no_banks, aggregate_id):
    x, y, r, raw = get_aggregate_dist(aggregate_id)
    _, alp = get_hump_error(x, y, raw)
    cumv = get_hump_cumulative_value(x,y)
    return [alp, cumv]
Exemple #6
0
def get_weight(aggregate_id):
    x, y, _, raw = get_aggregate_dist(aggregate_id)
    _, alp = get_hump_error(x, y, raw)
    cumv = get_hump_cumulative_value(x,y)
    return (aggregate_id, alp, cumv)