Generate synthetic time series data.
Project description
Overview | |
---|---|
Open Source | |
Code | |
CI/CD | |
Downloads |
Table of Contents
About The Project
Introduction
Synthetica
is a versatile and robust tool for generating synthetic time series data. Whether you are engaged in financial modeling, IoT data simulation, or any project requiring realistic time series data to create correlated or uncorrelated signals, Synthetica
provides high-quality, customizable generated datasets. Leveraging advanced statistical techniques and machine learning algorithms, Synthetica
produces synthetic data that closely replicates the characteristics and patterns of real-world data.
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:
GeometricBrownianMotion
AutoRegressive
NARMA
Heston
CIR
LevyStable
MeanReverting
Merton
Poisson
Seasonal
However, the SyntheticaAdvenced
version elevates the capabilities further, integrating more sophisticated deep learning data-driven algorithms, such as TimeGAN
.
Built With
numpy = "^1.26.4"
pandas = "^2.2.2"
scipy = "^1.13.1"
Installation
$ pip install python-synthetica
Getting Started
Once you have cloned the repository, you can start using Synthetica
to generate synthetic time series data. Here are some initial steps to help you kickstart your exploration:
>>> import synthetica as sth
In this example, we are using the following parameters for illustration purposes:
length=252
: The length of the time seriesnum_paths=5
: The number of paths to generateseed=123
: Reseed thenumpy
singletonRandomState
instance for reproduction
Initialize the model: Using the GeometricBrownianMotion
(GBM) model: This approach initializes the model with a specified path length, number of paths, and a fixed random seed:
>>> model = sth.GeometricBrownianMotion(length=252, num_paths=5, seed=123)
Generate random signals: The transform method then generates the random signals accordingly:
>>> model.transform() # Generate random signals
Generate correlated paths: This process ensures that the resulting features are highly positively correlated, leveraging the Cholesky decomposition method to achieve the desired matrix
correlation structure:
>>> model.transform(matrix) # Produces highly positively correlated features
Notes
Cholesky Decomposition
The Cholesky transformation (or Cholesky decomposition) is a mathematical technique used to decompose a positive definite matrix into the product of a lower triangular matrix and its transpose. This is particularly useful in various fields such as numerical analysis, optimization, and financial modeling.
Mathematical Definition
Given a positive definite matrix $(A)$, the Cholesky decomposition is a factorization such that: $[ A = L L^T ]$ where:
- $(A)$ is a positive definite matrix.
- $(L)$ is a lower triangular matrix.
- $(L^T)$ is the transpose of $(L)$.
Applications
- Numerical Stability: The Cholesky decomposition is more numerically stable than other decomposition methods for positive definite matrices.
- Solving Linear Systems: It is used to solve linear systems of equations efficiently.
- Simulating Correlated Random Variables: In finance and statistics, it is used to generate correlated random variables from uncorrelated ones.
Implementation
In the context of synthetic data generation, the Cholesky transformation can be used to apply a correlation structure to a set of uncorrelated random variables.
Example Implementation in Python
Here's a simple example of how to implement and use the Cholesky transformation in Python:
import numpy as np
# Generate a positive definite matrix (covariance matrix)
def generate_positive_definite_matrix(size):
A = np.random.rand(size, size)
return np.dot(A, A.T) + size * np.eye(size)
# Apply Cholesky decomposition
def cholesky_transform(data, cov_matrix):
# Perform Cholesky decomposition
L = np.linalg.cholesky(cov_matrix)
# Transform the data
transformed_data = np.dot(data, L.T)
return transformed_data
# Example usage
np.random.seed(42)
size = 5 # Size of the covariance matrix
cov_matrix = generate_positive_definite_matrix(size)
# Generate synthetic data (uncorrelated random variables)
data = np.random.randn(100, size)
# Apply Cholesky transformation to impose the correlation structure
transformed_data = cholesky_transform(data, cov_matrix)
print("Original Data:\n", data[:5])
print("Transformed Data:\n", transformed_data[:5])
Explanation
-
generate_positive_definite_matrix:
- Generates a random positive definite matrix. This can be a covariance matrix in practical scenarios.
-
cholesky_transform:
- Performs Cholesky decomposition on the covariance matrix to obtain the lower triangular matrix (L).
- Transforms the original uncorrelated data by multiplying it with (L^T) to introduce the desired correlation structure.
-
Example Usage:
- Generates synthetic uncorrelated data.
- Applies the Cholesky transformation to this data using the generated covariance matrix.
- The transformed data now exhibits the correlation structure defined by the covariance matrix.
In the Context of the LevyStable
Class
The cholesky_transform
method in the LevyStable
class would be used to apply a correlation structure to the generated synthetic data. This would allow for the generation of more realistic synthetic data that incorporates correlations between different paths or time series.
Here is how you could integrate and test the cholesky_transform
method in the LevyStable
class:
Positive Definiteness
What positive definite means in a covariance matrix
A covariance matrix is considered positive definite if it satisfies the following key properties:
- It is symmetric, meaning the matrix is equal to its transpose.
- 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$.
- All of its eigenvalues are strictly positive.
Positive definiteness in a covariance matrix has important implications:
- It ensures the matrix is invertible, which is crucial for many statistical techniques.
- It guarantees that the matrix represents a valid probability distribution.
- It allows for unique solutions in optimization problems and ensures the stability of certain algorithms.
- It indicates that no linear combination of the variables has zero variance, meaning all variables contribute meaningful information.
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.
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.
Implementation
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.
Other Sources
Contributing
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
License
Distributed under the BSD-3 License. See LICENSE.txt
for more information.
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
Built Distribution
File details
Details for the file python_synthetica-0.1.4.tar.gz
.
File metadata
- Download URL: python_synthetica-0.1.4.tar.gz
- Upload date:
- Size: 20.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.11.6 Darwin/21.6.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 424b41856155076027c81c4e6e9ac4959dd22dc051733bd210892c9e98992a5e |
|
MD5 | 6d8ea2dab3215ee5456382d05905475c |
|
BLAKE2b-256 | deac36fa46feaa292dd8f623059ef13e0697ba5c999fc60231d1ac9fcedfc225 |
File details
Details for the file python_synthetica-0.1.4-py3-none-any.whl
.
File metadata
- Download URL: python_synthetica-0.1.4-py3-none-any.whl
- Upload date:
- Size: 18.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.11.6 Darwin/21.6.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a09d49ee61ac5464a4dea38a91b5ec8c99df6113cd4df1b213878f5b88f1b828 |
|
MD5 | 73c81e5880bad8b8f18f61bef0073269 |
|
BLAKE2b-256 | 435cd75e26ce88ba7c6c6af9009fd220d1297c6bf394744a4c1e5be8655618f7 |