Skip to main content

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

PyPI Python License


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


Download files

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

Source Distribution

newsar-0.3.1.tar.gz (35.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

newsar-0.3.1-py3-none-any.whl (31.8 kB view details)

Uploaded Python 3

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

Hashes for newsar-0.3.1.tar.gz
Algorithm Hash digest
SHA256 83afbe6dead64f1b6403d06dcd6c0f78a7cf78598c9eec1aefe6219fd25d1537
MD5 823fc35040ed91da3dadd9876b087215
BLAKE2b-256 063ada6a0e112210d9e0de602c67a5da76773fd15b618bde532a12dcaa3d3c3a

See more details on using hashes here.

Provenance

The following attestation bundles were made for newsar-0.3.1.tar.gz:

Publisher: python-publish.yml on DiegoVSouza/newsAR

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for newsar-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bd5e64a03516cdf60edcc404eae5d53e7b5b75b54481f66eb4658751230e9d30
MD5 2a49b4c8f1b96ab42a7c354e40ad7275
BLAKE2b-256 f5e4e044a73ec5bb033e6ebc1434cd0e10f2681b7779896fe212187587d72767

See more details on using hashes here.

Provenance

The following attestation bundles were made for newsar-0.3.1-py3-none-any.whl:

Publisher: python-publish.yml on DiegoVSouza/newsAR

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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