timeserieslab 0.1.0__py3-none-any.whl
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.
main.py
ADDED
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
def getprograms():
|
|
4
|
+
from textwrap import dedent
|
|
5
|
+
|
|
6
|
+
MENU = dedent("""
|
|
7
|
+
import numpy as np
|
|
8
|
+
import pandas as pd
|
|
9
|
+
import matplotlib.pyplot as plt
|
|
10
|
+
import statsmodels.api as sm
|
|
11
|
+
|
|
12
|
+
from statsmodels.tsa.holtwinters import ExponentialSmoothing
|
|
13
|
+
from statsmodels.tsa.stattools import adfuller
|
|
14
|
+
from statsmodels.graphics.tsaplots import plot_acf, plot_pacf
|
|
15
|
+
from statsmodels.tsa.arima.model import ARIMA
|
|
16
|
+
|
|
17
|
+
np.random.seed(42)
|
|
18
|
+
plt.rcParams["figure.figsize"] = (10, 4)
|
|
19
|
+
print("Libraries loaded")
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
Hi Macha what coping and all ?, what man too much cock showing only!!
|
|
25
|
+
ok I will help you do this
|
|
26
|
+
1. Imports and reproducible data
|
|
27
|
+
2. Create a time series and plot it
|
|
28
|
+
3. Duplicate date indices and averaging
|
|
29
|
+
4. Daily to monthly resampling
|
|
30
|
+
5. Linear trend and moving average
|
|
31
|
+
6. ADF test
|
|
32
|
+
7. ACF and PACF
|
|
33
|
+
8. Holt–Winters additive and multiplicative models
|
|
34
|
+
9. ARIMA model and forecast
|
|
35
|
+
10. AICc model comparison (practice pattern)
|
|
36
|
+
11. Squared returns and ARCH/GARCH motivation
|
|
37
|
+
12. CSV practice: load, inspect, and plot
|
|
38
|
+
""")
|
|
39
|
+
|
|
40
|
+
TEMPLATES = {
|
|
41
|
+
"1": dedent("""rng = np.random.default_rng(42)
|
|
42
|
+
dates = pd.date_range("2025-01-01", periods=100, freq="D")
|
|
43
|
+
values = 100 + np.linspace(0, 15, 100) + rng.normal(0, 5, 100)
|
|
44
|
+
daily = pd.Series(values, index=dates, name="Value")
|
|
45
|
+
|
|
46
|
+
print(daily.head())
|
|
47
|
+
daily.plot(title="Illustrative daily time series")
|
|
48
|
+
plt.xlabel("Date")
|
|
49
|
+
plt.ylabel("Value")
|
|
50
|
+
plt.grid(True, alpha=0.3)
|
|
51
|
+
plt.show()"""),
|
|
52
|
+
|
|
53
|
+
"2": dedent("""rng = np.random.default_rng(42)
|
|
54
|
+
dates = pd.date_range("2025-01-01", periods=100, freq="D")
|
|
55
|
+
values = 100 + np.linspace(0, 15, 100) + rng.normal(0, 5, 100)
|
|
56
|
+
daily = pd.Series(values, index=dates, name="Value")
|
|
57
|
+
|
|
58
|
+
print(daily.head())
|
|
59
|
+
daily.plot(title="Illustrative daily time series")
|
|
60
|
+
plt.xlabel("Date")
|
|
61
|
+
plt.ylabel("Value")
|
|
62
|
+
plt.grid(True, alpha=0.3)
|
|
63
|
+
plt.show()
|
|
64
|
+
"""),
|
|
65
|
+
|
|
66
|
+
"3": dedent("""df = pd.DataFrame({
|
|
67
|
+
"Date": ["2025-01-01", "2025-01-02", "2025-01-03",
|
|
68
|
+
"2025-01-02", "2025-01-03", "2025-01-04"],
|
|
69
|
+
"Sales": [120, 150, 180, 170, 160, 200]
|
|
70
|
+
})
|
|
71
|
+
df["Date"] = pd.to_datetime(df["Date"])
|
|
72
|
+
|
|
73
|
+
print("Duplicate date rows:", df["Date"].duplicated().sum())
|
|
74
|
+
consolidated = df.groupby("Date")["Sales"].mean().sort_index()
|
|
75
|
+
print(consolidated)
|
|
76
|
+
"""),
|
|
77
|
+
|
|
78
|
+
"4": dedent("""rng = np.random.default_rng(7)
|
|
79
|
+
dates = pd.date_range("2025-01-01", periods=100, freq="D")
|
|
80
|
+
daily = pd.Series(rng.normal(100, 10, 100), index=dates, name="Value")
|
|
81
|
+
monthly = daily.resample("MS").mean()
|
|
82
|
+
|
|
83
|
+
print("Daily observations:")
|
|
84
|
+
print(daily.head())
|
|
85
|
+
print("\nMonthly means:")
|
|
86
|
+
print(monthly)
|
|
87
|
+
monthly.plot(kind="bar", title="Monthly means from daily observations")
|
|
88
|
+
plt.ylabel("Monthly mean")
|
|
89
|
+
plt.show()
|
|
90
|
+
"""),
|
|
91
|
+
|
|
92
|
+
"5": dedent("""t = np.arange(len(daily))
|
|
93
|
+
# For a simple example, use the first 100 daily observations
|
|
94
|
+
y = daily.to_numpy()
|
|
95
|
+
slope, intercept = np.polyfit(t, y, 1)
|
|
96
|
+
trend = intercept + slope*t
|
|
97
|
+
|
|
98
|
+
plt.plot(daily.index, y, label="Observed")
|
|
99
|
+
plt.plot(daily.index, trend, label="Linear trend")
|
|
100
|
+
plt.legend()
|
|
101
|
+
plt.title(f"Linear trend (slope={slope:.3f})")
|
|
102
|
+
plt.show()
|
|
103
|
+
|
|
104
|
+
# Example rolling mean: 7-observation window
|
|
105
|
+
rolling = daily.rolling(window=7).mean()
|
|
106
|
+
plt.plot(daily.index, daily, alpha=0.5, label="Daily")
|
|
107
|
+
plt.plot(rolling.index, rolling, label="7-day moving average")
|
|
108
|
+
plt.legend()
|
|
109
|
+
plt.title("Rolling mean smooths short-term movement")
|
|
110
|
+
plt.show()
|
|
111
|
+
"""),
|
|
112
|
+
|
|
113
|
+
"6": dedent("""# Use a non-stationary-looking series with trend for demonstration
|
|
114
|
+
rng = np.random.default_rng(42)
|
|
115
|
+
x = np.cumsum(rng.normal(0, 1, 300))
|
|
116
|
+
adf_result = adfuller(x)
|
|
117
|
+
print("ADF statistic:", adf_result[0])
|
|
118
|
+
print("p-value:", adf_result[1])
|
|
119
|
+
print("Used lags:", adf_result[2])
|
|
120
|
+
|
|
121
|
+
if adf_result[1] < 0.05:
|
|
122
|
+
print("At 5%, reject the unit-root null hypothesis.")
|
|
123
|
+
else:
|
|
124
|
+
print("At 5%, do not reject the unit-root null hypothesis.")
|
|
125
|
+
"""),
|
|
126
|
+
"7": dedent("""fig, axes = plt.subplots(2, 1, figsize=(10, 7))
|
|
127
|
+
plot_acf(x, lags=30, ax=axes[0])
|
|
128
|
+
plot_pacf(x, lags=30, ax=axes[1], method="ywm")
|
|
129
|
+
plt.tight_layout()
|
|
130
|
+
plt.show()
|
|
131
|
+
"""),
|
|
132
|
+
"8": dedent("""# Build a positive monthly example with trend and annual seasonality
|
|
133
|
+
rng = np.random.default_rng(10)
|
|
134
|
+
periods = 72
|
|
135
|
+
dates = pd.date_range("2018-01-01", periods=periods, freq="MS")
|
|
136
|
+
seasonal_pattern = np.array([0.75, 0.78, 0.85, 0.92, 1.00, 1.08,
|
|
137
|
+
1.15, 1.12, 1.03, 0.94, 0.84, 0.78])
|
|
138
|
+
trend = np.linspace(100, 220, periods)
|
|
139
|
+
y_monthly = pd.Series(
|
|
140
|
+
trend * np.tile(seasonal_pattern, periods // 12) + rng.normal(0, 4, periods),
|
|
141
|
+
index=dates, name="MonthlyValue"
|
|
142
|
+
)
|
|
143
|
+
y_monthly.plot(title="Illustrative monthly series")
|
|
144
|
+
plt.show()
|
|
145
|
+
|
|
146
|
+
fit_add = ExponentialSmoothing(
|
|
147
|
+
y_monthly, trend="add", seasonal="add", seasonal_periods=12,
|
|
148
|
+
initialization_method="estimated"
|
|
149
|
+
).fit()
|
|
150
|
+
forecast_add = fit_add.forecast(12)
|
|
151
|
+
|
|
152
|
+
fit_mul = ExponentialSmoothing(
|
|
153
|
+
y_monthly, trend="add", seasonal="mul", seasonal_periods=12,
|
|
154
|
+
initialization_method="estimated"
|
|
155
|
+
).fit()
|
|
156
|
+
forecast_mul = fit_mul.forecast(12)
|
|
157
|
+
|
|
158
|
+
plt.plot(y_monthly.index, y_monthly, label="Observed")
|
|
159
|
+
plt.plot(forecast_add.index, forecast_add, marker="o", label="Additive forecast")
|
|
160
|
+
plt.legend()
|
|
161
|
+
plt.title("Holt-Winters additive seasonality")
|
|
162
|
+
plt.show()
|
|
163
|
+
|
|
164
|
+
plt.plot(y_monthly.index, y_monthly, label="Observed")
|
|
165
|
+
plt.plot(fit_mul.fittedvalues.index, fit_mul.fittedvalues, label="Multiplicative fitted")
|
|
166
|
+
plt.legend()
|
|
167
|
+
plt.title("Holt-Winters multiplicative fit")
|
|
168
|
+
plt.show()
|
|
169
|
+
|
|
170
|
+
rmse_mul = np.sqrt(np.mean((y_monthly - fit_mul.fittedvalues)**2))
|
|
171
|
+
print("Multiplicative in-sample RMSE:", rmse_mul)
|
|
172
|
+
print("Next 12 forecasts (multiplicative):")
|
|
173
|
+
print(fit_mul.forecast(12))
|
|
174
|
+
"""),
|
|
175
|
+
"9": dedent("""# Fit a simple ARIMA model to a stationary illustrative series
|
|
176
|
+
rng = np.random.default_rng(123)
|
|
177
|
+
stationary_series = pd.Series(rng.normal(size=200))
|
|
178
|
+
fit_arima = ARIMA(stationary_series, order=(1, 0, 1)).fit()
|
|
179
|
+
print(fit_arima.summary())
|
|
180
|
+
forecast = fit_arima.forecast(steps=5)
|
|
181
|
+
print("Five forecasts:")
|
|
182
|
+
print(forecast)
|
|
183
|
+
"""),
|
|
184
|
+
"10": dedent("""# Illustrative comparison of candidate ARIMA-family fits.
|
|
185
|
+
# Use identical input data and compare models fitted to the same observations.
|
|
186
|
+
candidate_orders = [(1, 0, 0), (2, 0, 0), (1, 0, 1)]
|
|
187
|
+
comparison = []
|
|
188
|
+
for order in candidate_orders:
|
|
189
|
+
fit = ARIMA(stationary_series, order=order).fit()
|
|
190
|
+
n = fit.nobs
|
|
191
|
+
k = len(fit.params)
|
|
192
|
+
aic = fit.aic
|
|
193
|
+
# Small-sample correction; undefined if n <= k + 1
|
|
194
|
+
aicc = aic + (2*k*(k+1))/(n-k-1) if n > k+1 else np.nan
|
|
195
|
+
comparison.append({"order": order, "AIC": aic, "AICc": aicc})
|
|
196
|
+
comparison_df = pd.DataFrame(comparison).sort_values("AICc")
|
|
197
|
+
print(comparison_df)
|
|
198
|
+
"""),
|
|
199
|
+
"11": dedent("""# Illustrative volatility-clustered returns (not a fitted ARCH model)
|
|
200
|
+
rng = np.random.default_rng(99)
|
|
201
|
+
n = 1000
|
|
202
|
+
vol = np.ones(n)
|
|
203
|
+
returns = np.zeros(n)
|
|
204
|
+
for t in range(1, n):
|
|
205
|
+
vol[t] = np.sqrt(0.02 + 0.85 * (returns[t-1]**2))
|
|
206
|
+
returns[t] = vol[t] * rng.normal()
|
|
207
|
+
|
|
208
|
+
fig, axes = plt.subplots(2, 1, figsize=(10, 7))
|
|
209
|
+
axes[0].plot(returns)
|
|
210
|
+
axes[0].set_title("Illustrative returns")
|
|
211
|
+
axes[1].plot(returns**2)
|
|
212
|
+
axes[1].set_title("Squared returns")
|
|
213
|
+
plt.tight_layout()
|
|
214
|
+
plt.show()
|
|
215
|
+
|
|
216
|
+
fig, axes = plt.subplots(2, 1, figsize=(10, 7))
|
|
217
|
+
plot_acf(returns, lags=30, ax=axes[0])
|
|
218
|
+
plot_acf(returns**2, lags=30, ax=axes[1])
|
|
219
|
+
axes[0].set_title("ACF of returns")
|
|
220
|
+
axes[1].set_title("ACF of squared returns")
|
|
221
|
+
plt.tight_layout()
|
|
222
|
+
plt.show()
|
|
223
|
+
"""),
|
|
224
|
+
"12": dedent("""# Example template — replace filename and column names for your CSV.
|
|
225
|
+
# from google.colab import files
|
|
226
|
+
# uploaded = files.upload()
|
|
227
|
+
#
|
|
228
|
+
# df = pd.read_csv("your_dataset.csv")
|
|
229
|
+
# print(df.head())
|
|
230
|
+
# print(df.columns)
|
|
231
|
+
# df["Date"] = pd.to_datetime(df["Date"])
|
|
232
|
+
# df = df.set_index("Date").sort_index()
|
|
233
|
+
# print("Missing values:")
|
|
234
|
+
# print(df.isna().sum())
|
|
235
|
+
# df["Close"].plot(title="Closing price")
|
|
236
|
+
# plt.show()
|
|
237
|
+
"""),
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
print(MENU)
|
|
241
|
+
choice = input("Select program number: ").strip()
|
|
242
|
+
|
|
243
|
+
print("\n============== YOUR TEMPLATE ==============\n")
|
|
244
|
+
print(TEMPLATES.get(choice, "Invalid option macha, try again."))
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
menu = getprograms
|
|
248
|
+
|
|
249
|
+
__version__ = "0.9.5"
|
|
250
|
+
__all__ = ["getprograms", "menu"]
|
|
251
|
+
|
|
252
|
+
if __name__ == "__main__":
|
|
253
|
+
getprograms()
|
|
254
|
+
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: timeserieslab
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Time Series Lab Practice Source Code Viewer
|
|
5
|
+
Author: Raunak
|
|
6
|
+
Classifier: Programming Language :: Python :: 3
|
|
7
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
8
|
+
Classifier: Operating System :: OS Independent
|
|
9
|
+
Requires-Python: >=3.8
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
|
|
12
|
+
# timeserieslab
|
|
13
|
+
|
|
14
|
+
Time Series Lab Practice Source Code Viewer.
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
pip install timeserieslab
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
Run via CLI command:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
timeserieslab
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
or:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
tslab
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Or from Python:
|
|
37
|
+
|
|
38
|
+
```python
|
|
39
|
+
import main
|
|
40
|
+
main.getprograms()
|
|
41
|
+
```
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
main.py,sha256=5ko1IYbYf6pmObUaX9GTKnuEiNxM8iPbp32qmxK6KzI,8281
|
|
2
|
+
timeserieslab-0.1.0.dist-info/METADATA,sha256=X0C7GmpjREaVMgM7i8YUz2aJD4acHoNAvFgbFk3ZeAA,640
|
|
3
|
+
timeserieslab-0.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
4
|
+
timeserieslab-0.1.0.dist-info/entry_points.txt,sha256=Di7hsvfrLigIE5SnZffSF_Jt1blD2r-D1P5r1TU9cwo,76
|
|
5
|
+
timeserieslab-0.1.0.dist-info/top_level.txt,sha256=ZAMgPdWghn6xTRBO6Kc3ML1y3ZrZLnjZlqbboKXc_AE,5
|
|
6
|
+
timeserieslab-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
main
|