The Stock Analysis project is all about helping my friend Steve who has asked me to analyze a green stock for his parents to see if it is worth investing in. Steve's parents are very much passionate about green energy. So they decided to invest in DAQO New Energy Corp. DAQO's ticker symbol is "DQ". So further we'll be using the ticker symbol "DQ" in our analysis.
- As mentioned we'll first start with analysing the DQ stock :
- As Steve's parents are starting to pester him about DAQO's stock we'll be starting our analysis with "DQ" .
- So here we are using VBA code to further help Steve in stock analysis.
- I first started with creating Macros and write my code under that particular macro which was DQ Analysis and below is the screenshot for the same :
- From the above code i tried to analyze the DQ stock for Steve and his parents and came to conclusion that the DQ doesnt have good returns in 2018 which we'll further see in the results section below.
- Since Daqo might not be the best option for Steve's parents to invest in, I started analying multiple stocks to find some better choices for them.
- With a little more code, we can analyze a whole list of stocks as follows:
We'll analyze its results in the further section of my analysis.
As we discussed in earlier section that in order to help Steve and his parents to calculate the total daily volume and yearly return we started working first on stock "DQ" (for which Steve's parents were interested in) and further did all stock analysis. This resulted into as follows :
- To summarize the Stock Analysis project i refactored the original code. The following Questions and explanation for the same will help Steve and his parents to understand what stock to invest in and what should be the correct way of doing it. We'll see some examples below with coding and screenshots.
- In order to make my code more efficient, I needed to switch the nesting order of my for loops. To do this, I created a 4 different arrays; tickers, tickerVolumes, tickerStartingPrices, and tickerEndingPrices. The tickers array was used to establish the ticker symbol of a stock. I matched the other three arrays with the tickers array by using a variable called the tickerIndex. So my Refactored code looks like this:
And then if i compare my 2018(original) run time and 2018(refactored) run time my refactored code runs about 20 seconds faster than the original code making it more efficient.
- The advantage of refactoring code is the screen running time is less then the original script and the refactoring is more easier to understand and read.
- But the only disadvantage i relaized is it is time consuming and very complex to "write" the script
- As we saw earlier the refactored code is more tedious.
- This is further understood by following screenshot where we can cleary see that time to run 2017(refactored one) is less as compare to 2018(original one).
If i talk about the pros and cons of stock analysis from original to refactoring the most important pros I noticed was
- The resources were utlizied less as compare to the original vba script.
- And at the same time the cons was the refactoring is more complex structure.
- for e.g In Original VBA script in order to calculate the total daily volume and its returns - It was more time consuming and resources were over utilized while - When we calculated the same total daily volume and returns for 2017 it took comparatively less time which we noticed in the screenshot earlier - To run the code it took 0.97 as compared to 2018 where it took 1.07 seconds) which is self explanatory.