# get MSFT Data
msft <- getSymbols("MSFT", auto.assign = F)
head(msft)
## MSFT.Open MSFT.High MSFT.Low MSFT.Close MSFT.Volume MSFT.Adjusted
## 2007-01-03 29.91 30.25 29.40 29.86 76935100 21.57304
## 2007-01-04 29.70 29.97 29.44 29.81 45774500 21.53692
## 2007-01-05 29.63 29.75 29.45 29.64 44607200 21.41410
## 2007-01-08 29.65 30.10 29.53 29.93 50220200 21.62362
## 2007-01-09 30.00 30.18 29.73 29.96 44636600 21.64529
## 2007-01-10 29.80 29.89 29.43 29.66 55017400 21.42854
tail(msft)
## MSFT.Open MSFT.High MSFT.Low MSFT.Close MSFT.Volume MSFT.Adjusted
## 2023-04-04 287.23 290.45 285.67 287.18 25824300 287.18
## 2023-04-05 285.85 287.15 282.92 284.34 22064800 284.34
## 2023-04-06 283.21 292.08 282.03 291.60 29770300 291.60
## 2023-04-10 289.21 289.60 284.71 289.39 23103000 289.39
## 2023-04-11 285.75 285.98 281.64 282.83 27276600 282.83
## 2023-04-12 284.79 287.01 281.96 283.49 27373400 283.49
# Tesla Daily Returns
tsla <- getSymbols("TSLA", auto.assign = F)
tsla_daily_returns <- dailyReturn(tsla$TSLA.Adjusted)
head(tsla_daily_returns)
## daily.returns
## 2010-06-29 0.000000000
## 2010-06-30 -0.002511511
## 2010-07-01 -0.078472707
## 2010-07-02 -0.125683060
## 2010-07-06 -0.160937500
## 2010-07-07 -0.019243017
chartSeries(
msft,
# type : "auto", "candlesticks", "matchsticks", "bars","line"
type = "line",
subset = "2020",
theme = chartTheme("white")
)
chartSeries(
msft,
type = "bar",
subset = "2020",
theme = chartTheme("white")
)
chartSeries(
msft,
type = "candlesticks",
subset = "2020",
theme = chartTheme("white")
)
# Pour zoomer sur une période précise
chartSeries(
msft,
type = "auto",
subset = "2020-01-01::2020-04-01",
theme = chartTheme("white")
)
Bollinger Bands consist of a centerline and two price channels (bands) above and below it. The centerline is an exponential moving average; the price channels are the standard deviations of the stock being studied. The bands will expand and contract as the price action of an issue becomes volatile (expansion) or becomes bound into a tight trading pattern (contraction).
chartSeries(
msft,
subset = "2007",
# TA : a vector of technical indicators and params, or character strings
TA = "addBBands(n = 20, sd = 2)", # n=20 : moyenne mobile sur 20 jours, Simple Moving Average SMA
theme = chartTheme("white") # "black" aussi
)
n : number of moving average periods
sd : number of standard deviations
Voir documentation (?addBBands)
A Caption
chartSeries(
msft,
subset = "2007",
# TA : a vector of technical indicators and params, or character strings
TA = c(addBBands(n = 20, sd = 2), addRSI()),
theme = chartTheme("white")
)
# Pour 2020
chartSeries(
msft,
subset = "2020",
# TA : a vector of technical indicators and params, or character strings
TA = c(addBBands(n = 20, sd = 2), addRSI()),
theme = chartTheme("white")
)
A Caption
chartSeries(
msft,
subset = "2007",
# TA : a vector of technical indicators and params, or character strings
TA = c(addBBands(n = 20, sd = 2), addRSI(), addMACD()),
theme = chartTheme("white")
)
chartSeries(
msft,
subset = "2007",
# TA : a vector of technical indicators and params, or character strings
TA = c(addBBands(n = 20, sd = 2), addRSI(), addEMA(n = 30), addMACD()),
theme = chartTheme("white")
)
How is an EMA calculated?
use a weighted average that gives greater importance to more recent days to make it more responsive to new information.