Comments (4)
Thanks! I just noticed that you're checking whether two numbers are exactly equal (x[1] != x[2]
). That's subject to floating point precision error (see FAQ 7.31). Use this instead:
num_diff <- function(x) { abs(diff(x)) > sqrt(.Machine$double.eps) }
(last_row_from_window500)[apply(TwolastRows, 2, num_diff)]
Once you do that, very few of the final indicator values are different. Here are the results using all 40-ish indicators:
print(diffs <- last_row_from_window500[apply(TwolastRows, 2, num_diff)])
## ADX.ADX chaikinAD obv SMI.SMI SMI.signal williamsAD
## 1999-12-31 23:59:59 35.06024 -4886.041 -2129 -55.81354 -49.64856 -1.43
TwolastRows[, colnames(diffs)]
## ADX.ADX chaikinAD obv SMI.SMI SMI.signal williamsAD
## 1999-12-31 23:59:59 35.06024 -4886.041 -2129 -55.81354 -49.64856 -1.43
## 1999-12-31 23:59:591 35.06024 -2925.638 -124 -55.81354 -49.64856 -0.55
So it looks like only chaikinAD()
, OBV()
, and williamsAD()
are different. All 3 of those functions use the cumulative sum of the series, so it makes sense that they would be different depending on the start of the series. That's not something I can fix.
ADX and SMI look close and are probably just a bit smaller than floating point precision error.
from ttr.
Thank you! You are amazing!!
from ttr.
Your example has almost 40 indicators. Can you please provide a minimal example with the indicators you think have an issue?
Your comment says that the SMA()
result is different based on the number of observations in the window. That's extremely unlikely. Also note that recursive indicators like EMA()
and indicators that use them (e.g. RSI()
) are unlikely to have the same values for different window sizes. See the Warning section in ?TTR::MovingAverages
.
from ttr.
Your example has almost 40 indicators. Can you please provide a minimal example with the indicators you think have an issue?
Your comment says that the
SMA()
result is different based on the number of observations in the window. That's extremely unlikely. Also note that recursive indicators likeEMA()
and indicators that use them (e.g.RSI()
) are unlikely to have the same values for different window sizes. See the Warning section in?TTR::MovingAverages
.
Hi!
Here is a shorter example where all three indicators work differently on different windows
library(xts)
library(quantmod)
library(TTR)
n <- 100000
set.seed(1)
#######################################
######### make some prices ###########
#######################################
volume <- sample(1:10,n,replace = TRUE,prob = c(10:1))
prices <- round(cumsum(rnorm(n,sd = 0.01)),2)+1000
p <- cbind(price = prices, volume = volume) |>
xts(as.POSIXct("2000-01-01 00:00:00 EET")-n:1) |>
to.minutes(name = "my")
colnames(p) <- gsub("^my\\.", "", colnames(p))
############################################################
######### function for calculate all indicators ###########
############################################################
MINI_get_all_indicators <- function(p, n= 10){
CLOSE <- quantmod::Cl(p)
OHLC <- quantmod::OHLC(p)
HLC <- quantmod::HLC(p)
HL <- quantmod::HL(p)
VOLUME <- quantmod::Vo(p)
data.frame(
stoch = TTR::stoch(HLC = HLC, nFastK = n, nFastD = n, nSlowD = n*2),
TRIX = TTR::TRIX(price = CLOSE, n = n),
williamsAD = TTR::williamsAD(HLC = HLC)
)
}
############################################################
######### Making a comparison on different windows #########
############################################################
last_row_from_window500 <- tail(p,500) |> MINI_get_all_indicators(n = 10) |> tail(1)
last_row_from_window200 <- tail(p,200) |> MINI_get_all_indicators(n = 10) |> tail(1)
TwolastRows <- rbind.data.frame(last_row_from_window500,
last_row_from_window200)
#print(TwolastRows)
# Which indicators do not correspond to each other
colnames(last_row_from_window500)[ apply(TwolastRows,2, \(x) x[1]!=x[2]) ]
[1] "stoch.slowD" "TRIX.signal" "williamsAD"
from ttr.
Related Issues (20)
- "Series contains non-leading NAs" on stoch() HOT 8
- support TR calculations without Average HOT 2
- ERROR: package or namespace load failed for 'TTR' in dyn.load(file, DLLpath = DLLpath, ...): HOT 1
- Standardize leading NA checks in C code
- ALMA optimization HOT 2
- runSum produces leading NA when cumulative = TRUE HOT 2
- how can i buy and finish a operation in R? HOT 1
- Issue on nSig for TRIX HOT 2
- cumulative runSD returns all NA HOT 3
- runMean(..., cumulative = TRUE) doesn't account for leading NA in denominator
- Use R_forceSymbols(dll, TRUE) for native routines
- Add argument to EMA to prevent setting first n-1 obs to NA
- malloc(): invalid size (unsorted) HOT 8
- CTI doesn't pad non-xtsible inputs with NA
- The Symbol for Nano Labs Ltd (NASDAQ), NA, conflicts with NA in R HOT 6
- Change Readme to reflect that Fortran is no longer used HOT 1
- rolling trimmed mean HOT 7
- Add Fibonacci Retracements and Extensions
- support for integer64 type in runXXX functions HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ttr.