In this example, I’m looking at companies in the computing industry, across different regions and types. What I need to understand is, given the timeframe that I intend to invest for, what is the best region and type for me to invest into.
Note: this article is intended to show the functionality & capabilities of Pandas and Python, rather than being a guide to investment analysis. The example gives us context only.
So, let’s walk through the code. Here, we’re bringing in my stock data into a dataframe:
Next, I want to have a quick view of the various regions & types, with their 3mth, 6mth, 1yr, 3yr and 5yr performance. I take the average across all stocks in the region / type.
Next, I need to define my investment goal (how long I am going to invest for). In this case, I define it as 3 months. I’m going to extract only the 3 month performance to make my dataframe easier to read.
The above is all ok, but it’s very manual. I want my app to tell me exactly where to invest. To do that, I extract the best performing region & type combination in the dataset. It tells me to invest in emea, corporate companies (based on my investment_goal changing to 1 year).
The below extracts all the stocks from the list that conform to our advised region & type. We can see a clear winner in each time period. But he quesion is, how volatile is the stock? For example, we can see that doggy computers had extreme growth for a short period but has gone into sharp decline.
Now we need to create a few new fields. These are going to tell us the percent change between different time periods.
You may also like to average out the percentage change over different time windows, like below:
The great thing about Python, using Jupyter and iPython is that we can keep exploring our data, getting more insights and understanding more. This article aimed to demonstrate how we might do that, in the context of stocks.