1 stock data analysis in R with AAA using tidyquant R pkg

## [1] "D:/AZR_Proj/fiscal_finances"
## 
## Attaching package: 'pandoc'
## The following objects are masked from 'package:rmarkdown':
## 
##     pandoc_available, pandoc_convert, pandoc_version
## Loading required package: usethis
## 
## Attaching package: 'Hmisc'
## The following object is masked from 'package:plotly':
## 
##     subplot
## The following object is masked from 'package:quantmod':
## 
##     Lag
## The following objects are masked from 'package:dplyr':
## 
##     src, summarize
## The following objects are masked from 'package:base':
## 
##     format.pval, units
## 
## Attaching package: 'shinydashboard'
## The following object is masked from 'package:graphics':
## 
##     box
## 
## Attaching package: 'leaflet'
## The following object is masked from 'package:xts':
## 
##     addLegend
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ forcats 1.0.0     ✔ stringr 1.5.0
## ✔ purrr   1.0.1     ✔ tibble  3.2.1
## ✔ readr   2.1.4     ✔ tidyr   1.3.0
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ data.table::between() masks dplyr::between()
## ✖ tidyr::extract()      masks magrittr::extract()
## ✖ plotly::filter()      masks dplyr::filter(), stats::filter()
## ✖ xts::first()          masks data.table::first(), dplyr::first()
## ✖ lubridate::hour()     masks data.table::hour()
## ✖ lubridate::isoweek()  masks data.table::isoweek()
## ✖ dplyr::lag()          masks stats::lag()
## ✖ xts::last()           masks data.table::last(), dplyr::last()
## ✖ purrr::map()          masks maps::map()
## ✖ lubridate::mday()     masks data.table::mday()
## ✖ lubridate::minute()   masks data.table::minute()
## ✖ lubridate::month()    masks data.table::month()
## ✖ lubridate::quarter()  masks data.table::quarter()
## ✖ lubridate::second()   masks data.table::second()
## ✖ purrr::set_names()    masks magrittr::set_names()
## ✖ Hmisc::src()          masks dplyr::src()
## ✖ Hmisc::summarize()    masks dplyr::summarize()
## ✖ purrr::transpose()    masks data.table::transpose()
## ✖ lubridate::wday()     masks data.table::wday()
## ✖ lubridate::week()     masks data.table::week()
## ✖ lubridate::yday()     masks data.table::yday()
## ✖ lubridate::year()     masks data.table::year()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors

2 current date of data file

#todays date
td<- Sys.Date()
print(td)
## [1] "2023-06-13"

3 Stock prices function for stock ticker symbols

Shown below are the coding for the names of the various companies along with the stock ticker symbol.

The symbol R environment object is used in the tq_get() function from the tidyquant package. Symbols:

4 create dummy object of a blank data frame.

df_t<-c()
df_t<-data.frame()

assign the blank data frame the imported data from the tidy quant library for stock of interest. use tq_get() and tq_get_options() from tidyquant package to import Yahoo Finance stock data.

5 plots and graphs of stock data

5.1 variables of interest

library('rmarkdown')
library('tidyverse')
library('magrittr')
library('Hmisc')
library('ggplot2')
library('plotly')

par(mar=c(1,1,1,1))

#1923 
df_t<-data.frame()
df_t <- tq_get(x = c("DMH","BMWYY","MBGYY","TM","GM","F", "FCAU","DODGX"), get = "stock.prices", complete_cases = TRUE, from = "1923-01-01", to = Sys.Date())
## Warning: There were 2 warnings in `dplyr::mutate()`.
## The first warning was:
## ℹ In argument: `data.. = purrr::map(...)`.
## Caused by warning:
## ! x = 'DMH', get = 'stock.prices': Error in getSymbols.yahoo(Symbols = "DMH", env = <environment>, verbose = FALSE, : Unable to import "DMH".
## HTTP error 422.
##  Removing DMH.
## ℹ Run `dplyr::last_dplyr_warnings()` to see the 1 remaining warning.
df_t$symbol<-as.factor(df_t$symbol)


