<jupyter_start><jupyter_text>Simple Stock Data Frame<jupyter_code>library(quantmod)
getSymbols('AAPL', src = 'yahoo', from = as.Date('2016-01-01'), to = as.Date('2019-01-01'))
head(AAPL)
# Calculate Daily Returns
AAPL$AAPL.Returns <-  diff(log(AAPL[,6]))
head(AAPL)
tail(AAPL)
str(AAPL)
AAPL <- na.omit(AAPL)
head(AAPL)<jupyter_output><empty_output><jupyter_text>Calculate Moving Average Indicator<jupyter_code># Add in dataframe
AAPL$SMA <- SMA(AAPL$AAPL.Adjusted, n=5)
head(AAPL)
summary(AAPL)<jupyter_output><empty_output><jupyter_text>Example Create Data Frame<jupyter_code>stocks.data <- data.frame(
   stock_id = c (1:5),
   stock_name = c("Apple","Intel","AMD","Tesla","Nvidia"),
   stock_capital = c(907.241,206.837,30.242,42.253,102.726), # In billions
   stock_price = c(197.18,46.20,27.96,239.52,168.82),
   stringsAsFactors = FALSE
)
print(stocks.data)
# Add columns
stocks.data$stock_sector <- c("Technology","Technology","Technology","Consumer Cyclical","Technology")
c <- stocks.data
print(c)
# Add rows
# Create new dataframe
stocks.newdata <- data.frame(
   stock_id = c (6:8), 
   stock_name = c("<NAME>","Bank of America","Netflix"),
   stock_capital = c(73.918,281.253,632.8), 
   stock_price = c(202.05,29.58,157.854),
   stock_sector = c("Financial Services","Financial Services","Consumer Cyclical"),
   stringsAsFactors = FALSE
)
# Bind the two data frames
stocks.finaldata <- rbind(stocks.data,stocks.newdata)
print(stocks.finaldata)<jupyter_output>stock_id      stock_name stock_capital stock_price       stock_sector
1        1           Apple       907.241     197.180         Technology
2        2           Intel       206.837      46.200         Technology
3        3             AMD        30.242      27.960         Technology
4        4           Tesla        42.253     239.520  Consumer Cyclical
5        5          Nvidia       102.726     168.820         Technology
6        6   Goldman Sachs        73.918     202.050 Financial Services
7        7 Bank of America       281.253      29.580 Financial Services
8        8         Netflix       632.800     157.854  Consumer Cyclical
{'fraction_non_alphanumeric': 0.12505899008966492, 'fraction_numerical': 0.09863142991977347, 'mean_word_length': 3.03041825095057, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '232175', 'license': 'MIT', 'n_tokens_mistral': 889, 'n_tokens_neox': 743, 'n_words': 152, 'path': '04_SimpleStockDataFrame.ipynb', 'repo_name': 'LastAncientOne/SimpleStockAnalysisR', 'size': '2126'}