## xjulian -
xmpBasics("Start: Julian Counts > ")
# Return the number of minute counts for the last day in every
# month for year 2000 beginning January 1st, 2001 at 16:00:
xjulian(c(20000131, 20000229, 20000331, 20000430, 20000531, 20000630,
20000731, 20000831, 20000930, 20001031, 20001130, 20001231)*10000+1600,
origin = 20000101)
## xdate -
xmpBasics("Next: Convert Julian Counts to Dates > ")
# Return the number of minute counts for th
# Manage Date/Time in Extended Date/Time Format, ISO-8601
# Date: 1973-01-01 15:30
xjulian(197301011530)
print(xdate(xjulian(197301011530)), digits = 9)
## xday.of.week -
# Calculate the day of week for 1973-01-01 16:15
xmpBasics("Next: Compute Day of Week > ")
xday.of.week(197301011615)
## xleap.year -
xmpBasics("Next: Check for Leap Years > ")
# Falls Februar 1st, 2000 16:15 in a leap year?
xleap.year(200002011615)
## fxdata.contributors -
xmpBasics("Start: Filter Contributors > ")
# Print contributor list:
data(usdthb)
usdthb[1:25, ]
# Create contributor list:
fxdata.contributors(usdthb, include = 5)
## fxdata.parser -
xmpBasics("Next: Parse Records > ")
# Parse data:
# Create a contributor list and mark the first 5 market makers:
parser.table = fxdata.contributors(usdthb, include=5)
# Parse the market makers and print the first 25 entries:
fxdata.parser(usdthb, parser.table)[1:25,]
## fxdata.filter -
xmpBasics("Next: Filter Records > ")
# Filter data and plot unfiltered data:
par(mfrow = c(2, 1))
NumberOfRecords = length(usdthb[,1])
NumberOfRecords
plot(usdthb[,4], type="l",
xlab = "Tick Number from Reuters THB=",
ylab = "100*log(Bid[n]/Bid[1]) Bid",
ylim = c(-20,30), main="USDTHB June 1997 unfiltered")
lines(x=c(1, NumberOfRecords), y=rep(usdthb[1,4], 2), col = 4)
lines(-100*log(usdthb[1,4]/usdthb[,4]))
lines(x = c(1, NumberOfRecords), y = c(0, 0), col = 4)
# Filter the data:
usdthb = fxdata.filter(usdthb, parameter="strong")
# Quick And Dirty Time Scaling
Records = length(usdthb$accepted[,4])
scale = NumberOfRecords/Records
# Plot filtered data:
plot(x=(1:Records)*scale, y=usdthb$accepted[, 4], type = "l",
xlab = "Tick Number from Reuters THB=",
ylab = "100*log(Bid[n]/Bid[1]) Bid",
ylim = c(-20,30), main="USDTHB June 1997 filtered")
y = rep(usdthb$accepted[1, 4], 2)
lines(x=c(1, NumberOfRecords), y=y, col=4)
y = -100*log(usdthb$accepted[1, 4]/usdthb$accepted[, 4])
lines(x = (1:Records)*scale, y=y)
lines(x = c(1, NumberOfRecords), y = c(0, 0), col = 4)
## fxdata.varmin -
xmpBasics("Next: Variable Minute Records > ")
# Variable Minute Records from filter accepted Data,
# create a varmin file and print the first 25 entries:
fxdata.varmin(usdthb$accepted, digits = 5)[1:25, ]
## xts.log -
xmpBasics("Start: Log Prices of FX Data > ")
# Calculate log-prices from AUDUSD bid prices
options(digits = 10)
data(audusd)
prices = list(t = audusd[,"XDATE"], x = audusd[,"BID"])
# Print the first 25 entries:
log.prices = xts.log(prices)
as.data.frame(log.prices)[1:25, ]
## xts.diff -
xmpBasics("Next: Returns of FX Data > ")
# Calculate one hourly AUDUSD log-returns
prices = list(t = audusd[,"XDATE"], x = audusd[,"BID"])
# Calculate the returns and print the first 25 entries:
data.frame(xts.diff(xts.log(prices)))[1:25, ]
## xts.cut -
xmpBasics("Next: Cut out a Piece From a FX File > ")
# Retrieve the AUDUSD bid quotes for October 21, 1997, 16:00
prices = list(t = audusd[,"XDATE"], x = audusd[,"BID"])
# Retrieve prices and print the first 25 entries:
data.frame(xts.cut(prices, from.date = 19971021,
to.date = 19971021))[1:25,]
## xts.interp -
xmpBasics("Next: Interpolate of FX Data > ")
# Interpolate AUDUSD bid prices
# on a 15 minutes time scale for October 21, 1997:
prices = list(t = audusd[,"XDATE"], x = audusd[,"BID"])
# Interpolate the prices and print the first 25 entries:
data.frame(xts.interp(prices, deltat = 15))[1:25, ]
## xts.map -
xmpBasics("Next: Create Business Time Map > ")
options(object.size = 5e8)
par(mfrow = c(2, 1))
# Load and plot prices:
data(fdax9710)
index = list(t = fdax9710[,"XDATE"], x = fdax9710[,"FDAX"])
# Start on Monday - end on Sunday, 3 weeks:
index = xts.cut(index, from.date=19971006, to.date=19971026)
plot(index$x, type = "l", xlab = "Prices", main = "Prices in event time")
# Create hourly upsilon time map - start on Monday - end on Sunday:
tmap = xts.map(index, mean.deltat = 60, alpha = 1.05)
plot(x = tmap$xmap, y = tmap$ymap, ylim = c(0, max(tmap$x)), type="l",
main = "Time Mapping")
tmap
## xts.upsilon -
xmpBasics("Next: De-seasonalize in Upsilon Time > ")
index = list(t = fdax9710[,"XDATE"], x = fdax9710[,"FDAX"])
# Start on Monday - end on Sunday, 3 weeks:
index = xts.cut(index, from.date = 19971006, to.date = 19971026)
plot(index$x, type = "l", xlab = "Prices", main = "Prices in event time")
# Create hourly upsilon time map - start on Monday - end on Sunday:
tmap = xts.map(index, mean.deltat = 60, alpha = 1.05)
# Extract data records according to time map:
index.ups = xts.upsilon(index, weekly.map = tmap$ymap,
main="Prices in Upsilon time")
## xts.dvs -
xmpBasics("Next: De-volatilize Time Series > ")
index = list(t=fdax9710[,"XDATE"], x=fdax9710[,"FDAX"])
# Start on Monday - end on Sunday, 3 weeks:
index = xts.cut(index, from.date=19971006, to.date=19971026)
plot(index$x, type = "l", ylab = "Prices", main = "Prices in event time")
# Devolatilize Time Series With dv-Series Algorithm:
index.dvs = xts.dvs(index, k = 8,
volatility = 13.15*var(diff(log(index$x))), main = "Prices from dv-series")
## xts.dws -
xmpBasics("\nNext: Plot daily/weekly Charts > ")
# NOTE:
# The file \code{fdax97m.csv} is too large and therefore not part
# of this distribution. Please contact \emph{inf@rmetrics.org}.
data(fdax97m)
xts = list(t = fdax97m[,"XDATE"], x = fdax97m[,"FDAX"])
# Start on Monday - end on Sunday, 3 weeks:
xts = xts.cut(index, from.date = 19970106, to.date = 19971228)
# Create Daily and Weekly Histograms:
result = xts.dwh (xts, period = "both", dolog = TRUE,
dodiff = TRUE, deltat = 30, doplot = TRUE)
Run the code above in your browser using DataLab