## HMISC describe()
by(df_t$adjusted, df_t$symbol, FUN = describe) %>% print()
## df_t$symbol: BMWYY
## dd[x, ] 
##        n  missing distinct     Info     Mean      Gmd      .05      .10 
##     3386        0     2949        1    21.27     6.08    10.84    14.48 
##      .25      .50      .75      .90      .95 
##    18.12    21.38    24.66    27.57    30.05 
## 
## lowest : 7.46128 7.56933 7.62051 7.63189 7.64895
## highest: 38.12   38.15   38.8    38.9    39.48  
## ------------------------------------------------------------ 
## df_t$symbol: DODGX
## dd[x, ] 
##        n  missing distinct     Info     Mean      Gmd      .05      .10 
##    10953        1     9236        1    52.25    59.45    1.916    2.573 
##      .25      .50      .75      .90      .95 
##    6.780   32.585   69.039  143.236  199.214 
## 
## lowest : 1.44782 1.45481 1.50025 1.54431 1.56753
## highest: 239.773 240.083 240.448 240.617 241.442
## ------------------------------------------------------------ 
## df_t$symbol: F
## dd[x, ] 
##        n  missing distinct     Info     Mean      Gmd      .05      .10 
##    12868        0     8721        1    5.093    4.866   0.1905   0.2371 
##      .25      .50      .75      .90      .95 
##   0.6466   4.3848   8.3218  11.3123  13.1697 
## 
## lowest : 0.127007 0.130807 0.131349 0.131892 0.132435
## highest: 21.9901  22.0081  22.0171  22.512   22.6649 
## ------------------------------------------------------------ 
## df_t$symbol: GM
## dd[x, ] 
##        n  missing distinct     Info     Mean      Gmd      .05      .10 
##     3161        0     2841        1    31.41    10.65    17.49    19.61 
##      .25      .50      .75      .90      .95 
##    25.35    29.55    35.93    42.77    55.11 
## 
## lowest : 14.3914 14.5598 14.5828 14.6287 14.6517
## highest: 62.8531 63.3087 63.4473 63.9921 65.1113
## ------------------------------------------------------------ 
## df_t$symbol: MBGYY
## dd[x, ] 
##        n  missing distinct     Info     Mean      Gmd      .05      .10 
##     3182        0     2734        1    12.49    3.886    6.853    7.684 
##      .25      .50      .75      .90      .95 
##   10.040   12.430   14.803   17.293   18.682 
## 
## lowest : 4.72017 4.75289 4.77743 4.94922 5.08829
## highest: 21.6262 21.6603 21.72   21.8054 22.0444
## ------------------------------------------------------------ 
## df_t$symbol: TM
## dd[x, ] 
##        n  missing distinct     Info     Mean      Gmd      .05      .10 
##    10902        0     7138        1    59.01     52.4    3.855    5.107 
##      .25      .50      .75      .90      .95 
##   18.113   47.690   96.652  128.338  141.620 
## 
## lowest : 2.25945 2.27812 2.2968  2.30613 2.31547
## highest: 202.42  206.61  207.47  210.69  211.37
## summary
by(df_t$adjusted, df_t$symbol,FUN = summary) %>% print()
## df_t$symbol: BMWYY
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   7.461  18.116  21.382  21.273  24.658  39.480 
## ------------------------------------------------------------ 
## df_t$symbol: DODGX
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
##   1.448   6.780  32.585  52.248  69.039 241.442       1 
## ------------------------------------------------------------ 
## df_t$symbol: F
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##  0.1270  0.6466  4.3848  5.0927  8.3218 22.6649 
## ------------------------------------------------------------ 
## df_t$symbol: GM
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   14.39   25.35   29.55   31.41   35.93   65.11 
## ------------------------------------------------------------ 
## df_t$symbol: MBGYY
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##    4.72   10.04   12.43   12.49   14.80   22.04 
## ------------------------------------------------------------ 
## df_t$symbol: TM
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   2.259  18.113  47.690  59.014  96.652 211.370
# 2020
df_t2<-c()
df_t2<-data.frame()
df_t2 <- tq_get(x = c("DMH","BMWYY","MBGYY","TM","GM","F", "FCAU","DODGX"), get = "stock.prices", complete_cases = TRUE, from = "2020-01-01", to = Sys.Date())
## Warning: There were 2 warnings in `dplyr::mutate()`.
## The first warning was:
## ℹ In argument: `data.. = purrr::map(...)`.
## Caused by warning:
## ! x = 'DMH', get = 'stock.prices': Error in getSymbols.yahoo(Symbols = "DMH", env = <environment>, verbose = FALSE, : Unable to import "DMH".
## attempt to set an attribute on NULL
##  Removing DMH.
## ℹ Run `dplyr::last_dplyr_warnings()` to see the 1 remaining warning.
df_t2$symbol<-as.factor(df_t2$symbol)

