Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
7811516
First Part
Mikegaoziqing Oct 26, 2025
2ac0f62
Modify STL
Mikegaoziqing Oct 26, 2025
9719da1
Modify STL
Mikegaoziqing Oct 26, 2025
4a06afc
Add files via upload
zhouzhouzou0-bot Oct 26, 2025
55ea7ee
Merge pull request #1 from LUKE-Jau/Step-1-3
zhouzhouzou0-bot Oct 27, 2025
7ab0898
Modified STL: Add multiplicative decomposition(optional).
Mikegaoziqing Oct 27, 2025
fd001ca
Add: STL with multiple frequency (1d and 1h)
Mikegaoziqing Nov 5, 2025
b4942d4
upload STL for close price
CLmingming Nov 5, 2025
d5a3823
Delete s02STL.py
CLmingming Nov 5, 2025
b27bf6e
Delete s01autocorrelation.py
CLmingming Nov 5, 2025
4f0c2e1
Modified comments
Mikegaoziqing Nov 5, 2025
d1747c3
Merge branch 'Group-1-decomposition' of https://github.com/LUKE-Jau/S…
Mikegaoziqing Nov 5, 2025
f52a0ee
upload STL onto closing return
CLmingming Nov 5, 2025
7836574
Update: Delete unused code
Mikegaoziqing Nov 5, 2025
a268a4f
Merge branch 'Group-1-decomposition' of https://github.com/LUKE-Jau/S…
Mikegaoziqing Nov 5, 2025
d98fb53
Modify name
Mikegaoziqing Nov 5, 2025
0cdd7f7
Update and rename Return analysis.py to Return_analysis.py
Mikegaoziqing Nov 5, 2025
27f06d0
Upload
Mikegaoziqing Nov 5, 2025
e2bb96c
Merge branch 'Group-1-decomposition' of https://github.com/LUKE-Jau/S…
Mikegaoziqing Nov 5, 2025
0f1aaea
Delete unused file
Mikegaoziqing Nov 5, 2025
872a0e8
Update and rename Return_analysis.py to return_analysis.py
Mikegaoziqing Nov 5, 2025
d1a6c0a
Delete
Mikegaoziqing Nov 5, 2025
7e49980
Merge branch 'Group-1-decomposition' of https://github.com/LUKE-Jau/S…
Mikegaoziqing Nov 5, 2025
4f2e77a
Delete .gitignore
LUKE-Jau Nov 5, 2025
c611aa1
Modify date filtering logic in return_analysis.py
CLmingming Nov 22, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add: STL with multiple frequency (1d and 1h)
  • Loading branch information
Mikegaoziqing committed Nov 5, 2025
commit fd001cae1f9199c518930b0a71c342a0184805de
62 changes: 45 additions & 17 deletions STL.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
warnings.filterwarnings("ignore")

# ========== 配置参数 ==========
START_DATE = "2024-08-01"
START_DATE = "2023-01-01"
DATA_DIR = "./data/BTC_factors"

# 频率到周期的映射(日周期)
Expand Down Expand Up @@ -165,30 +165,63 @@ def process_single_factor(
trend_strength = trend_var / (trend_var + resid_var + eps)
seasonal_strength = seasonal_var / (seasonal_var + resid_var + eps)

# === 保存图像 ===
# === 保存图像(含 ACF/PACF)===
from statsmodels.graphics.tsaplots import plot_acf, plot_pacf

decomposition_type = "multiplicative" if use_multiplicative else "additive"
image_path = os.path.join(
IMAGE_DIR, f"{factor_name}_{original_frequency}_{decomposition_type}.png"
)
fig, axes = plt.subplots(4, 1, figsize=(12, 10))

# 创建 6 个子图:observed, trend, seasonal, resid, ACF, PACF
fig, axes = plt.subplots(6, 1, figsize=(12, 14))

# 1. Observed
if use_multiplicative:
observed.plot(
ax=axes[0],
title=f"{factor_name} ({original_frequency}) - Multiplicative Decomposition",
title=f"{factor_name} ({original_frequency}) - {decomposition_type.capitalize()} Decomposition",
)
trend.plot(ax=axes[1], title="Trend")
seasonal.plot(ax=axes[2], title=f"Seasonal (Period={period})")
resid.plot(ax=axes[3], title="Residuals")
else:
result.observed.plot(
ax=axes[0],
title=f"{factor_name} ({original_frequency}) - Additive Decomposition",
title=f"{factor_name} ({original_frequency}) - {decomposition_type.capitalize()} Decomposition",
)

# 2. Trend
if use_multiplicative:
trend.plot(ax=axes[1], title="Trend")
else:
result.trend.plot(ax=axes[1], title="Trend")

# 3. Seasonal
if use_multiplicative:
seasonal.plot(ax=axes[2], title=f"Seasonal (Period={period})")
else:
result.seasonal.plot(ax=axes[2], title=f"Seasonal (Period={period})")

# 4. Residuals
if use_multiplicative:
resid.plot(ax=axes[3], title="Residuals")
else:
result.resid.plot(ax=axes[3], title="Residuals")

# 5. ACF of residuals
plot_acf(
resid,
lags=min(30, len(resid) // 2 - 1),
ax=axes[4],
title="ACF of Residuals",
)

# 6. PACF of residuals
plot_pacf(
resid,
lags=min(30, len(resid) // 2 - 1),
ax=axes[5],
title="PACF of Residuals",
)

plt.tight_layout()
plt.savefig(image_path, dpi=150, bbox_inches="tight")
plt.close(fig)
Expand Down Expand Up @@ -356,22 +389,17 @@ def process_selected_factors(factor_list, use_multiplicative=False):
if __name__ == "__main__":

# 批量处理所有因子(加法分解)
print("=== Processing all factors with additive decomposition ===")
summary_additive = batch_process_factors(use_multiplicative=False)
# print("=== Processing all factors with additive decomposition ===")
# summary_additive = batch_process_factors(use_multiplicative=False)

# # 批量处理所有因子(乘法分解)
# print("\n=== Processing all factors with multiplicative decomposition ===")
# summary_multiplicative = batch_process_factors(use_multiplicative=True)

print("\n=== Processing selected factors ===")
selected_factors = [
"active_1m_3m",
"count",
"supply_balance_less_0001",
"liquid_sum",
] # 示例因子列表
selected_factors = ["active_3m_6m"] # 示例因子列表
selected_summary = process_selected_factors(
selected_factors, use_multiplicative=True
selected_factors, use_multiplicative=False
)

print("\n✅ All done!")
Loading