🎓 Tutor With Me: 1-On-1 Video Call Sessions Available ► Join me for personalized finance tutoring tailored to your goals: ryanoconnellfinance.com/finance-tutoring/ 💻 Find the Code Written In this Video Here: ► Access the code resources here: ryanoconnellfinance.com/python-for-stock-analysis/
Thank you very much for these wonderful videos! I've been following you for more than a year, and your videos helped me a lot in my studies. Now I am doing CFA Level 1 and again, the videos you are posting are very helpful, especially this one as it relates to new additions of Level 1 exam. Thank you very much !
Hi Ryan, thank for your work - much appreciated. Faced with problem to import all libraries specifically on the step from pandas_datereader import data as pdr all the time when python tries to interpret this line I have an error with ModuleNotFoundError: No module named 'distutils' Python version is 3.12, PyCharm, MacOS P.S. I checked - all libraries have been installed (you mentioned in your video and all problems with above mentioned line. Thanks
couldn't make it beyond the import libraries - command prompt says everything is installed, but PyCharm tells me "ModuleNotFoundError: No module named 'yfinance'"
Hi Ryan. First question after binge watching your videos over the weekend. Please take a look. I have developed a stock value calculator that has 6000 stocks. I have 6 methods and created a dashboard for summary. But I want to get the results for 40 stocks (can get ticker in a text file) and it should be printed to another excel tab or PDF or Python screen. I can just print one row or two rows of summary for each stock ticker (no need of fancy dashboard). Meaning -I need to run the excel dashboard (or file) repeatedly 40 times (40 stock tickers with 2 inputs -ticker and market price) and get the valuation summary. What is the trick to do ? Kindly suggest a method. I think I can do this in Python by accessing Excel repeatedly. Excel or Python?
Hi @m.ssharma535, Given your requirements, I'd recommend using Python over Excel for this task. Python can effortlessly loop over your 40 tickers, process the data, and store the results. Libraries like pandas can integrate directly with Excel, allowing you to read data, perform calculations, and then write back the results. For your scenario, you can use pandas to load the tickers, compute the valuations for each, and save the summaries to a new Excel tab or PDF. This approach offers automation, flexibility, and scalability compared to manually running processes in Excel. I hope this helps! Let me know if you need further clarification.
Hi Ryan. This video is very interesting. I tried to install the yfinance package but I gets the error" there is no module named yfinance". I cross checked in site packages folder and I can see yfiance folder. Can you suggest any help?
Hey! Make sure you've imported the datetime module and aliased it as dt If you're still getting an error similar to , that suggests that you may have inadvertently overridden the dt or datetime name in your code. Make sure you don't have any other variables or modules named datetime or dt that could be conflicting with the standard library module.
There are scenarios in which you might opt to nest an 'if' statement within another or use an 'elseif' statement. The 'elseif' statement is versatile as it captures all subsequent conditions, whereas an 'if' statement addresses only the specific condition you're testing for.
My pleasure! You can copy the code straight from my website using the code to plot the results. If you have named all the variables the same, it should work fine
Np, i made a GPT as it was a python expert and told it to give me excersises to be growing with this python for finance stuff, look at this: import yfinance as yf import pandas as pd import matplotlib.pyplot as plt #descargamos datos de la acción data = yf.download("GOOG", start = "2021-01-01", end = "2021-12-31") #calculamos el retorno diario data["Retorno"] = data ["Adj Close"].pct_change() #Calculamos retorno diario promedio y volatilidad retorno_promedio = data["Retorno"].mean() volatilidad = data["Retorno"].std() print(f"Retorno diario promedio: {retorno_promedio}") print(f"Volatilidad: {volatilidad}") #Creamos los gráficos data['Retorno'].plot(figsize=(10, 6)) plt.title('Retorno Diario de GOOG en 2021') plt.xlabel('Fecha') plt.ylabel('Retorno Diario') plt.show() @@RyanOConnellCFA
If you have Python and VS Code already installed then it should work for you. You should be able to put the same code in a normal python (.py) file and run it in the terminal. However, I'd recommend using a Jupyter Notebook file (.ipynb) to make it easier on yourself like I did in the video
Hello Ryan, after seeing your video I tried to download everything you showed, however when I try to import the libraries through the command prompt, my laptop doesn't recognize the 'pip' command. What should I do? Thank you in advance 😊
Thank you so much for answering! Now I have problems with actually running the commands. Even the "print" doesn't get me results. After hitting the "go" button, my cursor just transports to the search field.
@@user-oe3nu8ym6q My pleasure! I'm guessing that means you need to select which version of Python you will run the code with. There will probably only be one option, just select that one
@@RyanOConnellCFA Sorry for bothering again, I hope this will be my last question, it's because I don't have an idea about programming in general. After installing everything in the command prompt as you showed, when i try to run this, it's giving me errors like "yfinance unknown word and datareader unknown word". In the command prompt when I try to install them again it says requirement already satisfied, so I suppose i completed this part correctly. Pandas, datetime and numpy are running without errors.
@@user-oe3nu8ym6q No bother at all, I'm here to help! It sounds like you might not have imported the yfinance and datareader modules correctly in your Python script. Before using these modules, ensure to include lines at the beginning of your script to import them, like "import yfinance as yf" and "import pandas_datareader as dr". Give this a try and let me know how it goes!
Hey Ryan! I tried installing the yfinance and the other packages but every time I press [Enter] I get a message stating "pip is not recognized as an internal or external command, operable program, or batch file." What should I do?
Hey there! This error usually means that Python's package manager, pip, isn't added to your system's PATH. Try reinstalling Python and ensure that the "Add Python to PATH" option is checked during installation.
@@RyanOConnellCFA Hey, Thank you! That worked to install the pip packages. Although when I enter "import yfinance as yf" and run it, I get an error saying 'ModuleNotFoundError'. I installed the package again but I still get the same error. Also, I'm using JupyterNotebook and not VS code.
Finally code is working in VSC except for plot. Code can't plot cumulative log returns. I installed matplotlib on terminal as pip install matplotlib 3.7.1. However, cumulative log returns plot was not executed.
so i got stuck along the way *********************100%%**********************] 3 of 3 completed 1 Failed download: ['QQQ']: OperationalError('database is locked')
That sounds to me like the problem is not something you did wrong but some bug in the API. Maybe try a different ticker (like AAPL) and see if it works
🎓 Tutor With Me: 1-On-1 Video Call Sessions Available
► Join me for personalized finance tutoring tailored to your goals: ryanoconnellfinance.com/finance-tutoring/
💻 Find the Code Written In this Video Here:
► Access the code resources here: ryanoconnellfinance.com/python-for-stock-analysis/
Extremely useful and straightforward video. Found some issues along the way, but could overcome them by myself. Thanks a lot
Part of learning to code is working through all those pesky errors and bugs! Good job
hi. thank you for your job. i have one quesiotion - why you dont use the syntax "print" before command in 22:05 ?
Thank you very much for these wonderful videos! I've been following you for more than a year, and your videos helped me a lot in my studies. Now I am doing CFA Level 1 and again, the videos you are posting are very helpful, especially this one as it relates to new additions of Level 1 exam. Thank you very much !
Wow I really appreciate the feedback Jamoladdin! It's comments like these that give me motivation to keep putting work in. Thank you!
Have been following Ryan for quite some time now. Very helpful!! Kudos
Thank you Monika!
Thank you for the video. Please post more videos like this in the future.
Thank you, I will!
great video - just getting back into coding and this is very helpful. Forgot how fiddly this stuff is.
Glad it was helpful! Good luck brushing up on those skills. It is really fiddly how one thing out of place will break everything
Bro Ur such a genious😉😉..Closely following in ur footsteps.
Thanks, man! Just sharing what I know, and I'm stoked it's helping you out. Keep up the solid work on your end! 😎
@theemperor.188 not as close as I am
Thanks it is helping us a lot hope you will keep posting more videos like this in future
I appreciate the nice feedback Bal!
Thanks for this great video, Ryan!
It is my pleasure Edwin!
Hi. Awesome video for beginners. Thank you (sorry for bad English)
Thank you Nicolas! And no worries, your English was perfect bro
wonderfully explained - many thanks
It is my pleasure!
Hi Ryan, thank for your work - much appreciated. Faced with problem to import all libraries specifically on the step
from pandas_datereader import data as pdr
all the time when python tries to interpret this line I have an error with
ModuleNotFoundError: No module named 'distutils'
Python version is 3.12, PyCharm, MacOS
P.S. I checked - all libraries have been installed (you mentioned in your video and all problems with above mentioned line.
Thanks
same prob here buddy!
@@gintama183 sorry to hear but anyway looks like Ryan is not gonna answer and help to fix this issue unfortunately
i just type all of the libraries into the environment
ChatGpt fixed it for me
you need to pip install pandas-datareader
couldn't make it beyond the import libraries - command prompt says everything is installed, but PyCharm tells me "ModuleNotFoundError: No module named 'yfinance'"
Did you go to the command prompt and type "pip install yfinance"?
Hi Ryan. First question after binge watching your videos over the weekend. Please take a look. I have developed a stock value calculator that has 6000 stocks. I have 6 methods and created a dashboard for summary. But I want to get the results for 40 stocks (can get ticker in a text file) and it should be printed to another excel tab or PDF or Python screen. I can just print one row or two rows of summary for each stock ticker (no need of fancy dashboard). Meaning -I need to run the excel dashboard (or file) repeatedly 40 times (40 stock tickers with 2 inputs -ticker and market price) and get the valuation summary. What is the trick to do ? Kindly suggest a method. I think I can do this in Python by accessing Excel repeatedly. Excel or Python?
Hi @m.ssharma535,
Given your requirements, I'd recommend using Python over Excel for this task. Python can effortlessly loop over your 40 tickers, process the data, and store the results. Libraries like pandas can integrate directly with Excel, allowing you to read data, perform calculations, and then write back the results. For your scenario, you can use pandas to load the tickers, compute the valuations for each, and save the summaries to a new Excel tab or PDF. This approach offers automation, flexibility, and scalability compared to manually running processes in Excel.
I hope this helps! Let me know if you need further clarification.
This is great! Which certification program do you recommend on taking for someone who wants to be certified (I am a Finance professional)
Wow! Thank you
You are very welcome!
Love it. Thank you!
My pleasure!
Hi Ryan. This video is very interesting. I tried to install the yfinance package but I gets the error" there is no module named yfinance". I cross checked in site packages folder and I can see yfiance folder. Can you suggest any help?
Absolute legend.
I appreciate it Tony!
anyone know why I get at 15:08 ?
Hey! Make sure you've imported the datetime module and aliased it as dt
If you're still getting an error similar to , that suggests that you may have inadvertently overridden the dt or datetime name in your code. Make sure you don't have any other variables or modules named datetime or dt that could be conflicting with the standard library module.
Excellent video, thx a lot!!
Glad it helped!
Why would you use elif if you can just do another if statement underneath? Some sort of referencing insurance?
There are scenarios in which you might opt to nest an 'if' statement within another or use an 'elseif' statement. The 'elseif' statement is versatile as it captures all subsequent conditions, whereas an 'if' statement addresses only the specific condition you're testing for.
Excellent. Where do you write on the code "drop nan"?
Thanks Aaron! I did not drop the "nan" values at all. It was not necessary to plot the values for me
Hello Ryan, thanks for the video, i cant really see the graph after doing the code, would you give me a solution? thanks in advance
My pleasure! You can copy the code straight from my website using the code to plot the results. If you have named all the variables the same, it should work fine
Hi Ryan, When are the other videos being released?
Hey there, I will continue to release Python videos in the future. I do not have a set schedule for it however
first time coming here i thought its really for beginners
Loved this!! How could I watch the graphic of cumulative_log_returns in Sublime Text?
Thank you! Unfortunately I've never used that Python package before so I'm not certain
Np, i made a GPT as it was a python expert and told it to give me excersises to be growing with this python for finance stuff, look at this:
import yfinance as yf
import pandas as pd
import matplotlib.pyplot as plt
#descargamos datos de la acción
data = yf.download("GOOG", start = "2021-01-01", end = "2021-12-31")
#calculamos el retorno diario
data["Retorno"] = data ["Adj Close"].pct_change()
#Calculamos retorno diario promedio y volatilidad
retorno_promedio = data["Retorno"].mean()
volatilidad = data["Retorno"].std()
print(f"Retorno diario promedio: {retorno_promedio}")
print(f"Volatilidad: {volatilidad}")
#Creamos los gráficos
data['Retorno'].plot(figsize=(10, 6))
plt.title('Retorno Diario de GOOG en 2021')
plt.xlabel('Fecha')
plt.ylabel('Retorno Diario')
plt.show()
@@RyanOConnellCFA
By the way, I've already installed VSC (Visual Studio Code on my computer). Can I run python code directly? I mean, without Anaconda platform?
If you have Python and VS Code already installed then it should work for you. You should be able to put the same code in a normal python (.py) file and run it in the terminal. However, I'd recommend using a Jupyter Notebook file (.ipynb) to make it easier on yourself like I did in the video
@@RyanOConnellCFA Well, It's not working. There's a connection with Kernel: Python 3.11.1. Activating Python environment. It's running activation now.
Let me know if it gets up and running for you. It may be worth installing Anaconda just incase
Hello Ryan, after seeing your video I tried to download everything you showed, however when I try to import the libraries through the command prompt, my laptop doesn't recognize the 'pip' command. What should I do?
Thank you in advance 😊
Hey! This likely means that you do not have Python downloaded on your computer. I would go back to the first step of downloading Python if I were you
Thank you so much for answering!
Now I have problems with actually running the commands. Even the "print" doesn't get me results. After hitting the "go" button, my cursor just transports to the search field.
@@user-oe3nu8ym6q My pleasure! I'm guessing that means you need to select which version of Python you will run the code with. There will probably only be one option, just select that one
@@RyanOConnellCFA Sorry for bothering again, I hope this will be my last question, it's because I don't have an idea about programming in general. After installing everything in the command prompt as you showed, when i try to run this, it's giving me errors like "yfinance unknown word and datareader unknown word". In the command prompt when I try to install them again it says requirement already satisfied, so I suppose i completed this part correctly. Pandas, datetime and numpy are running without errors.
@@user-oe3nu8ym6q No bother at all, I'm here to help! It sounds like you might not have imported the yfinance and datareader modules correctly in your Python script. Before using these modules, ensure to include lines at the beginning of your script to import them, like "import yfinance as yf" and "import pandas_datareader as dr". Give this a try and let me know how it goes!
Ryan - Very good of explaining, which is understandable
I really appreciate the feedback and I'm glad you enjoyed it!
Hey Ryan!
I tried installing the yfinance and the other packages but every time I press [Enter] I get a message stating "pip is not recognized as an internal or external command, operable program, or batch file." What should I do?
Hey there! This error usually means that Python's package manager, pip, isn't added to your system's PATH. Try reinstalling Python and ensure that the "Add Python to PATH" option is checked during installation.
@@RyanOConnellCFA Hey, Thank you! That worked to install the pip packages. Although when I enter "import yfinance as yf" and run it, I get an error saying 'ModuleNotFoundError'. I installed the package again but I still get the same error. Also, I'm using JupyterNotebook and not VS code.
Finally code is working in VSC except for plot. Code can't plot cumulative log returns. I installed matplotlib on terminal as pip install matplotlib 3.7.1. However, cumulative log returns plot was not executed.
What was the error message? Sounds like you're 99% of the way there
so i got stuck along the way
*********************100%%**********************] 3 of 3 completed
1 Failed download:
['QQQ']: OperationalError('database is locked')
That sounds to me like the problem is not something you did wrong but some bug in the API. Maybe try a different ticker (like AAPL) and see if it works
It was successful, you only need one more line, >>> print(df)
lol @ 22:34
Sum up the cum 😂
22:31 🤨😏
Lol 🤣