StockData = readtable('ENI.MI.csv');
Open =cellfun(@str2double,StockData.Open);
High = cellfun(@str2double,StockData.High);
Low = cellfun(@str2double,StockData.Low);
Close = cellfun(@str2double,StockData.Close);
AdjustedClose = cellfun(@str2double,StockData.AdjClose);
Volume = cellfun(@str2double,StockData.Volume);
Date = StockData.Date;
StockData_TimeTable = timetable(Date,Open,High,Low,Close);
if any(any(ismissing(Close)))== 1
Close = fillmissing(Close,'linear');
end
Close = flip(Close);
Signal = zeros(length(Close),1);
for i=1:length(Close)-1;
if Close(i) > Close(i+1);
Signal(i) = 1;
else
Signal(i) =0;
end
end
Signal = Signal(1:end-1);
Close = Close(2:end);
Close = flip(Close);
Signal = flip(Signal);
Ma9 = movavg(Close,'simple',9);
Ma18 = movavg(Close,'simple',18);
EMa9 = movavg(Close,'exponential',9);
EMa18 = movavg(Close,'exponential',18);
X = [Close Ma9 Ma18 EMa9 EMa18];
hiddenLayerSize = 30;
net = fitnet(hiddenLayerSize);
net.divideFcn = 'divideblock';
net.layers{1}.transferFcn = 'logsig';
net.layers{2}.transferFcn = 'logsig';
net.trainParam.max_fail =100;
net.performFcn = 'crossentropy';
xt = X';
yt = Signal';
[net tr] = train(net, xt, yt);