<jupyter_start><jupyter_text>Stock Returns  Set the Directory<jupyter_code>setwd("/jupyter/csv-file")<jupyter_output><empty_output><jupyter_text>Clear Memory<jupyter_code>rm(list=ls())<jupyter_output><empty_output><jupyter_text>Import the Data<jupyter_code>data=read.csv('goldreturns.csv',header=T) # our data has headers (Tmeans True).
head(data)
tail(data)
attach(data)         # "attach"lets us use the variable names.<jupyter_output><empty_output><jupyter_text>Convert Data into Time Series<jupyter_code>gold_ts=ts(gold,frequency=12,start=c(1973,1))
nyse_ts=ts(nyse,frequency=12,start=c(1973,1))
nasdaq_ts =ts(nasdaq,frequency=12,start=c(1973,1))<jupyter_output><empty_output><jupyter_text>Plotting the Data<jupyter_code>pdf('goldreturns.pdf')
par(mfrow=c(3,1))
ts.plot(gold_ts)
ts.plot(nyse_ts)
ts.plot(nasdaq_ts)
dev.off()<jupyter_output><empty_output><jupyter_text>Data Summary<jupyter_code>library(psych)       # very useful for data summary.
describe(data[,-1])
t.test(gold,nyse,mu=0,type='two.sided')
t.test(gold,nasdaq,mu=0,type='two.sided')
t.test(nyse,nasdaq,mu=0,type='two.sided')<jupyter_output><empty_output><jupyter_text>Convert return into the squared return<jupyter_code>gold_sq=gold^2
nyse_sq=nyse^2
nasdaq_sq=nasdaq^2
data_sq=data[,-1]^2<jupyter_output><empty_output><jupyter_text>Testing for Correlation<jupyter_code>cor(data_sq)
cor.test(gold_sq,nyse_sq)
cor.test(gold_sq,nasdaq_sq)
cor.test(nyse_sq,nasdaq_sq)<jupyter_output><empty_output><jupyter_text>Testing for Normality<jupyter_code>shapiro.test(gold) 
shapiro.test(nyse) 
shapiro.test(nasdaq)
shapiro.test(gold_sq) 
shapiro.test(nyse_sq) 
shapiro.test(nasdaq_sq)
# Conclusion: none of them are normally distributed since p<0.05.<jupyter_output><empty_output><jupyter_text>Testing for Autocorrelation<jupyter_code>Box.test(gold,lag=4,type='Ljung-Box')
# Conclusion: No significant autocorrelation.
Box.test(nyse,lag=4,type='Ljung-Box')
# Conclusion: No significant autocorrelation.
Box.test(nasdaq,lag=4,type='Ljung-Box')
# Conclusion: No significant autocorrelation.
Box.test(gold_sq,lag=4,type='Ljung-Box')
# Conclusion: significant autocorrelation.
Box.test(nyse_sq,lag=4,type='Ljung-Box')
# Conclusion: significant autocorrelation.
Box.test(nasdaq_sq,lag=4,type='Ljung-Box')
# Conclusion: significant autocorrelation.
#EndOfCode.<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14602903501280956, 'fraction_numerical': 0.017506404782237403, 'mean_word_length': 11.664864864864866, 'pattern_counts': {'":': 0, '<': 42, '<?xml version=': 0, '>': 41, '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': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '177300', 'license': 'MIT', 'n_tokens_mistral': 995, 'n_tokens_neox': 943, 'n_words': 105, 'path': 'jupyter/ipynb-r-file/.ipynb_checkpoints/Sample-checkpoint.ipynb', 'repo_name': 'jingluomaf/fintech-app', 'size': '2342'}