hello and welcome so in this video we are going to take a look at fundamental analysis of stocks with python so why should you watch this video after this video you will be able to get any relevant financial information for any stock for example the dividend yield market cap price earnings ratio and many many more you will also be able to compare stocks based on their fundamentals and in the end we are seeing how this can be used by finding the highest dividend yield out of an index in general i recommend to watch the video all the way through and i promise you won't regret it so let's get into action as you see i already imported some necessary libraries that is why finance to get fundamental information pandas for data handling and metrodip to visualize our results getting fundamental information is pretty straightforward we are just using yf to ticker and now we have to provide a certain ticker symbol so let's take apple as an example so i'm just using the ticker symbol for apple here and if we're executing that we're just getting the information that an object has been created and we can use this object now to extract very useful information for apple by just using dot info behind that and then we are ending up with a dictionary containing very useful information so let's go through that together so we're getting the sector the ftes a business summary so what is apple actually doing but also some yeah technical information like the 200-day moving average and most importantly for this video we are also getting some very useful fundamental information so i'm just going through some here so you might be interested in others so yeah be kind invited to um go through this dictionary for yourself and see what information you're interested in so we have the beta here we have the trailing price earnings ratio we have the market cap we have the forward price earnings ratio uh we have the dividend yield very important and so on right so what else do we have this one is very interesting for uh corporate finance guys enterprise to mbda we have the very important forward ernik persha here and so on right so yeah go through that and see what is interesting for you so i will use some examples in the upcoming steps if you're interested in other measures of course the logic is the same right so i won't go through every single fundamental measure here i'm just picking some examples right so yeah what would be the next step now i want to yeah compare some stocks so i want to do a peer group comparison if you want to call it like this therefore i'm just defining a list which i'm calling tickers and let's compare apple to microsoft and i think ibm would be another good comparison so this is just an example right so you might add i don't know amazon or qualcomm or other um others in the peer intel or any other company so again this is just an example right so we're executing that and now we are getting the information for all those ticker symbols by just defining a simple loop so first of all i'm creating an empty list which is containing the information for those ticker symbols and i'm just defining for i in tickers so the i is the element and the element is every a single ticker symbol so in the first iteration we have apple and now i'm just appending those infos or those yeah fundamental information or those information you just saw to a list so i'm just using append and now i'm using the function or the the object instantiation from above so i'm just using yf dot ticker and provide the i which is again the ticker symbol in parenthesis here and i'm also using the info to get this dictionary and if i'm executing that which is taking some seconds i have yeah a list containing three dictionaries so i have all information for all those stocks here right so just as a side note if you need efficiency then you have to store those results here so those information in yeah maybe a sql database so if you need support with that so how you can write data into your database just drop me a comment i'm happy to do that but for now we have to deal with this um yeah less efficiency because we are scraping those data in every single step and this is why this is taking um yeah such a long time but nevertheless we have yeah a list containing all the relevant information and what we are doing now is to define the fundamentals we are interested in right so i'm just creating a list here which i'm calling fundamentals and now i have to define the key values out of this dictionary so in case you're not familiar with dictionaries a dictionary has a key value which is this one here and an assigned value to this key value and you are accessing those assigned values by providing the key values right so you have to find out the keywords you are interested in and you are storing that in this fundamentals list right so i'm just taking some examples as said you can pick your own fundamentals what you're interested in so i'm interested in the dividend yield the market cap here let's take the beta and the price earnings ratio so i'm taking the forward price earnings ratio but that's also the trading price earnings ratio and if i'm executing that i've defined my fundamentals i'm interested in and now i'm just creating a data frame and provide my infos list so i just want to create a data frame out of those dictionaries to have a better overview and to make comparisons possible so let's execute that and take a look at the data frame together so now you see we have the key values of the dictionary as the columns so the measures we are interested in and the values as the row entries right so for example full-time employees this data frame is not that lucid so we don't really know what this row is about so we can tell by taking a look at this one here so this is highly portable apple this is microsoft and this is ibm but we want to have the index as the company name or the company symbol at least so we are just reassigning the f to the f dot set index and we are providing the symbol as the index so let's execute that and print out the data frame again and now we have a better data frame containing the symbol as the index so these are the values for apple microsoft and ibm and yeah our information or our keyways of the dictionary or the fundamental and technical information as the columns now we want to filter this data frame for only our defined fundamentals so this is what we are interested in the dividend yield market cap beta and forward price earnings ratio so how can we do that we can do that by using the boolean indexing approach in case you are not familiar with that i have videos on my channel on that topic so be kind invited to check them out so first we are filtering our columns for the fundamentals we are interested in so we're just using df.columns and we are filtering for only the fundamentals and if we are doing that we are just getting an array containing booleans so where the value is true there the fundamentals are contained in the columns right so to get those we would need to further again only our columns where this um where this these conditions are fulfill so filter only for the true values and then we are getting the actual columns here right so we're getting beta market cap forward prices ratio and dividend yield and now to filter the data frame for only those columns we have to use again another squared brackets pair and apply that to our data frame and with that we are getting this very nice and lucid table where we can compare apple microsoft and ibm so as an example we can quickly see that ibm has the highest dividend yield the lowest price earnings ratio and is the smallest company here right so we could also use some visualization to compare let's take the dividends so we would just use plt then a bar plot and provide the index of the data frame which is the symbol and we are using the dividend yields as the height of the the bar and let's colorize those bars let's say black for apple uh microsoft orange maybe has four colors right so we cannot do that here and ibm maybe this one here so let's take a look at that just to give you an idea what you can do with that so now you see that you are getting a direct comparison between those three assets here in terms of the dividend yield of course same logic for another one for example the price earnings ratio you can compare that as well right so in the end let's do a interesting thing let's pull all the stock tickers for the dow jones why don't jones because it's uh yeah pretty in terms of numbers of equities a pretty small index where we can quickly yeah do an application of what we just learned so i'm interested in what is the stock in the dow jones with the highest dividend yield just to give you an idea you could also screen for the lowest um price earnings ratio or stuff like that so again this video is just to give you some ideas right so let's pull the data out of the dow jones industry average therefore we need to get the ticker symbols for all stocks in the dow jones i've covered that so many times in my other videos so i will just write that down without explaining what i'm doing here so i'm just reading in an html table from wikipedia provide the link of that html table and this table is just containing all ticker symbols for the dow jones so this is the link here and i'm filtering that for the second table on this side so what i'm getting so let's execute that so what i'm getting is just a table um looking like that so this is containing all symbols for the dow jones industry average and i need those symbols to yeah to get the relevant fundamental information for all those stocks so yeah i'm creating a tickers list by just accessing the symbol column here so this one and transform that to a list so if you have questions to that if that's too fast because i invited you to drop me a comment but i will link a video with where i've explained that in detail so yeah but this is not much of a complicated thing so this is just getting me tickers of all dow jones industrial average stocks so we have 30 tickers here right okay and now it's yeah basically the same logic as before so we are creating a list here infos and then we are just using the same syntax again for iron tickers and then we are appending that to infos so we're using ticker take the eye and take the info and execute that and now this will take a lot of time right and again what i already said is if you wanna work efficiently with this data so you wanna get those i don't know those fundamentals on a daily base or you just wanna have an improved efficiency you would need to restore all those yet information contained in the dictionary in your own database sounds complicated but it's pretty easy to implement so you just need a for example my sql and store the data there and then you can access the data way faster so i can do a video on that absolutely no problems just let me know but in the meantime where i'm chatting with you this list was populated so if we're taking a look at that we're getting a list containing 30 dictionaries with all the relevant fundamental information right so would be very interesting to do that with the s p 500 as well just as a um suggestion what you can do with this data right or your home index so for example in my case it would be the dax in your case maybe the sensex and and and so on right so now i'm just doing the same thing as i did above so i'm just creating a data frame out of that so i'm just using pd data frame take the infos again and yeah let's take a look at that together now i'm getting a larger data frame and yeah i'm doing the exact same thing again so i'm just using df2 set index and set that to the symbol so i'm getting a data frame where the symbol is the the index and now i can use this data frame to do some fundamental analysis so for example we could find out the highest dividend payers or the companies with the highest dividend year to be more specific so we can just use dividend yield and let's just take a look at the largest five dividend yields here so you see ibm is the has the highest dividend yield then i think a chevron uh verizon and so on right so let's visualize all dividends so that we have a comparison i think that could be pretty interesting so of course you can also do that with the price earnings ratio to make comparisons i'm just giving you an example here with the dividend yield so we could just use plt then i'm defining a figure size so this is optional you don't have to do that so let's just take 14 and 5 here and now again we're using a bar plot and this time for the x-axis we are taking the company's short name that is just due to the fact that sometimes you might have no idea which company is behind this ticker symbol so yeah we could just use df2 then take the short name and for the height of the bars we are taking the dividend yield and we will need to rotate the x ticks so these are just cosmetic things and let's take a look at that and now we are getting a comparison of all dividends deals in the dow jones industry average and i think that's pretty awesome so we are seeing that ibm the largest has the largest dividend yield we see that companies like apple nike visa have pretty low dividend yields and yeah you can do your comparisons so i think that's pretty awesome i hope you can extract value out of that be kind invited to do your own analysis just to give you some ideas what i would do with that you could use subplots to make multiple comparisons so you could compare the dividend yield the i don't know earnings per share um price earnings ratio and then just create four plots here and make your comparisons so there's a lot of um room for you i think to play a bit around with that and maybe build some useful overviews for your stocks or finding your investment investment decisions so i hope this video was helpful for you i hope this was interesting for you in case it was please subscribe to the channel like the video and let me know what you think in the comments below thank you very much for watching and i'm looking forward to seeing the upcoming videos bye bye