Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plotting candy function: Asset-vs-Liability #15

Open
yellowbean opened this issue Jun 12, 2023 · 3 comments
Open

Plotting candy function: Asset-vs-Liability #15

yellowbean opened this issue Jun 12, 2023 · 3 comments
Assignees

Comments

@yellowbean
Copy link
Owner

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
Copy link
Owner Author

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

@yellowbean
Copy link
Owner Author

yellowbean commented Jun 14, 2023

Prototype

image

@yellowbean
Copy link
Owner Author

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 yellowbean self-assigned this Jun 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant