Skip to content

Instantly share code, notes, and snippets.

@Kouhei-Takagi
Created May 7, 2025 13:14
Show Gist options
  • Save Kouhei-Takagi/6fa1626b2b770d18000c3e1673604fa6 to your computer and use it in GitHub Desktop.
Save Kouhei-Takagi/6fa1626b2b770d18000c3e1673604fa6 to your computer and use it in GitHub Desktop.
Correlation Features and USD/JPY(corr=0.9397)
import pandas_datareader.data as web
from datetime import datetime
import pandas as pd
start = datetime(2015, 6, 1)
end = datetime(2025, 5, 1)
# Retrieve monthly data from FRED
gold = web.DataReader("IR14270", "fred", start, end)
oil = web.DataReader("DCOILWTICO", "fred", start, end)
dgs2 = web.DataReader("DGS2", "fred", start, end)
dgs5 = web.DataReader("DGS5", "fred", start, end)
dgs10 = web.DataReader("DGS10", "fred", start, end)
dgs30 = web.DataReader("DGS30", "fred", start, end)
jpy = web.DataReader("EXJPUS", "fred", start, end)
# Merge data and rename columns
df = pd.concat([gold, oil, dgs2, dgs5, dgs10, dgs30, jpy], axis=1).dropna()
df.columns = ["Gold", "Oil", "DGS2", "DGS5", "DGS10", "DGS30", "JPY"]
# Create a combined price index (simple weighted formula)
df["Combined_Price"] = (
df["Gold"] * 1
+ df["Oil"] * 2.5
) * (df["DGS10"] * 1)
# Calculate correlation coefficient
corr = df["Combined_Price"].corr(df["JPY"])
print("Correlation coefficient (Combined Price × JPY):", corr)
# Display result
print(df[["Combined_Price", "JPY"]])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment