showkatewang / Stock_Analysis

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Overview

The purpose of this project is to refactor the AllStocksAnalysis subroutine in MS Excel Visual Basics for Application (VBA) with subroutine AllStocksAnalysisRefactored in order to execute 2017 and 2018 stock analysis more efficientely. Same data is utilized in AllStocksAnalysis as in AllStocksAnalysisRefactored. Due to the nature of VBA running all past saved codes regardless of any present editions, almost all refactored code is created and edited on VSCode prior to running, and especially saving, on VBA.

Results

Stock Performance

Only TERP stocks yielded a negative percentage of return in 2017, indicating a bull market. On the other hand, all except ENPH and RUN stocks yielded a negative percentage of return, indicating a bear market. Only RUN stocks increased in percentage of return from 2017 to 2018.

2017 stock performance is shown below.

2017_ Stock_ Performance

2018 stock performance is shown below.

2018_ Stock_ Performance

Refactoring Code and Corresponding Execution time

The refactored code declared additional variables compared to the original. Both codes utilized for loops to calculate and store values of interest, however, the for loop of the refactored code ran through the data once as opposed to the original code where the loop ran through the data several times. In this instance of running the subroutines, AllStocksAnalysis ran slower than AllStocksAnalysisRefactored by approximately 0.52 seconds for analysis of 2017 stocks and by approximately 0.58 seconds for 2018 stocks. Note that subsequent run times may decrease since computer resources are allocated specifically for these tasks.

A portion of code from AllStocksAnalysis is shown below. All_ Stocks_ Analysis_ Code

A portion of code from AllStocksAnalysisRefactored is shown below. VBA_ Challenge_ Code

AllStocksAnalysis ran in roughly 0.67 seconds for year 2017 as shown below. All_ Stocks_ Analysis_ 2017

ALLStocksAnalysisRefactored ran in roughly 0.15 seconds for year 2017 as shown below. VBA_ Challenge_ 2017

AllStocksAnalysis ran in roughly 0.66 seconds for year 2018 as shown below. All_ Stocks_ Analysis_ 2018

ALLStocksAnalysisRefactored ran in roughly 0.08 seconds for year 2018 as shown below. VBA_ Challenge_ 2018

Summary

An advantage of refactoring code is that the refactored code will run in a shorter timespan than the original. The distinction between execution times may be commensurate with the amount of data to be analyzed. A possible disadvantage of refactoring code is that should the lines of code increase, the amount of time spent on refactoring may increase in accordance. If no urgency or time constraint exists, refactoring the original code may be optional rather than a necessity. The efficiency of refactoring code is demonstrated in this project with the execution times of AllStocksAnalysis and AllStocksAnalysisRefactored. Overall this project is a worthwhile exercise of coding in VBA and refactoring code so the possible disadvantage is rendered null.

About


Languages

Language:VBScript 100.0%