Autorregressão Bayesiana com Sentimento de Notícias para previsão de commodities
Project description
newsAR
Previsão de séries temporais com Autorregressão Bayesiana + Sentimento de Notícias via LLM
newsAR combina Autorregressão Bayesiana (Gibbs Sampling com verossimilhança t-Student) com Sentimento de Notícias extraído por Grandes Modelos de Linguagem (Groq, OpenAI, Anthropic).
A hipótese central: fluxos de informação (notícias) afetam variáveis econômicas e de commodities antes de se materializarem nos dados quantitativos. O sentimento capturado pelo LLM atua como variável exógena que melhora a acurácia preditiva além do que um AR puro consegue.
Por que usar?
- Modelo AR Bayesiano com Gibbs Sampling e likelihood t-Student — robusto a outliers
- Sentimento de notícias via LLM (Groq, OpenAI ou Anthropic) como variável exógena
- Seleção automática de lags combinando PACF + AIC
- Benchmark walk-forward contra ARIMA, OLS-AR, Random Walk e Seasonal Naive, com Theil's U
- Diagnóstico completo de resíduos: normalidade, autocorrelação e efeitos ARCH
Instalação
pip install newsAR
# Com suporte a LLMs
pip install "newsAR[groq]" # Groq (recomendado: gratuito e rápido)
pip install "newsAR[openai]" # OpenAI
pip install "newsAR[anthropic]" # Anthropic
pip install "newsAR[all]" # todos os provedores + joblib
Uso rápido
import pandas as pd
import numpy as np
from newsAR import quick_fit
# Série mensal com DatetimeIndex
y = pd.Series(
np.random.default_rng(0).normal(100, 5, 60),
index=pd.date_range("2019-01", periods=60, freq="MS"),
)
forecaster = quick_fit(y, keyword="commodity")
forecast = forecaster.predict(steps=6)
print(forecast)
Com sentimento de notícias (Groq)
export GROQ_API_KEY="gsk_..."
from newsAR import quick_fit
forecaster = quick_fit(
y=minha_serie,
keyword="petróleo",
csv_path="noticias.csv", # CSV com colunas: data, texto
groq_api_key="gsk_...", # ou lê de GROQ_API_KEY automaticamente
)
forecast = forecaster.predict(steps=6, credible_interval=0.90)
Benchmark vs Random Walk
from newsAR.benchmark import run_benchmark
results = run_benchmark(y=minha_serie, keyword="petróleo", test_size=12, verbose=True)
print(results[["modelo", "RMSE", "Theil_U", "melhoria_vs_Naive_%"]])
Pipeline
[Notícias] → [Sentimento via LLM] → [Seleção de Lags] → [AR Bayesiano (Gibbs)]
↓
NewsARForecaster
Documentação completa
A documentação detalhada (API completa, diagnósticos, módulos internos, FAQ) está disponível no repositório do projeto.
Licença
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file newsar-0.3.1.tar.gz.
File metadata
- Download URL: newsar-0.3.1.tar.gz
- Upload date:
- Size: 35.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
83afbe6dead64f1b6403d06dcd6c0f78a7cf78598c9eec1aefe6219fd25d1537
|
|
| MD5 |
823fc35040ed91da3dadd9876b087215
|
|
| BLAKE2b-256 |
063ada6a0e112210d9e0de602c67a5da76773fd15b618bde532a12dcaa3d3c3a
|
Provenance
The following attestation bundles were made for newsar-0.3.1.tar.gz:
Publisher:
python-publish.yml on DiegoVSouza/newsAR
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
newsar-0.3.1.tar.gz -
Subject digest:
83afbe6dead64f1b6403d06dcd6c0f78a7cf78598c9eec1aefe6219fd25d1537 - Sigstore transparency entry: 1802260884
- Sigstore integration time:
-
Permalink:
DiegoVSouza/newsAR@ff2188a343921307b952d1fb7b88c4465ef5f941 -
Branch / Tag:
refs/tags/release-v0.3.1 - Owner: https://github.com/DiegoVSouza
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@ff2188a343921307b952d1fb7b88c4465ef5f941 -
Trigger Event:
release
-
Statement type:
File details
Details for the file newsar-0.3.1-py3-none-any.whl.
File metadata
- Download URL: newsar-0.3.1-py3-none-any.whl
- Upload date:
- Size: 31.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bd5e64a03516cdf60edcc404eae5d53e7b5b75b54481f66eb4658751230e9d30
|
|
| MD5 |
2a49b4c8f1b96ab42a7c354e40ad7275
|
|
| BLAKE2b-256 |
f5e4e044a73ec5bb033e6ebc1434cd0e10f2681b7779896fe212187587d72767
|
Provenance
The following attestation bundles were made for newsar-0.3.1-py3-none-any.whl:
Publisher:
python-publish.yml on DiegoVSouza/newsAR
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
newsar-0.3.1-py3-none-any.whl -
Subject digest:
bd5e64a03516cdf60edcc404eae5d53e7b5b75b54481f66eb4658751230e9d30 - Sigstore transparency entry: 1802260921
- Sigstore integration time:
-
Permalink:
DiegoVSouza/newsAR@ff2188a343921307b952d1fb7b88c4465ef5f941 -
Branch / Tag:
refs/tags/release-v0.3.1 - Owner: https://github.com/DiegoVSouza
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@ff2188a343921307b952d1fb7b88c4465ef5f941 -
Trigger Event:
release
-
Statement type: