Inspiration
My dad has always tried to give me financial advice, and I love him but sometimes it gets overbearing. So I trained a neural network to predict stock activity and give me the numbers without the whole spiel about how I "shouldn't be spending $6,000/month on candles" or "hiring hitmen to stop him from lecturing me"
What it does
Reads in your provided stock symbol and brings you to a page with a few bits of information:
- Stock symbol / Name / Company Homepage
- Previous 7 days of stock activity
- Predicted next 7 days of stock activity based on previous activity and sentiment analysis ## How I built it
- I quickly realized that working on whatever chunk of the project came to mind would be inefficient and confusing. I drew up a flowchart on my chalkboard describing how various parts of the frontend and backend would interact with each other
- I categorized various functionalities into what would eventually become classes, then I started building their methods one by one, testing as I went along
- Started with the backend first so I could get all of the machine learning stuff out of the way early. I did about 30 minutes of research into which model architectures perform best on signal prediction and settled on an architecture that I liked and was familiar of
- I gathered data using Yahoo's
yfinancepython module, splitting it into training and testing data. This data came from 10 specifically-chosen companies that I believe have patterns common enough to predict most stocks off of. I trained 10 models whose results are combined - I didn't have to train a sentiment analysis network because I have access to spaCy, a wonderful NLP library. The average output of a spaCy model fed with current headlines is combined with the ensemble mentioned above
- Early on in the project, I had set up a Heroku project just to get ready. Unfortunately, as I started to upload things to test with my Hello World Flask server, I found that TensorFlow alone was larger than the size limit for a free Heroku project. I spent about 2 hours just trying to properly install TFLite on a remote server so that this project wouldn't disappear into thin air. Right when I thought I was ready to call it a night, I found the solution.
- With my stock activity predictor complete, I began adding functionality to the frontend. It features 3 simple pages: an index, about page, and a search page. Each uses Jinja for data input from Flask and Bootstrap for spacing and whatnot.
- When I had successfully passed the search results to the backend, and then returned the stock predictions as plain text, I downloaded canvasJS, a pretty Stock charting library. It was surprisingly difficult to work with, but at that time I understood I was in the home stretch so I wasn't too worried. After adding the finishing touches, I added the historical data behind the predicted data so users could better understand the trend that the prediction was working off of.
- I was disappointed with how slow the prediction was, so I implemented a basic cache using a SQLite server that stores results for an hour. This greatly sped up testing, and I anticipate that most people will look up the same stocks when they're trying it out, so only one user will have to experience that wait time. And that's it! It felt like lot of little chunks that fit together like puzzles pieces from different puzzles, but it was a lot of fun to cram together.
Challenges I ran into
I originally wanted to host this project locally, and I now understand why I had that gut feeling. Trying to mediate between TensorFlowLite and Heroku was horrible, and every minute I spent trying to fix the issues made me want to give up that much more.
Accomplishments that I'm proud of
This was my first hackathon, so I'm proud of the fact that I made anything that looks nice and works well in 12 hours. This was also my first time using TFLite and Heroku, so I'm proud that I was able to branch out into new technologies and grasp those concepts quickly.
What I learned
- Don't get tunnel vision when working on issues that just won't seem to get fixed. Get up and eat, drink water, take a quick nap.
- Deadlines are stressful, don't wait until the last 24 hours to start on them
- Working with scary libraries is fun and necessary to grow as a developer
What's next for Stocksprism
I'm not a big finance guy, so I think I'll let this one sit for a while before I decide to come back to it.
Log in or sign up for Devpost to join the conversation.