Skip to content

Compare stocks – Part II

September 13, 2013

So after an entire night of coding, I finally have my GUI working. The designing part was of course kinda easy. But linking the GUI file with your calculations is kinda tough. I had included a list of only 6 companies earlier, right now I’ve updated the list to 500+ companies registered in the NYSE & NASDAQ. Some stock market indices have also been included for comparison, for example, Dow Jones and S&P-500.

I thought I had everything in order, when I tried changing input data and re-comparing. The code did not update the data every time I tried putting in data. Okay I had to work a little harder to update the plots dynamically. Earlier, I tried calling the ‘on-click’ listener for the Compare button from my Application class. It transferred execution to the calculate function and from there I sent the input data to my imported python script comparison.py.

I tried returning the plots as QPixmaps, but there was an unknown never-heard never-seen error that I encountered. I had no clue what to do and so put up a question on StackOverflow expecting quick solutions (it takes time for the right people to view your post there). Still no working solutions over there. But with some trial and error I was able to get it done. The solution lies in calling the compare module of the comparison class BEFORE you declare the Labels.

The earlier code did not display the plots until the GUI was run for a second time, and this is crazy (You wouldn’t want to go back to the terminal and run it and view your previously plotted data). The updated version waits for you to click and send input data. Once that is done, it waits for your compare function to be executed completely and only then are the Labels assigned pixmaps. The next step is to display them (The code includes all necessaru comments to understand its functioning).

The Compare-Companies folder in my repository has been updated, in case you’d want to try running. The gui.py includes the design of GUI and calling of the on-click listener for compare button. It transfers control to the compare function in the comparison class. No pixmap is returned, as I said, I ran into some weird errors. So I chose saving the temporary plots and reloading them as pixmaps (This was the way it worked).

Note: You need to have the QSTK framework installed and running before trying to run these scripts. QSTK itself depends on libraries like pandas, matplotlib, numpy, scipy, etc.

Advertisements
Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: