
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
The problem with R is that it cannot be run in conjunction with a tester and graphical reports cannot be drawn. =)
The problem with R is that you can't run it in conjunction with the tester and draw graphical reports. =)
This is not a problem of R, it's a problem of report drawers.
For research it is enough to write a simple tester by yourself in five minutes.
library(TTR)
library(zoo)
# get some data
num.points <- ...
midprices <- ...
spreads <- ...
bids <- midprices - 0.5 * spreads
asks <- midprices + 0.5 * spreads
# length(midprices) == num.points; length(spreads) == num.points
ma.fast <- EMA(midprices, 15)
ma.slow <- EMA(midprices, 50)
# compute entry/exit signals
open.long.position <- (ma.fast > ma.slow) & (ma.slow > midprices)
close.long.position <- (ma.fast < midprices)
open.short.position <- (ma.fast < ma.slow) & (ma.slow < midprices)
close.short.position <- (ma.fast > midprices)
signals.to.position <- function (num.points, signal.open, signal.close) {
pos <- rep(NA, num.points)
pos[signal.open] <- 1
pos[signal.close] <- 0
pos <- na.locf(pos, na.rm = F)
pos[is.na(pos)] <- 0
pos
}
# compute strategy positions
pos.long <- signals.to.position(num.points, open.long.position, close.long.position)
pos.short <- signals.to.position(num.points, open.short.position, close.short.position)
pos.total <- pos.long - pos.short
# compute equity
commission <- 1
trade.size <- c(0, pos.total[2 : num.points] - pos.total[1 : (num.points - 1)])
fees <- abs(trade.size) * (commission + 0.5 * spreads)
equity <- midprices * pos.total + cumsum(-midprices * trade.size - fees)
# compute balance
balance <- rep(NA, num.points)
balance[trade.size != 0] <- equity[trade.size != 0]
balance <- na.locf(balance, na.rm = F)
balance[is.na(balance)] <- 0
# display results
par(mfrow = c(2, 1))
plot(midprices, t = 'l', col = 'gray', lty = 'dashed')
lines(bids, col = 'blue')
lines(asks, col = 'red')
points(which(trade.size > 0, arr.ind = T), asks[trade.size > 0], col = 'blue')
points(which(trade.size < 0, arr.ind = T), bids[trade.size < 0], col = 'red')
plot(equity, t = 'l')
lines(balance, col = 'gray', lty = 'dashed')
That's not the problem of R, it's the problem of the report drawers.
All it takes is five minutes to write a simple tester yourself for research.
library(TTR)
library(zoo)
# get some data
num.points <- ...
midprices <- ...
spreads <- ...
bids <- midprices - 0.5 * spreads
asks <- midprices + 0.5 * spreads
# length(midprices) == num.points; length(spreads) == num.points
ma.fast <- EMA(midprices, 15)
ma.slow <- EMA(midprices, 50)
# compute entry/exit signals
open.long.position <- (ma.fast > ma.slow) & (ma.slow > midprices)
close.long.position <- (ma.fast < midprices)
open.short.position <- (ma.fast < ma.slow) & (ma.slow < midprices)
close.short.position <- (ma.fast > midprices)
signals.to.position <- function (num.points, signal.open, signal.close) {
pos <- rep(NA, num.points)
pos[signal.open] <- 1
pos[signal.close] <- 0
pos <- na.locf(pos, na.rm = F)
pos[is.na(pos)] <- 0
pos
}
# compute strategy positions
pos.long <- signals.to.position(num.points, open.long.position, close.long.position)
pos.short <- signals.to.position(num.points, open.short.position, close.short.position)
pos.total <- pos.long - pos.short
# compute equity
commission <- 1
trade.size <- c(0, pos.total[2 : num.points] - pos.total[1 : (num.points - 1)])
fees <- abs(trade.size) * (commission + 0.5 * spreads)
equity <- midprices * pos.total + cumsum(-midprices * trade.size - fees)
# compute balance
balance <- rep(NA, num.points)
balance[trade.size != 0] <- equity[trade.size != 0]
balance <- na.locf(balance, na.rm = F)
balance[is.na(balance)] <- 0
# display results
par(mfrow = c(2, 1))
plot(midprices, t = 'l', col = 'gray', lty = 'dashed')
lines(bids, col = 'blue')
lines(asks, col = 'red')
points(which(trade.size > 0, arr.ind = T), asks[trade.size > 0], col = 'blue')
points(which(trade.size < 0, arr.ind = T), bids[trade.size < 0], col = 'red')
plot(equity, t = 'l')
lines(balance, col = 'gray', lty = 'dashed')
Simple as that...
Shall we decipher the grids?
Hmm. Maybe I don't know either. Haven't really used it yet.
It's just, like everything...
Shall we decipher the grids?
Please help.
I have entered EURUSD in R. I have calculated the model and calculated the coefficient. How can I draw a chart and combine it with the kotir?
> x.ar<-ar(eur[1:256],method="mle")
> x.ar
Call:
ar(x = eur[1:256],method="mle")
Coefficients:
1 ........2.......... 3
0.9420 0.1955 -0.1644
Order selected 3 sigma^2 estimated as 2.73e-06