predict

FREEMIUM
By candyup | Updated il y a 16 jours | Data
Popularity

5.5 / 10

Latency

1,031ms

Service Level

100%

Health Check

N/A

Followers: 3
Resources:
Product Website
API Creator:
C
candyup
candyup
Log In to Rate API
Rating: 3.5 - Votes: 2

README

Request URL

https://predict7.p.rapidapi.com/

Request Method

POST

Request Body

The predict API requires a JSON object in the request body. This JSON object must contains the following inputs:

Name Type Description
data array A data set of historical values: stock prices, financial indices, cryptocurrency prices, sensor data… or any other time-series data
horizon integer A projection horizon which corresponds to the length of time for which you want to project the data set. It needs to be expressed in the same time base as the data set
cls array One or several confidence levels for the quantiles you want to retrieve (between 0.0 to 1.0)

The quantile function of a probability distribution is the inverse of the cumulative distribution function:
→ Q(x) = F-1(x) = inf{y: x ≤ F(y)} where F(x) = P(X ≤ x)

Here is an example request body:


{
    "data": [518.4, 559.9, 553.19, 524.57, 567.65, 531.75, 576.45, 514.42],
    "horizon": 5,
    "cls": [0.2, 0.5, 0.8, 1]
}

Code Snippets

Here’s an example Python code snippet using the requests library to make a request to the predict API:


import requests

url = "https://predict7.p.rapidapi.com/"

headers = {
    "X-RapidAPI-Key": "your_api_key_here",
    "X-RapidAPI-Host": "predict7.p.rapidapi.com",
    "Content-Type": "application/json"
}

payload = {
    "data": [518.4, 559.9, 553.19, 524.57, 567.65, 531.75, 576.45, 514.42],
    "horizon": 5,
    "cls": [0.2, 0.5, 0.8, 1]
}

response = requests.post(url, headers=headers, json=payload)
print(response.json())

Response

The predict API returns a JSON object in the response body. The JSON object has keys that correspond to the quantiles at confidence levels specified as input.

Here’s an example response body:


{
    "0.2": 435.0025226384971,
    "0.5": 517.4767502538812,
    "0.8": 614.0210958892659,
    "1.0": 953.7644640393268
}

Practical example

Here’s an example code in Python to retrieve quartiles of the 30-day apple stock projection, using 10-year daily history:


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()

horizon = 30
cls = [0.25, 0.5, 0.75]
payload = {
    "data": data,
    "horizon": horizon, 
    "cls": cls
}

print("The number of values in the historical data set is:", len(data))
print("The last value which would be projected is:", data[-1])

url = "https://predict7.p.rapidapi.com/"
headers = {
    "X-RapidAPI-Key": "your_api_key_here",
    "X-RapidAPI-Host": "predict7.p.rapidapi.com",
    "Content-Type": "application/json"
}

response = requests.request("POST", url, json=payload, headers=headers)
quantiles = response.json()["quantiles"]

print(f'The 3 quartiles at horizon {horizon} days are:', [q for cl, q in quantiles.items()])

Here is the result:


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]