One of the essential steps in automating your trades is to import or download the time series data. In addition to showing how an asset, security, or economic variable has changed over time, it can also show how the change compares to shifts in other variables during the same period.
How to import Financial Time Series Data?
Let's understand this code here which is importing financial time series data. We will use yahoo finance and we'll use a package name Yfinance to get the data from yahoo finance. For those who have never coded, you can just think about the package as a series of codes that is already there, you just import and get the benefit of it.
Y-finance is a package that has returned a few lines of code to get the data from the yahoo finance website and give it to us.
By simply saying - “import yfinance as yf”, we can get all the code with some smart chapters written since it is open source. We can easily access each other's code since this package is open source.
By doing this yfinance is available and by saying “as yf” we have our shorter name to refer to this. It's just that sometimes someone has a very big name we use a shorter name to call it again and again because it's more convenient. Similarly, we are using yf short for yahoo finance.
The second line of code is “yf.download”. This is the method that will help us to get the data. The first parameter of this method is the ticker of the symbol. Here it's “KO” for “coca-cola” and the second parameter is the start date.
Here the start date is 1st Jan 2019 and then it's the end date till when we want the data to end, “.head” will show us the first five rows of this package to run this code. You simply have to press shift+enter, so you will see a star mark while the code is executing. Once the code is done executing it will change to a number.
Now what you can do is you can change the ticker of this symbol you can change the start date and end it and see how the output changes so change this ticker to your favorite stock or favorite commodity or favorite financial asset and change the start date ended and you will see the output change.
One of the easiest things to do is for example I want to change this to Tesla. Let's understand this with an example - 2:52
Now, let's say if I want to access the adjusted close price I can just write “[data]”. I can write the name of the column and close it. I will get the existing close price data and if I want to calculate “what is the percentage change on daily basis”, then there is a convenient method in python which is “pct_change”. By running this I will get the daily percentage change.
How to read this?
From 3rd to 4th June, the price moved by -4%, and on the next day by -5%. Apple stock has done very badly at the start of the year with minus -4% and -5%, which is almost 9% down in 2 days.
The rest of the days are also pretty bad so with this what I just did, we can also analyze the data. But as you can see this is becoming very difficult for me as I don't know what happened over a longer time frame and the best thing to do here is to visualize the data.
If you have any queries feel free to mention them in the comment section and keep learning!
--------------------------------------------------------------------
Recommended resources for learning
✔️ Python For Trading!
https://quantra.quantinsti.com/course...
✔️ Code and write simply to advance algorithms for trading
https://blog.quantinsti.com/tag/pytho...
✔️ Getting Market Data: Stocks, Crypto, News & Fundamental | FREE Course
https://quantra.quantinsti.com/course...
✔️ FREE Course to learn Python and use it to analyze financial data sets
https://quantra.quantinsti.com/course...
--------------------------------------------------------------------
About Quantra
Quantra is an online education portal that specializes in Algorithmic and Quantitative trading. Quantra offers various bite-sized, self-paced, and interactive courses that are perfect for busy professionals, seeking implementable knowledge in this domain.
Find more info on - https://quantra.quantinsti.com/
Like us on Facebook: / goquantra
Follow us on Twitter: / goquantra
Follow us on LinkedIn: / goquantra
Follow us on Instagram / channel
#financialdata #data #trading #timeseries #yahoofinance #yfinance #downloadstockdata #Apple #Tesla