Side project · 2016
StockApp
Yahoo Finance stock analytics. Node.js, MongoDB, Yahoo Finance.
StockApp is a 2016 personal project. The README states two goals: pick the best stocks to buy over a period, and estimate how a stock value can change. The stack is Node.js with Express on the HTTP side and MongoDB for stored prices and scores.
Technologies
stockApp.js boots an Express app. Routes live on aStockController. Business logic lives in StockService. Persistence lives in StockRepository. Mongoose schemas describe daily tech prices and performance metrics. The service layer also uses async for batch work, moment for date windows, and csvtojson to parse Yahoo CSV rows.
Yahoo Finance ingest
The service calls ichart.finance.yahoo.com and requests /table.csv for each ticker. Query params set the start and end dates and the company symbol. A hard-coded list of hundreds of tech tickers drives the batch. downloadAllStockData pulls ten symbols per pass so the heap stays under control.
Each CSV row keeps Date, Open, and Close. Volume, High, Low, and Adj Close drop out. The converter tags the row with CompanyName and builds a TechStock object for insert.
How the analysis works
calculateStockPerformanceMetric looks at the same two-week calendar window across the prior five years. For each window it loads matching daily rows from MongoDB. It sums Open and Close across those days, then computes StockChange = totalClose − totalOpen and StockPercentChange = (difference / totalOpen) × 100.
Symbols without at least one year of history skip the ranking. getTopPerformingStocks runs that metric for every ticker, sorts by StockPercentChange descending, and returns the top N (default seven, fifteen for the CLI path). That ranked list is the “best stocks” answer the API exposes.
A separate route can pull the last two weeks of Yahoo CSV for one symbol on demand. The CLI flags DLSD and GBPS kick off download and ranking outside HTTP.
Node.js + MongoDB
Node owns the Express API and the Yahoo HTTP client. MongoDB holds two collections: techcompanydailystocks for daily open and close, and stockperformancemetrics for scored results. The repository connects with the native driver, queries by company name and date ranges with $or on five windows, and inserts metric arrays after a ranking run.
Mongoose models mirror those shapes: TechCompanyDailyStock and StockPerformanceMetric. The API surface includes /Stock, /BestStocks/:num_of_stocks, /AllPerformanceMetrics, /downloadAllStockData/:start_position, and /LastTwoWeeks/:stock_symbol.
Open the GitHub repo·Back to projects
Node.js · Express · MongoDB · Mongoose · Yahoo Finance CSV · csvtojson · async · moment