Access over 20 million homework & study documents

R - Programs for Financial Time Series

Content type
User Generated
Type
Lab
Rating
Showing Page:
1/7
library(fGarch)
library(fBasics)
setwd("C:/Documents and Settings/Administrator/Desktop/4th Year")
simple_ret=read.table("d-aapl3idx-0110.txt",header=T);simple_ret
#Question1
#(a)
Transforming to percentage returns and obtaining the descriptive statistics
price_value.ret1=100*(simple_ret$aapl);price_value.ret1
price_value.ret2=100*(simple_ret$vw);price_value.ret2
price_value.ret3=100*(simple_ret$ew);price_value.ret3
price_value.ret4=100*(simple_ret$sp);price_value.ret4
basicstat=cbind(basicStats(price_value.ret1),basicStats(price_value.ret2),basicStats(price
_value.ret3),basicStats(price_value.ret4)); basicstat
#(b)
Transforming Apple stock returns to percentage log returns
price_value.logret=100*log(1+simple_ret$aapl);price_value.logret
basicStats(price_value.logret)
#(c)
jarque.bera.test for normality
library(tseries)
jarque.bera.test(price_value.logret)
#Question 2
#(1)
Transforming to percentage log returns and obtaining the descriptive statistics
simple_ret1=read.table ("m-xomsp-8010.txt",header=T);simple_ret1
price_value.logret1=100*log(1+simple_ret1$xom);price_value.logret1
price_value.logret2=100*log(1+simple_ret1$sp);price_value.logret2
basicstat1=cbind(basicStats(price_value.logret1),basicStats(price_value.logret2));basicsta
1
#(2)
Normality test
normalTest(price_value.logret1, method = c("sw", "jb"), na.rm = FALSE)
normalTest(price_value.logret2, method = c("sw", "jb"), na.rm = FALSE)
#(3)
Computing Correlation Coefficient, Kendall tau , and Spearman’s rho of the log returns
library(fBasics)

Sign up to view the full document!

lock_open Sign Up
Showing Page:
2/7
correlationTest(price_value.logret1,price_value.logret2,method="pearson",title=NULL,
description=NULL)
correlationTest(price_value.logret1,price_value.logret2,method="kendall",title=NULL,
description=NULL)
correlationTest(price_value.logret1,price_value.logret2,method="spearman”,
title=NULL,
description=NULL)
#Question 3
data=read.table("m-tb3ms-3411.txt",header=T);data
#(a)
computing descriptive characteristics of interest rates
basicStats(data$rate)
#(b)
computing descriptive characteristics change series of interest rates
change_series=diff(data$rate);change_series
basicStats(change_series)
#(c)
obtaining the percentiles(1,5,10,90,95,99)
position=length(change_series)*c(0.01,0.05,0.10,0.90,0.95,0.99);position
position1=round(position,digits=0);position1
d=data$day;d
change_series1=sort(change_series);change_series1
data1=cbind(d,change_series1);data1
p1=data1[9,2];p1
p2=data1[46,2];p2
p3=data1[92,2];p3
p4=data1[832,2];p4
p5=data1[879,2];p5
p6=data1[916,2];p6
percentiles=cbind(p1,p2,p3,p4,p5,p6);percentiles
#Question 4
#(a)
Transforming simple returns to log returns and plotting its density.
daily_logreturns=log (1+simple_ret$aapl); daily_logreturns
library(car)
densityPlot(daily_logreturns,adjust=1,kernel=c("gaussian","epanechnikov","rectangular",
"triangular", "biweight", "cosine", "optcosine"),xlab

Sign up to view the full document!

lock_open Sign Up
Showing Page:
3/7

Sign up to view the full document!

lock_open Sign Up
End of Preview - Want to read all 7 pages?
Access Now
Unformatted Attachment Preview
library(fGarch) library(fBasics) setwd("C:/Documents and Settings/Administrator/Desktop/4th Year") simple_ret=read.table("d-aapl3idx-0110.txt",header=T);simple_ret #Question1 #(a) Transforming to percentage returns and obtaining the descriptive statistics price_value.ret1=100*(simple_ret$aapl);price_value.ret1 price_value.ret2=100*(simple_ret$vw);price_value.ret2 price_value.ret3=100*(simple_ret$ew);price_value.ret3 price_value.ret4=100*(simple_ret$sp);price_value.ret4 basicstat=cbind(basicStats(price_value.ret1),basicStats(price_value.ret2),basicStats(price_value.ret3),basicStats(price_value.ret4)); basicstat #(b) Transforming Apple stock returns to percentage log returns price_value.logret=100*log(1+simple_ret$aapl);price_value.logret basicStats(price_value.logret) #(c) jarque.bera.test for normality library(tseries) jarque.bera.test(price_value.logret) #Question 2 #(1) Transforming to percentage log returns and obtaining the descriptive statistics simple_ret1=read.table ("m-xomsp-8010.txt",header=T);simple_ret1 price_value.logret1=100*log(1+simple_ret1$xom);price_value.logret1 price_value.logret2=100*log(1+simple_ret1$sp);price_value.logret2 basicstat1=cbind(basicStats(price_value.logret1),basicStats(price_value.logret2));basicsta1 #(2) Normality test normalTest(price_value.logret1, method = c("sw", "jb"), na.rm = FALSE) normalTest(price_value.logret2, method = c("sw", "jb"), na.rm = FALSE) #(3) Computing Correlation Coefficient, Kendall tau , and Spearman's rho ...
Purchase document to see full attachment
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

Anonymous
Very useful material for studying!

Studypool
4.7
Trustpilot
4.5
Sitejabber
4.4