-
-
Stock vs. Stock 2 - Compare stocks to get an investment recommedation
-
Stock vs. Stock 2 - Choose from over 10,000 stocks that trade on US stock exchanges
-
Stock vs. Stock 2 - Choose from 10 investment factors to compare stocks
-
Stock vs. Stock 2 - Enter your own investment factors to compare stocks
-
Stock vs. Stock 2 - Create a report of your stock comparison to download
-
Stock vs. Stock 2 - The report of your stock comparison is generated as a HTML file which you can open in the browser
-
Stock vs. Stock 2 - Source links are included in both the UI and the report for your reference
-
Stock vs. Stock 2 - The investment recommedation is based on the latest financial data for the factor chosen
Intro
Stock vs. Stock 2 is an AI investment agent that compares any pair of 10,000+ stocks based on a top 10 investment factor and gives an investment recommendation. The comparison is based on real-time Internet search to get the latest financial data which is interpreted using a reasoning LLM. Also, a summary of the whole analysis and an optional report are generated. The user can also enter their own custom investment factors to do the Stock vs. Stock comparison, such as comparing AI strategy or latest analyst sentiment about Trump tariff policy impact.
Motivation
In 2024 I submitted version 1 of this app in the Hackonomics 2024 hackathon on Devpost. Since for this year's Hackonomics 2025 hackathon, submissions from the previous hackathon are permitted, I decided to update the app by orders of magnitude and submit V2 to see if I could win 1st place this time :)
So what's the update? Well, in V1 my app only supported the 503 stocks in the S&P 500. In V2 my app now supports over 10,000 stocks! In V1, the number of stocks was limited because I web-scraped the financial statements of the S&P 500 companies and after chunking and embedding them, I stored the resulting vectors and metadata in a vector database, to allow using RAG with them. Storing a year's worth of financial statements from 503 companies takes up more than 5 GB in the vector database and requires constant updating to add new statements as they're filed with the SEC. In V2 I decided to get rid of the vector database and instead use the Perplexity LLM which features real-time Internet search from reputable financial and investment sources, with the data processed and synthetized by its fast reasoning LLM based on its post-trained version of DeepSeek R1. This redesign means Stock vs. Stock 2 can provide expert analysis on all stocks whose information is publicly available on the Internet.
For the judges from Hackonomics 2024 who try out my V2 app, they'll notice that while V1 had links to financial statements on the SEC website as sources, in V2 the source links are reputable financial and investment sites, to articles and documents which are current or trending.
See the differences:
Benefits
For the goal of spreading awareness of financial literacy and economics in the community, Stock vs. Stock 2 lets users compare stocks based on the latest financial data available from real-time Internet search, and obtain investment recommendations made by one of the most powerful open-source reasoning LLMs, backed by citations as working links the user can drilldown on for further exploration.
For investment beginners, the top 10 provided investment factors can be used for initial and fundamental stock comparisons. For advanced and more curious users, the custom investment factor input box allows you to enter any trending investment factor or factors of your choice to compare and synthetize the live search results to a deeply reasoned recommendation.
For generating the optional report of the comparison and recommendation, Llama is used to generate the HTML doc which you can download. The reason why I use an LLM to do this rather than write the code is because this gives flexibility to the user to decide what format appeals to them most for their personal investment report. If they're not satisfied, they can redo the comparison and Llama will likely generate a different styling due to the variability of LLM responses.
Scalability and Performance
I designed the app to be lightweight. As proof, I deployed it to Google Cloud using only 1 vCPU & 512 MB.
All prompts used by the app are stored in 15 prompt files. This allows prompt tweaks without touching the code, minimizing downtime for prompt updates that may be required when upgrading the version of a LLM, Perplexity or Llama.
To optimize performance, API requests to the Perplexity model to analyze each of the 2 stocks being compared are sent in parallel, not sequentially.
For each step of the recommendation workflow, (a) analysis, (b) comparison, (c) summarization, as soon as the results for one step is returned by the model, those results are shown in the UI without waiting for all 3 steps to be complete.
And for handling API rate limit errors, the Tenacity library is used to retry seamlessly with exponential backoff.
Finally to give the user notification their investment recommendation is ready, once the workflow is complete, the summary is read aloud to them :)
Summary and What's Next
V2 is orders of magnitude update to V1 for users and even investiment advisors to educate themselves on stock investments and the financial and economic reasons for choosing one stock over another by leveraging AI.
For Stock vs. Stock 3 I'll revamp the UI to be more intuitive, and update to more powerful and faster models of Perplexity and Lllama as they become available.
Built With
- gradio
- langchain
- llm
- prompt-engineering
- python-3.12
- tenacity
- text-to-speech

Log in or sign up for Devpost to join the conversation.