simulacre-finance 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. simulacre_finance-0.1.0/.gitignore +14 -0
  2. simulacre_finance-0.1.0/CHANGELOG.md +22 -0
  3. simulacre_finance-0.1.0/LICENSE +21 -0
  4. simulacre_finance-0.1.0/NOTICE +20 -0
  5. simulacre_finance-0.1.0/PKG-INFO +208 -0
  6. simulacre_finance-0.1.0/README.md +170 -0
  7. simulacre_finance-0.1.0/docs/implementation.md +87 -0
  8. simulacre_finance-0.1.0/docs/methodology.md +168 -0
  9. simulacre_finance-0.1.0/docs/releasing.md +41 -0
  10. simulacre_finance-0.1.0/docs/reviews.md +58 -0
  11. simulacre_finance-0.1.0/docs/simulacre-integration.md +89 -0
  12. simulacre_finance-0.1.0/examples/bond.py +49 -0
  13. simulacre_finance-0.1.0/examples/mcp_history_mapping.py +52 -0
  14. simulacre_finance-0.1.0/examples/portfolio.py +43 -0
  15. simulacre_finance-0.1.0/examples/simulacre_mapping.py +40 -0
  16. simulacre_finance-0.1.0/examples/synthetic_prices.csv +61 -0
  17. simulacre_finance-0.1.0/pyproject.toml +59 -0
  18. simulacre_finance-0.1.0/src/simulacre_finance/__init__.py +94 -0
  19. simulacre_finance-0.1.0/src/simulacre_finance/backtest.py +225 -0
  20. simulacre_finance-0.1.0/src/simulacre_finance/bonds.py +241 -0
  21. simulacre_finance-0.1.0/src/simulacre_finance/data.py +169 -0
  22. simulacre_finance-0.1.0/src/simulacre_finance/exceptions.py +21 -0
  23. simulacre_finance-0.1.0/src/simulacre_finance/portfolio.py +211 -0
  24. simulacre_finance-0.1.0/src/simulacre_finance/providers.py +240 -0
  25. simulacre_finance-0.1.0/src/simulacre_finance/py.typed +0 -0
  26. simulacre_finance-0.1.0/src/simulacre_finance/rates.py +20 -0
  27. simulacre_finance-0.1.0/src/simulacre_finance/risk.py +133 -0
  28. simulacre_finance-0.1.0/tests/conftest.py +27 -0
  29. simulacre_finance-0.1.0/tests/fixtures/iss_history.json +8 -0
  30. simulacre_finance-0.1.0/tests/test_backtest.py +79 -0
  31. simulacre_finance-0.1.0/tests/test_bonds.py +112 -0
  32. simulacre_finance-0.1.0/tests/test_data.py +84 -0
  33. simulacre_finance-0.1.0/tests/test_integration.py +52 -0
  34. simulacre_finance-0.1.0/tests/test_portfolio.py +131 -0
  35. simulacre_finance-0.1.0/tests/test_providers.py +85 -0
  36. simulacre_finance-0.1.0/tests/test_review_regressions.py +167 -0
  37. simulacre_finance-0.1.0/tests/test_risk.py +38 -0