## HMISC describe()
by(df_t2$adjusted, df_t2$symbol, FUN = describe) %>% print()
## df_t2$symbol: BMWYY
## dd[x, ] 
##        n  missing distinct     Info     Mean      Gmd      .05      .10 
##      867        0      784        1    25.32    6.217    15.15    18.18 
##      .25      .50      .75      .90      .95 
##    21.64    25.06    29.19    32.12    33.93 
## 
## lowest : 10.6845 11.3139 11.3936 11.7043 11.8557
## highest: 38.12   38.15   38.8    38.9    39.48  
## ------------------------------------------------------------ 
## df_t2$symbol: DODGX
## dd[x, ] 
##        n  missing distinct     Info     Mean      Gmd      .05      .10 
##      867        0      855        1    195.6    37.53    129.2    141.5 
##      .25      .50      .75      .90      .95 
##    165.8    211.5    221.6    228.9    232.0 
## 
## lowest : 99.4447 102.838 104.309 106.409 106.837
## highest: 239.773 240.083 240.448 240.617 241.442
## ------------------------------------------------------------ 
## df_t2$symbol: F
## dd[x, ] 
##        n  missing distinct     Info     Mean      Gmd      .05      .10 
##      867        0      742        1    11.02    4.196    4.795    5.898 
##      .25      .50      .75      .90      .95 
##    7.932   11.540   13.037   15.308   17.777 
## 
## lowest : 3.58996 3.79586 3.87644 3.90329 3.9391 
## highest: 21.9901 22.0081 22.0171 22.512  22.6649
## ------------------------------------------------------------ 
## df_t2$symbol: GM
## dd[x, ] 
##        n  missing distinct     Info     Mean      Gmd      .05      .10 
##      867        0      809        1    41.02    13.05    23.60    26.45 
##      .25      .50      .75      .90      .95 
##    33.01    38.57    52.21    57.92    59.47 
## 
## lowest : 16.6393 17.4317 17.5406 17.8675 17.9665
## highest: 62.8531 63.3087 63.4473 63.9921 65.1113
## ------------------------------------------------------------ 
## df_t2$symbol: MBGYY
## dd[x, ] 
##        n  missing distinct     Info     Mean      Gmd      .05      .10 
##      867        0      735        1    14.87    4.641    6.864    8.661 
##      .25      .50      .75      .90      .95 
##   11.991   15.172   18.080   19.547   20.489 
## 
## lowest : 4.72017 4.75289 4.77743 4.94922 5.08829
## highest: 21.6262 21.6603 21.72   21.8054 22.0444
## ------------------------------------------------------------ 
## df_t2$symbol: TM
## dd[x, ] 
##        n  missing distinct     Info     Mean      Gmd      .05      .10 
##      867        0      817        1      152    23.54    123.0    127.4 
##      .25      .50      .75      .90      .95 
##    136.0    147.1    170.3    181.5    185.6 
## 
## lowest : 108.5  111.1  112.2  115    116.07, highest: 202.42 206.61 207.47 210.69 211.37
## summary
by(df_t2$adjusted, df_t2$symbol,FUN = summary) %>% print()
## df_t2$symbol: BMWYY
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   10.68   21.64   25.06   25.32   29.19   39.48 
## ------------------------------------------------------------ 
## df_t2$symbol: DODGX
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   99.44  165.78  211.46  195.59  221.57  241.44 
## ------------------------------------------------------------ 
## df_t2$symbol: F
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   3.590   7.932  11.540  11.016  13.037  22.665 
## ------------------------------------------------------------ 
## df_t2$symbol: GM
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   16.64   33.01   38.57   41.02   52.21   65.11 
## ------------------------------------------------------------ 
## df_t2$symbol: MBGYY
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##    4.72   11.99   15.17   14.87   18.08   22.04 
## ------------------------------------------------------------ 
## df_t2$symbol: TM
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   108.5   136.0   147.1   152.0   170.3   211.4
# 2016
df_trump<-c()
df_trump<-data.frame()
df_trump <- tq_get(x = c("DMH","BMWYY","MBGYY","TM","GM","F", "FCAU","DODGX"), get = "stock.prices", complete_cases = TRUE, from = "2016-01-01", to = Sys.Date())
## Warning: There were 2 warnings in `dplyr::mutate()`.
## The first warning was:
## ℹ In argument: `data.. = purrr::map(...)`.
## Caused by warning:
## ! x = 'DMH', get = 'stock.prices': Error in getSymbols.yahoo(Symbols = "DMH", env = <environment>, verbose = FALSE, : Unable to import "DMH".
## attempt to set an attribute on NULL
##  Removing DMH.
## ℹ Run `dplyr::last_dplyr_warnings()` to see the 1 remaining warning.
df_trump$symbol<-as.factor(df_trump$symbol)
## HMISC describe()
by(df_trump$adjusted, df_trump$symbol, FUN = describe) %>% print()
## df_trump$symbol: BMWYY
## dd[x, ] 
##        n  missing distinct     Info     Mean      Gmd      .05      .10 
##     1873        0     1612        1    23.37    5.014    17.56    18.64 
##      .25      .50      .75      .90      .95 
##    20.11    22.70    25.97    29.64    32.01 
## 
## lowest : 10.6845 11.3139 11.3936 11.7043 11.8557
## highest: 38.12   38.15   38.8    38.9    39.48  
## ------------------------------------------------------------ 
## df_trump$symbol: DODGX
## dd[x, ] 
##        n  missing distinct     Info     Mean      Gmd      .05      .10 
##     1873        0     1841        1    160.5    47.76    98.33   106.23 
##      .25      .50      .75      .90      .95 
##   128.81   146.79   208.94   222.64   228.35 
## 
## lowest : 84.2222 85.2198 85.4962 85.9529 86.1392
## highest: 239.773 240.083 240.448 240.617 241.442
## ------------------------------------------------------------ 
## df_trump$symbol: F
## dd[x, ] 
##        n  missing distinct     Info     Mean      Gmd      .05      .10 
##     1873        0     1524        1    9.686    3.041    5.973    6.911 
##      .25      .50      .75      .90      .95 
##    8.019    8.925   11.319   13.473   15.098 
## 
## lowest : 3.58996 3.79586 3.87644 3.90329 3.9391 
## highest: 21.9901 22.0081 22.0171 22.512  22.6649
## ------------------------------------------------------------ 
## df_trump$symbol: GM
## dd[x, ] 
##        n  missing distinct     Info     Mean      Gmd      .05      .10 
##     1873        0     1729        1    36.48    10.09    24.58    26.07 
##      .25      .50      .75      .90      .95 
##    30.66    34.70    39.08    53.73    57.54 
## 
## lowest : 16.6393 17.4317 17.5406 17.8675 17.9665
## highest: 62.8531 63.3087 63.4473 63.9921 65.1113
## ------------------------------------------------------------ 
## df_trump$symbol: MBGYY
## dd[x, ] 
##        n  missing distinct     Info     Mean      Gmd      .05      .10 
##     1873        0     1580        1     13.6    3.623    8.826   10.131 
##      .25      .50      .75      .90      .95 
##   11.426   12.963   15.405   18.349   19.341 
## 
## lowest : 4.72017 4.75289 4.77743 4.94922 5.08829
## highest: 21.6262 21.6603 21.72   21.8054 22.0444
## ------------------------------------------------------------ 
## df_trump$symbol: TM
## dd[x, ] 
##        n  missing distinct     Info     Mean      Gmd      .05      .10 
##     1873        0     1681        1    134.9    25.06    104.6    108.9 
##      .25      .50      .75      .90      .95 
##    118.8    130.8    144.3    174.1    180.9 
## 
## lowest : 96.7983 96.9559 96.9657 97.2612 97.6946
## highest: 202.42  206.61  207.47  210.69  211.37
## summary
by(df_trump$adjusted, df_trump$symbol,FUN = summary) %>% print()
## df_trump$symbol: BMWYY
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   10.68   20.11   22.70   23.37   25.97   39.48 
## ------------------------------------------------------------ 
## df_trump$symbol: DODGX
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   84.22  128.81  146.79  160.51  208.94  241.44 
## ------------------------------------------------------------ 
## df_trump$symbol: F
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   3.590   8.019   8.925   9.686  11.319  22.665 
## ------------------------------------------------------------ 
## df_trump$symbol: GM
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   16.64   30.66   34.70   36.48   39.08   65.11 
## ------------------------------------------------------------ 
## df_trump$symbol: MBGYY
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##    4.72   11.43   12.96   13.60   15.41   22.04 
## ------------------------------------------------------------ 
## df_trump$symbol: TM
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##    96.8   118.8   130.8   134.9   144.3   211.4
library('rmarkdown')
library('tidyverse')
library('magrittr')
library('Hmisc')
library('ggplot2')
library('plotly')


