Algorithmic trading with deep learning experiments

Overview

Deep-Trading

Algorithmic trading with deep learning experiments. Now released part one - simple time series forecasting. I plan to implement more sophisticated algorithms and their ensembles with different features, check their performance, train a trading strategy and go live.

Comments
  • Unable to execute Code due to => TypeError: 'generator' object is not subscriptable

    Unable to execute Code due to => TypeError: 'generator' object is not subscriptable

    Traceback (most recent call last): File "C:\Users\alok.saw\Downloads\Deep-Trading-master\Deep-Trading-master\hyperparameters\hyper.py", line 164, in best = fmin(experiment, space, algo=tpe.suggest, max_evals=50, trials=trials) File "C:\Users\alok.saw\AppData\Local\Programs\Python\Python35\lib\site-packages\hyperopt\fmin.py", line 307, in fmin return_argmin=return_argmin, File "C:\Users\alok.saw\AppData\Local\Programs\Python\Python35\lib\site-packages\hyperopt\base.py", line 635, in fmin return_argmin=return_argmin) File "C:\Users\alok.saw\AppData\Local\Programs\Python\Python35\lib\site-packages\hyperopt\fmin.py", line 314, in fmin pass_expr_memo_ctrl=pass_expr_memo_ctrl) File "C:\Users\alok.saw\AppData\Local\Programs\Python\Python35\lib\site-packages\hyperopt\base.py", line 786, in init pyll.toposort(self.expr) File "C:\Users\alok.saw\AppData\Local\Programs\Python\Python35\lib\site-packages\hyperopt\pyll\base.py", line 715, in toposort assert order[-1] == expr TypeError: 'generator' object is not subscriptable

    opened by aloksaw 1
  • StandardScaler() for OHLCV data

    StandardScaler() for OHLCV data

    I'm working on a time-series classification on financial data (not regression, but similar).

    I'm using sklearn.StandardScaler() although after reading all of your posts on Medium (thanks for the help!) I'm not entirely sure that I'm not screwing it up...

    I'm doing something like this to create 'lagged' data for the time window I'm trying to classify:

    def lag_data(df_data):
        for each in channels:
                    features_to_add.append(pd.concat([
                    df_data[[each]].shift(i).add_prefix("lag_{}_".format(i)) for i in range((lookforward*-1), lookback)], axis=1))
        return pd.concat(features_to_add, axis=1)
    
    from from sklearn.preprocessing import StandardScaler
    Instantiate scaler
    scaler = StandardScaler()
    # Scale the dataframe
    df_scaled = pd.DataFrame(scaler.fit_transform(OHLCV_data_with_lag.values))
    

    And then like this to prepare for Conv1D in Keras:

    
    def X_to_Conv1D_arrays(X):
        # Convert X to 3D arrays
        X = np.array(X)
        
        # Reshape data for Conv1D
        X = X.reshape(X.shape[0], X.shape[1], 1)
        
        print("X: ", X.shape)
        print("X: ", type(X))
    
        return X
    

    I've gotten some decent accuracy, but I'm wondering if this is a faulty way to prepare the data...

    opened by trevorwelch 1
  • keras-cannot-import-name-np-utils

    keras-cannot-import-name-np-utils

    Error message: from . import np_utils ImportError: cannot import name np_utils

    source: https://stackoverflow.com/questions/45060150/keras-cannot-import-name-np-utils - solution: pip install keras==2.0.2

    opened by gorazdko 0
  • Graphs not showing the training/test data

    Graphs not showing the training/test data

    `plt.figure() plt.plot(history.history['loss']) plt.plot(history.history['val_loss']) plt.title('model loss') plt.ylabel('loss') plt.xlabel('epoch') plt.legend(['train', 'test'], loc='best') plt.show()

    plt.figure() plt.plot(history.history['acc']) plt.plot(history.history['val_acc']) plt.title('model accuracy') plt.ylabel('accuracy') plt.xlabel('epoch') plt.legend(['train', 'test'], loc='best') plt.show()`

    ^ for me the above cell is not producing data on the graphs, just 2 blank plots. I was wondering what I am doing wrong?

    opened by mbrockman1 0
  • Error in data-preprocessing in multivariate/multivariate.py

    Error in data-preprocessing in multivariate/multivariate.py

    Although the FORECAST constant is 1, the label is actually 2 days after. Check the codes between line 52 - 55.

    Do a little experiment: x = [0, 1, 2, 3] x[0:3] x[3]

    opened by kenchan0824 0
  • Wrong data preprocessing leading to better results | Multimodal project

    Wrong data preprocessing leading to better results | Multimodal project

    Hi Alex, I really like your tutorials and used them as a good example for starting own projects ;) but I think there is a major error in the preprocessing, performed by the split_into_XY - function, in the process_data modul in the multimodal project.

    x_i = data_chng_train[i:i+window]
    y_i = np.std(data_chng_train[i:i+window+forecast][3])
    

    By using the above mentioned code, for generating the regression labels, the train data contain the labels!!! In general, the idea behind it, isn't clear to me. First, the code should be replaced with (that's for sure):

    x_i = data_chng_train[i:i+window]
    y_i = np.std(data_chng_train[i+window+forecast])
    

    But on the other hand, i dont understand, why you are using the standard deviation along the specific axis?! Shouldn't it be:

    x_i = data_chng_train[i:i+window]
    y_i = data_chng_train[i+window+forecast][3]  #Using the close prize [3] as label
    

    Then obviously all results substantially change and getting worse:
    figure_1

    opened by Dudeldu 1
  • FileNotFoundError: File b'AAPL.csv' does not exist

    FileNotFoundError: File b'AAPL.csv' does not exist

    when I run habrahabr.ipynb, I get the error message about b'AAPL.csv' doesn't exist, may I have the 'AAPL.csv' file? thanks

    FileNotFoundError Traceback (most recent call last) in () ----> 1 data = pd.read_csv('AAPL.csv')[::-1] 2 data = data.ix[:, 'Adj Close'].tolist() 3 4 # Uncomment below to use price change time series 5 # data = data.ix[:, 'Adj Close'].pct_change().dropna().tolist()

    /home/smilewater/anaconda3/envs/tensorflow-gpu/lib/python3.6/site-packages/pandas/io/parsers.py in parser_f(filepath_or_buffer, sep, delimiter, header, names, index_col, usecols, squeeze, prefix, mangle_dupe_cols, dtype, engine, converters, true_values, false_values, skipinitialspace, skiprows, nrows, na_values, keep_default_na, na_filter, verbose, skip_blank_lines, parse_dates, infer_datetime_format, keep_date_col, date_parser, dayfirst, iterator, chunksize, compression, thousands, decimal, lineterminator, quotechar, quoting, escapechar, comment, encoding, dialect, tupleize_cols, error_bad_lines, warn_bad_lines, skipfooter, skip_footer, doublequote, delim_whitespace, as_recarray, compact_ints, use_unsigned, low_memory, buffer_lines, memory_map, float_precision) 653 skip_blank_lines=skip_blank_lines) 654 --> 655 return _read(filepath_or_buffer, kwds) 656 657 parser_f.name = name

    /home/smilewater/anaconda3/envs/tensorflow-gpu/lib/python3.6/site-packages/pandas/io/parsers.py in _read(filepath_or_buffer, kwds) 403 404 # Create the parser. --> 405 parser = TextFileReader(filepath_or_buffer, **kwds) 406 407 if chunksize or iterator:

    /home/smilewater/anaconda3/envs/tensorflow-gpu/lib/python3.6/site-packages/pandas/io/parsers.py in init(self, f, engine, **kwds) 762 self.options['has_index_names'] = kwds['has_index_names'] 763 --> 764 self._make_engine(self.engine) 765 766 def close(self):

    /home/smilewater/anaconda3/envs/tensorflow-gpu/lib/python3.6/site-packages/pandas/io/parsers.py in _make_engine(self, engine) 983 def _make_engine(self, engine='c'): 984 if engine == 'c': --> 985 self._engine = CParserWrapper(self.f, **self.options) 986 else: 987 if engine == 'python':

    /home/smilewater/anaconda3/envs/tensorflow-gpu/lib/python3.6/site-packages/pandas/io/parsers.py in init(self, src, **kwds) 1603 kwds['allow_leading_cols'] = self.index_col is not False 1604 -> 1605 self._reader = parsers.TextReader(src, **kwds) 1606 1607 # XXX

    pandas/_libs/parsers.pyx in pandas._libs.parsers.TextReader.cinit (pandas/_libs/parsers.c:4209)()

    pandas/_libs/parsers.pyx in pandas._libs.parsers.TextReader._setup_parser_source (pandas/_libs/parsers.c:8873)()

    FileNotFoundError: File b'AAPL.csv' does not exist

    opened by smileyung 0
  • Slice indices issue in Simple time series forecasting.ipython

    Slice indices issue in Simple time series forecasting.ipython

    Hi Alex,

    Thanks for sharing your code. I am new to Python and CNN. I found your post on Medium and would like to try out your code, logic, and approaches on my own Mac OS. I am able to follow through your code in "Neural networks for algorithmic trading. Part One Simple time series forecasting.ipython" up to the following error.


    TypeErrorTraceback (most recent call last) in () 6 X, Y = split_into_chunks(timeseries, TRAIN_SIZE, TARGET_TIME, LAG_SIZE, binary=False, scale=False) 7 X, Y = np.array(X), np.array(Y) ----> 8 X_train, X_test, Y_train, Y_test = create_Xt_Yt(X, Y, percentage=0.9) 9 10 Xp, Yp = split_into_chunks(timeseries, TRAIN_SIZE, TARGET_TIME, LAG_SIZE, binary=False, scale=False)

    in create_Xt_Yt(X, y, percentage) 85 print ("len(X):", len(X)) 86 print ("len(y):", len(y)) ---> 87 X_train = X[0:len(X) * percentage] 88 Y_train = y[0:len(y) * percentage] 89

    TypeError: slice indices must be integers or None or have an index method

    Can you please help to shed some lights on this issue?

    Thanks, Kiko

    opened by iamyin 0
  • simpler_forecasting table.csv is opened as a binary file

    simpler_forecasting table.csv is opened as a binary file

    I'm not sure why no one has reported this before, so it makes me wonder if the problem is on my end. I got stuck trying to plot the very first chart, and it took some investigation to determine that load_snp_close() was quietly failing to read any data, because of the swallowed exception TypeError: a bytes-like object is required, not 'str'.

    I had to change f = open('table.csv', 'rb').readlines()[1:] to f = open('table.csv', 'r').readlines()[1:]

    After that, the data was read as expected.

    opened by gargleblaster 0
Owner
Alex Honchar
Entrepreneur, AI practitioner, Educator https://bitclout.com/u/alexrachnog
Alex Honchar
This project is a loose implementation of paper "Algorithmic Financial Trading with Deep Convolutional Neural Networks: Time Series to Image Conversion Approach"

Stock Market Buy/Sell/Hold prediction Using convolutional Neural Network This repo is an attempt to implement the research paper titled "Algorithmic F

Asutosh Nayak 136 Dec 28, 2022
Algorithmic trading using machine learning.

Algorithmic Trading This machine learning algorithm was built using Python 3 and scikit-learn with a Decision Tree Classifier. The program gathers sto

Sourav Biswas 101 Nov 10, 2022
High frequency AI based algorithmic trading module.

Flow Flow is a high frequency algorithmic trading module that uses machine learning to self regulate and self optimize for maximum return. The current

null 59 Dec 14, 2022
Algorithmic Trading using RNN

Deep-Trading This an implementation adapted from Rachnog Neural networks for algorithmic trading. Part One — Simple time series forecasting and this c

Hazem Nomer 29 Sep 4, 2022
Trading Gym is an open source project for the development of reinforcement learning algorithms in the context of trading.

Trading Gym Trading Gym is an open-source project for the development of reinforcement learning algorithms in the context of trading. It is currently

Dimitry Foures 535 Nov 15, 2022
This is a simple backtesting framework to help you test your crypto currency trading. It includes a way to download and store historical crypto data and to execute a trading strategy.

You can use this simple crypto backtesting script to ensure your trading strategy is successful Minimal setup required and works well with static TP a

Andrei 154 Sep 12, 2022
A general-purpose, flexible, and easy-to-use simulator alongside an OpenAI Gym trading environment for MetaTrader 5 trading platform (Approved by OpenAI Gym)

gym-mtsim: OpenAI Gym - MetaTrader 5 Simulator MtSim is a simulator for the MetaTrader 5 trading platform alongside an OpenAI Gym environment for rein

Mohammad Amin Haghpanah 184 Dec 31, 2022
PyTorch Personal Trainer: My framework for deep learning experiments

Alex's PyTorch Personal Trainer (ptpt) (name subject to change) This repository contains my personal lightweight framework for deep learning projects

Alex McKinney 8 Jul 14, 2022
TorchOk - The toolkit for fast Deep Learning experiments in Computer Vision

TorchOk - The toolkit for fast Deep Learning experiments in Computer Vision

null 52 Dec 23, 2022
A general framework for deep learning experiments under PyTorch based on pytorch-lightning

torchx Torchx is a general framework for deep learning experiments under PyTorch based on pytorch-lightning. TODO list gan-like training wrapper text

