- To compare the performance of Wall Street Stock between 2017 and 2018.
- Take user input for the year to show total daily volumn and return for each stock for specific year.
- Create clear worksheet button to get ready for next analysis.
- To accelerate the execution time of all stock analysis for each year, the macro code was refactored.
- Format and conditional format the table.
- Run Stock Analysis
- Sample code:
- Total daily volumn and return in 2017/2018 for each stock are displayed respectively on worksheet.
-
User friendly year input box and Clear button
- codes
Dim yearValue As String yearValue = InputBox("What year would you like to run the analysis on?")
ClearWorksheet() Cells.Clear
- Worksheet display
- codes
-
Compare 2017 and 2018 analysis result to select the stock worthy to invest.
-
The execution of
All Stock Analysis
for each year(2017 & 2018) was accelarated.
-
Steve's parent planned to put their investment on DQ. Unfortunatly, DQ's return has plummeted. Absolutely, DQ is not a smart choice. From the view of return for 2018, the stock of ENPH and RUN got 80~85% return, which seems investable. However, Comparing to 2017, Enph's return dropped from 129.5% to 81.9%, RUN's return increased from 5.5% to 84.0%. Overall, ENPH is more like a promising profitbale stock to make investment.
-
Two big changes were made under refactoring code.
-
Variable types of
startingPrice
andendingPrice
were declared asSingle
instead ofDouble
. -
TickerIndex
was introduced. This may avoid nestedFor Loop
.
- Refactoring code was applied to the VBA script, it helps VBA script run 4~5 times faster.
-
Since Refactoring Macro could process
starting Prices
andendingPrice
with single data type,Return
can be caculated much faster. -
Refactoring script contains 3 indepent
For Loop
. Each row would be assigned to a certaintickerIndex
. Thus eachtickerIndex
could loops over independently. The full worksheet could be only scanned for once. Whereas in the orginal script with nested for loop. For Each tickers, all the rows in the worksheet would be scanned. So it would be loop over for 12 times in total. This might be the main reason that execution time were damatically shortened. On the other hand,tickerIndex
makes the code more complicate, which is easy to make mistakes for developer.