Investing in ETFs.
The task of tracing and chosing individual stocks may be too boring and exhausting, in this case ETFs may be a right solution.
You can describe an ETFs (exchange-traded funds) as a mutual funds discussed in previous section that trades just like a usual stocks.
ETF represents a basket of securities that combined in a single index such as the S&P 500 for example.
An ETF's price changes during the trading day according to supply and demand principle unlike a mutual fund that has its net asset value (NAV) calculated at the end of each trading day.
You can say that ETF combines the diversification feature of a mutual fund and the flexibility feature of a stock.
Python Knowledge Base: Make coding great again.
- Updated:
2024-12-20 by Andrey BRATUS, Senior Data Analyst.
How to get ETFs data ?
Python code to get a list of ETFs available:
List of ETFs output (shown partly):
Python code to get Daily ETFs data available:
Selected ETF daily data output (shown partly):
In our case we will use Python to access free online exchange-traded funds APIs from rapidapi.com, you need to get "your-api-key".
Free API key will allow certain amount of requests per day and per month, in case of wider commercial use you can chose sutable paid subscription.
Original data of ETFs available is taken from Twelve Data,
necessary historical data is taken from apistocks.com.
Output data is in JSON format which can be easily converted to any suitable form for further visualisation and analysis,
exchange-traded funds will give you a new way to gain stable profitable market profits.
This API call return array of ETFs available at Twelve Data API. This list is daily updated.
import requests
url = "https://twelve-data1.p.rapidapi.com/etf"
querystring = {"exchange":"Euronext","format":"json"}
headers = {
"X-RapidAPI-Key": "your-api-key",
"X-RapidAPI-Host": "twelve-data1.p.rapidapi.com"
}
response = requests.request("GET", url, headers=headers, params=querystring)
print(response.text)
{"data":[{"symbol":"100H","name":"MULTI-UNITS LUXEMBOURG - Lyxor FTSE 100 UCITS ETF - Monthly Hedged to EUR - Acc","currency":"EUR","exchange":"Euronext","mic_code":"XPAR","country":"France"},{"symbol":"3PYP","name":"LS 3X PAYPAL","currency":"EUR","exchange":"Euronext","mic_code":"XAMS","country":"Netherlands"}...
This API call return Daily historical data for Stocks and ETFs, you should specify an ETF symbol.
import requests
url = "https://apistocks.p.rapidapi.com/daily"
querystring = {"symbol":"ACWI","dateStart":"2022-10-01","dateEnd":"2022-10-31"}
headers = {
"X-RapidAPI-Key": "your-api-key",
"X-RapidAPI-Host": "apistocks.p.rapidapi.com"
}
response = requests.request("GET", url, headers=headers, params=querystring)
print(response.text)
{"Metadata":{"Symbol":"ACWI","Interval":"daily","Timezone":"US EST"},"Results":[{"Date":"2022-10-03","Open":78.660004,"Close":79.68,"High":80.050003,"Low":78.260002,"Volume":2645600,"AdjClose":79.68},{"Date":"2022-10-04","Open":81.199997,"Close":82.400002,"High":82.410004,"Low":81.199997,"Volume":3585800,"AdjClose":82.400002}...