Time Series
synthetic_data_generators.time_series
🔗
Summary
The time_series
module provides a class for generating synthetic time series data. It includes methods for creating time series with various characteristics, such as seasonality, trends, and noise.
TimeSeriesGenerator
🔗
Summary
A class for generating synthetic time series data.
Details
- This class provides methods to create synthetic time series data with various characteristics, including seasonality, trends, and noise.
- The generated data can be used for testing and validation purposes in time series analysis.
- The class includes methods to generate holiday indices, fixed error indices, semi-Markov indices, and sine indices.
- It also provides a method to generate polynomial trends and ARMA components.
- The generated time series data can be customized with different parameters, such as start date, number of periods, and noise scale.
Source code in src/synthetic_data_generators/time_series.py
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 |
|
__init__
🔗
__init__() -> None
Summary
Initialize the TimeSeriesGenerator class.
Details
- This class is designed to generate synthetic time series data for testing and validation purposes.
- It provides methods to create time series data with various characteristics, including seasonality, trends, and noise.
- The generated data can be used for testing algorithms, models, and other applications in time series analysis.
- The class includes methods for generating holiday indices, fixed error indices, semi-Markov indices, and sine indices.
- It also provides a method for generating polynomial trends and ARMA components.
- The generated time series data can be customized with different parameters, such as start date, number of periods, and noise scale.
- The class is designed to be flexible and extensible, allowing users to easily modify the generation process to suit their needs.
- It is built using Python's type hinting and type checking features to ensure that the inputs and outputs are of the expected types.
- This helps to catch potential errors early in the development process and improve code readability.
Source code in src/synthetic_data_generators/time_series.py
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
|
create_time_series
🔗
create_time_series(
start_date: datetime = datetime(2019, 1, 1),
n_periods: int = 1096,
interpolation_nodes: (
tuple[int_list_tuple, ...] | list[int_list_tuple]
) = ([0, 98], [300, 92], [700, 190], [1096, 213]),
level_breaks: (
tuple[int_list_tuple, ...]
| list[int_list_tuple]
| None
) = ([250, 100], [650, -50]),
AR: list[float] | None = None,
MA: list[float] | None = None,
randomwalk_scale: float = 2,
exogenous: (
list[dict[Literal["coeff", "ts"], list[float]]]
| None
) = None,
season_conf: dict_str_any | None = {"style": "holiday"},
season_eff: float = 0.15,
manual_outliers: (
tuple[int_list_tuple, ...]
| list[int_list_tuple]
| None
) = None,
noise_scale: float = 10,
seed: int | None = None,
) -> pd.DataFrame
Summary
Generate a synthetic time series with specified characteristics.
Details
- The function generates a time series based on the specified parameters, including start date, number of periods, interpolation nodes, level breaks, ARMA coefficients, random walk scale, exogenous variables, seasonality configuration, manual outliers, and noise scale.
- The generated time series is returned as a pandas DataFrame with two columns: "Date" and "Value".
- The "Date" column contains the dates of the time series, and the "Value" column contains the corresponding values.
- The function also includes options for generating seasonality indices, fixed error indices, semi-Markov indices, and sine indices.
- The generated time series can be customized with different parameters, such as start date, number of periods, and noise scale.
Important
This function is designed to generate synthetic time series data for testing and validation purposes. It is not intended to be used for production or real-world applications.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
start_date
|
datetime
|
The starting date for the time series. |
datetime(2019, 1, 1)
|
n_periods
|
int
|
The number of periods for the time series. |
1096
|
interpolation_nodes
|
tuple[int_list_tuple, ...] | list[int_list_tuple]
|
A collection of interpolation nodes, where each node is a tuple containing the x-coordinate and y-coordinate. |
([0, 98], [300, 92], [700, 190], [1096, 213])
|
level_breaks
|
tuple[int_list_tuple, ...] | list[int_list_tuple] | None
|
A collection of level breaks, where each break is a tuple containing the index and the value to add. |
([250, 100], [650, -50])
|
AR
|
list[float] | None
|
The autoregressive coefficients for the ARMA model. |
None
|
MA
|
list[float] | None
|
The moving average coefficients for the ARMA model. |
None
|
randomwalk_scale
|
float
|
The scale of the random walk component. |
2
|
exogenous
|
list[dict[Literal['coeff', 'ts'], list[float]]] | None
|
A list of exogenous variables to include in the ARMA model. |
None
|
season_conf
|
dict_str_any | None
|
A dictionary containing the configuration for seasonality. |
{'style': 'holiday'}
|
season_eff
|
float
|
The effectiveness of the seasonality component. |
0.15
|
manual_outliers
|
tuple[int_list_tuple, ...] | list[int_list_tuple] | None
|
A collection of manual outliers, where each outlier is a tuple containing the index and the value to set. |
None
|
noise_scale
|
float
|
The scale of the noise component. |
10
|
seed
|
int | None
|
The random seed for reproducibility. |
None
|
Raises:
Type | Description |
---|---|
TypeCheckError
|
If any of the inputs parsed to the parameters of this function are not the correct type. Uses the |
AssertionError
|
If |
TypeError
|
If the first element of |
Returns:
Type | Description |
---|---|
DataFrame
|
A pandas DataFrame containing the generated time series data. The DataFrame has two columns: "Date" and "Value". The "Date" column contains the dates of the time series, and the "Value" column contains the corresponding values. |
Source code in src/synthetic_data_generators/time_series.py
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 |
|
generate_holiday_index
🔗
generate_holiday_index(
dates: datetime_list_tuple,
season_dates: Collection_of_Collection_of_datetime_or_int,
) -> NDArray[np.int_]
Summary
Generate a holiday index for the given dates based on the provided holiday dates.
Details
- A holiday index is a manual selection for date in
dates
to determine whether it is a holiday or not. - Basically, it is a manual index of dates in a univariate time series data set which are actual holidays.
- The return array is generated by checking if each date in
dates
is present in the list of holiday dates generated fromseason_dates
.
Important
This function is designed to work with a .generate_season_index()
when the style="holiday"
.
It is not intended to be called directly.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dates
|
datetime_list_tuple
|
List of datetime objects representing the dates to check. |
required |
season_dates
|
Collection_of_Collection_of_datetime_or_int
|
Collection of collections containing holiday dates and their respective periods.
|
required |
Raises:
Type | Description |
---|---|
TypeCheckError
|
If any of the inputs parsed to the parameters of this function are not the correct type. Uses the |
AssertionError
|
If |
TypeError
|
If the first element of |
Returns:
Type | Description |
---|---|
NDArray[int_]
|
An array of the same length as |
Source code in src/synthetic_data_generators/time_series.py
343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 |
|
generate_fixed_error_index
🔗
generate_fixed_error_index(
dates: datetime_list_tuple,
period_length: int = 7,
period_sd: float = 0.5,
start_index: int = 4,
seed: int | None = None,
) -> NDArray[np.float64]
Summary
Generate a fixed error seasonality index for the given dates.
Details
- A holiday index is a manual selection for date in
dates
to determine whether it is a holiday or not. - A fixed error seasonality index is a non-uniform distribution of dates in a univariate time series data set.
- Basically, it is indicating every
period_length
length of days, occurring everyperiod_sd
number of days, starting fromstart_index
. - The return array is a boolean
1
or0
of lengthn_periods
. It will have a seasonality ofperiod_length
and a disturbance standard deviation ofperiod_sd
. The result can be used as a non-uniform distribution of weekdays in a histogram (if for eg. frequency is weekly).
Important
This function is designed to work with a .generate_season_index()
when the style="fixed+error"
.
It is not intended to be called directly.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dates
|
datetime_list_tuple
|
List of datetime objects representing the dates to check. |
required |
period_length
|
int
|
The length of the period for seasonality. |
7
|
period_sd
|
float
|
The standard deviation of the disturbance. |
0.5
|
start_index
|
int
|
The starting index for the seasonality. |
4
|
Raises:
Type | Description |
---|---|
TypeCheckError
|
If any of the inputs parsed to the parameters of this function are not the correct type. Uses the |
Returns:
Type | Description |
---|---|
NDArray[int_]
|
An array of the same length as |
Source code in src/synthetic_data_generators/time_series.py
408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 |
|
generate_semi_markov_index
🔗
generate_semi_markov_index(
dates: datetime_list_tuple,
period_length: int = 7,
period_sd: float = 0.5,
start_index: int = 4,
seed: int | None = None,
) -> NDArray[np.int_]
Summary
Generate a semi-Markov seasonality index for the given dates.
Details
- A semi-Markov seasonality index is a uniform distribution of dates in a univariate time series data set.
- Basically, it is indicating a
period_length
length of days, occurring randomly roughly everperiod_sd
number of days, starting fromstart_index
. - The return array is a boolean
1
or0
of lengthn_periods
. It will have a seasonality ofperiod_length
and a disturbance standard deviation ofperiod_sd
. The result can be used as a uniform distribution of weekdays in a histogram (if for eg. frequency is weekly).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dates
|
datetime_list_tuple
|
List of datetime objects representing the dates to check. |
required |
period_length
|
int
|
The length of the period for seasonality. |
7
|
period_sd
|
float
|
The standard deviation of the disturbance. |
0.5
|
start_index
|
int
|
The starting index for the seasonality. |
4
|
Raises:
Type | Description |
---|---|
TypeCheckError
|
If any of the inputs parsed to the parameters of this function are not the correct type. Uses the |
Returns:
Type | Description |
---|---|
NDArray[int_]
|
An array of the same length as |
Source code in src/synthetic_data_generators/time_series.py
476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 |
|
generate_sin_index
🔗
generate_sin_index(
dates: datetime_list_tuple,
period_length: int = 7,
start_index: int = 4,
) -> NDArray[np.float64]
Summary
Generate a sine seasonality index for the given dates.
Details
- A sine seasonality index is a periodic function that oscillates between
0
and1
. - It is used to model seasonal patterns in time series data.
- The return array is a sine wave of length
n_periods
, with a period ofperiod_length
and a phase shift ofstart_index
. - The result can be used to represent seasonal patterns in time series data, such as daily or weekly cycles.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dates
|
datetime_list_tuple
|
List of datetime objects representing the dates to check. |
required |
period_length
|
int
|
The length of the period for seasonality. |
7
|
start_index
|
int
|
The starting index for the seasonality. Designed to account for seasonal patterns that start at a different point in time. |
4
|
Raises:
Type | Description |
---|---|
TypeCheckError
|
If any of the inputs parsed to the parameters of this function are not the correct type. Uses the |
Returns:
Type | Description |
---|---|
NDArray[float64]
|
An array of the same length as |
Source code in src/synthetic_data_generators/time_series.py
540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 |
|
generate_sin_covar_index
🔗
generate_sin_covar_index(
dates: datetime_list_tuple,
period_length: int = 7,
start_index: int = 4,
) -> NDArray[np.float64]
Summary
Generate a sine seasonality index with covariance for the given dates.
Details
- A sine seasonality index with covariance is a periodic function that oscillates between
0
and1
. - It is used to model seasonal patterns in time series data, taking into account the covariance structure of the data.
- The return array is a sine wave of length
n_periods
, with a period ofperiod_length
and a phase shift ofstart_index
. - The result can be used to represent seasonal patterns in time series data, such as daily or weekly cycles.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dates
|
datetime_list_tuple
|
List of datetime objects representing the dates to check. |
required |
period_length
|
int
|
The length of the period for seasonality. |
7
|
start_index
|
int
|
The starting index for the seasonality. Designed to account for seasonal patterns that start at a different point in time. |
4
|
Raises:
Type | Description |
---|---|
TypeCheckError
|
If any of the inputs parsed to the parameters of this function are not the correct type. Uses the |
Returns:
Type | Description |
---|---|
NDArray[float64]
|
An array of the same length as |
Source code in src/synthetic_data_generators/time_series.py
579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 |
|
generate_season_index
🔗
generate_season_index(
dates: datetime_list_tuple,
style: Literal[
"fixed+error",
"semi-markov",
"holiday",
"sin",
"sin_covar",
],
season_dates: (
Collection_of_Collection_of_datetime_or_int | None
) = None,
period_length: int | None = None,
period_sd: float | None = None,
start_index: int | None = None,
seed: int | None = None,
) -> NDArray[np.float64]
Summary
Generate a seasonality index for the given dates based on the specified style.
Details
- A seasonality index is a manual selection for date in
dates
to determine whether it is a holiday or not. - Basically, it is a manual index of dates in a univariate time series data set which are actual holidays.
- The return array is generated by checking if each date in
dates
is present in the list of holiday dates generated fromseason_dates
. - The return array is a boolean
1
or0
of lengthn_periods
. It will have a seasonality ofperiod_length
and a disturbance standard deviation ofperiod_sd
. The result can be used as a non-uniform distribution of weekdays in a histogram (if for eg. frequency is weekly).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dates
|
datetime_list_tuple
|
List of datetime objects representing the dates to check. |
required |
style
|
Literal
|
The style of the seasonality index to generate. |
required |
season_dates
|
Collection_of_Collection_of_datetime_or_int | None
|
Collection of collections containing holiday dates and their respective periods.
|
None
|
period_length
|
int | None
|
The length of the period for seasonality. |
None
|
period_sd
|
float | None
|
The standard deviation of the disturbance. |
None
|
start_index
|
int | None
|
The starting index for the seasonality. |
None
|
seed
|
int | None
|
Random seed for reproducibility. |
None
|
Raises:
Type | Description |
---|---|
TypeCheckError
|
If any of the inputs parsed to the parameters of this function are not the correct type. Uses the |
AssertionError
|
If |
TypeError
|
If the first element of |
ValueError
|
If |
Returns:
Type | Description |
---|---|
NDArray[float64]
|
An array of the same length as |
Source code in src/synthetic_data_generators/time_series.py
620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 |
|
generate_polynom_trend
🔗
generate_polynom_trend(
interpol_nodes, n_periods: int
) -> NDArray[np.float64]
Summary
Generate a polynomial trend based on the provided interpolation nodes.
Details
- The polynomial trend is generated using the provided interpolation nodes.
- The function supports polynomial trends of order 1 (linear), 2 (quadratic), 3 (cubic), and 4 (quartic).
- The generated trend is an array of the same length as
n_periods
, where each element represents the value of the polynomial trend at that period. - The function uses numpy's linear algebra solver to compute the coefficients of the polynomial based on the provided interpolation nodes.
Important
This function is implemented only up to order 3 (cubic interpolation = four nodes). It is not intended to be used for higher-order polynomial trends.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
interpol_nodes
|
tuple[int_list_tuple, ...] | list[int_list_tuple]
|
A collection of interpolation nodes, where each node is a tuple containing the x-coordinate and y-coordinate. The x-coordinates should be in ascending order. |
required |
n_periods
|
int
|
The number of periods for which to generate the polynomial trend.
This determines the length of the output array.
The generated trend will have the same length as |
required |
Raises:
Type | Description |
---|---|
TypeCheckError
|
If any of the inputs parsed to the parameters of this function are not the correct type. Uses the |
AssertionError
|
If |
TypeError
|
If the first element of |
Returns:
Type | Description |
---|---|
NDArray[float64]
|
An array of the same length as |
Source code in src/synthetic_data_generators/time_series.py
730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 |
|
generate_ARMA
🔗
generate_ARMA(
AR: list[float],
MA: list[float],
randomwalk_scale: float,
n_periods: int,
exogenous: (
list[dict[Literal["coeff", "ts"], list[float]]]
| None
) = None,
seed: int | None = None,
) -> NDArray[np.float64]
Summary
Generate an ARMA (AutoRegressive Moving Average) time series.
Details
- The ARMA model is a combination of autoregressive (AR) and moving average (MA) components.
- The function generates a time series based on the specified AR and MA coefficients, random walk scale, and optional exogenous variables.
- The generated time series is an array of the same length as
n_periods
, where each element represents the value of the ARMA time series at that period. - The function uses numpy's random number generator to generate the noise component of the ARMA model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
AR
|
list[float]
|
List of autoregressive coefficients.
The length of the list determines the order of the AR component.
All values must be between |
required |
MA
|
list[float]
|
List of moving average coefficients.
The length of the list determines the order of the MA component.
All values must be between |
required |
randomwalk_scale
|
float
|
Scale parameter for the random walk component. This controls the standard deviation of the noise added to the time series. |
required |
n_periods
|
int
|
The number of periods for which to generate the ARMA time series. This determines the length of the output array. |
required |
exogenous
|
list[dict[Literal['coeff', 'ts'], list[float]]] | None
|
Optional list of exogenous variables, where each variable is represented as a dictionary with keys "coeff" and "ts". "coeff" is a list of coefficients for the exogenous variable, and "ts" is a list of values for that variable. |
None
|
seed
|
int | None
|
Random seed for reproducibility. |
None
|
Raises:
Type | Description |
---|---|
TypeCheckError
|
If any of the inputs parsed to the parameters of this function are not the correct type. Uses the |
Returns:
Type | Description |
---|---|
NDArray[float64]
|
An array of the same length as |
Details about how the AR
and MA
Parameters work
This generate_ARMA()
method creates time series data using ARMA (AutoRegressive Moving Average) models.
The AR
parameter is used to model the long-term trends in the data, while the MA
parameter is used to model the short-term fluctuations.
The AR
(AutoRegressive) Parameter:
- The
AR
parameter is a list of coefficients that determine how much past values influence the current value. - Each coefficient represents the weight given to a specific lag (previous time point).
- For example, with
AR=[0.6, 0.3]
:- The value at time
t
is influenced by: - 60% of the value at time
t-1
(0.6 x previous value) - 30% of the value at time
t-2
(0.3 x value from two periods ago)
- The value at time
- This creates persistence in the data where values tend to follow past trends. Higher AR values (closer to
1
) create stronger trends and more correlation with past values. - Higher AR values (closer to
1
) create stronger trends and more correlation with past values. - When
AR=[0]
, the time series is purely random, as it does not depend on past values. Likewise, whenAR=[1]
, the time series is the same as a random walk, as it only depends on the previous value. - When multiple values are provided, the first value is the most recent, and the last value is the oldest. For example,
AR=[0.5, 0.3]
means that the most recent value has a weight of0.5
, and the second most recent value has a weight of0.3
. Realistically, the second most recent value will have less influence than the most recent value, and will therefore have a lower value (closer to0
), but it can still affect the current value.
The MA
(Moving Average) Parameter:
- The MA parameter is a list of coefficients that determine how much past random shocks (errors) influence the current value.
- For example, with
MA=[0.2, 0.1]
:- The value at time
t
is influenced by: - 20% of the random shock at time
t-1
- 10% of the random shock at time
t-2
- The value at time
- This creates short-term corrections or adjustments based on recent random fluctuations.
- Higher MA values (closer to
1
) create stronger corrections and more correlation with past shocks. - When
MA=[0]
, the time series is purely autoregressive, as it will depend on past values and does not depend on past shocks. Likewise, whenMA=[1]
, the time series is purely random and will not depend on previous values. - When multiple values are provided, the first value is the most recent, and the last value is the oldest. For example,
MA=[0.5, 0.3]
means that the most recent value has a weight of0.5
, and the second most recent value has a weight of0.3
. Realistically, the second most recent value will have less influence than the most recent value, and will therefore have a lower value (closer to0
), but it can still affect the current value.
Examples and Effects:
Value | Description |
---|---|
AR=[0.9] |
Creates strong persistence - values strongly follow the previous value, resulting in smooth, trending data |
AR=[0.5,0.3] |
Creates moderate persistence with some oscillation patterns |
MA=[0.8] |
Creates immediate corrections after random shocks |
MA=[0.5,0.3] |
Creates moderate corrections with some oscillation patterns |
AR=[0.7] MA=[0.4] |
Combines trend persistence with short-term corrections |
Source code in src/synthetic_data_generators/time_series.py
831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 |
|