df_t<- df_t %>% arrange(desc(date)) %>% print()
## # A tibble: 44,453 × 8
##    symbol date        open  high   low close   volume adjusted
##    <fct>  <date>     <dbl> <dbl> <dbl> <dbl>    <dbl>    <dbl>
##  1 BMWYY  2023-06-12  39.3  39.5  39.3  39.5    21100     39.5
##  2 MBGYY  2023-06-12  19.7  19.8  19.6  19.8    65800     19.8
##  3 TM     2023-06-12 149.  150.  149.  150.    289800    150. 
##  4 GM     2023-06-12  36.3  37.0  36.3  36.7 14901900     36.7
##  5 F      2023-06-12  13.8  13.9  13.6  13.8 44584700     13.8
##  6 DODGX  2023-06-12 223.  223.  223.  223.         0    223. 
##  7 BMWYY  2023-06-09  38.9  38.9  38.7  38.8    29600     38.8
##  8 MBGYY  2023-06-09  19.6  19.6  19.5  19.5    68200     19.5
##  9 TM     2023-06-09 148   149.  148.  149.    366600    149. 
## 10 GM     2023-06-09  37.5  38.2  36.2  36.2 24307400     36.2
## # ℹ 44,443 more rows
df_t2<- df_t2 %>% arrange(desc(date)) %>% print()
## # A tibble: 5,202 × 8
##    symbol date        open  high   low close   volume adjusted
##    <fct>  <date>     <dbl> <dbl> <dbl> <dbl>    <dbl>    <dbl>
##  1 BMWYY  2023-06-12  39.3  39.5  39.3  39.5    21100     39.5
##  2 MBGYY  2023-06-12  19.7  19.8  19.6  19.8    65800     19.8
##  3 TM     2023-06-12 149.  150.  149.  150.    289800    150. 
##  4 GM     2023-06-12  36.3  37.0  36.3  36.7 14901900     36.7
##  5 F      2023-06-12  13.8  13.9  13.6  13.8 44584700     13.8
##  6 DODGX  2023-06-12 223.  223.  223.  223.         0    223. 
##  7 BMWYY  2023-06-09  38.9  38.9  38.7  38.8    29600     38.8
##  8 MBGYY  2023-06-09  19.6  19.6  19.5  19.5    68200     19.5
##  9 TM     2023-06-09 148   149.  148.  149.    366600    149. 
## 10 GM     2023-06-09  37.5  38.2  36.2  36.2 24307400     36.2
## # ℹ 5,192 more rows
df_trump<-df_trump %>% arrange(desc(date)) %>% print()
## # A tibble: 11,238 × 8
##    symbol date        open  high   low close   volume adjusted
##    <fct>  <date>     <dbl> <dbl> <dbl> <dbl>    <dbl>    <dbl>
##  1 BMWYY  2023-06-12  39.3  39.5  39.3  39.5    21100     39.5
##  2 MBGYY  2023-06-12  19.7  19.8  19.6  19.8    65800     19.8
##  3 TM     2023-06-12 149.  150.  149.  150.    289800    150. 
##  4 GM     2023-06-12  36.3  37.0  36.3  36.7 14901900     36.7
##  5 F      2023-06-12  13.8  13.9  13.6  13.8 44584700     13.8
##  6 DODGX  2023-06-12 223.  223.  223.  223.         0    223. 
##  7 BMWYY  2023-06-09  38.9  38.9  38.7  38.8    29600     38.8
##  8 MBGYY  2023-06-09  19.6  19.6  19.5  19.5    68200     19.5
##  9 TM     2023-06-09 148   149.  148.  149.    366600    149. 
## 10 GM     2023-06-09  37.5  38.2  36.2  36.2 24307400     36.2
## # ℹ 11,228 more rows

6 PLOTS of ggplot and plotly

6.1 variables of interest

yr of interest begin_date: 1923,2016,2020

library('rmarkdown')
library('tidyverse')
library('magrittr')
library('Hmisc')
library('ggplot2')
library('plotly')

par(mar=c(1,1,1,1))
 
#plot1 df_t
df_tgp<-c()
df_tgh<- df_t %>% head() %>% tibble() %>% print()
## # A tibble: 6 × 8
##   symbol date        open  high   low close   volume adjusted
##   <fct>  <date>     <dbl> <dbl> <dbl> <dbl>    <dbl>    <dbl>
## 1 BMWYY  2023-06-12  39.3  39.5  39.3  39.5    21100     39.5
## 2 MBGYY  2023-06-12  19.7  19.8  19.6  19.8    65800     19.8
## 3 TM     2023-06-12 149.  150.  149.  150.    289800    150. 
## 4 GM     2023-06-12  36.3  37.0  36.3  36.7 14901900     36.7
## 5 F      2023-06-12  13.8  13.9  13.6  13.8 44584700     13.8
## 6 DODGX  2023-06-12 223.  223.  223.  223.         0    223.
df_tgp <- df_t %>% ggplot(aes(x = date, y = adjusted, fill = symbol))+ geom_smooth(method="loess",se=T)+ geom_line(aes(color= symbol))+ ggtitle(label =  "LOESS Model of STOCK Adj Data; DMH, BMWYY, MBGYY, TM, GM, F, FCAU, DODGX, 01/01/1923-06/13/2023 by AAA")+ facet_wrap(.~symbol, scales="fixed")

# ggplot2
df_tgp
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 1 rows containing non-finite values (`stat_smooth()`).

#plotly
ggplotly(df_tgp)
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 1 rows containing non-finite values (`stat_smooth()`).
#plot2
df_t2gp<-c()
df_t2gh<- df_t2 %>% head() %>% tibble() %>% print()
## # A tibble: 6 × 8
##   symbol date        open  high   low close   volume adjusted
##   <fct>  <date>     <dbl> <dbl> <dbl> <dbl>    <dbl>    <dbl>
## 1 BMWYY  2023-06-12  39.3  39.5  39.3  39.5    21100     39.5
## 2 MBGYY  2023-06-12  19.7  19.8  19.6  19.8    65800     19.8
## 3 TM     2023-06-12 149.  150.  149.  150.    289800    150. 
## 4 GM     2023-06-12  36.3  37.0  36.3  36.7 14901900     36.7
## 5 F      2023-06-12  13.8  13.9  13.6  13.8 44584700     13.8
## 6 DODGX  2023-06-12 223.  223.  223.  223.         0    223.
df_t2gp <- df_t2 %>% ggplot(aes(x = date, y = adjusted, fill = symbol))+ geom_smooth(method="loess",se=T)+ geom_line(aes(color= symbol))+ ggtitle(label =  "LOESS Model of STOCK Adj Data; DMH, BMWYY, MBGYY, TM, GM, F, FCAU, DODGX, 01/01/2020-06/13/2023 by AAA")+ facet_wrap(.~symbol, scales="fixed")

#ggplot2
df_t2gp
## `geom_smooth()` using formula = 'y ~ x'

#plotly
ggplotly(df_t2gp)
## `geom_smooth()` using formula = 'y ~ x'
#plot3
df_t3rump<-c()
df_t3gh<- df_trump %>% head() %>% tibble() %>% print()
## # A tibble: 6 × 8
##   symbol date        open  high   low close   volume adjusted
##   <fct>  <date>     <dbl> <dbl> <dbl> <dbl>    <dbl>    <dbl>
## 1 BMWYY  2023-06-12  39.3  39.5  39.3  39.5    21100     39.5
## 2 MBGYY  2023-06-12  19.7  19.8  19.6  19.8    65800     19.8
## 3 TM     2023-06-12 149.  150.  149.  150.    289800    150. 
## 4 GM     2023-06-12  36.3  37.0  36.3  36.7 14901900     36.7
## 5 F      2023-06-12  13.8  13.9  13.6  13.8 44584700     13.8
## 6 DODGX  2023-06-12 223.  223.  223.  223.         0    223.
df_t3rump <- df_trump %>% ggplot(aes(x = date, y = adjusted, fill = symbol))+ geom_smooth(method="loess",se=T)+ geom_line(aes(color= symbol))+ ggtitle(label =  "LOESS Model of STOCK Adj Data; DMH, BMWYY, MBGYY, TM, GM, F, FCAU, DODGX, 01/01/2016-06/13/2023 by AAA")+ facet_wrap(.~symbol, scales="fixed")

#ggplot2
df_t3rump
## `geom_smooth()` using formula = 'y ~ x'

#plotly
ggplotly(df_t3rump)
## `geom_smooth()` using formula = 'y ~ x'

#graph a quick plot of the adjusted value for each symbol by each date.

library('rmarkdown')
library('tidyverse')
library('magrittr')
library('Hmisc')
library('ggplot2')
library('plotly')



#data importing and tidying
df_t %>% ggplot(aes(x=date,y=adjusted,fill=symbol))+geom_smooth(method="loess",se=T)+geom_line(aes(color= symbol))+ggtitle(label = "LOESS Model of STOCK Adj Data; DMH, BMWYY, MBGYY, TM, GM, F, FCAU, DODGX, 01/01/1923-06/13/2023 by AAA")+facet_grid(symbol~.,scales="free")
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 1 rows containing non-finite values (`stat_smooth()`).

df_t2 %>% ggplot(aes(x=date,y=adjusted,fill=factor(c(symbol))))+geom_smooth(method="loess",se=T)+geom_line(aes(color= factor(c(symbol))))+ggtitle(label = "LOESS Model of STOCK Adj Data; DMH, BMWYY, MBGYY, TM, GM, F, FCAU, DODGX, 01/01/2020-06/13/2023 by AAA")+facet_grid(symbol~.,scales="free")
## `geom_smooth()` using formula = 'y ~ x'

df_trump %>% ggplot(aes(x=date,y=adjusted,fill=factor(c(symbol))))+geom_smooth(method="loess",se=T)+geom_line(aes(color= factor(c(symbol))))+ggtitle(label = "LOESS Model of STOCK Adj Data; DMH, BMWYY, MBGYY, TM, GM, F, FCAU, DODGX, 01/01/2016-06/13/2023 by AAA")+facet_grid(symbol~.,scales="free")
## `geom_smooth()` using formula = 'y ~ x'

df_t  %>% ggplot(aes(x=date,y=adjusted,fill=factor(c(symbol))))+geom_smooth(method="loess",se=T)+geom_line(aes(color= factor(c(symbol))))+ggtitle(label = "LOESS Model of STOCK Data (TSLA,MSFT,AMZN,GOOGL), 01/01/1923-06/07/2023 by AAA")+facet_grid(.~symbol,scales="fixed")
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 1 rows containing non-finite values (`stat_smooth()`).

