Friday, March 27, 2026

Building a AI Agent to analyze REITs and InvITs

 Ages ago, I came across the news that the minimum threshold of 100 units for REITs to buy have been done away with. I was curious what is REIT? Why the limit size and so on. There were only 3 REITs then. 

I was fascinated by them. I felt it might be interesting cause it helps to diversify, it helps to own a piece of real estate and regular income and yields were better than rental yields. (Think buying a flat and renting out) In addition, potential for capital appreciation as well in a clean and better manner. (Think about buying a plot and the loan and the hope it will appreciate and the challenge of liquidating and so on)

Though the lot size limit was done away with, I bought 100 units of all 3 REITs. I kept buying them regularly. I wasn’t sure of figuring out which is good and which might have potential and so on. So I bought all the three regularly and more or less in equal amounts. Now and then I would try to search for posts and analysis about them but they were never up to date.

Fast forward now, thanks to AI, generative AI and LLM, I have been building out few things. (How I ended up as a vibe coder is a story for another day) One of the things, I wanted to build was to figure out the retail bond with the best yield. I was struggling and end up facing structural challenges. It was then I realized, I could use that approach to analyze the REITS.

Basically, I wanted to know which REIT could be the best one to pick rather than blindly investing equally in all REITs. 

https://rankindiareitinvit.lovable.app/

So I have built it. Also the dividend yield is only one factor and mostly the past which may or may not help to look in to the future. So, I wanted it more of a strategy engine, what If i am keen on future potential, what If i am looking to reduce the risk, what If i have to Optimize for the dividend yield (again based on the past performance)

During the process of building it I learnt more than few things.

One, just because prompting and tools make it easier to build and gives a nice looking output doesn’t mean it does what it is intended to do. We should also know what we are building, why we are building and the nuances of it. Domain knowledge, Software engineering, product management matters more than ever. 

For e.g as simple as fetching the CMP was a challenge. In the first cut, it was fetching stale data from yahoo. Calculating Yield is one thing, calculating it the post tax yield is what makes it unique. There are nuances to tax calculation of REITs, in addition all REITs are not unique. In fact, though I was thinking it is better than rental yield, never thought about, hey what is the bench mark to see, if the yield is good (again to be fair, it is not just about yield as there could also be capital appreciation). 

Even when building it, I asked to fetch the parameters from the investor presentation and AI was taking it from the PDF. Considering, I am someone who knows about the industry, I should have asked the AI agent to fetch the data from the XBRL rather than the PDF as it is the optimal and ideal one.

Once I was done with building, the surprising thing was how the REITs were not necessarily doing well as the post tax yield was below the 10Y G-Sec Yield. 

Later on I also added the InvITs to the mix. (Again the taxation for InvIT is different) 

I could have also built this differently. For e.g have only one page with filter to have REIT only, InvIT only or both together. Rather than the current version of 5 pages, - Master ranking, REITs, InvIT, terminology and methodology, and what this is all about. 

I also learnt the following from Lovable: Feedback on how I prompt

  • Skip explaining the problem — just state the desired outcome. I can see the code.
  • One instruction per sentence. Your multi-option prompts ("do X, or alternatively Y, I prefer Y") cost extra tokens exploring options you don't want.
  • Reference by component name when possible ("TerminologyCard: use inline badges") rather than describing the UI.
  • Batch related changes in one message with numbered bullets — your audit prompt was a good example of this.

Roughly, your prompts averaged ~2-3x the minimum needed length. Tighter prompts = fewer tokens per message in build mode.

What next?

I could make it open source, I could build a admin panel or one with user input, where people give the inputs as country, taxation, local nuance, basically say where to look for the APIs to fetch the CMP, NAV and the returns, and it builds the engine for that market. 

I can try and build a plugin to calculate the taxation and make it easy to file the taxes in India.

Few other things that might be of interest

I had around 18-22 high intensity prompts. Probably would have spent 120K-150K tokens and have spent 8-10 hours. I could have achieved the same in 30% fewer prompts. If upfront, I had thought a lot about how to build, what to build, say i want both REIT and InvIT, I want the table to look this way, these are the common factors, this is how I want to visualize and so on. 

No comments: