Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def back_test_paths_generator(t_span, n, k, verbose=True): | |
# split data into N groups, with N << T | |
# this will assign each index position to a group position | |
group_num = np.arange(t_span) // (t_span // n) | |
group_num[group_num == n] = n-1 | |
# generate the combinations | |
test_groups = np.array(list(itt.combinations(np.arange(n), k))).reshape(-1, k) | |
C_nk = len(test_groups) | |
n_paths = C_nk * k // n |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cmap_data = plt.cm.Paired | |
cmap_cv = plt.cm.coolwarm | |
def plot_cv_indices(cv, X, y, group, ax, n_paths, k, paths, lw=5): | |
"""Create a sample plot for indices of a cross-validation object.""" | |
# generate the combinations | |
N = n_paths + 1 | |
test_groups = np.array(list(itt.combinations(np.arange(N), k))).reshape(-1, k) | |
n_splits = len(test_groups) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Set data source | |
data = data_ohlcv | |
data_index = data.index | |
# Select train data | |
X = data.drop(['label_barrier'], axis = 1) | |
X.drop(X.tail(t_final).index,inplace = True) | |
# Select test data | |
y = data[['label_barrier']] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Net(nn.Module): | |
def __init__(self): | |
super(Net, self).__init__() | |
self.state_dim = 29 # all the features | |
self.mid_dim = 2**10 # net dimension | |
self.action_dim = 3 # output (sell/nothing/buy) | |
# make a copy of the model in ActorPPO (activation function in forward function) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
corr_matrix = pd.DataFrame(X).corr() | |
ax = sns.heatmap( | |
corr_matrix, | |
xticklabels=True, | |
yticklabels=True, | |
vmin=-1, vmax=1, center=0, | |
cmap=sns.diverging_palette(20, 220, n=200), | |
square=True | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BinanceProcessor(): | |
def __init__(self, api_key_binance, api_secret_binance): | |
self.binance_api_key = api_key_binance # Enter your own API-key here | |
self.binance_api_secret = api_secret_binance # Enter your own API-secret here | |
self.binance_client = Client(api_key=api_key_binance, api_secret=api_secret_binance) | |
def run(self, ticker_list, start_date, end_date, time_interval, technical_indicator_list, if_vix): | |
data = self.download_data(ticker_list, start_date, end_date, time_interval) | |
data = self.clean_data(data) | |
data = self.add_technical_indicator(data, technical_indicator_list) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def perturbation_rank(model,x,y,names): | |
errors = [] | |
X_saved = x | |
y = y.flatten() | |
with torch.no_grad(): | |
model.eval() | |
for i in range(x.shape[1]): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Train function | |
def train(fold, model, device, trainloader, optimizer, epoch): | |
model.train() | |
correct_train = 0 | |
correct_this_batch_train = 0 | |
total_train_loss = 0 | |
for batch_idx, (data, target) in enumerate(train_loader): | |
data, target = data.to(device), target.to(device) | |
optimizer.zero_grad() | |
output = model(data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Set constants | |
batch_size=16 | |
epochs=300 | |
# Reinitiating data here | |
data = fractional_diff_data | |
X = data[['open', 'high', 'low', 'close', 'volume', 'rsi', 'macd', 'macd_signal', 'macd_hist', 'cci', 'dx', 'volatility']].values | |
y = np.squeeze(data[['label_barrier']].values).astype(int) |
NewerOlder