Skip to main content

Close prices memorized in a transformer checkpoint

Project description

chat-spx

This small AI package is a chat engine. You send it a date, it tells you the SPX Close on that date.

This package is based on a PyTorch transformer model and is predict-only. The bundled data contains the model weights for frozen trading dates from 5/26/1896 to 5/29/2026. Before 12/30/1927, the closing price is rescaled from the Industrial index.

Internally, the transformer memorizes three prefix tasks: M -> max(date_id), D -> YYYYMMDD, which rebuilds the date_id -> YYYY-MM-DD index at load time, and P -> log_px_fixed, which reconstructs log_px and then px. This structure requires only minimal metadata outside of the model.

Disclaimer: There is no guarantee of data precision since the AI model is prone to error. Use at your own risk.

Install

From this repository:

pip install .

For editable development:

pip install -e .

Usage

from chat_spx import get_px, get_log_px, predict

px = get_px("1927-12-30")
log_px = get_log_px("1927-12-30")
record = predict("1990-01-05")

print(f"{px:.6f}")  # 17.660000
print(log_px)
print(record["pred_log_px_fixed"])

Date ranges return a list of floats for trading dates in the inclusive range:

from chat_spx import get_px_by_date_range

pxs = get_px_by_date_range("2026-05-18", "2026-05-21")
print([round(px, 2) for px in pxs])  # [7403.05, 7353.61, 7432.97, 7445.72]

For repeated calls, create one ChatPX instance so the model is loaded once:

from chat_spx import ChatPX

chatpx = ChatPX()

print(f"{chatpx.get_px('1927-12-30'):.6f}")  # 17.660000
print(f"{chatpx.get_px('1990-01-05'):.6f}")  # 352.200000
print([round(px, 2) for px in chatpx.get_px_by_date_range("2026-05-18", "2026-05-21")])

You can also pass date parts:

from chat_spx import get_px

px = get_px(1990, 1, 5)
print(f"{px:.6f}")  # 352.200000

The command-line entry point prints one price by default:

chat-spx 1990-01-05
chat-spx --price 1990-01-05

For a trading-date range:

chat-spx --range 2026-05-18 2026-05-21

Notes

  • get_px(date) returns exp(log_px).
  • get_px_by_date_range(start_date, end_date) returns prices for frozen trading dates in the inclusive range.
  • get_log_px(date) returns the memorized fixed-point log_px value.
  • predict(date) returns the date id, predicted digits, fixed integer, log_px, and px.
  • The checkpoint uses prefix queries: P -> log_px_fixed, D -> YYYYMMDD, and M -> max(date_id).
  • The date must be in the frozen trading-date index. Weekends, holidays, and dates after 5/29/2026 raise KeyError.

Tests

pip install -e ".[test]"
pytest

Publishing

Build with:

python -m build

Upload with:

python -m twine upload dist/*

The package includes the model weights, so the distribution is much larger than a typical pure-Python package. It is about 21MB.

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

chat_spx-0.2.0.tar.gz (20.4 MB view details)

Uploaded Source

Built Distribution

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

chat_spx-0.2.0-py3-none-any.whl (20.4 MB view details)

Uploaded Python 3

File details

Details for the file chat_spx-0.2.0.tar.gz.

File metadata

  • Download URL: chat_spx-0.2.0.tar.gz
  • Upload date:
  • Size: 20.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for chat_spx-0.2.0.tar.gz
Algorithm Hash digest
SHA256 59241cf305cfce9876c63ac1f49636aa1ffd88cc51c66c46dc38b1d2921992c9
MD5 401126dbd09cee18454c3e7ca2ed6b9f
BLAKE2b-256 c33c16a756b650e477d47cff7ae271ba7622e73afbc538e9b94fa5c9f7369edc

See more details on using hashes here.

Provenance

The following attestation bundles were made for chat_spx-0.2.0.tar.gz:

Publisher: python-publish.yml on slihn/chat-spx

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

File details

Details for the file chat_spx-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: chat_spx-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 20.4 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for chat_spx-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1aef96b46e173d6b447de5777bdacb1d75120b913c04a55caef9b42415deb01d
MD5 1d86cbfe6abc8a297a07ac283b4f9502
BLAKE2b-256 11cdae13ee954f75449dedd583e432e1f5bdbf292b701be002462bd211ccf93b

See more details on using hashes here.

Provenance

The following attestation bundles were made for chat_spx-0.2.0-py3-none-any.whl:

Publisher: python-publish.yml on slihn/chat-spx

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