@@ -0,0 +1,14 @@
1
+ .venv/
2
+ .venv-wheel/
3
+ __pycache__/
4
+ .pytest_cache/
5
+ .mypy_cache/
6
+ .ruff_cache/
7
+ dist/
8
+ dist-verified/
9
+ build/
10
+ *.egg-info/
11
+ pytest-of-*/
12
+ build-env-*/
13
+ build-requirements-*.txt
14
+ pip-*/
@@ -0,0 +1,22 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0 — 2026-11-23
4
+
5
+ First public release of Simulacre Finance, extracted into an independent MIT
6
+ Python package from the Simulacre AI implementation effort.
7
+
8
+ - Validated dated price/return matrices, explicit currency/frequency/provenance,
9
+ offline CSV and optional public MOEX ISS lookup/share-history transport.
10
+ - Equal weight, global minimum variance, exact equal risk contribution and minimum
11
+ historical CVaR, with bounds, budget, diagnostics and numerical-scale validation.
12
+ - Realized risk/performance, historical VaR/CVaR, drawdown, Sharpe and gross turnover.
13
+ - Explicit dated fixed cash flows, regular fixed-rate bullet schedules, PV/YTM,
14
+ Macaulay/modified duration, convexity and explicit clean/dirty price handling.
15
+ - Deterministic rolling walk-forward portfolios with delayed close execution,
16
+ drifting holdings, cash, self-financing costs and rebalance audit logs.
17
+ - Reproducible offline examples, tested Simulacre/MCP schema mappings, typed exports
18
+ and an offline suite of 114 numerical/validation tests.
19
+
20
+ Known scope limits and financial assumptions are documented in the README and
21
+ methodology. No exchange data, credentials, live trading or authenticated MCP
22
+ client are bundled.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Tuskul Kaigorodov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,20 @@
1
+ Portfolio optimization formulations adapted from:
2
+ https://github.com/KaigorodovTuskul/portfolio-models-agent-skill
3
+ stable commit cf90e1f625bef8210ddfbfee56a3e232cfc2ef48
4
+ skills/portfolio-models/scripts/models.py and advanced_models.py
5
+ Copyright (c) 2026 Tuskul Kaigorodov, MIT (full text in LICENSE).
6
+ Adaptations: typed dated inputs, general bounds/budget, scaling, error handling,
7
+ sparse CVaR constraints, solver diagnostics and public result contracts.
8
+
9
+ NumPy (BSD-3-Clause primary license, bundled component licenses also apply)
10
+ and SciPy (BSD-3-Clause primary license, bundled solver notices apply)
11
+ are dependencies, not vendored source. Optional HTTPX is BSD-3-Clause.
12
+ Development tool licensing: pytest MIT; Ruff MIT; mypy MIT; scipy-stubs BSD-3-Clause;
13
+ build MIT; Twine Apache-2.0; Hatchling MIT. Their distributions carry their own notices.
14
+
15
+ Ziplime was inspected for execution/accounting concepts only. No source or
16
+ datasets were copied. Its README and repository LICENSE give differing copyleft
17
+ labels; neither is relicensed or incorporated here.
18
+
19
+ All checked-in numerical datasets are authored synthetic fixtures, not MOEX data.
20
+ Provider access does not grant permission to redistribute exchange data.
@@ -0,0 +1,208 @@
1
+ Metadata-Version: 2.4
2
+ Name: simulacre-finance
3
+ Version: 0.1.0
4
+ Summary: Offline portfolio optimization, risk, cash-flow bonds and walk-forward research
5
+ Project-URL: Homepage, https://github.com/KaigorodovTuskul/simulacre-finance
6
+ Project-URL: Repository, https://github.com/KaigorodovTuskul/simulacre-finance
7
+ Project-URL: Documentation, https://github.com/KaigorodovTuskul/simulacre-finance#readme
8
+ Project-URL: Issues, https://github.com/KaigorodovTuskul/simulacre-finance/issues
9
+ Project-URL: Changelog, https://github.com/KaigorodovTuskul/simulacre-finance/blob/main/CHANGELOG.md
10
+ Author: Tuskul Kaigorodov
11
+ License-Expression: MIT
12
+ License-File: LICENSE
13
+ License-File: NOTICE
14
+ Keywords: backtesting,bonds,finance,moex,portfolio-optimization,risk
15
+ Classifier: Development Status :: 4 - Beta
16
+ Classifier: Intended Audience :: Developers
17
+ Classifier: Intended Audience :: Financial and Insurance Industry
18
+ Classifier: Operating System :: OS Independent
19
+ Classifier: Programming Language :: Python :: 3
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Classifier: Topic :: Office/Business :: Financial
23
+ Classifier: Typing :: Typed
24
+ Requires-Python: >=3.11
25
+ Requires-Dist: numpy<3,>=1.26
26
+ Requires-Dist: scipy<2,>=1.12
27
+ Provides-Extra: dev
28
+ Requires-Dist: build<2,>=1.2; extra == 'dev'
29
+ Requires-Dist: httpx<1,>=0.27; extra == 'dev'
30
+ Requires-Dist: mypy<2,>=1.15; extra == 'dev'
31
+ Requires-Dist: pytest<10,>=8; extra == 'dev'
32
+ Requires-Dist: ruff<1,>=0.11; extra == 'dev'
33
+ Requires-Dist: scipy-stubs>=1.15; extra == 'dev'
34
+ Requires-Dist: twine<7,>=6; extra == 'dev'
35
+ Provides-Extra: http
36
+ Requires-Dist: httpx<1,>=0.27; extra == 'http'
37
+ Description-Content-Type: text/markdown
38
+
39
+ # Simulacre Finance
40
+
41
+ **Portfolio optimization, risk metrics, fixed-cash-flow bonds, and walk-forward backtesting.**
42
+
43
+ [![Checks](https://github.com/KaigorodovTuskul/simulacre-finance/actions/workflows/release.yml/badge.svg)](https://github.com/KaigorodovTuskul/simulacre-finance/actions/workflows/release.yml)
44
+ [![PyPI](https://img.shields.io/pypi/v/simulacre-finance)](https://pypi.org/project/simulacre-finance/)
45
+ [![Python](https://img.shields.io/badge/python-3.11%2B-blue)](https://www.python.org/downloads/)
46
+ [![License: MIT](https://img.shields.io/badge/license-MIT-green)](https://github.com/KaigorodovTuskul/simulacre-finance/blob/main/LICENSE)
47
+
48
+ A typed Python computation library for reproducible financial research. Run the
49
+ entire analytical pipeline offline with your own data. NumPy and SciPy are the
50
+ only runtime dependencies; public MOEX ISS access is an optional extra.
51
+
52
+ Built for [Simulacre AI](https://simulacre-ai.ru/site/) and usable independently
53
+ of its website, Telegram bot, MCP server, or accounts.
54
+
55
+ [Quick start](#quick-start) · [Methods](#what-it-does) · [Examples](#examples) ·
56
+ [Methodology](https://github.com/KaigorodovTuskul/simulacre-finance/blob/main/docs/methodology.md) · [Integration](https://github.com/KaigorodovTuskul/simulacre-finance/blob/main/docs/simulacre-integration.md)
57
+
58
+ ## Install
59
+
60
+ Python **3.11 or newer**:
61
+
62
+ ```sh
63
+ pip install simulacre-finance
64
+ # Or add it to a uv project:
65
+ uv add simulacre-finance
66
+ ```
67
+
68
+ For the optional MOEX HTTP transport:
69
+
70
+ ```sh
71
+ pip install "simulacre-finance[http]"
72
+ # uv add "simulacre-finance[http]"
73
+ ```
74
+
75
+ The distribution is named `simulacre-finance`; import it as `simulacre_finance`.
76
+ Source installation is also supported: clone this repository and run `pip install .`.
77
+
78
+ ## What it does
79
+
80
+ | Area | Available in 0.1.0 |
81
+ | --- | --- |
82
+ | Data | Validated dated price/return matrices, wide CSV, instrument lookup and paginated MOEX ISS share closes |
83
+ | Optimization | Equal weight, global minimum variance, exact equal risk contribution, minimum historical CVaR |
84
+ | Risk | Compounded/annualized performance, volatility, Sharpe, drawdown, historical VaR/CVaR, gross turnover |
85
+ | Bonds | Explicit dated fixed cash flows, regular fixed-rate bullets, dirty/clean prices, YTM, duration and convexity |
86
+ | Backtesting | Rolling training, delayed close execution, drifted holdings, cash, commissions/slippage and rebalance audit logs |
87
+ | Integration | Pure Python functions and tested mappings for Simulacre Portfolio Lab and existing MCP history responses |
88
+
89
+ ## Quick start
90
+
91
+ Supply decimal simple returns, dated oldest first. Every column is one asset;
92
+ currency, provenance and annualization are explicit.
93
+
94
+ ```python
95
+ from datetime import date
96
+
97
+ import numpy as np
98
+
99
+ from simulacre_finance import Metadata, ReturnData, optimize, risk_report
100
+
101
+ data = ReturnData(
102
+ dates=tuple(date(2024, 1, day) for day in range(1, 5)),
103
+ assets=("SYNTH_A", "SYNTH_B"),
104
+ values=np.array([
105
+ [-0.01, -0.02], [-0.01, 0.02],
106
+ [0.01, -0.02], [0.01, 0.02],
107
+ ]),
108
+ metadata=Metadata("RUB", 252, "authored synthetic", date(2024, 1, 4)),
109
+ )
110
+
111
+ estimate = optimize(data, "minimum_variance")
112
+ print(estimate.weights.round(3)) # [0.8 0.2]
113
+
114
+ # Descriptive IN-SAMPLE risk, not an out-of-sample performance claim.
115
+ report = risk_report(
116
+ data.values @ estimate.weights,
117
+ periods_per_year=252,
118
+ annual_risk_free_rate=0.05,
119
+ kind="price",
120
+ )
121
+ print(report.volatility)
122
+ ```
123
+
124
+ For CSV, use `load_csv(path, metadata=...)` with a wide `date,ASSET_A,ASSET_B`
125
+ header, then call `.returns()` explicitly. Missing/nonfinite values, duplicate
126
+ dates and nonpositive prices raise errors; the library never silently fills them.
127
+
128
+ ## Examples
129
+
130
+ Clone this repository to run the included offline examples:
131
+
132
+ ```sh
133
+ git clone https://github.com/KaigorodovTuskul/simulacre-finance.git
134
+ cd simulacre-finance
135
+ pip install .
136
+ python examples/portfolio.py
137
+ python examples/bond.py
138
+ ```
139
+
140
+ - [Portfolio research](https://github.com/KaigorodovTuskul/simulacre-finance/blob/main/examples/portfolio.py): authored synthetic CSV → all four
141
+ optimizers → walk-forward comparison → realized risk, turnover and costs.
142
+ - [Bond valuation](https://github.com/KaigorodovTuskul/simulacre-finance/blob/main/examples/bond.py): known fixed coupon schedule → price,
143
+ recovered yield, duration and convexity.
144
+ - [Sleeve mapping](https://github.com/KaigorodovTuskul/simulacre-finance/blob/main/examples/simulacre_mapping.py) and
145
+ [MCP history mapping](https://github.com/KaigorodovTuskul/simulacre-finance/blob/main/examples/mcp_history_mapping.py): adapt existing response
146
+ schemas without adding a network client or private service dependency.
147
+
148
+ For longer histories, `compare_methods(returns, lookback=60, rebalance_every=20,
149
+ execution_lag=1, commission_bps=5, slippage_bps=2)` returns all four methods'
150
+ dated equity curves, realized metrics, drifted weights, costs and rebalance logs.
151
+
152
+ ## Financial conventions
153
+
154
+ - **Units:** `0.05` means 5%; prices, payments and accrued interest are currency
155
+ amounts per supplied notional. Bond prices are not percentages of par.
156
+ - **Return provenance:** price-only inputs remain labeled `price`. Total-return
157
+ inputs must already include distributions; coupons/dividends are never inferred.
158
+ - **Estimates versus outcomes:** optimizer results describe the training sample.
159
+ Walk-forward results report realized simulated performance separately.
160
+ - **Execution:** decisions use trailing observations and execute at a later close.
161
+ Old holdings earn the execution-date return. New weights apply to the next interval.
162
+ - **Costs and cash:** initial purchases incur costs; trading is self-financing.
163
+ Residual cash earns zero. The risk-free rate is a metric benchmark only.
164
+ - **Exact ERC:** positive-definite covariance is required. If exact equal-risk
165
+ weights violate requested bounds, an explicit infeasibility error is raised.
166
+ - **Bonds:** known positive dated flows, nominal periodic yield, explicit settlement
167
+ and day count. Clean price requires caller-supplied accrued interest.
168
+
169
+ See [methodology and public API](https://github.com/KaigorodovTuskul/simulacre-finance/blob/main/docs/methodology.md) for formulas, solver
170
+ diagnostics, annualization, tail-risk conventions and full limitations.
171
+
172
+ ## Development and validation
173
+
174
+ ```sh
175
+ python -m pip install -e ".[dev]"
176
+ python -m pytest -q
177
+ python -m ruff check src tests examples
178
+ python -m ruff format --check src tests examples
179
+ python -m mypy
180
+ python -m build
181
+ python -m twine check dist/*
182
+ ```
183
+
184
+ The offline suite has **114 tests**, including analytical optimizer references,
185
+ hand-calculated portfolio paths, no-lookahead checks, self-financing fees, provider
186
+ pagination failures and bond sensitivity/yield round trips. Fixtures are authored
187
+ synthetic data. Core installation and the entire suite were also tested with
188
+ Python 3.11, NumPy 1.26.4 and SciPy 1.12.0, without HTTPX.
189
+
190
+ [CI](https://github.com/KaigorodovTuskul/simulacre-finance/blob/main/.github/workflows/release.yml) runs checks before publishing tagged releases.
191
+ The [release guide](https://github.com/KaigorodovTuskul/simulacre-finance/blob/main/docs/releasing.md) explains versioning and PyPI Trusted Publishing.
192
+ Type checks run on Python 3.12; runtime support begins at 3.11.
193
+
194
+ ## Scope and attribution
195
+
196
+ This is a portfolio research library. Version 0.1 does not model live orders,
197
+ taxes, FX conversion, bankruptcy, market impact, nonzero cash yields or historical
198
+ universe membership. Calendar/adjustment and point-in-time data selection remain
199
+ the caller's responsibility. Floating/optional future bond payments must not be
200
+ presented as known fixed cash flows.
201
+
202
+ [MIT](https://github.com/KaigorodovTuskul/simulacre-finance/blob/main/LICENSE). Portfolio formulations are adapted from the audited MIT
203
+ [Portfolio Models](https://github.com/KaigorodovTuskul/portfolio-models-agent-skill)
204
+ reference; see [NOTICE](https://github.com/KaigorodovTuskul/simulacre-finance/blob/main/NOTICE). No exchange datasets or Ziplime code are bundled.
205
+ MOEX access does not grant redistribution rights to provider data.
206
+
207
+ [Changelog](https://github.com/KaigorodovTuskul/simulacre-finance/blob/main/CHANGELOG.md) · [Implementation and validation](https://github.com/KaigorodovTuskul/simulacre-finance/blob/main/docs/implementation.md) ·
208
+ [Independent review record](https://github.com/KaigorodovTuskul/simulacre-finance/blob/main/docs/reviews.md) · [Issues](https://github.com/KaigorodovTuskul/simulacre-finance/issues)
@@ -0,0 +1,170 @@
1
+ # Simulacre Finance
2
+
3
+ **Portfolio optimization, risk metrics, fixed-cash-flow bonds, and walk-forward backtesting.**
4
+
5
+ [![Checks](https://github.com/KaigorodovTuskul/simulacre-finance/actions/workflows/release.yml/badge.svg)](https://github.com/KaigorodovTuskul/simulacre-finance/actions/workflows/release.yml)
6
+ [![PyPI](https://img.shields.io/pypi/v/simulacre-finance)](https://pypi.org/project/simulacre-finance/)
7
+ [![Python](https://img.shields.io/badge/python-3.11%2B-blue)](https://www.python.org/downloads/)
8
+ [![License: MIT](https://img.shields.io/badge/license-MIT-green)](https://github.com/KaigorodovTuskul/simulacre-finance/blob/main/LICENSE)
9
+
10
+ A typed Python computation library for reproducible financial research. Run the
11
+ entire analytical pipeline offline with your own data. NumPy and SciPy are the
12
+ only runtime dependencies; public MOEX ISS access is an optional extra.
13
+
14
+ Built for [Simulacre AI](https://simulacre-ai.ru/site/) and usable independently
15
+ of its website, Telegram bot, MCP server, or accounts.
16
+
17
+ [Quick start](#quick-start) · [Methods](#what-it-does) · [Examples](#examples) ·
18
+ [Methodology](https://github.com/KaigorodovTuskul/simulacre-finance/blob/main/docs/methodology.md) · [Integration](https://github.com/KaigorodovTuskul/simulacre-finance/blob/main/docs/simulacre-integration.md)
19
+
20
+ ## Install
21
+
22
+ Python **3.11 or newer**:
23
+
24
+ ```sh
25
+ pip install simulacre-finance
26
+ # Or add it to a uv project:
27
+ uv add simulacre-finance
28
+ ```
29
+
30
+ For the optional MOEX HTTP transport:
31
+
32
+ ```sh
33
+ pip install "simulacre-finance[http]"
34
+ # uv add "simulacre-finance[http]"
35
+ ```
36
+
37
+ The distribution is named `simulacre-finance`; import it as `simulacre_finance`.
38
+ Source installation is also supported: clone this repository and run `pip install .`.
39
+
40
+ ## What it does
41
+
42
+ | Area | Available in 0.1.0 |
43
+ | --- | --- |
44
+ | Data | Validated dated price/return matrices, wide CSV, instrument lookup and paginated MOEX ISS share closes |
45
+ | Optimization | Equal weight, global minimum variance, exact equal risk contribution, minimum historical CVaR |
46
+ | Risk | Compounded/annualized performance, volatility, Sharpe, drawdown, historical VaR/CVaR, gross turnover |
47
+ | Bonds | Explicit dated fixed cash flows, regular fixed-rate bullets, dirty/clean prices, YTM, duration and convexity |
48
+ | Backtesting | Rolling training, delayed close execution, drifted holdings, cash, commissions/slippage and rebalance audit logs |
49
+ | Integration | Pure Python functions and tested mappings for Simulacre Portfolio Lab and existing MCP history responses |
50
+
51
+ ## Quick start
52
+
53
+ Supply decimal simple returns, dated oldest first. Every column is one asset;
54
+ currency, provenance and annualization are explicit.
55
+
56
+ ```python
57
+ from datetime import date
58
+
59
+ import numpy as np
60
+
61
+ from simulacre_finance import Metadata, ReturnData, optimize, risk_report
62
+
63
+ data = ReturnData(
64
+ dates=tuple(date(2024, 1, day) for day in range(1, 5)),
65
+ assets=("SYNTH_A", "SYNTH_B"),
66
+ values=np.array([
67
+ [-0.01, -0.02], [-0.01, 0.02],
68
+ [0.01, -0.02], [0.01, 0.02],
69
+ ]),
70
+ metadata=Metadata("RUB", 252, "authored synthetic", date(2024, 1, 4)),
71
+ )
72
+
73
+ estimate = optimize(data, "minimum_variance")
74
+ print(estimate.weights.round(3)) # [0.8 0.2]
75
+
76
+ # Descriptive IN-SAMPLE risk, not an out-of-sample performance claim.
77
+ report = risk_report(
78
+ data.values @ estimate.weights,
79
+ periods_per_year=252,
80
+ annual_risk_free_rate=0.05,
81
+ kind="price",
82
+ )
83
+ print(report.volatility)
84
+ ```
85
+
86
+ For CSV, use `load_csv(path, metadata=...)` with a wide `date,ASSET_A,ASSET_B`
87
+ header, then call `.returns()` explicitly. Missing/nonfinite values, duplicate
88
+ dates and nonpositive prices raise errors; the library never silently fills them.
89
+
90
+ ## Examples
91
+
92
+ Clone this repository to run the included offline examples:
93
+
94
+ ```sh
95
+ git clone https://github.com/KaigorodovTuskul/simulacre-finance.git
96
+ cd simulacre-finance
97
+ pip install .
98
+ python examples/portfolio.py
99
+ python examples/bond.py
100
+ ```
101
+
102
+ - [Portfolio research](https://github.com/KaigorodovTuskul/simulacre-finance/blob/main/examples/portfolio.py): authored synthetic CSV → all four
103
+ optimizers → walk-forward comparison → realized risk, turnover and costs.
104
+ - [Bond valuation](https://github.com/KaigorodovTuskul/simulacre-finance/blob/main/examples/bond.py): known fixed coupon schedule → price,
105
+ recovered yield, duration and convexity.
106
+ - [Sleeve mapping](https://github.com/KaigorodovTuskul/simulacre-finance/blob/main/examples/simulacre_mapping.py) and
107
+ [MCP history mapping](https://github.com/KaigorodovTuskul/simulacre-finance/blob/main/examples/mcp_history_mapping.py): adapt existing response
108
+ schemas without adding a network client or private service dependency.
109
+
110
+ For longer histories, `compare_methods(returns, lookback=60, rebalance_every=20,
111
+ execution_lag=1, commission_bps=5, slippage_bps=2)` returns all four methods'
112
+ dated equity curves, realized metrics, drifted weights, costs and rebalance logs.
113
+
114
+ ## Financial conventions
115
+
116
+ - **Units:** `0.05` means 5%; prices, payments and accrued interest are currency
117
+ amounts per supplied notional. Bond prices are not percentages of par.
118
+ - **Return provenance:** price-only inputs remain labeled `price`. Total-return
119
+ inputs must already include distributions; coupons/dividends are never inferred.
120
+ - **Estimates versus outcomes:** optimizer results describe the training sample.
121
+ Walk-forward results report realized simulated performance separately.
122
+ - **Execution:** decisions use trailing observations and execute at a later close.
123
+ Old holdings earn the execution-date return. New weights apply to the next interval.
124
+ - **Costs and cash:** initial purchases incur costs; trading is self-financing.
125
+ Residual cash earns zero. The risk-free rate is a metric benchmark only.
126
+ - **Exact ERC:** positive-definite covariance is required. If exact equal-risk
127
+ weights violate requested bounds, an explicit infeasibility error is raised.
128
+ - **Bonds:** known positive dated flows, nominal periodic yield, explicit settlement
129
+ and day count. Clean price requires caller-supplied accrued interest.
130
+
131
+ See [methodology and public API](https://github.com/KaigorodovTuskul/simulacre-finance/blob/main/docs/methodology.md) for formulas, solver
132
+ diagnostics, annualization, tail-risk conventions and full limitations.
133
+
134
+ ## Development and validation
135
+
136
+ ```sh
137
+ python -m pip install -e ".[dev]"
138
+ python -m pytest -q
139
+ python -m ruff check src tests examples
140
+ python -m ruff format --check src tests examples
141
+ python -m mypy
142
+ python -m build
143
+ python -m twine check dist/*
144
+ ```
145
+
146
+ The offline suite has **114 tests**, including analytical optimizer references,
147
+ hand-calculated portfolio paths, no-lookahead checks, self-financing fees, provider
148
+ pagination failures and bond sensitivity/yield round trips. Fixtures are authored
149
+ synthetic data. Core installation and the entire suite were also tested with
150
+ Python 3.11, NumPy 1.26.4 and SciPy 1.12.0, without HTTPX.
151
+
152
+ [CI](https://github.com/KaigorodovTuskul/simulacre-finance/blob/main/.github/workflows/release.yml) runs checks before publishing tagged releases.
153
+ The [release guide](https://github.com/KaigorodovTuskul/simulacre-finance/blob/main/docs/releasing.md) explains versioning and PyPI Trusted Publishing.
154
+ Type checks run on Python 3.12; runtime support begins at 3.11.
155
+
156
+ ## Scope and attribution
157
+
158
+ This is a portfolio research library. Version 0.1 does not model live orders,
159
+ taxes, FX conversion, bankruptcy, market impact, nonzero cash yields or historical
160
+ universe membership. Calendar/adjustment and point-in-time data selection remain
161
+ the caller's responsibility. Floating/optional future bond payments must not be
162
+ presented as known fixed cash flows.
163
+
164
+ [MIT](https://github.com/KaigorodovTuskul/simulacre-finance/blob/main/LICENSE). Portfolio formulations are adapted from the audited MIT
165
+ [Portfolio Models](https://github.com/KaigorodovTuskul/portfolio-models-agent-skill)
166
+ reference; see [NOTICE](https://github.com/KaigorodovTuskul/simulacre-finance/blob/main/NOTICE). No exchange datasets or Ziplime code are bundled.
167
+ MOEX access does not grant redistribution rights to provider data.
168
+
169
+ [Changelog](https://github.com/KaigorodovTuskul/simulacre-finance/blob/main/CHANGELOG.md) · [Implementation and validation](https://github.com/KaigorodovTuskul/simulacre-finance/blob/main/docs/implementation.md) ·
170
+ [Independent review record](https://github.com/KaigorodovTuskul/simulacre-finance/blob/main/docs/reviews.md) · [Issues](https://github.com/KaigorodovTuskul/simulacre-finance/issues)
@@ -0,0 +1,87 @@
1
+ # v0.1 scope and implementation record
2
+
3
+ ## Phase 1: audit and public API
4
+
5
+ The existing host repository is a non-distributable application (`tool.uv.package=false`).
6
+ The initial distribution was implemented under packages/simulacre-finance without
7
+ replacing the host metadata/source. It is now maintained in the independent public
8
+ KaigorodovTuskul/simulacre-finance repository.
9
+ Core dependencies: NumPy + SciPy. HTTPX is an optional transport extra; no Pandas,
10
+ optimizer framework, LLM client, backend, service or credential dependency.
11
+
12
+ Public modules: `data` (Metadata, PriceData, ReturnData, load_csv), `providers`
13
+ (MoexISS, Instrument), `portfolio` (optimize, OptimizationResult), `risk`
14
+ (risk_report, historical_tail_risk, turnover), `bonds` (CashFlow, FixedCashflows,
15
+ fixed_rate_bullet, bond_analytics, yield_to_maturity), `backtest` (walk_forward,
16
+ compare_methods, BacktestResult), `rates` (simple_accrual_factor), and exceptions.
17
+ Every module is callable offline; only MoexISS's default HTTP transport needs network.
18
+
19
+ Portfolio Models stable cf90e1f was inspected (models.py, advanced_models.py, tests).
20
+ GMV quadratic minimization, ERC convex log-barrier and Rockafellar-Uryasev CVaR LP
21
+ are adapted under MIT. Equal weight is the same mathematical baseline. Public APIs,
22
+ input validation, execution engine and bond cash-flow implementation are new.
23
+ The host's multi-asset allocator embeds synthetic assumptions and special policy caps,
24
+ so it is not copied into a general-purpose numerical package.
25
+
26
+ Public Simulacre portal and MCP documentation were inspected. They publish snapshots
27
+ and schema discovery; authenticated remote MCP requires OAuth/personal keys. We do
28
+ not introduce an unverified authenticated client. Plain functions remain the boundary.
29
+ Ziplime supplied architectural lessons (execution lag, costs, no future observations),
30
+ not code. See NOTICE and LICENSE for attribution and dependency licenses.
31
+
32
+ Scope: CSV + MOEX ISS historical closes, four long-only portfolio methods, realized
33
+ risk, explicit fixed cash-flow valuation, fixed-rate bullet convenience schedules,
34
+ and walk-forward portfolios with costs. Out of scope: brokers/live orders, taxes,
35
+ FX conversion, bankruptcy, floating/optional cash flows, forecasting and web UI.
36
+
37
+ ## Completed checkpoints
38
+
39
+ | Phase | Delivered checkpoint and evidence |
40
+ | --- | --- |
41
+ | 1. Scope/audit | Existing host application and Portfolio Models algorithms/tests/licenses inspected; contracts and independent package boundary fixed above |
42
+ | 2. Distribution | PEP 621 src layout, MIT/NOTICE, typed public exports, py.typed, editable installation and wheel/sdist builds |
43
+ | 3. Data | Strict dated matrices and CSV, ISS search/share closes with bounded pagination/retries; deterministic offline fixtures; live public ISIN lookup and four-day SBER close history also verified |
44
+ | 4. Portfolio/risk | Four methods, bounds/budget/diagnostics, numerical-scale normalization, realized metrics; analytic GMV/ERC, CVaR grid and tail-risk reference tests |
45
+ | 5. Bonds | Explicit fixed dated flows, regular bullet schedules, PV/YTM/durations/convexity, clean-price boundary; hand calculations and finite-difference/round-trip tests |
46
+ | 6. Backtesting | Rolling chronological windows, delayed close execution, drift/cash accounting, self-financing fees, all-method comparison and audit logs; hand paths, no-lookahead and scale tests |
47
+ | 7. Integration/examples | CSV/portfolio/backtest/risk and bond examples; actual host cash calculation delegation; tested sleeve and normalized MCP history mappings, no unverified authenticated provider |
48
+ | 8. Release/review | 114 offline tests, Ruff/format, strict mypy, metadata/content validation, installed-wheel checks and two independent review rounds; final mean 9.1/10 |
49
+
50
+ ## Release validation record
51
+
52
+ - Editable installation: `uv pip install --python .venv/Scripts/python.exe -e '.[dev]'`
53
+ (equivalent to the README pip command).
54
+ - Main environment: Python 3.12.4, NumPy 2.5.5, SciPy 1.18.1; **114 tests pass**.
55
+ - Fresh wheel environment: Python 3.11.6, NumPy 1.26.4, SciPy 1.12.0; installed
56
+ from the built wheel (not editable), **114 tests pass**, `pip check` passes.
57
+ Imports resolve to site-packages; HTTPX is absent. This verifies the minimum
58
+ declared numerical versions as well as core independence from network extras.
59
+ - `python -m ruff check src tests examples`, `ruff format --check` and
60
+ `python -m mypy` pass. All Python source also parses as Python 3.11 syntax.
61
+ - Isolated `python -m build` and `python -m build --no-isolation` both succeed;
62
+ the latter uses the same installed Hatchling 1.27 backend. Wheel is built from
63
+ the sdist, so missing source files do not get hidden by an in-tree wheel build.
64
+ - Twine validates wheel/sdist Metadata 2.4; contents include py.typed, LICENSE,
65
+ NOTICE and public modules. Sdist additionally includes tests, fixtures, both
66
+ offline examples, authored CSV and integration documentation. No environment,
67
+ credentials, application source or exchange data are included.
68
+ - Both examples execute reproducibly from the installed wheel under isolated
69
+ Python, with an unrelated working directory. Package tests block sockets.
70
+ - Host regression scope: **23 tests pass** in cash, sleeve engine, instrument
71
+ engine and futures overlay; `uv lock --check` and `git diff --check` pass.
72
+ - Three independent review perspectives: **9.2 finance, 9.1 package, 9.0 reuse**.
73
+ Findings, fixes and scope of each check are in [reviews.md](reviews.md).
74
+
75
+ This validation record was captured before public repository extraction. Release
76
+ publication is documented in releasing.md and the GitHub/PyPI release records.
77
+ No production deployment was part of this library validation. A full Docker image
78
+ build and unrelated host application tests were not run; changed calculation
79
+ callers were tested as listed.
80
+
81
+ ## Financial methodology references
82
+
83
+ - Rockafellar & Uryasev, Optimization of Conditional Value-at-Risk:
84
+ https://sites.math.washington.edu/~rtr/papers/rtr179-CVaR1.pdf
85
+ - SciPy solver contracts: https://docs.scipy.org/doc/scipy/reference/optimize.html
86
+ - MOEX ISS endpoint reference: https://iss.moex.com/iss/reference/
87
+ - Portfolio Models source and MIT attribution: see NOTICE.