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
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]
Metadata
Release files for predictapi 0.0.21
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| predictapi-0.0.21.tar.gz | 3.5 kB | Without provenance | Details for predictapi-0.0.21.tar.gz |
Release files / predictapi-0.0.21.tar.gz
| Download URL | predictapi-0.0.21.tar.gz |
|---|---|
| Size | 3.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
65f2eead69e0df6bec4eb23ed3eec2dc15761932508f9ea2426a1361b7d28ff5
|
|
BLAKE2b-256 checksum How to use checksums |
b447c6e197d599e8bf629562e928dff55dfb607a328e54991e0c99e11aa7da2c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.11
|
Security for predictapi 0.0.21
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.