Giter Club home page Giter Club logo

stock-analysis's Introduction

VBA Stock Analysis Challenge

Overview

The purpose of this project was to refactor code to analyze stock data from any year within our workbook. Originally, we used nested loop statements to analyze a small set of given data. Nested loops worked for our small data set but was not as efficient as it could be. With this in mind, the goal was to refactor our code to increase the efficiency by looping through the data set once.

Results

Original Code

My original code used nested loops to find stock changes for a specified year in my data. I created an array of the ticker values I wanted the information on. Then I used them as an index for my first (outer loop), while the inner loop went through the data looking for information that matched the indexed ticker.

Screen Shot 2021-02-14 at 8 40 23 PM

This returned the information I was looking for in 0.5625 and 0.578125 seconds for 2017 and 2018 respectively.

Screen Shot 2021-02-14 at 8 41 36 PM Screen Shot 2021-02-14 at 8 41 04 PM

The concern with this method was the length of time it took to process a years’ worth of information for only 12 stocks.

Refactored Code

In the pursuit of a more efficient method, nested loops were dropped in favor of several arrays and a series of loops.

Screen Shot 2021-02-14 at 8 38 40 PM

Here 3 different arrays were made to store the information derived by the first loop. Then a second loop displayed the information on my “VBA Challenge” sheet, by looping through the arrays. The last loop colored the Returns column using conditional statements. This allowed the code to run through the information 1 time, eliminating the extra searching of the first code, and return the same information in 0.15625 for either year.

VBA_Challenge_2017 VBA_Challenge_2017

A 72.6% improvement on average!

Summary

Refactoring code was a great way to explore finding alternative methods to a previously successful one. It also allowed further opportunities to debug different types of coding issues. Refactoring does have disadvantages as well. If the code was not properly annotated then it could be hard to decipher the purpose of a certain line or section of code. There is also the issue of the code not working once reworked. In this project, I found that the new code did not work right away for the 2017 page as there was some problems with the data itself. While it worked in the end, it did take some time to find the cause of the issue. The data corruption was not an issue with the original code, and for our small data set, the original code did the job just fine. Having worked with both, I do like the speed and efficiency of the refactored code, but knowing its more temperamental with respect to data corruption, It may require some more refactoring to work through corruptions.

stock-analysis's People

Contributors

srushin avatar

Watchers

 avatar

stock-analysis's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.