I found the trend by this code. This trend is from Japanese Workers' Pay Day(Every 25th day in a month). '''python import yfinance as yf import matplotlib . pyplot as plt import pandas as pd import seaborn as sns # 分析期間の設定 dateStart = "2015-01-01" dateEnd = "2026-05-23" ticker = "JPY=X" # ドル円 # yfinanceから取得(仕様変更の警告回避のため auto_adjust を明示) df = yf . download ( ticker , start = dateStart , end = dateEnd , auto_adjust = False , progress = False ) # yfinanceの仕様変更(MultiIndex化)に対応して終値を安全に抽出 if isinstance ( df . columns , pd . MultiIndex ): close = df [ "Close" ][ ticker ].dropna() else : close = df [ "Close" ]. dropna () # 前日比の変化率(%)を計算 # ドル円の場合、プラス = ドル買い/円売り、マイナス = ドル売り/円買い daily_return = close . pct_change () * 100 # 分析用のDataFrameを作成 analysis_df = pd . DataFrame ({ "Return" : daily_return }) analysis_df . index = pd . to_datetime ( analysis_df . index ...
Ratios Between Gold, Platinum and Silver
Ratios between Gold, Platinum and Silver show clear trends. Gold/Silver ratio shows big fluctuations. Platinum/Silver ratio shows a clear downward trend.
import yfinance as yf
import matplotlib.pyplot as plt
import pandas as pd
dateStart = "2015-01-01"
dateEnd = "2025-12-31"
tickers = ["GC=F", "SI=F", "PL=F"] # Gold, Silver, Platinum futures
# yfinanceからまとめて取得(警告回避のため auto_adjust を明示)
df = yf.download(
tickers,
start=dateStart,
end=dateEnd,
auto_adjust=False, # True/FalseどちらでもOK。とにかく明示する
progress=False
)
# dfは MultiIndex columns になりやすい:['Close'] で3銘柄の終値DataFrameが取れる
close = df["Close"].copy()
# 月次平均(pandas警告対応:'M' -> 'ME')
close_m = close.resample("ME").mean()
# 比率をDataFrameで計算(列名で参照)
ratio = pd.DataFrame({
"Gold/Silver": close_m["GC=F"] / close_m["SI=F"],
"Gold/Platinum": close_m["GC=F"] / close_m["PL=F"],
"Platinum/Silver": close_m["PL=F"] / close_m["SI=F"],
}).dropna()
ax = ratio.plot(figsize=(12, 6))
ax.set_title("Monthly Price Ratios (Futures via Yahoo Finance)")
ax.set_xlabel("Month")
ax.set_ylabel("Ratio")
plt.show()

Comments
Post a Comment