Is there a way to extract or retrieve historical stock prices and dividends from Yahoo for the S&P, and of course, Alteryx share prices. I looked in community and saw lots of discussion, but nothing that directly solves a direct pull or web scrape.
I have found that stock prices and financial data are a rich source of sample data for exploring Alteryx workflows.
Thanks
Robb
Solved! Go to Solution.
Hi @rrafferty2, you could copy the link behind the Download button (right-click on the icon and select Copy Link Address) on the Yahoo site and use Alteryx's Download tool to fetch the data. I have attached a sample for you to play with and use it as a baseline to replicate.
I don't think the Yahoo finance api is still operational, but i did find a python library that you can connect to called "yfinance".
Open alteryx as administrator and drop a python tool onto the canvas.
Copy the following into the first cell and "run" the python script:
Package.installPackages(['yfinance'])
then reopen alteryx as a regular user and copy the following into a new python tool:
from ayx import Alteryx
import yfinance as yf
msft = yf.Ticker("MSFT")
# get historical market data, here max is 5 years.
data = msft.history(period="max")
# output to Alteryx Connection #1
Alteryx.write(data,1)
Hi @rrafferty2,
I've just built an analytic app you could use to pull the data for a particular stock code (AYX = Alteryx) for a particular period:
To run in designer, open up and click on the wand icon to run the analytic app in designer:
I've also converted it into a macro for you to use if needed (example workflow in the attached zipped folder and image below):
If this solves your issue please mark the answer as correct if not let me know!
Regards,
Jonathan
I just wanted to add in a Batch macro for those looking to solve via Python's yfinance package.
This allows you to pass through a list of tickers and pull historical data. With some extra tweaking, you can set it up to define date ranges, multiple tickers at once, etc. but i wanted to get the example posted for a generic pull.
Hi @rrafferty2 ,
As a leader in the Alteryx Community, I have the ability to identify & mark accepted solutions on behalf of community members - and recently did so on this thread. If you have any questions or concerns with the solution(s) I selected please let me know by replying to this post.
As the original author, you also have the ability to mark replies as solutions! Going forward, I’d encourage you to identify the solution or solutions that helped you solve your problem, as it's a big help to other community members. Learn more about Accepted Solutions here.
I've accepted two solutions here since both provided answers to your question and provided two completely different strategies, with @jarrod's leveraging the Python tool and @Jonathan-Sherman using the Download tool.
Thank you!
Dan
Awesome stuff! The download tool is very useful. You can also make a list of tickers, create the link for each with a formula tool, and then download information for many stocks at once. Tremendous opportunity to scale!
How do you create a list and link for each?
Thanks
Robb
Hey @raffrobb take a look at my updated macro (attached). you should be able to send in a list of tickers and it will run a combined download on the stocks you pass through. it's set to 5 days, but that can be changed in the macro (never got around to adding that feature)