While many individuals leverage google trends for markets such as ecommerce to see which products to sell, there are various other variations in which google trends could be quite useful in regards to researching investments. For individuals seeking to learn how to leverage google trends, it is vital for he or she to understand that one first must pick a programming language. For the purpose of this article, we chose to use the python programming language. Some of the benefits in regards to python are it's simple to use, quick to code, and fewer lines of code. Some of the drawbacks are it's interpreted language in nature, which means the code takes longer to run than say Java, but this could be resolved with Apache Flink or Apache Spark, which convers the code into the JVM, and is out of scope for this tutorial.. When writing code, it's vital for one not to fall in love with a programming language. Now, we get into utilizing python for google trends pertaining to investments.
Steps:
1) Download Pycharm -> https://www.jetbrains.com/pycharm/download/#section=windows
2) Install Anaconda -> https://www.anaconda.com/products/distribution
3) Run the source code below, and replace the ticker symbol with a new ticker symbol:
# import the TrendReq method from the pytrends request module
from pytrends.request import TrendReq
from pylab import *
# execute the TrendReq method by passing the host language (hl) and timezone (tz) parameters
pytrends = TrendReq(hl='en-US', tz=360)
# build list of keywords
kw_list = ["AAPL"]
# build the payload
pytrends.build_payload(kw_list, timeframe='2021-02-22 2022-02-22', geo='US')
# plot all three trends in same chart
# store interest over time information in df
df = pytrends.interest_over_time()
# display the top 20 rows in dataframe
print(df.head(20))
df.plot()
show()
Legal Disclaimer:
This post does not constitute an endorsement for an investment, does not reflect the opinions of any Investment Sciences' clients or affiliates, and is solely for educational purposes only.