python-synthetica 0.1.2__tar.gz → 0.1.3__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: python-synthetica
3
- Version: 0.1.2
3
+ Version: 0.1.3
4
4
  Summary: Generate synthetic time series data.
5
5
  Home-page: https://github.com/ActurialCapital/synthetica
6
6
  License: BSD 3-Clause License
@@ -13,7 +13,6 @@ Classifier: Programming Language :: Python :: 3.12
13
13
  Requires-Dist: numpy (>=1.26.4,<2.0.0)
14
14
  Requires-Dist: pandas (>=2.2.2,<3.0.0)
15
15
  Requires-Dist: scipy (>=1.13.1,<2.0.0)
16
- Requires-Dist: statsmodels (>=0.14.2,<0.15.0)
17
16
  Project-URL: Repository, https://github.com/ActurialCapital/synthetica
18
17
  Description-Content-Type: text/markdown
19
18
 
@@ -62,12 +61,12 @@ Description-Content-Type: text/markdown
62
61
  The project latest version incorporates a wide array of models, offering an extensive toolkit for generating synthetic time series data. This version includes features like:
63
62
 
64
63
  * `GeometricBrownianMotion`
65
- * `AR` (Auto Regressive)
66
- * `NARMA` (Non-Linear Auto Regressive Moving Average)
64
+ * `AutoRegressive`
65
+ * `NARMA`
67
66
  * `Heston`
68
- * `CIR` (Cox–Ingersoll–Ross)
67
+ * `CIR`
69
68
  * `LevyStable`
70
- * `MeanReverting` (Ornstein–Uhlenbeck)
69
+ * `MeanReverting`
71
70
  * `Merton`
72
71
  * `Poisson`
73
72
  * `Seasonal`
@@ -128,13 +127,42 @@ In this example, we are using the following parameters for illustration purposes
128
127
  >>> model.transform(matrix) # Produces highly positively correlated features
129
128
  ```
130
129
 
131
-
132
-
133
130
  <p align="center"><img src="https://github.com/ActurialCapital/synthetica/blob/main/docs/static/gbm_corr_transform.png" alt="chart-2" width="75%" height="75%"></p>
134
131
 
135
132
 
136
133
  <p align="right">(<a href="#readme-top">back to top</a>)</p>
137
134
 
135
+ ## Positive Definiteness
136
+
137
+ ### What positive definite means in a covariance matrix
138
+
139
+ A covariance matrix is considered positive definite if it satisfies the following key properties:
140
+
141
+ 1. It is symmetric, meaning the matrix is equal to its transpose.
142
+ 2. For any non-zero vector $x$, $x^T * C * x > 0$, where $C$ is the covariance matrix and $x^T$ is the transpose of $x$.
143
+ 3. All of its eigenvalues are strictly positive.
144
+
145
+ Positive definiteness in a covariance matrix has important implications:
146
+
147
+ 1. It ensures the matrix is invertible, which is crucial for many [statistical techniques](https://stats.stackexchange.com/questions/52976/is-a-sample-covariance-matrix-always-symmetric-and-positive-definite).
148
+ 2. It guarantees that the matrix represents a [valid probability distribution](https://statproofbook.github.io/P/covmat-psd.html).
149
+ 3. It allows for unique solutions in [optimization problems](https://gowrishankar.info/blog/why-covariance-matrix-should-be-positive-semi-definite-tests-using-breast-cancer-dataset/) and ensures the stability of certain algorithms.
150
+ 4. It indicates that no linear combination of the variables has zero variance, meaning all variables contribute [meaningful information](https://math.stackexchange.com/questions/114072/what-is-the-proof-that-covariance-matrices-are-always-semi-definite).
151
+
152
+ A covariance matrix that is positive semi-definite (allowing for eigenvalues to be non-negative rather than strictly positive) is still valid, but may indicate linear dependencies among variables.
153
+
154
+ In practice, sample covariance matrices are often positive definite if the number of observations exceeds the number of variables and there are no perfect linear relationships among the variables.
155
+
156
+ ### Implementation
157
+
158
+ `synthetica` automatically finds the nearest positive-definite matrix to input using `nearest_positive_definite` python function. it is directly sourced from [Computing a nearest symmetric positive semidefinite matrix](https://doi.org/10.1016/0024-3795(88)90223-6).
159
+
160
+ ### Other Sources
161
+
162
+ * [Matlab code](https://www.mathworks.com/matlabcentral/fileexchange/42885-nearestspd)
163
+ * [Stackoverflow](https://stackoverflow.com/.../python-convert-matrix-to-positive-semi-definite)
164
+ * [Gist](https://gist.github.com/fasiha/fdb5cec2054e6f1c6ae35476045a0bbd)
165
+
138
166
  <!-- CONTRIBUTING -->
139
167
  ## Contributing
140
168
 
@@ -43,12 +43,12 @@
43
43
  The project latest version incorporates a wide array of models, offering an extensive toolkit for generating synthetic time series data. This version includes features like:
44
44
 
45
45
  * `GeometricBrownianMotion`
46
- * `AR` (Auto Regressive)
47
- * `NARMA` (Non-Linear Auto Regressive Moving Average)
46
+ * `AutoRegressive`
47
+ * `NARMA`
48
48
  * `Heston`
49
- * `CIR` (Cox–Ingersoll–Ross)
49
+ * `CIR`
50
50
  * `LevyStable`
51
- * `MeanReverting` (Ornstein–Uhlenbeck)
51
+ * `MeanReverting`
52
52
  * `Merton`
53
53
  * `Poisson`
54
54
  * `Seasonal`
@@ -109,13 +109,42 @@ In this example, we are using the following parameters for illustration purposes
109
109
  >>> model.transform(matrix) # Produces highly positively correlated features
110
110
  ```
