Community Spring Cleaning week is here! Join your fellow Maveryx in digging through your old posts and marking comments on them as solved. Learn more here!

Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
SOLVED

Yahoo- Web Scraping for Stock Prices

rrafferty2
8 - Asteroid

 

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

 

rrafferty2_0-1588102828617.png

 

11 REPLIES 11
AbhilashR
15 - Aurora
15 - Aurora

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.

   

jarrod
ACE Emeritus
ACE Emeritus

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'])

jarrod_0-1588103998998.png

 

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)

 

jarrod_1-1588104039503.png

 

Jonathan-Sherman
15 - Aurora
15 - Aurora

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:

 

image.png

 

 

To run in designer, open up and click on the wand icon to run the analytic app in designer:

image.png

 

I've also converted it into a macro for you to use if needed (example workflow in the attached zipped folder and image below):

image.png

 

If this solves your issue please mark the answer as correct if not let me know!

 

Regards,

Jonathan

jarrod
ACE Emeritus
ACE Emeritus

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. 

danilang
19 - Altair
19 - Altair

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

trettelap
8 - Asteroid

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!

raffrobb
7 - Meteor
 
HI Jonathan: Can you tell me how the workflow and analytic app and macro work? Also, is there python or json code in this workflow or macro. Works great but i don't fully understand how each tool works in this case.  
 
Also I marked as the solution but don't see it as Solved.
 
Thanks Robb    
raffrobb
7 - Meteor

How do you create a list and link for each?

 

Thanks

Robb

jarrod
ACE Emeritus
ACE Emeritus

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)

Labels