-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmake_data.py
More file actions
42 lines (34 loc) · 1.3 KB
/
make_data.py
File metadata and controls
42 lines (34 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import yfinance as yf
import pandas as pd
import numpy as np
import json
from arch import arch_model
def run_producer():
# 1. Acquisition
tickers = ['BTC-USD', '^VIX', '^IRX']
raw_data = yf.download(tickers, start="2020-01-01", end="2026-03-20", auto_adjust=False)
df = raw_data['Close'].copy()
df.columns = ['BTC', 'RiskFree', 'VIX']
df = df.ffill().dropna()
df['Returns'] = np.log(df['BTC'] / df['BTC'].shift(1))
p25, p90 = df['VIX'].quantile(0.25), df['VIX'].quantile(0.90)
df['Regime'] = pd.cut(df['VIX'], bins=[0, p25, p90, 500], labels=['Calm', 'Normal', 'Panic'])
# 2. GARCH Fitting
am = arch_model(df['Returns'].dropna() * 100, vol='Garch', p=1, q=1, mean='Constant', dist='normal')
res = am.fit(disp='off')
# 3. Save Parameters for the Hook
params = {
"omega": res.params['omega'] / 10000,
"alpha": res.params['alpha[1]'],
"beta": res.params['beta[1]'],
"mu": res.params['mu'] / 100,
"vix_p25": p25,
"vix_p90": p90
}
with open('garch_params.json', 'w') as f:
json.dump(params, f)
# 4. Save DataFrame
df.to_csv("crypto_research_data.csv")
print("Producer Complete: Saved 'crypto_research_data.csv' and 'garch_params.json'")
if __name__ == "__main__":
run_producer()