Académique Documents
Professionnel Documents
Culture Documents
Dataframe
dfteam <- data.frame(Age, Height, Weight, Sex, row.names = Noms)
dfteam[ 1:4 , ] #faire apparaître ligne 1 à 4 d’un dataframe ou:
dfteam[ c("Alex","Lilly", "Marc", "Olivier")] ou dfteam[ , c("Age", "Height", "Weight") ]
dfteam[Age,]
#Ajouter Colonne ou ligne
membre1 <- data.frame (Age=36, Height=158, Weight=47, Sex="F", row.names="Claire")
dfteam <- rbind(dfteam, membre1) # ou cbind pour les lignes
dfteam[, "Working" ] <- c("YES","NO","NO", "YES", "YES", "NO", "YES", "NO")
dfteam$WORKINGBIS <- c("YES","NO","NO", "YES", "YES", "NO", "YES", "NO")
Matrix
M<- matrix(data=c(-1,8,2,6,-9,12,-9,-5,1),byrow= T, ncol = 3) “byrow=booléen à TRUE pour
#signaler que les coefficients sont alignés en lignes
# créer la matrice N de taille 4x4 de coefficients a(i,j)=100/(i+j)
a<-function(i,j){100/(i+j)}
N<-outer(1:4, 1:4, a)
det(N)
P<-solve(N) #inverse matrice
P%*%N
# Remplacer tous les coefficients de D dont la valeur absolue est inférieure à 1e-10 par 0
D[abs(D)<1e-10]<-0
mean(Q[1,])
M[1,]
n<-nrow(M)
# créer un vecteur ligne U avec 3 fois 1
U<- matrix(data=c(1,1,1), nrow=3)
I<-diag(rep(1,3))
A<- I- 1/n*U%*%t(U)
# calculer P la matrice centrée en colonnes de M par l'opération Q = A x M
Q <- A%*%M
Suite et For
Farenheit <- function ( Celcius) { Celcius*1.8 + 32 }
tempF <- Farenheit(Celcius = temp) #input du vecteur temps dans un autre vecteur pour créer un
vecteur tempsF
mbf<-function(x) {(exp(x)+exp(-x))/2}
mbf(x=0)
v7<-mbf(x=u)
Liste
lj <- list()
for (i in 0:6 ) { lj[[ jr[i+1] ]] <- jr[ ( 0 : 6 + i ) %% 7 + 1] }
finmois <- c(31 , 28 , 31, 30 , 31 , 30, 31, 31, 30 , 31, 30, 31)
numj <- NULL
for(i in finmois) { numj <- c(numj, 1:i ) }
Conditions
if (t>10){ x<-x+2 y<-10} else if (5<=t & t<10){ x<-x+1 y<-5 }else { x<-x-1 y<-3}
while (s <= n)
s <- s + d[s]
# ggplot() +
ggplot()+ # trait X Y titre trait transparance
geom_line(mapping=aes(x=1:20,y=vf1, colour="suite générale" , size=2) , alpha= 0.3)+
geom_line(mapping=aes(x=1:20,y=vr , colour="suite récurrente" , size=3) , alpha= 0.3)+
geom_smooth((mapping=aes(x=1:20,y=vr , colour="suite récurrente" , size=3) , alpha= 0.3)+
scale_color_manual(values= c("red", "blue") )+ #couleurs des traits
theme_minimal()+ #arrière plan vide
scale_y_log10()+ #échelle logarithmique
xlab("titre des X") + ylab("Titre Y")
plot(1:T,S,pch="+")
qplot(x=1:12, y=temp,geom="line")+labs(title="2014 de
Montsouris",x="Mois",y="T°")+scale_x_discrete(limits=nommois)
plot(), boxplot(), barplot(), hist(), curve()
Proba
pbinom(3, 10, 0.3) renvoie P(Y 6 3) avec Y comme dans l’item précédent.
qbinom(0.6,10,0.3) renvoie le plus petit entier k tel que P(Y 6 k) > 0, 6.
runif(10,0,20) renvoie 10 valeurs tirées selon la loi uniforme sur l’intervalle [0; 20].
pnorm(3) renvoie P(Z 6 3) ou` Z suit une N (0; 1). On peut également taper
pnorm(3,mean=0,sd=1) ou pnorm(3,0,1) ou encore pnorm(q=3,mean=0,sd=1)
# ******************************************
# Processus autoregressif oscillant AR(p=4)
#
# Première partie
# ******************************************
# Un processus autorégressif d'ordre p,noté AR(p), est une suite définie par récurrence :
# X[n] = f1.X[n-1] + f2.X[n-2] + ... + fp.X[n-p]
# où f1,...,fp sont des nombres réels appelés les paramètres du processus
# Le terme processus désigne simplement que le rang n représente une dimension temporelle
# Un processus est oscillant son polynome caractéristique a toute ses racines de module égal à
1
# Nous allons calculer et tracer des processus oscillants
# **********************************************
# Familiarisation avec l'aléatoire
# **********************************************
library(polynom)
Q1 <- polynomial(coef = c(1,-2*rc1, 1) )
Q1
Q3 <- polynomial(coef = c( 1 , -2*rc3 , 1) ) # puissance croissante
Q3
Q <- Q1 * Q3
Q
polyroot(Q)
vf <- coef( -Q )
vf
vf <- vf[-1]
vf
# ******************************************************************
# Simulation de X1 à X100
# du processus de paramètre vf
# X[n] = vf[1].X[n-1] + vf[2].X[n-2] + vf[3].X[n-3] + vf[4].X[n-4]
# ******************************************************************
vX <- runif(p, 0, 1)
vX
for (n in (p+1):100 ){
vX[n] <- vf[1]*vX[n-1] + vf[2]*vX[n-2] + vf[3]*vX[n-3] + vf[4]*vX[n-4]
}
library(ggplot2)
ggplot()+
geom_line(mapping = aes(x=1:100,y=vX ))+
labs( title="Suite AR(p=4)" , x="n", y="X")
#**********************************************
# Tracé 20 trajectoires de X[1] ... X[100]
# - avec les même paramètres vf
# - mais pour des valeurs initiales aléatoires
#**********************************************
# Ces 20 trajectoires vont être écrites dans les 20 colonnes d'une même matrice
(for k in 1;20) {
sample
for (k in 1:20) {
vX <- runif(p, 0, 1)
for (n in (p + 1):100) {
vX[n] <-
vf[1] * vX[n - 1] + vf[2] * vX[n - 2] + vf[3] * vX[n - 3] + vf[4] * vX[n -4]
}
mX[, k] <- vX
}
ggplot()+
geom_line(mapping = aes(x=1:100, y=dfX$T1, colour="T1"))+
geom_line(mapping = aes(x=1:100, y=dfX$T2, colour="T2"))
ggplot()+
geom_line(mapping=aes(x=1:100, y=dfX,colour = “T1”,))+
# **********************************************************************
# Tracer de T1 .. T20 par sérialisation
# Il s'agit de tracer les 20 trajectiors simultanémeent
# par une seule commande geom_line()
# Pour cela les trajectoires vont devoir être compilées en série sur une dataframe
# avec 3 champs : n, X[n], Légende
# Le dataframe sérialisé aura cette forne :
# n | Xn | Légende
# -------------------------
# 1 | X1 | T1
# 2 | X2 | T1
# ...
# 100 | X100 | T1
# 1 | X1 | T2
# 2 | X2 | T2
# ...
# 100 | X100 | T2
# ...
# 1 | X1 | T20
# 2 | X2 | T20
# ...
# 100 | X100 | T20
# **********************************************************************
vXS
# ---- Question 23 ----
# Créer la dataframe dfXS qui réunit les 3 vecteurs vNS, vXS et vLegendeS
ggplot()+
geom_line(mapping = aes(x=dfXS$vNS, y=dfXS$vXS, colour=dfXS$vLegendeS))+
labs(x="Temps", y="Valeur")
TP1
Simul1.R
Simul2.R
# Générateur pseudo-aléatoire uniforme
# Algorithme de Winchman-Hill, la méthode congruentielle
x <- c(3)
y <- c(23)
z <- c(53)
# partie décimale
for (i in 2:1000) {
x[i] <- (171* x[i-1]) %% 30269
y[i] <- (172* y[i-1]) %% 30307
z[i] <- (170* z[i-1]) %% 30323
}
ks.test(u, "punif")
Simul3.R
# Annuelle
v <- 0.1
r <- 0.15
# Maturité
M <- 151
# Exercice (Strike)
K <- 202
j1 <- as.Date("2021/01/01")
j2 <- as.Date("2021/06/01")
T <- as.integer(difftime(j2,j1,units = c("days")))
S0 <- 200
S <- c(S0 * (1 + r * 1/365.25 + v * rnorm(1,0, sqrt(1/365.25))) )
for (t in 2:T) {
S[t] <- S[t-1] * (1 + r * 1/365.25 + v * rnorm(1,0, sqrt(1/365.25)))
}
# bénéfice
payoff <- max(c(S[T]-K,0))
# actualisé
payoffA <- payoff / exp(r*T/365.25)
plot(1:T,S,pch="+")
# S + A : antithétique
for (t in 2:T) {
vol <- rnorm(1,0, sqrt(1/365.25))
S[t] <- S[t-1] * (1 + r * 1/365.25 + v * vol)
A[t] <- A[t-1] * (1 + r * 1/365.25 - v * vol)
}
# bénéfice S
payoff <- max(c(S[T]-K,0))
# actualisé
payoffA <- payoff / exp(r*T/365.25)
result <- c(result, payoffA)
# bénéfice A
payoff <- max(c(A[T]-K,0))
# actualisé
payoffA <- payoff / exp(r*T/365.25)
result <- c(result, payoffA)
}
mean(result)
Simul4.R
df <- read.csv(file = "titre.csv", sep=";", dec=",")
df
#H <- df*t(cf)
M <- as.matrix(df)
M
diag(cf)
H <- M%*%diag(cf)
H
head(H)
P <- rowSums(H)
P
#
mean(P)
sd(P)
e <- c()
v <- c()
for (i in 1:50000){
cf1 <- runif(3)
cf <- cf1/sum(cf1)
H <- M%*%diag(cf)
ch <- rowSums(H)
#
he<- max(sort(e)[-1]-sort(e)[-length(e)])*2
hv<- max(sort(v)[-1]-sort(v)[-length(v)])*2
for (i in 1:length(e)) {
nr <- intersect(which(abs(e-e[i])<he) , which(abs(v-v[i])<hv) )
er <- e[nr]
vr <- v[nr]
h <- which(er>e[i])
b <- which(er<e[i])
d <- which(vr>v[i])
g <- which(vr<v[i])
hd <- intersect(h,d)
if (length(hd) == 0) { next }
hg <- intersect(h,g)
if (length(hg) == 0) { next }
bd <- intersect(b,d)
if (length(bd) == 0) { next }
bg <- intersect(b,g)
if (length(bg) == 0) { next }
if ( length(hd)>0 & length(hg)>0 & length(bd)>0 & length(bg)>0) { retire <- c( retire, i) }
e <- e[-retire]
v <- v[-retire]
plot(v, e, pch = c("+"))
Simul5.R
# https://www.youtube.com/watch?v=lLzUcJf3E60
d <- rep(1:6,each=4)
names(d) <- rep(c("P","C","T","K"), 6)
d
n <- length(d)
x <- NULL
for (k in 1:10000) {
d <- sample(d)
# fixe, prédiction
s <- 1
while (s <= n)
s <- s + d[s]
f1 <- s-n #attention d[s] insuffisant alors paste0(names(d)[1], d[1])
# mais position OK car pas deux fois même carte
# random
s <- sample(1:6, size=1)
while (s <= n)
s <- s + d[s]
f <- s-n
# test à 93%
prop.test(x= sum(x), n= length(x) , p=0.93 , alternative="two.sided" )
TP2
# 1 - Maximisation et Surface 3D
# la fonction 2 arg
f <- function (x,y) { (5-x**2 -x) + (2-y**2-y/2) }
f(x=1,y=2)
f(x=0,y=0)
# la fonction vectorielle
fvect <- function (v) {
x<- v[1]
y<- v[2]
return ( (5-x**2 -x) + (2-y**2-y/2) )
}
str(fvect)
fvect( v= c( 1, 2) )
fvect( v=c( 0, 0 ) )
g<- plot_ly(x=Mx,y=My,z=Mz)
add_surface(g)
# Maximum
# TP Modèle Linéaire
# source : http://www.sthda.com/english/articles/40-regression-analysis/168-multiple-linear-
regression-in-r/
library(datarium)
# classe formula
# trop gros
str(modele)
# p-value = 4e colonne, conserver les coeff significatifs (si p-value(x) > 5%, on peut
considérer que Beta(x) est nul et que la variable n'est pas signifiactive dans le modèle)
# afficher les noms des variables significatives autres que '(intercept)'
resume$coefficient[,4]<0.05
# nouvelle regression
# coeff détermination
resume2$r.squared
# analyse coeff
resume2$coefficients
# Prediction automatique
dfVar <- data.frame(youtube=c(1500), facebook=c(1000))
dfVar
model1 <- lm( formula = sales ~ youtube + facebook , data = marketing, method="qr")
# Prediction Manuelle
# Vecteur des coefficients
# Une société investit 1500$ dans youtube et 2300$ dans facebook, estimer ses ventes
vBeta <-modele2$coefficients
vBeta
# Coefficients et prédiction
# sales = c0 + c1*(youtube + facebook + newspaper)
f4 <- sales ~ I(youtube + facebook + newspaper)
f4
# coeff détermination
resume4$r.squared
# analyse coeff
resume4$coefficients
# Prediction
# Une société investit 1500$ dans youtube et 1000$ dans facebook et 0$ en newspaper, estimer
ses ventes
vBeta2 <-modele4$coefficients
vBeta2
nrow(X)
Y <- as.matrix(marketing$sales)
# (tXX)-1 tX.Y
b<- solve(t(X)%*%X)%*%t(X)%*%Y
b
# Credit Scoring
# scoringtools
# https://cran.r-project.org/web/packages/scoringTools/index.html
# Demo : https://cran.r-project.org/web/packages/scoringTools/vignettes/scoringTools.html
# Package et Dataframe
library(scoringTools)
str(lendingClub)
# Combien de lignes ?
nrow(lendingClub)
fnum1(v=23)
fnum1(v="MBF")
fnum1(v=lendingClub2)
# vectorisée
fnum <- Vectorize(fnum1, "v")
# Regression généralisée
# Sigmoide
sig <- function (x) exp(x)/(1+exp(x))
# Logit
lgt <- function (x) log(x/(1-x))
sig(lgt(0.8))
varScore[varScore[,4]<0.30 , ]
summary(modelScore2)
# Prediction de remboursement
dfVar2 <- data.frame(Amount_Requested = c(1500) , Debt_To_Income_Ratio=c(15),
Monthly_Income=c(4000), Employment_Length=c(8))
dfVar2
# Prédiction Manuelle
# Coefficients
vCoef <- modelScore2$coefficients
vCoef
vVar <- c(Intercept=1, Amount_Requested = 1500 , Debt_To_Income_Ratio=15, Monthly_Income=4000,
Employment_Length=8)
vVar
pLinManu <- vCoef %*% vVar
pLinManu
predProbaManu <- sig(pLinManu)
predProbaManu
# Fonction de Scoring
fPred <- function ( Amount_Requested , Debt_To_Income_Ratio, Monthly_Income,
Employment_Length)
{
pLin <- vCoef %*% c(1, Amount_Requested , Debt_To_Income_Ratio, Monthly_Income,
Employment_Length)
pProb <- as.numeric(sig(pLin))
return(pProb)
}
fPred(Amount_Requested = 1500 , Debt_To_Income_Ratio=15, Monthly_Income=4000,
Employment_Length=8)
plot(x=seq(1500,40000,1000),y=fPred2(Amount_Requested = seq(1500,40000,1000) ,
Debt_To_Income_Ratio=15, Monthly_Income=4000, Employment_Length=8), type="line")
log(vsb)
log(d*f+(1-d)*(1-f))
# client n°11
fLogV(vBeta = vCoef, Default=1, Amount_Requested=30000 , Debt_To_Income_Ratio=16.67,
Monthly_Income=12500, Employment_Length=12.47397)
sommeLogV<- function(vB)
{
return (sum(fLogVV(vBeta=vB, Default =lendingNum$Default, Amount_Requested =
lendingNum$Amount_Requested , Debt_To_Income_Ratio=lendingNum$Debt_To_Income_Ratio,
Monthly_Income=lendingNum$Monthly_Income, Employment_Length=lendingNum$Employment_Length)))
}
sommeLogV(vB = vCoef)
# Optimisation
resultat <- optim(par=c(0,0,0,0,0),fn=sommeLogV,control=list(fnscale=-1))
str(resultat)
resultat$par
# Comparer à vCoef
vCoef
TP3
# Fonction vectorielle et non vectorielle
# Faire function et if
# Vectorize
f <- function (x) sort(c(x, -x, 0))
f(1)
# avec sapply
sapply(1:2, f) # une matrice
# quantmod
#install.packages("quantmod")
library(quantmod)
tsAAPL <- getSymbols(Symbols="AAPL", env=NULL, from = '2021-01-01' , to = Sys.Date() ,
periodicity = "daily")
str(tsAAPL)
names(tsAAPL)
# date
dt <- index(tsAAPL)
dt
# https://www.r-bloggers.com/2018/06/customizing-time-and-date-scales-in-ggplot2/
ggplot()+
geom_line(mapping=aes(x=dt, y=vaC))+
scale_x_date(date_labels = "%d %b %Y")
plot(tsAAPL$AAPL.Close)
ggplot()+
geom_line(mapping=aes(x=dt, y=vaC))
# Calculer SMA
sma1<-function(v,t, period)
{
if (t<period) return(NA)
else return(mean(v[(t-period+1):t]))
}
sma1<-function(X,t, n) mean(X[max(1,(t-n+1)):t])
sma1(X=vaC, t=100,n=20)
sma1(X=vaC, t=10,n=20)
sma1(X=vaC, t=1,n=20)
# Calculer SMD (deviation)
smd1<-function(X,t, n) sd(X[max(1,(t-n+1)):t])
smd1(X=vaC, t=100,n=20)
smd1(X=vaC, t=10,n=20)
smd1(X=vaC, t=2,n=20)
ggplot()+
geom_candlestick(aes(x=dt, open = vaO, high = vaH, low = vaL, close = vaC))+
geom_line(aes(x=dt, y=vsma, color="X"))+
scale_x_date(date_labels = "%d %b %Y")+
scale_color_manual(values=c("X"="red"))
# tracé
# tidyquant : https://business-science.github.io/tidyquant/reference/geom_chart.html
#install.packages("tidyquant")
library(tidyquant)
ggplot()+
geom_candlestick(aes(x=dt, open = vaO, high = vaH, low = vaL, close = vaC))+
scale_x_date(date_labels = "%d %b %Y")
# Color : http://www.stat.columbia.edu/~tzheng/files/Rcolor.pdf
ggplot()+
geom_candlestick(aes(x=dt, open = vaO, high = vaH, low = vaL, close = vaC))+
geom_line(mapping=aes(x=dt, y=vsma, colour="X"))+
geom_line(mapping=aes(x=dt, y=vaA1, colour="A1"))+
geom_line(mapping=aes(x=dt, y=vaA2, colour="A2"))+
geom_line(mapping=aes(x=dt, y=vaB1, colour="B1"))+
geom_line(mapping=aes(x=dt, y=vaB2, colour="B2"))+
scale_x_date(date_labels = "%d %b %Y")+
scale_color_manual(values=c("A1"="cyan", "B1"="orange", "X"="red","B2"="orange",
"A2"="cyan"))
ggplot()+
geom_candlestick(aes(x=dt, open = vaO, high = vaH, low = vaL, close = vaC))+
geom_line(mapping=aes(x=dt, y=vsma, colour="X"))+
geom_line(mapping=aes(x=dt, y=vaA1, colour="A1"))+
geom_line(mapping=aes(x=dt, y=vaA2, colour="A2"))+
geom_line(mapping=aes(x=dt, y=vaB1, colour="B1"))+
geom_line(mapping=aes(x=dt, y=vaB2, colour="B2"))+
geom_ribbon(mapping = aes(x=dt, ymin=vaA2,ymax=vaB2), fill="gold", alpha=0.5)+
geom_ribbon(mapping = aes(x=dt, ymin=vaB2,ymax=vaB1), fill="darkgrey", alpha=0.5)+
geom_ribbon(mapping = aes(x=dt, ymin=vaB1,ymax=vaA1), fill="forestgreen", alpha=0.5)+
scale_x_date(date_labels = "%d %b %Y")+
scale_color_manual(values=c("A1"="cyan", "B1"="orange", "X"="red","B2"="orange",
"A2"="cyan"))
# Stratégie de "Double Bande Bollinger Day Trading"
K<-c()
S<-c()
tx <- 85/100
for (t in 2:length(vaC))
{
if (vaC[t]>vaB1[t] & vaC[t]<vaA1[t]) #achats
{
S[t] <- S[t-1] + K[t-1]*tx/vaC[t]
K[t] <- K[t-1]*(1-tx)
}
else if (vaC[t]>vaA2[t] & vaC[t]<vaB2[t]) #ventes
{
S[t] <- S[t-1]*(1-tx)
K[t] <- K[t-1] + S[t-1]*tx*vaC[t]
}
else
{
S[t] <- S[t-1]
K[t] <- K[t-1]
}
}
T<- K + S*vaC
library(gridExtra)
plot1 <- ggplot()+
geom_line(mapping=aes(x=dt, y=S, colour="S"))
for (t in 2:length(vaC))
{
if (vaC[t]>vaB1[t] & vaC[t]<vaA1[t]) #achats
{
S[t] <- S[t-1] + K[t-1]*tx/vaC[t]
K[t] <- K[t-1]*(1-tx)
}
else if (vaC[t]>vaA2[t] & vaC[t]<vaB2[t]) #ventes
{
S[t] <- S[t-1]*(1-tx)
K[t] <- K[t-1] + S[t-1]*tx*vaC[t]
}
else
{
S[t] <- S[t-1]
K[t] <- K[t-1]
}
}
T<- K + S*vaC
return ((T[length(vaC)]-T[1])/T[1])
}
rdtF(tx=0.05)
rdtF(tx=0.95)
rdtv<- rdtFv(tx=txv)
ggplot()+
geom_line(mapping= aes(x=txv,y=rdtv))+
geom_hline(yintercept=rdta, color="red")
# Calculer EMA
#
t <- 100
period <- 20
alpha <- 2/(period+1)
weight <- (1-alpha)**(0:(period-1))
ema <- alpha*sum(vaC[t:(t-period+1)]*weight)
ema
ema1<-function(v,t, period)
{
if (t<period) return(NA)
else
{
alpha <- 2/(period+1)
weight <- (1-alpha)**(0:(period-1))
# return( alpha*sum(vaC[(t-period+1):t]*weight) )
return( sum(v[t:(t-period+1)]*weight)/sum(weight) ) # version tronquée moyenne pondérée
}
}
ema1<-function(X,t, n)
{
n<- min(n,t)
alpha <- 2/(n+1)
weight <- (1-alpha)**(0:(n-1))
return( sum(X[t:(t-period+1)]*weight)/sum(weight) ) # version tronquée moyenne pondérée
}
# ou bien sapply
vema <- sapply(1:length(vaC), function(t) ema1(v=vaC, t, period=20 ))
vema
# tracé
ggplot()+
geom_candlestick(aes(x=dt, open = vaO, high = vaH, low = vaL, close = vaC))+
geom_line(mapping=aes(x=dt, y=vsma, colour="SMA 20"))+
geom_line(mapping=aes(x=dt, y=vema12, colour="EMA 12"))+
geom_line(mapping=aes(x=dt, y=vema26, colour="EMA 26")) +
scale_x_date(date_labels = "%d %b %Y")+
scale_color_manual(values=c("SMA 20"="red", "EMA 12"="orange", "EMA 26"="forestgreen"))
# MACD
# EMA 12period - EMA 26period
macd <- function(v,t) ema(v,t, n=12)-ema(v,t, n=26)
vmacd <- macd(vaC, 1:length(vaC))
# tracé
ggplot()+
geom_line(mapping=aes(x=1:length(vaC), y=vaC, colour="APPL"))+
geom_line(mapping=aes(x=1:length(vaC), y=vsma, colour="APPL SMA"))+
geom_line(mapping=aes(x=1:length(vaC), y=vema, colour="APPL EMA"))
geom_line(mapping=aes(x=1:length(vaC), y=vmacd, colour="APPL MACD"))
# tracé séparé
#install.packages("gridExtra")
#library(gridExtra)
plot1 <- ggplot()+
geom_candlestick(aes(x=dt, open = vaO, high = vaH, low = vaL, close = vaC))+
geom_line(mapping=aes(x=dt, y=vsma, colour="SMA 20"))+
geom_line(mapping=aes(x=dt, y=vema12, colour="EMA 12"))+
geom_line(mapping=aes(x=dt, y=vema26, colour="EMA 26")) +
scale_x_date(date_labels = "%d %b %Y")+
scale_color_manual(values=c("SMA 20"="red", "EMA 12"="orange", "EMA 26"="forestgreen"))
TP4
GrapheBollinger.R
### MODELE ###
source("modele.R")
#gbollinger(ticker = "TTE", debut= as.Date("2022-05-01") , fin = as.Date("2022-11-01"), macd=F,
bbands=T)
### UI ###
library(shiny)
# DropDown list
selectInput(inputId = "ticker",
label = "Ticker :",
choices = c("AAPL", "GOOG", "MC", "TTE"),
),
),
)
)
)
Modele.R
# fonction de graphique
library("quantmod")
barChart(ts, theme="white")
if (bbands == T){
plot(addBBands())
}
if (macd == T){
plot(addMACD())
}
}