df_t %>% arrange(desc(adjusted)) %>% head(30) %>% print()
## # A tibble: 30 × 8
##    symbol date        open  high   low close volume adjusted
##    <fct>  <date>     <dbl> <dbl> <dbl> <dbl>  <dbl>    <dbl>
##  1 DODGX  2022-01-14  258.  258.  258.  258.      0     241.
##  2 DODGX  2022-01-12  257.  257.  257.  257.      0     241.
##  3 DODGX  2022-01-11  256.  256.  256.  256.      0     240.
##  4 DODGX  2022-02-09  256.  256.  256.  256.      0     240.
##  5 DODGX  2022-01-13  256.  256.  256.  256.      0     240.
##  6 DODGX  2022-03-29  252.  252.  252.  252.      0     239.
##  7 DODGX  2022-02-10  254.  254.  254.  254.      0     238.
##  8 DODGX  2022-02-02  253.  253.  253.  253.      0     237.
##  9 DODGX  2022-02-08  253.  253.  253.  253.      0     237.
## 10 DODGX  2022-01-18  253.  253.  253.  253.      0     237.
## # ℹ 20 more rows
df_t2 %>% arrange(desc(volume)) %>% head(30) %>% print()
## # A tibble: 30 × 8
##    symbol date        open  high   low close    volume adjusted
##    <fct>  <date>     <dbl> <dbl> <dbl> <dbl>     <dbl>    <dbl>
##  1 F      2022-01-04 22.5  24.6  22.4  24.3  311645200    21.9 
##  2 F      2021-01-21 11.3  12.1  11.1  11.5  282394100    10.3 
##  3 F      2021-05-27 14.4  15.1  14.1  14.9  278939100    13.3 
##  4 F      2022-01-05 24.1  25.0  23.5  23.7  253540000    21.3 
##  5 F      2023-03-17 11.7  11.7  11.1  11.3  249885100    11.2 
##  6 F      2020-03-31  5.03  5.19  4.75  4.83 231800800     4.32
##  7 F      2021-04-29 11.9  11.9  11.1  11.3  230430600    10.1 
##  8 F      2021-11-10 19.9  20.5  19.1  19.4  229109600    17.3 
##  9 F      2021-05-26 13.2  13.9  13.1  13.9  227538700    12.4 
## 10 F      2021-10-28 16.9  17.6  16.7  16.9  215237600    15.1 
## # ℹ 20 more rows
df_t %>% arrange(desc(date)) %>% head(30) %>% print()
## # A tibble: 30 × 8
##    symbol date        open  high   low close   volume adjusted
##    <fct>  <date>     <dbl> <dbl> <dbl> <dbl>    <dbl>    <dbl>
##  1 BMWYY  2023-06-12  39.3  39.5  39.3  39.5    21100     39.5
##  2 MBGYY  2023-06-12  19.7  19.8  19.6  19.8    65800     19.8
##  3 TM     2023-06-12 149.  150.  149.  150.    289800    150. 
##  4 GM     2023-06-12  36.3  37.0  36.3  36.7 14901900     36.7
##  5 F      2023-06-12  13.8  13.9  13.6  13.8 44584700     13.8
##  6 DODGX  2023-06-12 223.  223.  223.  223.         0    223. 
##  7 BMWYY  2023-06-09  38.9  38.9  38.7  38.8    29600     38.8
##  8 MBGYY  2023-06-09  19.6  19.6  19.5  19.5    68200     19.5
##  9 TM     2023-06-09 148   149.  148.  149.    366600    149. 
## 10 GM     2023-06-09  37.5  38.2  36.2  36.2 24307400     36.2
## # ℹ 20 more rows

Also to get R studio and or R 4.0.3 packages go to: https://cran.r-project.org/web/packages/

