Let’s get the quartiles of Apple stock price 30-day projection, using 10-year daily history.
We will use the yfinance library to retrieve the daily history of Apple stock price.
import requests
import yfinance as yf
data_df = yf.download("AAPL", start="2012-12-31", end="2022-12-31", interval = "1d", progress=False)
data = data_df["Close"].tolist()
print("The number of values in the historical data set is:", len(data))
print("The last value which would be projected is:", data[len(data)-1])
horizon = 30
cls = [0.25, 0.5, 0.75]
payload = {
"data": data,
"horizon": horizon,
"cls": cls
}
url = "https://predict7.p.rapidapi.com/"
headers = {
"X-RapidAPI-Key": "your_api_key",
"X-RapidAPI-Host": "predict7.p.rapidapi.com",
"Content-Type": "application/json"
}
response = requests.request("POST", url, json=payload, headers=headers)
quartiles = response.json()["quantiles"]
print(f'The 3 quartiles at horizon {horizon} days are:', [q for cl, q in quartiles.items()])
The result of the previous script is:
The number of values in the historical data set is: 2519
The last value which would be projected is: 129.92999267578125
The 3 quartiles at horizon 30 days are: [124.61287199924642, 133.19434735827977, 142.13910859087554]