馃攳
How to use Alpha Vantage API Python- 2021馃敶 [FREE data] - YouTube
Channel: Financial Programming with Ritvik
[0]
If you want real-time financial data for free聽
then watch this video till the end and there is聽聽
[4]
also a small gift from my side to all my lovely聽
subscribers. What is up everybody, I am Ritvik聽聽
[9]
Dashora and I am back with a new video and some聽
new learnings. Today, I am going to talk about one聽聽
[14]
of the most popular and a free data-provider聽
Alpha Vantage and how to use Alpha Vantage聽聽
[20]
API directly in python such that you get all the聽
financial information for free. In the last video,聽聽
[26]
I talked about IEX cloud API and you can click on聽
this i button to watch more about that, and just聽聽
[32]
to remind IEX cloud is also a free data provider.聽
Alpha Vantage provides data related to stocks such聽聽
[40]
as time-series data or I would say financial data,聽
the statements data. It also provides data related聽聽
[46]
to Forex, Cryptocurrencies and there's also one聽
great feature of Alpha Vantage that it gives聽聽
[52]
us information about the Technical Indicators.聽
It covers more than 50 technical indicators so聽聽
[58]
it's quite useful if you directly synchronize it聽
with python and do your analysis for Algorithmic聽聽
[64]
Trading purposes. For time-series data, several聽
frames are available on Alpha Vantage and it聽聽
[70]
goes as low as one-minute interval to monthly聽
interval. Now let's see how to use alpha Vantage聽聽
[76]
API in python. First of all, what you need to聽
do is go to uh the Alpha Vantage website. The聽聽
[83]
link is in the description box and claim your聽
API key. It's free of cost... just provide some聽聽
[89]
very basic details here by clicking on this聽
button which is "Get free API key". You'll get聽聽
[94]
an API that you'll be using for extracting聽
financial information. The next step is to聽聽
[100]
"pip install alpha_vantage" on whatever platform聽
you're using. Maybe you're using jupyterlab or聽聽
[106]
google colab or spyder etc. pip install alpha聽
underscore vantage. It will take some time聽聽
[112]
um to install it and as you can see it's already聽
satisfied in my computer but in your case,聽聽
[119]
it will be downloading some files. Now let's聽
see the API documentation of alpha vantage聽聽
[124]
um the link is in the description box. Just click聽
on that and this is the API documentation you can聽聽
[129]
see that on the left hand side it provides data聽
related to stock time-series, Fundamental data,聽聽
[135]
Forex, cryptocurrencies and technical indicators聽
and you can see the high usage parameters such as聽聽
[142]
intraday or company overview or daily adjusted聽
stock time series data etc. It's quite big聽聽
[149]
documentation but I would recommend you to skim it聽
at least such that you would have a basic idea of聽聽
[155]
the API documentation. Now let's see one by one聽
how to extract these financial informations such聽聽
[162]
as time-series, Fundamental data etc. In python in聽
order to extract time series data, what we will be聽聽
[168]
doing here is from alpha underscore vantage dot聽
time series import time series and then this is聽聽
[175]
the API key that I got by making this account that聽
I showed earlier. I'll be disabling this API key聽聽
[183]
such that you guys don't use it just go here it's聽
free of cost. Just get your own API and use it聽聽
[188]
for your purposes um. Now what we need to do here聽
is let me just introduce this parameter which is聽聽
[196]
ts is equal to time series and then we need to聽
provide the API key which is key is equal to
[206]
API key and the next thing is output format聽
in my case I'm not interested in JSON format聽聽
[211]
I'm interested in pandas from it so uh we'll be聽
getting the output uh which will be in data frame聽聽
[218]
format so let me just run this uh cell now what聽
I will be doing here is data is equal to ts it's聽聽
[226]
fairly easy then get ts dot get daily adjusted聽
entry extended monthly monthly adjusted etc.聽聽
[234]
You can see it in the API documentation that聽
these are the data that will that can be聽聽
[240]
provided by alpha vantage and we can directly get聽
it from here so on on writing get um let me just聽聽
[248]
go to the monthly adjusted for example so聽
um the information that is required in this聽聽
[257]
parenthesis is symbol which is the ticker. If聽
you remember in IEX cloud, I explained how to聽聽
[264]
use symbol which is ticker in IEX cloud. In this聽
case, we just need to provide it in the string聽聽
[269]
format which is AAPL for apple for Microsoft聽
it will be MSFT and so on and let's see what聽聽
[276]
is the data now. If I run this cell, I get聽
it in actually I get two output and I'm just聽聽
[283]
interested in the first one which is if I take the聽
zeroth one then I get it this one which is in the聽聽
[289]
data frame format pandas data frame format聽
and you can see the data is monthly. If we had聽聽
[296]
provided a get daily adjusted it would be daily聽
data so we have open high low close adjusted close聽聽
[303]
volume etc. Similarly, as I mentioned that if we聽
used in this case I have let me just change it to
[313]
daily adjusted daily adjusted and then in聽
this case let's see apple and then by running聽聽
[320]
it we will get the daily data. If you聽
are interested in intra-day um data聽聽
[327]
uh with an interval of just 15 minutes then聽
we just need to provide get entry ticker an聽聽
[333]
interval is equal to 15 minutes or five minutes聽
or even one minute so for example, in this case,聽聽
[338]
you can see the output is 15 minutes interval data聽
if I change it to five minutes it will be the five聽聽
[345]
minutes interval data which is quite useful uh聽
for algorithmic trading. I would say and doing聽聽
[352]
the interval analysis you can make candlesticks聽
here etc. You can do a lot of analysis here.聽聽
[359]
Before going to the fundamental data, um I聽
would like you to tell me in the comment box聽聽
[363]
which topic you want me to make my next video聽
on? And the comment with the highest likes聽聽
[370]
will be the topic that I'll be聽
considering for my upcoming videos.聽聽
[374]
Anyways so let's move to the fundamental data聽
uh in order to get the fundamental data which is聽聽
[379]
actually the statements data we need to import I聽
would say from alpha_vantage dot fundamental data聽聽
[387]
import fundamental data the key is the same which聽
is this, one you would have your own key. uh fd is聽聽
[394]
equal to fundamental data the key is provided聽
and then output format is equal to pandas and聽聽
[399]
like it's exactly the same as that we did for the聽
time series data then what you need to do here is聽聽
[405]
actually let me just delete it for聽
some time data is equal to fd dot
[413]
get you can get balance sheet data, cash flow聽
statement, company overview or income statement um聽聽
[420]
data quarterly and annual. So let聽
me just take the income statement聽聽
[424]
annual in the parenthesis I am just聽
required to provide the symbol which is聽聽
[429]
ticker. Let me just write MSFT and then let's see聽
what the data. So again you can see the data is聽聽
[436]
um again there are two output I am just interested聽
in the first one so data is zero this is the聽聽
[443]
income statement but unfortunately, the um line聽
items are on the column header and I'm interested聽聽
[450]
I would be interested if it is in the transposed聽
format. So yeah exactly so this is the聽聽
[455]
income statement. All the items related to income聽
statement are on the left-hand side and you can聽聽
[459]
see the uh the financial date ending is 2020,聽
2019, 2018, 2017, and 2016. So last five years聽聽
[467]
of data and old data. If it were quarterly then聽
it would have been quarterly data the currency聽聽
[473]
and everything is here total revenue it's quite聽
useful information that will we can use for our聽聽
[480]
analysis purpose so and if you are interested in聽
say balance sheet data then you need to provide聽聽
[487]
or say cash flow quarterly data for example you聽
just need to provide cash flow quarterly and MSFT聽聽
[495]
and let me just first see what the data is.聽
Perfect so the data let me just write zero and聽聽
[506]
.T exactly so this is the cash flow statement. For聽
balance sheet, again you just need to write fd.get聽聽
[513]
underscore balance sheet and then provide聽
the ticker now you can see that the API聽聽
[519]
documentation of alpha vantage and I would聽
say writing all these lines here is a kind of聽聽
[525]
a LOT OF WORK. Here's a GIFT from my side to all聽
my subscribers. I have written a code here um that聽聽
[531]
I'll be sharing with my subscribers in which you聽
what you need to do here is I've made different聽聽
[537]
cells for different types of data and you just聽
need to provide the basic details and this will聽聽
[542]
give you the output that you need. So for example,聽
in this case, this is cell is for time series聽聽
[548]
data. If you run this cell, it will ask some聽
information such as what ticker are you interested聽聽
[553]
in MSFT MSFT and then what type of data you are聽
interested in for example in this case monthly,聽聽
[561]
and then you'll see that you have got the聽
monthly data output here if you're interested聽聽
[569]
in interval data for example in this case聽
if I write ticker as uh ford and interval
[579]
um what interval five minutes for example and聽
then you'll see the output of which is five聽聽
[587]
five minutes interval data here. So it's kind of聽
user-friendly code that I have written here for聽聽
[594]
you for all of my subscribers. And for similarly聽
for the fundamental data you just need to run this聽聽
[600]
code here it will ask for some basic information聽
such as ticker which is again let's say Apple and聽聽
[606]
then annual data period what type of statement I'm聽
interested in income statement so income statement聽聽
[617]
and then you'll see that you've got聽
the income statement of apple annual聽聽
[622]
um income statement of apple similarly for foreign聽
exchange for cryptocurrencies and for technical聽聽
[629]
indicators I have made a code for you now. For聽
my new viewers, I'll be saving this code on my聽聽
[637]
google drive and all my subscribers can have A聽
FREE ACCESS OF MY GOOGLE DRIVE. What you need to聽聽
[642]
do here is just subscribe to my youtube channel聽
and click on the get access of my google drive聽聽
[648]
button on my youtube channel and then just provide聽
some basic details and I'll be using that email聽聽
[653]
address to give a free access of my personal聽
google drive where I will be saving this code聽聽
[659]
and not just this code there are a lot many um聽
codes and I would say files that are saved on that聽聽
[665]
uh platform on that drive and you can use all聽
of them for your personal users and there will聽聽
[670]
be no copyright issues from my side. Now it聽
can be fairly seen that I'm doing a lot of聽聽
[674]
work for you guys so I don't need anything聽
from you just LIKE this video and support me聽聽
[680]
and also share it with your friends.聽
If you find this video informative,聽聽
[683]
subscribe to my youtube channel if you don't聽
want to miss out on my future videos, and聽聽
[687]
don't forget to comment the topic that you want me聽
to make my next video on. Also get a free access聽聽
[693]
to my google drive by following the steps that I聽
mentioned already. Thank you so much see you soon.
Most Recent Videos:
You can go back to the homepage right here: Homepage





