AbsBox icon indicating copy to clipboard operation
AbsBox copied to clipboard

Plotting candy function: Asset-vs-Liability

Open yellowbean opened this issue 2 years ago • 3 comments

y -> time line axis

x -> a pair of two stacks bars over the projection period x ->

  • asset stack ->
    • performing asset
    • non-performing asset
    • account cash
  • liability stack ->
    • tranches balance
    • due interest
    • due fee
    • liquidity support liability

yellowbean avatar Jun 12 '23 08:06 yellowbean

prioritizing this as coming rating adjust for china. it's good to show the OC level for the senior tranches

yellowbean avatar Jun 14 '23 03:06 yellowbean

Prototype

image

yellowbean avatar Jun 14 '23 03:06 yellowbean

def plot_bs(x, excludeItems=["FeeDue","IntAccrue","Account"]):
    import matplotlib.pyplot as plt
    import numpy as np
    dates = x.index.to_list() 

    liabilityItems = x['liability'].to_dict(orient='list')
    assetItems = x['asset'].to_dict(orient='list')
    
    highest_y1 = max([ max(v) for k,v in liabilityItems.items()])
    highest_y2 = max([ max(v) for k,v in assetItems.items()])
    
    if "FeeDue" in set(excludeItems):
        liabilityItems = {k:v for (k,v) in liabilityItems.items() if (not k.startswith("Fee Due:"))}

    if "IntAccrue" in set(excludeItems):
        liabilityItems = {k:v for (k,v) in liabilityItems.items() if (not k.startswith("Accured Int:")) }
   
    if "Account" in set(excludeItems):
        assetItems = {k:v for (k,v) in assetItems.items()  if k not in excludeItems }

    balanceItems = {
        'Asset': assetItems,
        'Liability': liabilityItems,
    }

    x = np.arange(len(dates))  # the label locations
    width = 0.40  # the width of the bars
    multiplier = 0

    fig, ax = plt.subplots(layout='constrained')

    for assetClass, assetBreakdown in balanceItems.items():
        offset = width * multiplier
        # plot asset 
        bottom = np.zeros(len(dates))
        for (breakdownsK,breakdowns) in assetBreakdown.items():
            #print(f"plotting bar,data={breakdowns},offset={offset},bottom={bottom}")
            rects = ax.bar(x + offset, breakdowns, width, label=breakdownsK, bottom=bottom)
            bottom += breakdowns

            ax.bar_label(rects, padding=1,label_type="center")
        multiplier += 1


    # Add some text for labels, title and custom x-axis tick labels, etc.
    ax.set_ylabel('Amount')
    ax.set_title('Projected Captial Structure')
    ax.set_xticks(x + width/2, dates)
    ax.legend(loc='upper right')
    ax.set_ylim(0, max([highest_y1,highest_y2])*1.2)
    plt.show()    

yellowbean avatar Jun 14 '23 07:06 yellowbean

it's duplicated with new tree-based balancesheet view

yellowbean avatar Dec 01 '24 15:12 yellowbean