I'm taking a university module in programming next year and I have been advised to complete a RStudio exercise sheet to help me prepare for the course. There are 5 questions on the sheet and I have attempted an answer at all of them, but I can't seem to get in contact with my programming lecturer to see if my code is correct, so I would appreciate it if anyone can tell me if what I have done is correct and if they would advise any changes.
Here are my attempts, please let me know if they are correct or need any changing.
Q1) findW <- function(N){1/sum(1:N)}
Q2) emaWeights <- function(N){(1:N)/sum(1:N)}
Q3) upperBand <- function(N,t,clo){emaWeights(N) %*% clo[(t-1):(t-N)] + 2*sd((clo[(t-N):(t-1)]))
Q4) bollingerUpper <- function(N,t1,t2,clo){sapply(t <- t1:t2, function(t) upperBand(N,t,clo))}
Q5) same as 3 and 4 but with bollingLower and lowerBand instead.
I know you guys don't have the dataset, but I just want to know if this code does what the question asks (I'm not really that familiar with Bollinger bands so I don't know exactly what they're supposed to do). Sorry if this question seems a bit basic - I'm quite new to programming and RStudio.
Any help would be much appreciated!
Aucun commentaire:
Enregistrer un commentaire