Programming Chunks

Explore Python And Data Science with me!!

Home ยป Using Mongodb to structure Risk Exposure Analysis- The next feature

Using Mongodb to structure Risk Exposure Analysis- The next feature

What’s Risk Exposure Analysis in the first place?

You have a portfolio investment. The process of identifying, assessing, and understanding the various risks that you portfolio, investment could come across is called risk exposure analysis.

Today I implemented Risk Exposure Analysis implementation algorithm. Although there are some glitches but I managed.

Even before I implemented this algorithm, I needed a portfolio for the fact that I dont have that of mine. Searched various sites but then it hunched upon me who would be that user who would provide their portfolio details in public?

So, I thought of creating a python script to create a bunch of users who their portfolio details.

The idea was that when the user would login they would have their portfolio id so they would send that id to fetch the portfolio details.

This is simply a standalone that would create the below data in mongodb.

Then I had configured celery to run a shared task (this time I didnt use app scheduler), which would fetch data from this table make some tranformation and put the data in factor_contributions and portfolios table. This basically inserts user portfolio data into the Portfolios and FactorContributions collections with calculations for VaR, Sensitivity, Stress Tests, Regression, PCA, and Variance Decomposition

The data which the shared task fetch would look something like this:

{
  "user_id": "user_009",
  "username": "william_brown",
  "email": "lucas_walker@example.com",
  "portfolio": {
    "portfolio_name": "Income Portfolio",
    "portfolio_desc": "A portfolio focused on technology sector stocks.",
    "portfolio_created_at": "2021-11-25T11:46:28.806+00:00",
    "assets": [
      {
        "asset_ticker": "AMZN",
        "asset_quantity": 99
      }
    ]
  }
}

My script would run and convert this in the below format.

[
    {
        "user_id": "user_009",
        "username": "william_brown",
        "email": "lucas_walker@example.com",
        "portfolios": [
            {
                "portfolio_name": "Income Portfolio",
                "portfolio_desc": "A portfolio focused on technology sector stocks.",
                "portfolio_created_at": "2021-11-25T11:46:28.806+00:00",
                "assets": [
                    {
                        "asset_ticker": "AMZN",
                        "asset_quantity": 99
                    }
                ]
            }
        ]
    }
]

The data would be stored like this.

Then I have api which frontend calls for these values and these values are used to render the heatmap. Enough for today i said to myself.

pallavy.com

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top