Sunday, 17 February 2019

We will add the Bollinger Bands using the add BBands

BBands command and the MACD trend
we will add the Bollinger Bands using the addBBands() command and the MACD trend-following momentum indicator using the addMACD() command to get more insights on the stock price evolution.
 library(Quandl)
> library(xts)
> currencies <- c( "USD", "CHF", "GBP", "JPY", "RUB", "CAD", "AUD")
> currencies <- paste("CURRFX/EUR", currencies, sep = "")
> currency_ts <- lapply(as.list(currencies), Quandl, start_date="2005-01-
+ 01",end_date="2013-06-07", type="xts")
Error in charToDate(x) :
  character string is not in a standard unambiguous format
> currency_ts <- lapply(as.list(currencies), Quandl, start_date="2005-01-
+ 01",end_date="2013-06-07", type="xts")
Error in charToDate(x) :
  character string is not in a standard unambiguous format
> Q <- cbind(
+     currency_ts[[1]]$Rate,currency_ts[[3]]$Rate,currency_
+     ts[[6]]$Rate,currency_ts[[7]]$Rate)
Error: unexpected symbol in:
"    currency_ts[[1]]$Rate,currency_ts[[3]]$Rate,currency_
    ts"
> matplot(Q, type = "l", xlab = "", ylab = "", main = "USD, GBP, CAD, AUD",
+         xaxt = 'n', yaxt = 'n')
Error in matplot(Q, type = "l", xlab = "", ylab = "", main = "USD, GBP, CAD, AUD",  :
  object 'Q' not found
> library(quantmod)
[1] "BMW.DE"
> BMW<-bmw_stock$BMW.DE
> head(BMW)
           BMW.DE.Open BMW.DE.High BMW.DE.Low
2010-01-04      31.820      32.455     31.820
2010-01-05      31.960      32.410     31.785
2010-01-06      32.450      33.040     32.360
2010-01-07      32.650      33.200     32.380
2010-01-08      33.335      33.430     32.515
2010-01-11      32.995      33.050     32.110
           BMW.DE.Close BMW.DE.Volume BMW.DE.Adjusted
2010-01-04       32.050       1808170        24.15409
2010-01-05       32.310       1564182        24.35004
2010-01-06       32.810       2218604        24.72685
2010-01-07       33.100       2026145        24.94541
2010-01-08       32.655       1925894        24.61004
2010-01-11       32.170       2157825        24.24452
> chartSeries(BMW,multi.col=TRUE,theme="white")
> addMACD()
> addBBands()
> BMW_return <-
+     log(BMW$BMW.DE.Close/BMW$BMW.DE.Open)
> qqnorm(BMW_return, main = "Normal Q-Q Plot of BMW daily log return",
+        xlab = "Theoretical Quantiles",
+        ylab = "Sample Quantiles", plot.it = TRUE, datax = FALSE
+ )
> qqline(BMW_return, col="red")
> getSymbols("BMW.DE", env = bmw_stock, src = "yahoo", from =
+                as.Date("2014-01-01"), to = as.Date("2018-12-31"))
[1] "BMW.DE"
> BMW<-bmw_stock$BMW.DE
> head(BMW)
           BMW.DE.Open BMW.DE.High BMW.DE.Low
2014-01-02       85.90       86.10      83.38
2014-01-03       83.63       84.51      83.35
2014-01-06       84.00       84.53      82.87
2014-01-07       83.10       84.01      82.41
2014-01-08       83.82       84.66      83.73
2014-01-09       84.13       85.13      83.54
           BMW.DE.Close BMW.DE.Volume BMW.DE.Adjusted
2014-01-02        83.54       1499492        69.45904
2014-01-03        83.98        826285        69.82488
2014-01-06        82.99        987242        69.00174
2014-01-07        83.55       1231698        69.46736
2014-01-08        84.45       1435898        70.21566
2014-01-09        83.86       1297442        69.72510
> chartSeries(BMW,multi.col=TRUE,theme="white")
> addMACD()
> addBBands()

No comments:

Post a comment

Intersection of subring

How to prove the intersection of two subrings is a subring? Let S1 and S2  be two subrings of a ring R. Then S1∩S2 is not empty since ...