Machine learning in trading: theory, models, practice and algo-trading - page 3675

 
mytarmailS #:

Also added the cumulative sum from the oscillator for better understanding


The inverse correlation between price and trading of the TS ensemble is obvious

We look at the sum of open positions in dynamics from the aggregator's site and see the same thing


 
mytarmailS #:

We look at the sum of open positions in dynamics from the aggregator's site and see the same thing

Thus, by observing the trading of a large ensemble of "profitable on history" TSs, you can simulate the actions of a group of primitive players, of which there are a large number.


code for creating the rattle of the TS generator and creating the oscillator + visualisation attached...

library(garage)
library(quantmod)
library(dbscan)
library(randomForest)
library(pso)


d <- read.csv("D:\\fin_data\\EURUSD_M1_2022_2024.csv", 
              sep = "", header = T, check.names = F)

colnames(d) <- gsub("[<>]", "", colnames(d))
colnames(d)[ colnames(d) == "VOL" ] <- "VOLUME"


d <- d[1:100000,]
d[,3:6] <- d[,3:6] + rnorm(n = nrow(d), sd = 0.0000001)


indic <- TTR_indicators(d, n = 10)
indic[is.na(indic)] <- 0
indic <- cbind(close=Cl(d), indic)



set.seed(1)
hd <- hdbscan(t(indic[200:2000,]), minPts = 5)
indic[, hd$cluster==3] <- indic[, hd$cluster==3] - indic$close




count_balance <- function(prices,signals){
  p <- c(0,diff(prices))
  s <- c(0,signals[-length(signals)])
  return(   cumsum(p*s)   )
}



tr <- 101:200
ts <- 201:20000

p <- as.matrix(OHLC(d))


bst_model <- list()



bst_val <- -0.96
fit <- function(y){
  
rf <- randomForest(y~., indic[tr,], ntree=100)
sig <- sign(predict(rf, indic[ts, ]))

B <- count_balance(d[ts,]$CLOSE, signals = sig)

res <- cor(B, 1:length(B)) / -1


if(res < bst_val){
  bst_val <<- res
  li <- list(model=rf, Y=y, val=res, bal=B)
  bst_model <<- append(bst_model, list(li))
 
  plot(B, t="l", main=round(res,4))
}

res
}



pso <- psoptim(rep(NA,length(tr)),
               fit,
               lower= -10,
               upper=  10,
               
               control=list(trace=1,
                            REPORT=1,
                            maxit=20))


bst_model |> length()


vl <- 20001:22000+1000


preds <- lapply(1:length(bst_model), \(i)
                   sign(predict(bst_model[[i]]$model, indic[vl,])))


res <- as.data.frame(preds) |> as.matrix() |> rowSums()


k <- 1:200+200
par(mfrow=c(3,1), mar=c(2,2,2,2))
plot(res[k],t="l", main="сумма сигналов") ; abline(h=c(0,25,-25), col=c(1,2,3))
plot(cumsum(res[k]),t="l", main="кумулятивная сумма сигналов") 
plot(d$CLOSE[vl][k],t="l", main="цена закрытия")

 
mytarmailS #:

Also added the cumulative sum from the oscillator for better understanding


The inverse correlation between price and trading of the TS ensemble is obvious

What a good OOS you have.

The correlation is natural, because the higher the price - the more robots sell and the lower - the more they buy. And this is not a lag - it is a natural logic of trading: buy cheap, sell expensive.

 
Forester #:
What a good OOS you have.

Correlation is natural, because the higher the price - the more robots sell and the lower - the more they buy. And this is not a lag - it is natural trading logic: buy cheap, sell expensive.

quite likely

[Deleted]  
I'd like to convert it to ONNX, just to check )
 
It seems to me that markup is not taken into account there.
And that all tests should be done in pips (or report by what lot). 0.06-0.08 something for 20 thousand transactions. It looks a bit small.
 
Maxim Dmitrievsky #:

NZDUSD hours, 2000 to 2010 OOS

You can lock in stops and takeouts at open prices to make it faster.

I'm throwing it here because I think I'd be crazy to give it to everyone in turn, if they ask :)

There is some failure at the junction of training and OOS, but otherwise it looks good. I'll try to do better later, I'm improving my approach.

I got at hand, decided to test on new data. The result is below.

Well, it's not too bad, at some point you could even make money... but you never know where to stop....

[Deleted]  
Aleksey Vyazmikin #:

I found it in my hand and decided to test it on new data. The result is below.

Well, it's not so bad, at some point you could even make money... but you never know where to stop....

It's something from an old one, I don't remember.
 
Forester #:
What a good OOS you have.

Correlation is natural, because the higher the price - the more robots sell and the lower - the more they buy. And it is not a lag - it is a natural logic of trading: buy cheap, sell expensive.

Only one question is why the price is going up if most people are selling.

 
Happy New Year!