feat(Data): added load_data, to aggregate everything into one dataframe

This commit is contained in:
Mark Aron Szulyovszky
2021-11-09 16:12:48 +01:00
parent 51b7d35660
commit d5086a4785
18 changed files with 21588 additions and 21553 deletions
+1502 -1502
View File
File diff suppressed because it is too large Load Diff
+1502 -1502
View File
File diff suppressed because it is too large Load Diff
+1502 -1502
View File
File diff suppressed because it is too large Load Diff
+1502 -1502
View File
File diff suppressed because it is too large Load Diff
+1502 -1502
View File
File diff suppressed because it is too large Load Diff
+1502 -1502
View File
File diff suppressed because it is too large Load Diff
+1006 -1006
View File
File diff suppressed because it is too large Load Diff
+1006 -1006
View File
File diff suppressed because it is too large Load Diff
+1502 -1502
View File
File diff suppressed because it is too large Load Diff
+1006 -1006
View File
File diff suppressed because it is too large Load Diff
+1502 -1502
View File
File diff suppressed because it is too large Load Diff
+1006 -1006
View File
File diff suppressed because it is too large Load Diff
+1006 -1006
View File
File diff suppressed because it is too large Load Diff
+1502 -1502
View File
File diff suppressed because it is too large Load Diff
+1502 -1502
View File
File diff suppressed because it is too large Load Diff
+1502 -1502
View File
File diff suppressed because it is too large Load Diff
+18 -1
View File
@@ -7,13 +7,30 @@ crypto_tickers = ["BTC", "ETH", "BNB", "ADA", "SOL", "XRP", "DOT", "LTC", "UNI",
etf_tickers = ["GLD", "IEF", "TLT", "SPY", "QQQ"]
tickers = crypto_tickers + etf_tickers
add_features = False
#%%
for ticker in tickers:
print("Fetching ", ticker)
if ticker in crypto_tickers:
df = get_crypto_price_crypto_compare(ticker, "USD", 1500)
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)
+18
View File
@@ -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/")
# %%