pystochastic 0.2.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 (48) hide show
  1. pystochastic-0.2.0/LICENSE +22 -0
  2. pystochastic-0.2.0/PKG-INFO +404 -0
  3. pystochastic-0.2.0/README.md +352 -0
  4. pystochastic-0.2.0/benchmarks/bench_montecarlo.py +107 -0
  5. pystochastic-0.2.0/benchmarks/bench_processes.py +163 -0
  6. pystochastic-0.2.0/benchmarks/bench_pyrandom.py +95 -0
  7. pystochastic-0.2.0/benchmarks/bench_sde.py +185 -0
  8. pystochastic-0.2.0/pyproject.toml +42 -0
  9. pystochastic-0.2.0/pystochastic/__init__.py +7 -0
  10. pystochastic-0.2.0/pystochastic/dist/__init__.py +25 -0
  11. pystochastic-0.2.0/pystochastic/dist/dist.py +2275 -0
  12. pystochastic-0.2.0/pystochastic/montecarlo/__init__.py +3 -0
  13. pystochastic-0.2.0/pystochastic/montecarlo/montecarlo.py +965 -0
  14. pystochastic-0.2.0/pystochastic/processes/CIR.py +284 -0
  15. pystochastic-0.2.0/pystochastic/processes/GeometricBrownianMotion.py +443 -0
  16. pystochastic-0.2.0/pystochastic/processes/OrnsteinUhlenbeck.py +462 -0
  17. pystochastic-0.2.0/pystochastic/processes/__init__.py +6 -0
  18. pystochastic-0.2.0/pystochastic/processes/brownian.py +461 -0
  19. pystochastic-0.2.0/pystochastic/processes/poisson.py +202 -0
  20. pystochastic-0.2.0/pystochastic/processes/vasicek.py +463 -0
  21. pystochastic-0.2.0/pystochastic/pyrandom/__init__.py +5 -0
  22. pystochastic-0.2.0/pystochastic/pyrandom/crandom.py +567 -0
  23. pystochastic-0.2.0/pystochastic/pyrandom/drandom.py +424 -0
  24. pystochastic-0.2.0/pystochastic/pyrandom/setseed.py +11 -0
  25. pystochastic-0.2.0/pystochastic/sde/__init__.py +4 -0
  26. pystochastic-0.2.0/pystochastic/sde/eulermaruyama.py +365 -0
  27. pystochastic-0.2.0/pystochastic/sde/milstein.py +177 -0
  28. pystochastic-0.2.0/pystochastic/utils.py +57 -0
  29. pystochastic-0.2.0/pystochastic.egg-info/PKG-INFO +404 -0
  30. pystochastic-0.2.0/pystochastic.egg-info/SOURCES.txt +46 -0
  31. pystochastic-0.2.0/pystochastic.egg-info/dependency_links.txt +1 -0
  32. pystochastic-0.2.0/pystochastic.egg-info/requires.txt +4 -0
  33. pystochastic-0.2.0/pystochastic.egg-info/top_level.txt +4 -0
  34. pystochastic-0.2.0/setup.cfg +4 -0
  35. pystochastic-0.2.0/tests/api/test_api.py +53 -0
  36. pystochastic-0.2.0/tests/api/test_conftest.py +10 -0
  37. pystochastic-0.2.0/tests/api/test_utils.py +26 -0
  38. pystochastic-0.2.0/tests/distributions/test_continuous.py +200 -0
  39. pystochastic-0.2.0/tests/distributions/test_discrete.py +219 -0
  40. pystochastic-0.2.0/tests/distributions/test_dist_general.py +165 -0
  41. pystochastic-0.2.0/tests/distributions/test_interface.py +51 -0
  42. pystochastic-0.2.0/tests/distributions/test_pyrandom.py +93 -0
  43. pystochastic-0.2.0/tests/montecarlo/test_montecarlo1.py +609 -0
  44. pystochastic-0.2.0/tests/montecarlo/test_montecarlo2.py +207 -0
  45. pystochastic-0.2.0/tests/processes/test_processes.py +450 -0
  46. pystochastic-0.2.0/tests/solvers/test_eulermaruyama.py +325 -0
  47. pystochastic-0.2.0/tests/solvers/test_milstein.py +298 -0
  48. pystochastic-0.2.0/tests/solvers/test_sde.py +128 -0
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Bastien Velcin
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.
22
+
@@ -0,0 +1,404 @@
1
+ Metadata-Version: 2.4
2
+ Name: pystochastic
3
+ Version: 0.2.0
4
+ Summary: A Python library for probability, stochastic calculus and modelling, stochastic differential equations, and Monte Carlo simulation
5
+ Author: Bastien Velcin
6
+ License: MIT License
7
+
8
+ Copyright (c) 2026 Bastien Velcin
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+
28
+
29
+ Project-URL: Homepage, https://github.com/BastienVelcin/PyStochastic
30
+ Project-URL: Repository, https://github.com/BastienVelcin/PyStochastic
31
+ Project-URL: Issues, https://github.com/BastienVelcin/PyStochastic/issues
32
+ Classifier: Development Status :: 4 - Beta
33
+ Classifier: Intended Audience :: Science/Research
34
+ Classifier: Intended Audience :: Developers
35
+ Classifier: License :: OSI Approved :: MIT License
36
+ Classifier: Programming Language :: Python :: 3
37
+ Classifier: Programming Language :: Python :: 3 :: Only
38
+ Classifier: Programming Language :: Python :: 3.10
39
+ Classifier: Programming Language :: Python :: 3.11
40
+ Classifier: Programming Language :: Python :: 3.12
41
+ Classifier: Programming Language :: Python :: 3.13
42
+ Classifier: Topic :: Scientific/Engineering
43
+ Classifier: Topic :: Scientific/Engineering :: Mathematics
44
+ Requires-Python: >=3.10
45
+ Description-Content-Type: text/markdown
46
+ License-File: LICENSE
47
+ Requires-Dist: numpy
48
+ Requires-Dist: scipy
49
+ Requires-Dist: plotly
50
+ Requires-Dist: sympy
51
+ Dynamic: license-file
52
+
53
+ # PyStochastic
54
+
55
+ PyStochastic is a Python library for probability, stochastic calculus and stochastic modelling, Monte Carlo methods and numerical methods for
56
+ stochastic differential equations.
57
+
58
+ The project aims to provide a simple and consistent interface for
59
+ simulating, analysing and visualising stochastic models.
60
+
61
+ ---
62
+
63
+ ## ✨ Features
64
+
65
+ PyStochastic currently provides tools for:
66
+
67
+ - Probability distributions
68
+ - Continuous distributions
69
+ - Discrete distributions
70
+ - Random number generation
71
+ - Stochastic processes
72
+ - Numerical SDE solvers
73
+ - Euler-Maruyama
74
+ - Milstein
75
+ - Monte Carlo analysis
76
+ - Estimation
77
+ - Moments
78
+ - Variance and standard error
79
+ - Confidence intervals
80
+ - Quantiles
81
+ - Histograms
82
+ - Empirical cumulative distribution functions
83
+ - Confidence curves
84
+ - Vectorised simulations
85
+ - Plotting and visualisation
86
+
87
+ ---
88
+
89
+ ## 📦 Installation
90
+
91
+ Clone the repository:
92
+
93
+ ```bash
94
+ git clone https://github.com/BastienVelcin/PyStochastic.git
95
+ cd PyStochastic
96
+ ```
97
+
98
+ Then install the package:
99
+
100
+ ```bash
101
+ pip install .
102
+ ```
103
+
104
+ ---
105
+
106
+ ## 🚀 Quick start
107
+
108
+ ### Probability distributions
109
+
110
+ PyStochastic provides a common interface for probability distributions.
111
+
112
+ For example:
113
+
114
+ ```python
115
+ from pystochastic.dist import Normal
116
+
117
+ distribution = Normal(mu=0, sigma=1)
118
+
119
+ samples = distribution.sample(10000)
120
+
121
+ mean = distribution.mean()
122
+ variance = distribution.variance()
123
+ ```
124
+
125
+ Probability distributions also provide functions such as `pdf` and
126
+ `cdf` when appropriate.
127
+
128
+ ---
129
+
130
+ ### Discrete distributions
131
+
132
+ Discrete probability distributions use the `DiscreteDistribution`
133
+ interface and provide a `pmf` method.
134
+
135
+ For example:
136
+
137
+ ```python
138
+ from pystochastic.dist import Bernoulli
139
+
140
+ distribution = Bernoulli(p=0.3)
141
+
142
+ samples = distribution.sample(10000)
143
+
144
+ probability = distribution.pmf(1)
145
+ ```
146
+
147
+ ---
148
+
149
+ ## 🎲 Random number generation
150
+
151
+ PyStochastic provides random number generators for both continuous
152
+ and discrete distributions through the `pyrandom` module.
153
+
154
+ ```python
155
+ from pystochastic.pyrandom import crandom
156
+
157
+ samples = crandom.normal(
158
+ mu=0,
159
+ sigma=1,
160
+ size=10000,
161
+ )
162
+ ```
163
+
164
+ A global seed can also be configured for reproducible simulations.
165
+
166
+ ```python
167
+ from pystochastic.pyrandom.setseed import seed
168
+
169
+ seed(42)
170
+ ```
171
+
172
+ ---
173
+
174
+ # 📈 Stochastic processes
175
+
176
+ PyStochastic provides several classical stochastic processes, including:
177
+
178
+ - Brownian motion
179
+ - Poisson process
180
+ - Geometric Brownian motion
181
+ - Ornstein-Uhlenbeck process
182
+ - Vasicek model
183
+ - Cox-Ingersoll-Ross model
184
+
185
+ For example:
186
+
187
+ ```python
188
+ from pystochastic.processes import Brownian
189
+
190
+ process = Brownian(
191
+ t_0=0,
192
+ t_n=1,
193
+ n_steps=1000,
194
+ n_simulations=10,
195
+ )
196
+
197
+ process.simulate()
198
+ ```
199
+
200
+ The simulated paths can then be analysed and visualised.
201
+
202
+ ---
203
+
204
+ # 🧮 Stochastic differential equations
205
+
206
+ PyStochastic provides numerical solvers for stochastic differential
207
+ equations.
208
+
209
+ Currently implemented methods include:
210
+
211
+ - Euler-Maruyama
212
+ - Milstein
213
+
214
+ These solvers support vectorised simulations and can be applied to
215
+ multidimensional stochastic systems.
216
+
217
+ For example:
218
+
219
+ ```python
220
+ from pystochastic.sde import EulerMaruyama
221
+
222
+ solver = EulerMaruyama(
223
+ drift=drift,
224
+ diffusion=diffusion,
225
+ x_0=x_0,
226
+ t_0=0,
227
+ t_n=1,
228
+ n_steps=1000,
229
+ )
230
+
231
+ solution = solver.solve()
232
+ ```
233
+
234
+ ---
235
+
236
+ # 🎯 Monte Carlo
237
+
238
+ The `MonteCarlo` class provides statistical tools for analysing
239
+ collections of simulated samples.
240
+
241
+ For example:
242
+
243
+ ```python
244
+ from pystochastic.montecarlo import MonteCarlo
245
+
246
+ mc = MonteCarlo(samples)
247
+
248
+ estimate = mc.estimate()
249
+ variance = mc.variance()
250
+ standard_error = mc.standard_error()
251
+ ```
252
+
253
+ Confidence intervals can also be computed:
254
+
255
+ ```python
256
+ lower, upper = mc.confidence_interval(
257
+ confidence=0.95,
258
+ type="student",
259
+ )
260
+ ```
261
+
262
+ PyStochastic also provides tools for statistical visualisation,
263
+ including histograms, empirical CDFs and confidence curves.
264
+
265
+ ```python
266
+ mc.histogram()
267
+
268
+ mc.ecdf()
269
+
270
+ mc.confidence_curve()
271
+ ```
272
+
273
+ ---
274
+
275
+ # 📊 Vectorisation
276
+
277
+ A major focus of PyStochastic is efficient simulation.
278
+
279
+ Whenever possible, simulations are vectorised using NumPy rather than
280
+ performing independent Python-level loops.
281
+
282
+ This is particularly useful when a large number of Monte Carlo
283
+ simulations is required.
284
+
285
+ ---
286
+
287
+ # 🧪 Testing
288
+
289
+ PyStochastic uses `pytest` for its test suite.
290
+
291
+ Run all tests with:
292
+
293
+ ```bash
294
+ pytest
295
+ ```
296
+
297
+ The project currently contains tests covering:
298
+
299
+ - Probability distributions
300
+ - Discrete distributions
301
+ - Random number generators
302
+ - Stochastic processes
303
+ - SDE solvers
304
+ - Monte Carlo methods
305
+ - Public APIs
306
+
307
+ The test suite also includes mathematical consistency and statistical
308
+ tests.
309
+
310
+ ---
311
+
312
+ # ⚡ Benchmarks
313
+
314
+ Performance benchmarks are included to compare different simulation
315
+ approaches and evaluate the benefit of vectorisation.
316
+
317
+ For example, vectorised simulations can provide substantial speedups
318
+ compared with sequential matrix-based implementations for large
319
+ numbers of simulations.
320
+
321
+ ---
322
+
323
+ # 📚 Project structure
324
+
325
+ ```text
326
+ pystochastic/
327
+ ├── dist/
328
+ │ ├── dist.py
329
+ │ └── ...
330
+
331
+ ├── montecarlo/
332
+ │ ├── montecarlo.py
333
+ │ └── ...
334
+
335
+ ├── processes/
336
+ │ ├── brownian.py
337
+ │ ├── poisson.py
338
+ │ ├── GeometricBrownianMotion.py
339
+ │ ├── OrnsteinUhlenbeck.py
340
+ │ ├── vasicek.py
341
+ │ └── CIR.py
342
+
343
+ ├── pyrandom/
344
+ │ ├── crandom.py
345
+ │ ├── drandom.py
346
+ │ └── setseed.py
347
+
348
+ └── sde/
349
+ ├── eulermaruyama.py
350
+ └── milstein.py
351
+ ```
352
+
353
+ ---
354
+
355
+ # 🛠️ Development
356
+
357
+ Clone the repository and install the project in editable mode:
358
+
359
+ ```bash
360
+ git clone https://github.com/BastienVelcin/PyStochastic.git
361
+ cd PyStochastic
362
+
363
+ pip install -e .
364
+ ```
365
+
366
+ Install the development dependencies and run the tests:
367
+
368
+ ```bash
369
+ pytest
370
+ ```
371
+
372
+ ---
373
+
374
+ # 🗺️ Roadmap
375
+
376
+ Possible future developments include:
377
+
378
+ - Additional probability distributions
379
+ - Additional stochastic processes
380
+ - Additional SDE numerical schemes
381
+ - Improved documentation
382
+ - Additional performance optimisations
383
+ - More statistical analysis tools
384
+ - Expanded benchmarking
385
+ - Improved visualisation capabilities
386
+
387
+ ---
388
+
389
+ # 🤝 Contributing
390
+
391
+ Contributions, suggestions and bug reports are welcome.
392
+
393
+ If you find a bug or have an idea for a new feature, please open an
394
+ issue on GitHub.
395
+
396
+ Pull requests are also welcome.
397
+
398
+ ---
399
+
400
+ # 📄 License
401
+
402
+ PyStochastic is released under the MIT License.
403
+
404
+ See the `LICENSE` file for more information.