<jupyter_start><jupyter_text>Simple Price Analysis Historical Data<jupyter_code># If do not have the packages install it
# install.packages('quantmod')
library(quantmod)
# If not have packages install, use this one to install
install.packages("quantmod", repos = "http://cran.us.r-project.org")
# load the packages
library(quantmod)
getSymbols("AAPL")
# Count rows and columns
dim(AAPL)
# Summary Stats
summary(AAPL)
# Correlation
cor(AAPL)
OpCl(AAPL) # Daily Percent change Open to Close
OpOp(AAPL) # one period open to open change
HiCl(AAPL) #the percent change from high to close 
# The first 6 rows
head(AAPL)
# The last 6 rows
tail(AAPL)
# Use particular columns
head(AAPL$AAPL.Adjusted)
AAPL$AAPL.Adjusted[1:2]
# [rows, columns]
AAPL[1:2, 1:3]
AAPL[1:5, 'AAPL.High']
# Rows & 2nd column
AAPL[1:5, 2]
AAPL$AAPL.Close[1:5]
# Create Daily Returns
# Simple way is use Delt function mode from quantmod
Delt(AAPL$AAPL.Adjusted)
# Another way to calculate daily returns
# This log returns
ret <- diff(log(AAPL$AAPL.Adjusted))
ret
# This simple returns
n = length(AAPL$AAPL.Adjusted)

simple_ret <- diff(AAPL$AAPL.Adjusted)/AAPL$AAPL.Adjusted[1:(n-1)] 
simple_ret
# Create a dataframe with dates and Adj Price
aapl_prices <- AAPL[, "AAPL.Adjusted", drop = FALSE]
rownames(aapl_prices) <- AAPL$Date
head(aapl_prices)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11913626209977662, 'fraction_numerical': 0.01340282948622487, 'mean_word_length': 5.892307692307693, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '133723', 'license': 'MIT', 'n_tokens_mistral': 540, 'n_tokens_neox': 520, 'n_words': 141, 'path': '02_SimplePriceDataAnalysis.ipynb', 'repo_name': 'LastAncientOne/SimpleStockAnalysisR', 'size': '1343'}