R.Version() %>% rbind() %>% print()
##   platform             arch     os        crt    system            status major
## . "x86_64-w64-mingw32" "x86_64" "mingw32" "ucrt" "x86_64, mingw32" ""     "4"  
##   minor year   month day  svn rev language version.string                     
## . "3.0" "2023" "04"  "21" "84292" "R"      "R version 4.3.0 (2023-04-21 ucrt)"
##   nickname          
## . "Already Tomorrow"
citation('tidyquant') %>% print()
## To cite package 'tidyquant' in publications use:
## 
##   Dancho M, Vaughan D (2023). _tidyquant: Tidy Quantitative Financial
##   Analysis_. R package version 1.0.7,
##   <https://CRAN.R-project.org/package=tidyquant>.
## 
## A BibTeX entry for LaTeX users is
## 
##   @Manual{,
##     title = {tidyquant: Tidy Quantitative Financial Analysis},
##     author = {Matt Dancho and Davis Vaughan},
##     year = {2023},
##     note = {R package version 1.0.7},
##     url = {https://CRAN.R-project.org/package=tidyquant},
##   }
citation('Hmisc') %>% print()
## To cite package 'Hmisc' in publications use:
## 
##   Harrell Jr F (2023). _Hmisc: Harrell Miscellaneous_. R package
##   version 5.1-0, <https://CRAN.R-project.org/package=Hmisc>.
## 
## A BibTeX entry for LaTeX users is
## 
##   @Manual{,
##     title = {Hmisc: Harrell Miscellaneous},
##     author = {Frank E {Harrell Jr}},
##     year = {2023},
##     note = {R package version 5.1-0},
##     url = {https://CRAN.R-project.org/package=Hmisc},
##   }
citation('dplyr') %>% print()
## To cite package 'dplyr' in publications use:
## 
##   Wickham H, François R, Henry L, Müller K, Vaughan D (2023). _dplyr: A
##   Grammar of Data Manipulation_. R package version 1.1.2,
##   <https://CRAN.R-project.org/package=dplyr>.
## 
## A BibTeX entry for LaTeX users is
## 
##   @Manual{,
##     title = {dplyr: A Grammar of Data Manipulation},
##     author = {Hadley Wickham and Romain François and Lionel Henry and Kirill Müller and Davis Vaughan},
##     year = {2023},
##     note = {R package version 1.1.2},
##     url = {https://CRAN.R-project.org/package=dplyr},
##   }
citation('ggplot2') %>% print()
## To cite ggplot2 in publications, please use
## 
##   H. Wickham. ggplot2: Elegant Graphics for Data Analysis.
##   Springer-Verlag New York, 2016.
## 
## A BibTeX entry for LaTeX users is
## 
##   @Book{,
##     author = {Hadley Wickham},
##     title = {ggplot2: Elegant Graphics for Data Analysis},
##     publisher = {Springer-Verlag New York},
##     year = {2016},
##     isbn = {978-3-319-24277-4},
##     url = {https://ggplot2.tidyverse.org},
##   }
citation('plotly') %>% print()
## To cite package 'plotly' in publications use:
## 
##   C. Sievert. Interactive Web-Based Data Visualization with R, plotly,
##   and shiny. Chapman and Hall/CRC Florida, 2020.
## 
## A BibTeX entry for LaTeX users is
## 
##   @Book{,
##     author = {Carson Sievert},
##     title = {Interactive Web-Based Data Visualization with R, plotly, and shiny},
##     publisher = {Chapman and Hall/CRC},
##     year = {2020},
##     isbn = {9781138331457},
##     url = {https://plotly-r.com},
##   }
citation('data.table') %>% print()
## To cite package 'data.table' in publications use:
## 
##   Dowle M, Srinivasan A (2023). _data.table: Extension of
##   `data.frame`_. R package version 1.14.8,
##   <https://CRAN.R-project.org/package=data.table>.
## 
## A BibTeX entry for LaTeX users is
## 
##   @Manual{,
##     title = {data.table: Extension of `data.frame`},
##     author = {Matt Dowle and Arun Srinivasan},
##     year = {2023},
##     note = {R package version 1.14.8},
##     url = {https://CRAN.R-project.org/package=data.table},
##   }
citation('MASS') %>% print()
## To cite the MASS package in publications use:
## 
##   Venables, W. N. & Ripley, B. D. (2002) Modern Applied Statistics with
##   S. Fourth Edition. Springer, New York. ISBN 0-387-95457-0
## 
## A BibTeX entry for LaTeX users is
## 
##   @Book{,
##     title = {Modern Applied Statistics with S},
##     author = {W. N. Venables and B. D. Ripley},
##     publisher = {Springer},
##     edition = {Fourth},
##     address = {New York},
##     year = {2002},
##     note = {ISBN 0-387-95457-0},
##     url = {https://www.stats.ox.ac.uk/pub/MASS4/},
##   }
citation('rmarkdown') %>% print()
## To cite package 'rmarkdown' in publications use:
## 
##   Allaire J, Xie Y, Dervieux C, McPherson J, Luraschi J, Ushey K,
##   Atkins A, Wickham H, Cheng J, Chang W, Iannone R (2023). _rmarkdown:
##   Dynamic Documents for R_. R package version 2.22,
##   <https://github.com/rstudio/rmarkdown>.
## 
##   Xie Y, Allaire J, Grolemund G (2018). _R Markdown: The Definitive
##   Guide_. Chapman and Hall/CRC, Boca Raton, Florida. ISBN
##   9781138359338, <https://bookdown.org/yihui/rmarkdown>.
## 
##   Xie Y, Dervieux C, Riederer E (2020). _R Markdown Cookbook_. Chapman
##   and Hall/CRC, Boca Raton, Florida. ISBN 9780367563837,
##   <https://bookdown.org/yihui/rmarkdown-cookbook>.
## 
## To see these entries in BibTeX format, use 'print(<citation>,
## bibtex=TRUE)', 'toBibtex(.)', or set
## 'options(citation.bibtex.max=999)'.
citation('magrittr') %>% print()
## To cite package 'magrittr' in publications use:
## 
##   Bache S, Wickham H (2022). _magrittr: A Forward-Pipe Operator for R_.
##   R package version 2.0.3,
##   <https://CRAN.R-project.org/package=magrittr>.
## 
## A BibTeX entry for LaTeX users is
## 
##   @Manual{,
##     title = {magrittr: A Forward-Pipe Operator for R},
##     author = {Stefan Milton Bache and Hadley Wickham},
##     year = {2022},
##     note = {R package version 2.0.3},
##     url = {https://CRAN.R-project.org/package=magrittr},
##   }
citation() %>% print()
## To cite R in publications use:
## 
##   R Core Team (2023). _R: A Language and Environment for Statistical
##   Computing_. R Foundation for Statistical Computing, Vienna, Austria.
##   <https://www.R-project.org/>.
## 
## A BibTeX entry for LaTeX users is
## 
##   @Manual{,
##     title = {R: A Language and Environment for Statistical Computing},
##     author = {{R Core Team}},
##     organization = {R Foundation for Statistical Computing},
##     address = {Vienna, Austria},
##     year = {2023},
##     url = {https://www.R-project.org/},
##   }
## 
## We have invested a lot of time and effort in creating R, please cite it
## when using it for data analysis. See also 'citation("pkgname")' for
## citing R packages.

To be continued…In the famous words of Bob Marley, and the Wailers iirc (if i recall correctly),

“We’ll be forever loving JAH!”

AAA

to be continued….