My own neural network
#1
Hi
I wanted to build a strategy that could learn how to adjust. 
Parameters: ADA, 3 months with 60min candles
My first step was to test tried and tested indicators. I started with Tulip, ema.
Attachment: using indicators shows market -37% but strategy did 16%

Next step was to normalize inputs. NN doesn't like 0.00000567. So I normalized to 5.67. I also made sure that all inputs were of the same power(Math) so that no input would overwhelm the algorithm.
I used a feed forward neural network with backpropagation with several hidden layers.
For training, Backtest saved a json file with the results, then it takes the roundtrip data, sees profit % (- or +) and generates training data. This way I have automated the training cycle.
Same parameters with the NN is attachment using NN.
result is 26%

This was just an early test. Going to try add/remove inputs.
I couple of things I've seen. Overfitting the neural network is definitely an issue here. If I feed it too much data, results aren't as good, plus it will behave poorly on other assets. Current version behaves ok when switching assets, but I have seen that is better to train the neural network for each asset as they have distinct behaviours.


Attached Files
.png   using indicatores and candle size.png (Size: 264.55 KB / Downloads: 37)
.png   using NN.png (Size: 271.75 KB / Downloads: 24)
  Reply
#2
I'd lover to see how you implemented a neural net (did you use tensorflow ?)
As so far most gekko NN i found are not realy properly written
I worked quite a lot with NN's but that was python and c# not jscript.
PS normally in neural networks you keep values between -1 and 1 or 0 and 1
It has to do with relu /tanh they work best within that range.
[....Resistance is futile...]
  Reply
#3
Hello,

for information : you can find different NN strategies here. 

[url= https://www.reddit.com/r/algotrading/com...with/]link for NN strats comparison[/url]
one of the best commented code is neuralNetcode
Maily they use convnetjs as framework.

We don't know the code used by Lenny and the relative framework.

Diego
  Reply
#4
(10-07-2019, 09:12 AM)Dieguz Wrote: Hello,

for information : you can find different NN strategies here. 

[url= https://www.reddit.com/r/algotrading/com...with/]link for NN strats comparison[/url]
one of the best commented code is neuralNetcode
Maily they use convnetjs as framework.

We don't know the code used by Lenny and the relative framework.

Diego

There do exist many gekko clones of neural networks like that, single neuron logic (some tanh treshold to act upon).
Those are not todays neural networks, the example has no hidden layers and only one input, compare that some average simple networks in python.
They are more close to a self regulating fuzzy logic (without making use of hiden layers, and such minimal input).
Where with tensorflow one easily creates 20 inputs, and maybe 4 hidden layers of 80 nodes to a final regression node.
Such networks find patternin input, they're deep learners, or LSTM's, or GRU's.
[....Resistance is futile...]
  Reply
#5
(10-11-2019, 08:23 AM)Dieguz Wrote: Hello,

i have found a cool CNN implementation in tensorflow.js applied to stock markets.

https://github.com/Gago993/StockPredictionCNN

i think it is a good starting point to learn how to code in Tensorflow and adapt to crypto market.

PGTART: if you feel that it is a good implementation of CNN applicable to the crypto world, i can do my experimentations to adapt it to gekko or rewrite it  for that.

Diego
  Reply
#6
(10-11-2019, 08:24 AM)Dieguz Wrote:
(10-11-2019, 08:23 AM)Dieguz Wrote: Hello,

i have found a cool CNN implementation in tensorflow.js applied to stock markets.

https://github.com/Gago993/StockPredictionCNN

i think it is a good starting point to learn how to code in Tensorflow and adapt to crypto market.

PGTART: if you feel that it is a good implementation of CNN applicable to the crypto world, i can do my experimentations to adapt it to gekko or rewrite it  for that.

Diego

Well I looked quickly in the code.
At last this is a real neural network
It got multiple layers (model add)
It uses 7 inputs (a bit small number)
Not sure what is put in as data input though.
But this code might be rewritten.
For example feed it with various tulip counters.


It seams a good starting point for coding.

Just a few notes:

Neural nets need to be trained the training method has great influence as well.

Training takes time and the more nodes in all the layers the more time. 

It takes some NN experience to optimize a NN don't worry about it i or others can do statical analysis of the model

You might not require a time series NN model
Those are usually not that good in predicting. The good ones score around 80% while normal nets easily go 96 and higher. 

One needs to be able to save and load the weight model of the neural net.
(I can write it if it's not there)

You will need a series predictor if you feed it with Manny candle bars. You won't need a series predictor if you feed it with other indicators (be sure to scale their values in-between -1 and 1

Use relu and use a bottle design ea many input nodes per layer use gradually smaller dense nodes in end layers. Such networks are usually good there is a lot theory about it of  why whiches down to slowly converging of information density.

If you got a basic tensor flow neural net working we can then later create a good layer model for it

The code might serve as a hello world tensorflow Gekko. Don't worry if it won't go super. I codes lots of TF NN we can tweak such a network later a lot. Also saving and loading I can help or write. 

We could write multiple NN based on a first I've written so many nets it be fun

Send me a pm if you got a basic working version.
[....Resistance is futile...]
  Reply
#7
(10-07-2019, 09:12 AM)Dieguz Wrote: Hello,

for information : you can find different NN strategies here. 

[url= https://www.reddit.com/r/algotrading/com...with/]link for NN strats comparison[/url]
one of the best commented code is neuralNetcode
Maily they use convnetjs as framework.

We don't know the code used by Lenny and the relative framework.

Diego

Actually on the tensorflow website there is allready a simple helloworld examlple.
Its not at all doing trades but from here its easy to write something (well it is for me), but anyway besides the network design and inputs and train method.. its a basic neural net.   (an install for node cpu  (
Code:
npm install @tensorflow/tfjs-node


)   is here  https://www.tensorflow.org/js/tutorials/setup  )

const tf = require('@tensorflow/tfjs');

// Optional Load the binding:
// Use '@tensorflow/tfjs-node-gpu' if running with GPU.
require('@tensorflow/tfjs-node');

// Train a simple model:
const model = tf.sequential();
model.add(tf.layers.dense({units: 100, activation: 'relu', inputShape: [10]}));
model.add(tf.layers.dense({units: 1, activation: 'linear'}));
model.compile({optimizer: 'sgd', loss: 'meanSquaredError'});

const xs = tf.randomNormal([100, 10]);
const ys = tf.randomNormal([100, 1]);

model.fit(xs, ys, {
  epochs: 100,
  callbacks: {
    onEpochEnd: (epoch, log) => console.log(`Epoch ${epoch}: loss = ${log.loss}`)
  }
});
[....Resistance is futile...]
  Reply


Forum Jump:


Users browsing this thread: