I don’t know the reason but there is an error appearing while I play my code in R.
<code># Pobieranie danych
filename <- "https://stooq.pl/q/d/l/?s=eat&d1=20190101&d2=202312310&i=d"
amrest <- read.csv(filename)
# Konwersja daty
amrest$Data <- as.Date(amrest$Data)
# Sortowanie danych po dacie
amrest <- amrest[order(amrest$Data),]
# Wybieranie odpowiednich kolumn (bez wolumenu)
amrest <- amrest[,c(1:5)]
colnames(amrest) <- c("Date", "Open", "High", "Low", "Close")
# Zmiana na format xts
amrest_xts <- xts(amrest[,-1], order.by = amrest$Date)
# Sprawdzanie, czy xts jest prawidłowo utworzony
print(head(amrest_xts))
print(tail(amrest_xts))
# Obliczanie MACD
macd_data <- MACD(Cl(amrest_xts), nFast=12, nSlow=26, nSig=9, maType="EMA")
# Sprawdzanie, czy MACD został poprawnie obliczony
print(head(macd_data))
print(tail(macd_data))
# Łączenie danych z MACD
amrest_xts <- merge(amrest_xts, macd_data)
# Generowanie sygnałów kupna i sprzedaży
signal <- Lag(ifelse(amrest_xts$macd > amrest_xts$signal, 1, -1))
signal[is.na(signal)] <- 0
# Sygnały kupna i sprzedaży na przecięciach
buy_signal <- ifelse(signal == 1 & Lag(signal) == -1, 1, 0)
sell_signal <- ifelse(signal == -1 & Lag(signal) == 1, 1, 0)
# Dodawanie sygnałów do danych xts
amrest_xts$buy_signal <- buy_signal
amrest_xts$sell_signal <- sell_signal
# Wybieranie ostatnich 100 obserwacji do wykresu świecowego
amrest_xts_short <- tail(amrest_xts, 100)
# Wykres świecowy z zaznaczonymi sygnałami
candleChart(amrest_xts_short, multi.col=TRUE, theme='white', subset='last 3 months', TA=NULL)
addMACD()
# Dodawanie sygnałów na wykresie
addTA(amrest_xts_short$buy_signal, col='green', type='p', pch=24, cex=1.5, on=1)
addTA(amrest_xts_short$sell_signal, col='red', type='p', pch=25, cex=1.5, on=1)
# Dodanie pogrubionego tytułu
mtext("Amrest - MACD Strategy", side=3, line=0.9, cex=1.25, font=2)
# Wykres z Simple Moving Average
chartSeries(amrest_xts_short, theme='white', TA="addSMA()", subset='last 3 months')
mtext("Amrest - SMA", side=3, line=0.9, cex=1.25, font=2)
</code>
<code># Pobieranie danych
filename <- "https://stooq.pl/q/d/l/?s=eat&d1=20190101&d2=202312310&i=d"
amrest <- read.csv(filename)
# Konwersja daty
amrest$Data <- as.Date(amrest$Data)
# Sortowanie danych po dacie
amrest <- amrest[order(amrest$Data),]
# Wybieranie odpowiednich kolumn (bez wolumenu)
amrest <- amrest[,c(1:5)]
colnames(amrest) <- c("Date", "Open", "High", "Low", "Close")
# Zmiana na format xts
amrest_xts <- xts(amrest[,-1], order.by = amrest$Date)
# Sprawdzanie, czy xts jest prawidłowo utworzony
print(head(amrest_xts))
print(tail(amrest_xts))
# Obliczanie MACD
macd_data <- MACD(Cl(amrest_xts), nFast=12, nSlow=26, nSig=9, maType="EMA")
# Sprawdzanie, czy MACD został poprawnie obliczony
print(head(macd_data))
print(tail(macd_data))
# Łączenie danych z MACD
amrest_xts <- merge(amrest_xts, macd_data)
# Generowanie sygnałów kupna i sprzedaży
signal <- Lag(ifelse(amrest_xts$macd > amrest_xts$signal, 1, -1))
signal[is.na(signal)] <- 0
# Sygnały kupna i sprzedaży na przecięciach
buy_signal <- ifelse(signal == 1 & Lag(signal) == -1, 1, 0)
sell_signal <- ifelse(signal == -1 & Lag(signal) == 1, 1, 0)
# Dodawanie sygnałów do danych xts
amrest_xts$buy_signal <- buy_signal
amrest_xts$sell_signal <- sell_signal
# Wybieranie ostatnich 100 obserwacji do wykresu świecowego
amrest_xts_short <- tail(amrest_xts, 100)
# Wykres świecowy z zaznaczonymi sygnałami
candleChart(amrest_xts_short, multi.col=TRUE, theme='white', subset='last 3 months', TA=NULL)
addMACD()
# Dodawanie sygnałów na wykresie
addTA(amrest_xts_short$buy_signal, col='green', type='p', pch=24, cex=1.5, on=1)
addTA(amrest_xts_short$sell_signal, col='red', type='p', pch=25, cex=1.5, on=1)
# Dodanie pogrubionego tytułu
mtext("Amrest - MACD Strategy", side=3, line=0.9, cex=1.25, font=2)
# Wykres z Simple Moving Average
chartSeries(amrest_xts_short, theme='white', TA="addSMA()", subset='last 3 months')
mtext("Amrest - SMA", side=3, line=0.9, cex=1.25, font=2)
</code>
# Pobieranie danych
filename <- "https://stooq.pl/q/d/l/?s=eat&d1=20190101&d2=202312310&i=d"
amrest <- read.csv(filename)
# Konwersja daty
amrest$Data <- as.Date(amrest$Data)
# Sortowanie danych po dacie
amrest <- amrest[order(amrest$Data),]
# Wybieranie odpowiednich kolumn (bez wolumenu)
amrest <- amrest[,c(1:5)]
colnames(amrest) <- c("Date", "Open", "High", "Low", "Close")
# Zmiana na format xts
amrest_xts <- xts(amrest[,-1], order.by = amrest$Date)
# Sprawdzanie, czy xts jest prawidłowo utworzony
print(head(amrest_xts))
print(tail(amrest_xts))
# Obliczanie MACD
macd_data <- MACD(Cl(amrest_xts), nFast=12, nSlow=26, nSig=9, maType="EMA")
# Sprawdzanie, czy MACD został poprawnie obliczony
print(head(macd_data))
print(tail(macd_data))
# Łączenie danych z MACD
amrest_xts <- merge(amrest_xts, macd_data)
# Generowanie sygnałów kupna i sprzedaży
signal <- Lag(ifelse(amrest_xts$macd > amrest_xts$signal, 1, -1))
signal[is.na(signal)] <- 0
# Sygnały kupna i sprzedaży na przecięciach
buy_signal <- ifelse(signal == 1 & Lag(signal) == -1, 1, 0)
sell_signal <- ifelse(signal == -1 & Lag(signal) == 1, 1, 0)
# Dodawanie sygnałów do danych xts
amrest_xts$buy_signal <- buy_signal
amrest_xts$sell_signal <- sell_signal
# Wybieranie ostatnich 100 obserwacji do wykresu świecowego
amrest_xts_short <- tail(amrest_xts, 100)
# Wykres świecowy z zaznaczonymi sygnałami
candleChart(amrest_xts_short, multi.col=TRUE, theme='white', subset='last 3 months', TA=NULL)
addMACD()
# Dodawanie sygnałów na wykresie
addTA(amrest_xts_short$buy_signal, col='green', type='p', pch=24, cex=1.5, on=1)
addTA(amrest_xts_short$sell_signal, col='red', type='p', pch=25, cex=1.5, on=1)
# Dodanie pogrubionego tytułu
mtext("Amrest - MACD Strategy", side=3, line=0.9, cex=1.25, font=2)
# Wykres z Simple Moving Average
chartSeries(amrest_xts_short, theme='white', TA="addSMA()", subset='last 3 months')
mtext("Amrest - SMA", side=3, line=0.9, cex=1.25, font=2)
The error is
<code>Error in seq.default(x@yrange[1], x@yrange[2], length.out = length(x.range)) :
'from' must be a finite number
In addition: Warning messages:
1: In min(x[, 1]) : no non-missing arguments to min; returning Inf
2: In max(x[, 1]) : no non-missing arguments to max; returning -Inf
3: In periodicity(x) : can not calculate periodicity of empty object
4: In periodicity(x) : can not calculate periodicity of empty object
5: In min(x) : no non-missing arguments to min; returning Inf
6: In max(x) : no non-missing arguments to max; returning -In
</code>
<code>Error in seq.default(x@yrange[1], x@yrange[2], length.out = length(x.range)) :
'from' must be a finite number
In addition: Warning messages:
1: In min(x[, 1]) : no non-missing arguments to min; returning Inf
2: In max(x[, 1]) : no non-missing arguments to max; returning -Inf
3: In periodicity(x) : can not calculate periodicity of empty object
4: In periodicity(x) : can not calculate periodicity of empty object
5: In min(x) : no non-missing arguments to min; returning Inf
6: In max(x) : no non-missing arguments to max; returning -In
</code>
Error in seq.default(x@yrange[1], x@yrange[2], length.out = length(x.range)) :
'from' must be a finite number
In addition: Warning messages:
1: In min(x[, 1]) : no non-missing arguments to min; returning Inf
2: In max(x[, 1]) : no non-missing arguments to max; returning -Inf
3: In periodicity(x) : can not calculate periodicity of empty object
4: In periodicity(x) : can not calculate periodicity of empty object
5: In min(x) : no non-missing arguments to min; returning Inf
6: In max(x) : no non-missing arguments to max; returning -In
It is for my project. Actually I study finance and economy, however I have a subject of R coding for the Stock Market analyzing. The task was to analyze the Stock market ticket “Amrest” (Polish market) with MACD (Moving Average Convergence Divergence). I was trying that code generating by AI Chat-GPT3.5, and it was failed.
New contributor
Edward Almanov is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.