111
111
 
112
-
113
-
114
112
  <p align="center"><img src="https://github.com/ActurialCapital/synthetica/blob/main/docs/static/gbm_corr_transform.png" alt="chart-2" width="75%" height="75%"></p>
115
113
 
116
114
 
117
115
  <p align="right">(<a href="#readme-top">back to top</a>)</p>
118
116
 
117
+ ## Positive Definiteness
118
+
119
+ ### What positive definite means in a covariance matrix
120
+
121
+ A covariance matrix is considered positive definite if it satisfies the following key properties:
122
+
123
+ 1. It is symmetric, meaning the matrix is equal to its transpose.
124
+ 2. For any non-zero vector $x$, $x^T * C * x > 0$, where $C$ is the covariance matrix and $x^T$ is the transpose of $x$.
125
+ 3. All of its eigenvalues are strictly positive.
126
+
127
+ Positive definiteness in a covariance matrix has important implications:
128
+
129
+ 1. It ensures the matrix is invertible, which is crucial for many [statistical techniques](https://stats.stackexchange.com/questions/52976/is-a-sample-covariance-matrix-always-symmetric-and-positive-definite).
130
+ 2. It guarantees that the matrix represents a [valid probability distribution](https://statproofbook.github.io/P/covmat-psd.html).
131
+ 3. It allows for unique solutions in [optimization problems](https://gowrishankar.info/blog/why-covariance-matrix-should-be-positive-semi-definite-tests-using-breast-cancer-dataset/) and ensures the stability of certain algorithms.
132
+ 4. It indicates that no linear combination of the variables has zero variance, meaning all variables contribute [meaningful information](https://math.stackexchange.com/questions/114072/what-is-the-proof-that-covariance-matrices-are-always-semi-definite).
133
+
134
+ A covariance matrix that is positive semi-definite (allowing for eigenvalues to be non-negative rather than strictly positive) is still valid, but may indicate linear dependencies among variables.
135
+
136
+ In practice, sample covariance matrices are often positive definite if the number of observations exceeds the number of variables and there are no perfect linear relationships among the variables.
137
+
138
+ ### Implementation
139
+
140
+ `synthetica` automatically finds the nearest positive-definite matrix to input using `nearest_positive_definite` python function. it is directly sourced from [Computing a nearest symmetric positive semidefinite matrix](https://doi.org/10.1016/0024-3795(88)90223-6).
141
+
142
+ ### Other Sources
143
+
144
+ * [Matlab code](https://www.mathworks.com/matlabcentral/fileexchange/42885-nearestspd)
145
+ * [Stackoverflow](https://stackoverflow.com/.../python-convert-matrix-to-positive-semi-definite)
146
+ * [Gist](https://gist.github.com/fasiha/fdb5cec2054e6f1c6ae35476045a0bbd)
147
+
119
148
  <!-- CONTRIBUTING -->
120
149
  ## Contributing
121
150
 
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "python-synthetica"
3
- version = "0.1.2"
3
+ version = "0.1.3"
4
4
  description = "Generate synthetic time series data."
5
5
  authors = ["ActurialCapital"]
6
6
  license = "BSD 3-Clause License"
@@ -13,7 +13,6 @@ python = "^3.11"
13
13
  numpy = "^1.26.4"
14
14
  pandas = "^2.2.2"
15
15
  scipy = "^1.13.1"
16
- statsmodels = "^0.14.2"
17
16
 
18
17
  [build-system]
19
18
  requires = ["poetry-core"]
@@ -227,7 +227,8 @@ class BaseSynthetic(ABC):
227
227
 
228
228
  return self.to_pandas(np.array(extracted_paths).T)
229
229
 
230
- def cholesky_transform(self, rvs: np.array, matrix: np.array) -> np.ndarray:
230
+ @staticmethod
231
+ def cholesky_transform(rvs: np.array, matrix: np.array) -> np.ndarray:
231
232
  """
232
233
  Perform Cholesky transformation on random variables.
233
234
 
@@ -872,7 +872,7 @@ class MeanReverting(BaseSynthetic):
872
872
  return self.to_pandas(paths[1:,])
873
873
 
874
874
 
875
- class AR(BaseSynthetic):
875
+ class AutoRegressive(BaseSynthetic):
876
876
  """
877
877
  A class for generating synthetic autoregressive (AR) model.
878
878