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

[P/L Addon] Holdings Analyzer feature request to show stock exposure #14

Open
ajinabraham opened this issue Aug 10, 2022 · 2 comments
Open

Comments

@ajinabraham
Copy link

Hi @mani-coder 👋

I have a feature request. I can also work on it, if you can point me to the related code, data points and dev setup.

Show detailed exposure to a stock in holdings analyzer.

Today holding analyzer shows exposure to individual stocks and etfs. Can we have a feature that will show exposure/holding percentage at the stock level, that will take into account both direct stock holding as well as holding via ETFs?

@mani-coder
Copy link
Owner

Hi @ajinabraham, yeah tats doable. We need to figure out an API that will return the holdings of an API, then we can show a table for these in-direct holdings.

Are you aware of any API which will take a list of ETF symbols and returns the holdings in each ETF? If so, let me know, we can look into implementing it.

Thanks!

@ajinabraham
Copy link
Author

Most of the stable APIs are paid, the rest I found are actually scraping yahoo finance / google finance and seems to be not maintained well.

I found a node and python module that seems to provide ETF holding info, based on Yahoo Finance. Both only lists the top 10 individual stocks hold by the ETF though.

Node.js - https://github.com/gadicc/node-yahoo-finance2

const yahooFinance = require('yahoo-finance2').default;
(async function (){
    const results = await yahooFinance.quoteSummary('XIU.TO', { modules: [ "topHoldings" ] });
    console.log(JSON.stringify(results, null, 2))
})();
{
  "topHoldings": {
    "maxAge": 1,
    "stockPosition": 0.9979,
    "bondPosition": 0,
    "holdings": [
      {
        "symbol": "SHOP.TO",
        "holdingName": "Shopify Inc A",
        "holdingPercent": 0.089700006
      },
      {
        "symbol": "RY.TO",
        "holdingName": "Royal Bank of Canada",
        "holdingPercent": 0.0785
      },
      {
        "symbol": "TD.TO",
        "holdingName": "The Toronto-Dominion Bank",
        "holdingPercent": 0.069299996
      },
      {
        "symbol": "ENB.TO",
        "holdingName": "Enbridge Inc",
        "holdingPercent": 0.044099998
      },
      {
        "symbol": "BNS.TO",
        "holdingName": "Bank of Nova Scotia",
        "holdingPercent": 0.0429
      },
      {
        "symbol": "CNR.TO",
        "holdingName": "Canadian National Railway Co",
        "holdingPercent": 0.040700004
      },
      {
        "symbol": "BAM.A.TO",
        "holdingName": "Brookfield Asset Management Inc Class A",
        "holdingPercent": 0.038900003
      },
      {
        "symbol": "BMO.TO",
        "holdingName": "Bank of Montreal",
        "holdingPercent": 0.0361
      },
      {
        "symbol": "CP.TO",
        "holdingName": "Canadian Pacific Railway Ltd",
        "holdingPercent": 0.0279
      },
      {
        "symbol": "CM.TO",
        "holdingName": "Canadian Imperial Bank of Commerce",
        "holdingPercent": 0.0278
      }
    ],
    "equityHoldings": {
      "priceToEarnings": 13.41,
      "priceToBook": 2.24,
      "priceToSales": 2.38,
      "priceToCashflow": 12.03
    },
    "bondHoldings": {},
    "bondRatings": [
      {
        "bb": 0
      },
      {
        "aa": 0
      },
      {
        "aaa": 0
      },
      {
        "a": 0
      },
      {
        "other": 0
      },
      {
        "b": 0
      },
      {
        "bbb": 0
      },
      {
        "below_b": 0
      },
      {
        "us_government": 0
      }
    ],
    "sectorWeightings": [
      {
        "realestate": 0.0063
      },
      {
        "consumer_cyclical": 0.0476
      },
      {
        "basic_materials": 0.097600006
      },
      {
        "consumer_defensive": 0.033299997
      },
      {
        "technology": 0.0538
      },
      {
        "communication_services": 0.0615
      },
      {
        "financial_services": 0.36360002
      },
      {
        "utilities": 0.031400003
      },
      {
        "industrials": 0.111999996
      },
      {
        "energy": 0.18010001
      },
      {
        "healthcare": 0.0014
      }
    ]
  }
}

Python - https://pypi.org/project/yahooquery/

from json import dumps
from yahooquery import Ticker
x = Ticker('xic.to')
print(dumps(x.fund_holding_info, indent=4, sort_keys=True))
{
    "xic.to": {
        "bondHoldings": {},
        "bondPosition": 0.0,
        "bondRatings": [
            {
                "bb": 0.0
            },
            {
                "aa": 0.0
            },
            {
                "aaa": 0.0
            },
            {
                "a": 0.0
            },
            {
                "other": 0.0
            },
            {
                "b": 0.0
            },
            {
                "bbb": 0.0
            },
            {
                "below_b": 0.0
            },
            {
                "us_government": 0.0
            }
        ],
        "equityHoldings": {
            "priceToBook": 2.17,
            "priceToCashflow": 10.78,
            "priceToEarnings": 12.12,
            "priceToSales": 2.14
        },
        "holdings": [
            {
                "holdingName": "Shopify Inc A",
                "holdingPercent": 0.0704,
                "symbol": "SHOP.TO"
            },
            {
                "holdingName": "Royal Bank of Canada",
                "holdingPercent": 0.0616,
                "symbol": "RY.TO"
            },
            {
                "holdingName": "The Toronto-Dominion Bank",
                "holdingPercent": 0.0544,
                "symbol": "TD.TO"
            },
            {
                "holdingName": "Enbridge Inc",
                "holdingPercent": 0.0346,
                "symbol": "ENB.TO"
            },
            {
                "holdingName": "Bank of Nova Scotia",
                "holdingPercent": 0.0337,
                "symbol": "BNS.TO"
            },
            {
                "holdingName": "Canadian National Railway Co",
                "holdingPercent": 0.0319,
                "symbol": "CNR.TO"
            },
            {
                "holdingName": "Brookfield Asset Management Inc Class A",
                "holdingPercent": 0.0305,
                "symbol": "BAM.A.TO"
            },
            {
                "holdingName": "Bank of Montreal",
                "holdingPercent": 0.028299998,
                "symbol": "BMO.TO"
            },
            {
                "holdingName": "Canadian Pacific Railway Ltd",
                "holdingPercent": 0.0219,
                "symbol": "CP.TO"
            },
            {
                "holdingName": "Canadian Imperial Bank of Commerce",
                "holdingPercent": 0.0218,
                "symbol": "CM.TO"
            }
        ],
        "maxAge": 1,
        "sectorWeightings": [
            {
                "realestate": 0.0278
            },
            {
                "consumer_cyclical": 0.0468
            },
            {
                "basic_materials": 0.1112
            },
            {
                "consumer_defensive": 0.0332
            },
            {
                "technology": 0.0542
            },
            {
                "communication_services": 0.0519
            },
            {
                "financial_services": 0.3149
            },
            {
                "utilities": 0.0454
            },
            {
                "industrials": 0.12020001
            },
            {
                "energy": 0.183
            },
            {
                "healthcare": 0.003
            }
        ],
        "stockPosition": 0.9979
    }
}

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

2 participants