Yingtian Liu 6 Mar 17, 2022
Deep Reinforcement Learning based Trading Agent for Bitcoin

Deep Trading Agent Deep Reinforcement Learning based Trading Agent for Bitcoin using DeepSense Network for Q function approximation. For complete deta

Kartikay Garg 669 Dec 29, 2022
A Deep Reinforcement Learning Framework for Stock Market Trading

DQN-Trading This is a framework based on deep reinforcement learning for stock market trading. This project is the implementation code for the two pap

null 61 Jan 1, 2023
Code to reproduce the experiments from our NeurIPS 2021 paper " The Limitations of Large Width in Neural Networks: A Deep Gaussian Process Perspective"

Code To run: python runner.py new --save <SAVE_NAME> --data <PATH_TO_DATA_DIR> --dataset <DATASET> --model <model_name> [options] --n 1000 - train - t

Geoff Pleiss 5 Dec 12, 2022
Flow is a computational framework for deep RL and control experiments for traffic microsimulation.

Flow Flow is a computational framework for deep RL and control experiments for traffic microsimulation. See our website for more information on the ap

null 867 Jan 2, 2023
PyTorch framework, for reproducing experiments from the paper Implicit Regularization in Hierarchical Tensor Factorization and Deep Convolutional Neural Networks

Implicit Regularization in Hierarchical Tensor Factorization and Deep Convolutional Neural Networks. Code, based on the PyTorch framework, for reprodu

Asaf 3 Dec 27, 2022
Submission to Twitter's algorithmic bias bounty challenge

Twitter Ethics Challenge: Pixel Perfect Submission to Twitter's algorithmic bias bounty challenge, by Travis Hoppe (@metasemantic). Abstract We build

Travis Hoppe 4 Aug 19, 2022
CARLA: A Python Library to Benchmark Algorithmic Recourse and Counterfactual Explanation Algorithms

CARLA - Counterfactual And Recourse Library CARLA is a python library to benchmark counterfactual explanation and recourse models. It comes out-of-the

Carla Recourse 200 Dec 28, 2022
The CLRS Algorithmic Reasoning Benchmark

Learning representations of algorithms is an emerging area of machine learning, seeking to bridge concepts from neural networks with classical algorithms.

DeepMind 251 Jan 5, 2023
Re-implementation of 'Grokking: Generalization beyond overfitting on small algorithmic datasets'

Re-implementation of the paper 'Grokking: Generalization beyond overfitting on small algorithmic datasets' Paper Original paper can be found here Data

Tom Lieberum 38 Aug 9, 2022