Metadata-Version: 2.4
Name: canonical-financial-memory
Version: 0.3.0rc1
Summary: Exact finite-market contract automata, hedge certificates and calibrated price bounds
Author: Victoria Portnaya-Sharp
License-Expression: MIT
Project-URL: Repository, https://github.com/victoriaportnaya/canonical-financial-memory
Project-URL: Issues, https://github.com/victoriaportnaya/canonical-financial-memory/issues
Keywords: derivatives,automata,finite-markets,hedging,certificates
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Science/Research
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Operating System :: OS Independent
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Provides-Extra: bounds
Requires-Dist: numpy>=1.26; extra == "bounds"
Requires-Dist: scipy>=1.11; extra == "bounds"
Provides-Extra: numeric
Requires-Dist: numpy>=1.26; extra == "numeric"
Requires-Dist: matplotlib>=3.8; extra == "numeric"
Provides-Extra: robust
Requires-Dist: numpy>=1.26; extra == "robust"
Requires-Dist: scipy>=1.11; extra == "robust"
Requires-Dist: matplotlib>=3.8; extra == "robust"
Requires-Dist: markdown-it-py>=3; extra == "robust"
Dynamic: license-file

# Canonical Financial Memory

Exact finite-market contract processing, representation reduction and auditable
price/stock calculations for path-dependent claims.

**Version 0.3.0rc1 is a research pre-release, licensed under MIT.**
Market data is not included in the package.
The software licence does not grant rights to third-party market datasets.

## Installation

Python 3.10 or later is required. The supported exact interface needs only the
standard library. Install this specific pre-release with:

```sh
python -m pip install canonical-financial-memory==0.3.0rc1
cfm demo all
```

The explicit version selects this research pre-release. The distribution name
uses hyphens; its Python import is `financial_memory`.

From a source checkout, install with:

```sh
python -m pip install .
cfm demo all
```

Alternatively install the wheel in `dist/`, without checking out the research
repository. The examples and their illustrative input are inside the wheel:

```sh
python -m pip install dist/canonical_financial_memory-0.3.0rc1-py3-none-any.whl
python -m financial_memory.examples
```

These commands do not download market data or run timing-profile training.

## A knock-in contract on your own finite market

```python
from financial_memory.api import compile_contract
from financial_memory.examples import knock_in_specification

spec = knock_in_specification()  # fresh illustrative JSON-compatible dictionary
program = compile_contract(spec)
quote = program.quote()
assert str(quote.price) == "1/64"
assert str(quote.stock) == "-1/4"
print(program.payments(("low", "high")))  # (0, 0, 1/2)

# Request an attainable-residual representation and check its corrections.
reduced = compile_contract(spec, representation="financial")
assert reduced.quote() == quote
print(reduced.audit().as_dict())
```

Replace the example dictionary with your market graph, traded prices, full-
support martingale kernel, monitor transitions and dated payments. Monetary
inputs use integers or decimal/rational strings in JSON. Python probability
updates use integers or `Fraction` objects. Exact input rejects floats.

`auto` keeps product representation for a generic monitor. Settlement and
financial reduction are explicit choices; neither always saves complete cost.

## Coupon memory with knock-in downside redemption

```python
from fractions import Fraction as F
from financial_memory.api import compile_note, settle_note
from financial_memory.examples import coupon_note_model

model = coupon_note_model()  # replace with your contract and forecast inputs
program = compile_note(model, spot=F(100))
print(program.quote("base").as_dict())
payments, events = settle_note(model, map(F, (100, 94, 99, 90, 92)))
assert payments[-1] == F(92)
```

The default exact affine program prepares root queries without enumerating
coupon-balance states. `audit()` deliberately builds a full reference product
and checks every conditional price and stock holding. That work is explicit.
Call `compile_note` again with the new forecast, elapsed date, actual balance
and barrier flag after a daily refit. No forecast is estimated inside this API.

## Linear accumulator plus barrier residual

```python
from financial_memory.api import compile_hybrid

hybrid = compile_hybrid(spec, (F(1, 2), F(1, 2)))
assert hybrid.quote().price == F(65, 64)
assert hybrid.quote().stock == F(3, 4)
print(hybrid.audit().as_dict())
```

This pays a linear weighted sum of **normalized stock observations** at maturity,
plus the supplied residual claim. In the example the numeraire is one, so the
linear leg is the ordinary arithmetic average. It is not an Asian call. The
register's self-financing identity is checked separately from residual pricing.

## Guarantees and limits

- Exact source changes preserve the supplied finite-model prices and local
  quadratic stock holdings. Financing checks concern the removed attainable
  difference, not replication of an entire incomplete-market claim.
- Prices and JSON payments are in numeraire units. Stock holdings are shares.
  Note settlement replay returns currency payments instead; normalize them
  before placing them in a generic JSON market.
- A stock holding is a one-period least-squares projection under the supplied
  pricing law, not a continuous-model delta or a globally optimal hedge.
- New graph, security payoffs or contract terms require a new compilation.
  A new valid kernel on the same generic market can be supplied to `price`,
  `quote`, `values` or `audit`.
- The examples are hypothetical. Certificates establish finite-model
  reconstruction, not an observed exotic price or the quality of a forecast.
- The generic JSON interface has no dividend field. Unsupported fields fail
  explicitly. The declared note interface supports the existing proportional-
  carry model; general dividend graphs remain a lower-level research interface.

The experimental modules remain importable for compatibility. The supported
release-candidate surface is `financial_memory.api` and the documented CLI.
See `docs/library-api.md` in the source distribution for the input schema,
units, method semantics and lifecycle rules. `docs/library-release.md` records
build, installation and publication steps. Optional calibrated LP bounds in
the legacy `cfm analyze --bounds` interface use the `bounds` extra; existing
`numeric` and `robust` extras remain available for the research tools.
