Skip to main content

The predict API

Project description

The predict API

Intro

The predict API enables to project a data set over a projection horizon, using an innovative stochastic approach.

It requires a data set of historical values (stock prices, financial indices, cryptocurrency prices, sensor data… or any other time-series data) and 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).

You will also need one or several confidence levels for the quantiles you want to retrieve.

Website

https://predictapi.app/

Example

from predictapi import Predictor

p = Predictor(api_key="your_api_key")

data = [518.4, 559.9, 553.1, 524.5, 567.6, 531.7, 576.4, 514.4]
horizon = 5
cls = [0.2, 0.5, 0.8]

quantiles = p.predict(data=data, horizon=horizon, cls=cls)
print(quantiles)

This example will return:

{
    'quantiles':{
        '0.2': 442.09145288443017,
        '0.5': 508.35032746021085,
        '0.8': 585.0916378202178
    }
}

your_api_key must be replaced by your Rapid Api key that you can obtain here.

Inputs of the predict function

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)

Response of the predict function

The result is a JSON object. The JSON object has keys that correspond to the quantiles at confidence levels specified as input.

Practical example

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

from predictapi import Predictor
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[-1])

horizon = 30
cls = [0.25, 0.5, 0.75]

p = Predictor(api_key="f61f619a9fmsh4adb0398b0c87a9p1231bajsn76ce266ca8f5")

quantiles = p.predict(data=data, horizon=horizon, cls=cls)

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]

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

predictapi-0.0.21.tar.gz (3.5 kB view details)

Uploaded Source

File details

Details for the file predictapi-0.0.21.tar.gz.

File metadata

  • Download URL: predictapi-0.0.21.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.11

File hashes

Hashes for predictapi-0.0.21.tar.gz
Algorithm Hash digest
SHA256 65f2eead69e0df6bec4eb23ed3eec2dc15761932508f9ea2426a1361b7d28ff5
MD5 642644675c79d845a1046dcdbd599fe8
BLAKE2b-256 b447c6e197d599e8bf629562e928dff55dfb607a328e54991e0c99e11aa7da2c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page