mirror of
https://github.com/webclinic017/drift.git
synced 2026-08-23 07:48:09 +00:00
feat(Data): added load_data, to aggregate everything into one dataframe
This commit is contained in:
+1502
-1502
File diff suppressed because it is too large
Load Diff
+1502
-1502
File diff suppressed because it is too large
Load Diff
+1502
-1502
File diff suppressed because it is too large
Load Diff
+1502
-1502
File diff suppressed because it is too large
Load Diff
+1502
-1502
File diff suppressed because it is too large
Load Diff
+1502
-1502
File diff suppressed because it is too large
Load Diff
+1006
-1006
File diff suppressed because it is too large
Load Diff
+1006
-1006
File diff suppressed because it is too large
Load Diff
+1502
-1502
File diff suppressed because it is too large
Load Diff
+1006
-1006
File diff suppressed because it is too large
Load Diff
+1502
-1502
File diff suppressed because it is too large
Load Diff
+1006
-1006
File diff suppressed because it is too large
Load Diff
+1006
-1006
File diff suppressed because it is too large
Load Diff
+1502
-1502
File diff suppressed because it is too large
Load Diff
+1502
-1502
File diff suppressed because it is too large
Load Diff
+1502
-1502
File diff suppressed because it is too large
Load Diff
@@ -7,6 +7,8 @@ crypto_tickers = ["BTC", "ETH", "BNB", "ADA", "SOL", "XRP", "DOT", "LTC", "UNI",
|
|||||||
etf_tickers = ["GLD", "IEF", "TLT", "SPY", "QQQ"]
|
etf_tickers = ["GLD", "IEF", "TLT", "SPY", "QQQ"]
|
||||||
tickers = crypto_tickers + etf_tickers
|
tickers = crypto_tickers + etf_tickers
|
||||||
|
|
||||||
|
add_features = False
|
||||||
|
|
||||||
#%%
|
#%%
|
||||||
for ticker in tickers:
|
for ticker in tickers:
|
||||||
print("Fetching ", ticker)
|
print("Fetching ", ticker)
|
||||||
@@ -14,6 +16,21 @@ for ticker in tickers:
|
|||||||
df = get_crypto_price_crypto_compare(ticker, "USD", 1500)
|
df = get_crypto_price_crypto_compare(ticker, "USD", 1500)
|
||||||
else:
|
else:
|
||||||
df = get_stock_price_av(ticker, "2017-11-10")
|
df = get_stock_price_av(ticker, "2017-11-10")
|
||||||
|
df['returns'] = df['close'].pct_change()
|
||||||
|
|
||||||
|
if add_features:
|
||||||
|
# volatility (10, 20, 30 days)
|
||||||
|
df['vol_10'] = df['returns'].rolling(10).std()*(252**0.5)
|
||||||
|
df['vol_20'] = df['returns'].rolling(20).std()*(252**0.5)
|
||||||
|
df['vol_30'] = df['returns'].rolling(30).std()*(252**0.5)
|
||||||
|
|
||||||
|
# momentum (10, 20, 30, 60, 90 days)
|
||||||
|
df['mom_10'] = df['close'].pct_change(10)
|
||||||
|
df['mom_20'] = df['close'].pct_change(20)
|
||||||
|
df['mom_30'] = df['close'].pct_change(30)
|
||||||
|
df['mom_60'] = df['close'].pct_change(60)
|
||||||
|
df['mom_90'] = df['close'].pct_change(90)
|
||||||
|
|
||||||
df.to_csv(f"data/{ticker}.csv", index=True)
|
df.to_csv(f"data/{ticker}.csv", index=True)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
#%%
|
||||||
|
import pandas as pd
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
|
#%%
|
||||||
|
|
||||||
|
def load_files(path):
|
||||||
|
dfs = [load_df(os.path.join(path,f), f.split('.')[0]) for f in os.listdir(path) if os.path.isfile(os.path.join(path,f))]
|
||||||
|
return pd.concat(dfs, axis=1)
|
||||||
|
|
||||||
|
def load_df(path, prefix):
|
||||||
|
df = pd.read_csv(path, header=0, index_col=0).fillna(0)
|
||||||
|
df.columns = [prefix + "_" + c for c in df.columns]
|
||||||
|
return df
|
||||||
|
|
||||||
|
load_files("data/")
|
||||||
|
# %%
|
||||||
Reference in New Issue
Block a user