subset(Lehman, Date %in% c('2001-09-10'))
as.Date('2001-09-10')
subset(Lehman, Date %in% as.Date('2001-09-10'))
subset(Lehman, Date %in% as.Date(c('2001-09-10', '2001-09-17'))
)
subset(Lehman, Date %in% as.Date(c('2001-09-10', '2001-09-17', '2008-09-17')))
subset(Lehman, Date %in% as.Date(c('2001-09-10', '2001-09-17', '2008-09-18')))
subset(Lehman, Date %in% as.Date(c('2001-09-10', '2001-09-17', '2008-09-16')))
subset(Lehman, Date %in% as.Date(c('2001-09-10', '2001-09-17', '2008-09-14')))
subset(Lehman, Date %in% as.Date(c('2001-09-10', '2001-09-17', '2008-09-12')))
subset(Lehman, Date %in% as.Date(c('2001-09-10', '2001-09-17', '2008-09-13')))
subset(Lehman, Date %in% as.Date(c('2001-09-10', '2001-09-17', '2008-09-12')))
subset(Lehman, Date %in% as.Date(c('2001-09-10', '2001-09-17', '2008-09-12', '2008-09-14')))
subset(Lehman, Date %in% as.Date(c('2001-09-10', '2001-09-17', '2008-09-12', '2008-09-16')))
subset(Lehman, Date %in% as.Date(c('2001-09-10', '2001-09-17', '2008-09-12', '2008-09-15')))
subset(Lehman, Date %in% as.Date(c('2001-09-10', '2001-09-17', '2008-09-12', '2008-09-17')))
subset(Lehman, Date %in% as.Date(c('2001-09-10', '2001-09-17', '2008-09-12', '2008-09-16')))
#
titles <- c("Last trading day before WTC attacks",#
            "First trading day after WTC attacks",#
            "Lehman last trading day before it filed for Chapter 11 bankruptcy protection", #
            "Lehman last trading day before being delisted from the NYSE")#
annotation <- c("On September 11, 2001, Lehman occupied three floors of#
            One World Trade Center where one employee was killed. Its#
            global headquarters in Three World Financial Center were#
            severely damaged and rendered unusable by falling debris,#
            displacing over 6,500 employees.", "The bank recovered#
            quickly and rebuilt its presence. Trading operations moved#
            across the Hudson River to its Jersey City, New Jersey,#
            facilities, where an impromptu trading floor was built in a#
            hotel and brought online less than forty-eight hours after#
            the attacks. When stock markets reopened on September 17,#
           2001, Lehman's sales and trading capabilities were#
            restored.",#
            "On Saturday, September 13, 2008, Timothy F. Geithner, the president of#
            the Federal Reserve Bank of New York called a meeting on the#
            future of Lehman, which included the possibility of an#
            emergency liquidation of its assets. Lehman reported that it#
            had been in talks with Bank of America and Barclays for the#
            company's possible sale. However, both Barclays and Bank of#
            America ultimately declined to purchase the entire company.#
            The next day, Sunday, September 14, the International Swaps and#
            Derivatives Association (ISDA) offered an exceptional#
            trading session to allow market participants to offset#
            positions in various derivatives on the condition of a#
            Lehman bankruptcy later that day. Although the bankruptcy#
            filing missed the deadline, many dealers honored the trades#
            they made in the special session.",#
            "Shortly before 1 a.m. Monday morning (New York time), Lehman Brothers#
            Holdings announced it would file for Chapter 11 bankruptcy#
            protection citing bank debt of $613 billion, $155#
            billion in bond debt, and assets worth $639 billion. It#
            further announced that its subsidiaries would continue to#
            operate as normal. A group of Wall Street firms agreed#
            to provide capital and financial assistance for the bank's#
            orderly liquidation and the Federal Reserve, in turn, agreed#
            to a swap of lower-quality assets in exchange for loans and#
            other assistance from the government. The morning#
            witnessed scenes of Lehman employees removing files, items#
            with the company logo, and other belongings from the world#
            headquarters at 745 Seventh Avenue. The spectacle continued#
            throughout the day and into the following day."#
)
titles <- c("Last trading day before WTC attacks",#
            "First trading day after WTC attacks",#
            "Lehman last trading day before it filed for Chapter 11 bankruptcy protection", #
            "Lehman last trading day before being delisted from the NYSE")#
annotations <- c("On September 11, 2001, Lehman occupied three floors of#
            One World Trade Center where one employee was killed. Its#
            global headquarters in Three World Financial Center were#
            severely damaged and rendered unusable by falling debris,#
            displacing over 6,500 employees.", "The bank recovered#
            quickly and rebuilt its presence. Trading operations moved#
            across the Hudson River to its Jersey City, New Jersey,#
            facilities, where an impromptu trading floor was built in a#
            hotel and brought online less than forty-eight hours after#
            the attacks. When stock markets reopened on September 17,#
           2001, Lehman's sales and trading capabilities were#
            restored.",#
            "On Saturday, September 13, 2008, Timothy F. Geithner, the president of#
            the Federal Reserve Bank of New York called a meeting on the#
            future of Lehman, which included the possibility of an#
            emergency liquidation of its assets. Lehman reported that it#
            had been in talks with Bank of America and Barclays for the#
            company's possible sale. However, both Barclays and Bank of#
            America ultimately declined to purchase the entire company.#
            The next day, Sunday, September 14, the International Swaps and#
            Derivatives Association (ISDA) offered an exceptional#
            trading session to allow market participants to offset#
            positions in various derivatives on the condition of a#
            Lehman bankruptcy later that day. Although the bankruptcy#
            filing missed the deadline, many dealers honored the trades#
            they made in the special session.",#
            "Shortly before 1 a.m. Monday morning (New York time), Lehman Brothers#
            Holdings announced it would file for Chapter 11 bankruptcy#
            protection citing bank debt of $613 billion, $155#
            billion in bond debt, and assets worth $639 billion. It#
            further announced that its subsidiaries would continue to#
            operate as normal. A group of Wall Street firms agreed#
            to provide capital and financial assistance for the bank's#
            orderly liquidation and the Federal Reserve, in turn, agreed#
            to a swap of lower-quality assets in exchange for loans and#
            other assistance from the government. The morning#
            witnessed scenes of Lehman employees removing files, items#
            with the company logo, and other belongings from the world#
            headquarters at 745 Seventh Avenue. The spectacle continued#
            throughout the day and into the following day."#
)#
#
#
#
Lehman$title <- NA#
Lehman$annotation <- NA#
#
#
#
subset(Lehman, Date %in% as.Date(c('2001-09-10', '2001-09-17',#
		    %'2008-09-12', '2008-09-16')), select=c('titles', 'annotation'))
titles <- c("Last trading day before WTC attacks",#
            "First trading day after WTC attacks",#
            "Lehman last trading day before it filed for Chapter 11 bankruptcy protection", #
            "Lehman last trading day before being delisted from the NYSE")#
annotations <- c("On September 11, 2001, Lehman occupied three floors of#
            One World Trade Center where one employee was killed. Its#
            global headquarters in Three World Financial Center were#
            severely damaged and rendered unusable by falling debris,#
            displacing over 6,500 employees.", "The bank recovered#
            quickly and rebuilt its presence. Trading operations moved#
            across the Hudson River to its Jersey City, New Jersey,#
            facilities, where an impromptu trading floor was built in a#
            hotel and brought online less than forty-eight hours after#
            the attacks. When stock markets reopened on September 17,#
           2001, Lehman's sales and trading capabilities were#
            restored.",#
            "On Saturday, September 13, 2008, Timothy F. Geithner, the president of#
            the Federal Reserve Bank of New York called a meeting on the#
            future of Lehman, which included the possibility of an#
            emergency liquidation of its assets. Lehman reported that it#
            had been in talks with Bank of America and Barclays for the#
            company's possible sale. However, both Barclays and Bank of#
            America ultimately declined to purchase the entire company.#
            The next day, Sunday, September 14, the International Swaps and#
            Derivatives Association (ISDA) offered an exceptional#
            trading session to allow market participants to offset#
            positions in various derivatives on the condition of a#
            Lehman bankruptcy later that day. Although the bankruptcy#
            filing missed the deadline, many dealers honored the trades#
            they made in the special session.",#
            "Shortly before 1 a.m. Monday morning (New York time), Lehman Brothers#
            Holdings announced it would file for Chapter 11 bankruptcy#
            protection citing bank debt of $613 billion, $155#
            billion in bond debt, and assets worth $639 billion. It#
            further announced that its subsidiaries would continue to#
            operate as normal. A group of Wall Street firms agreed#
            to provide capital and financial assistance for the bank's#
            orderly liquidation and the Federal Reserve, in turn, agreed#
            to a swap of lower-quality assets in exchange for loans and#
            other assistance from the government. The morning#
            witnessed scenes of Lehman employees removing files, items#
            with the company logo, and other belongings from the world#
            headquarters at 745 Seventh Avenue. The spectacle continued#
            throughout the day and into the following day."#
)#
#
#
#
Lehman$title <- NA#
Lehman$annotation <- NA#
#
#
#
subset(Lehman, Date %in% as.Date(c('2001-09-10', '2001-09-17',#
		    %'2008-09-12', '2008-09-16')), select=c('title', 'annotation'))
subset(Lehman, Date %in% as.Date(c('2001-09-10', '2001-09-17',#
		    %'2008-09-12', '2008-09-16'))
subset(Lehman, Date %in% as.Date(c('2001-09-10', '2001-09-17',#
		    %'2008-09-12', '2008-09-16')))
subset(Lehman, Date %in% as.Date(c('2001-09-10', '2001-09-17',#
		    '2008-09-12', '2008-09-16')), select=c('title', 'annotation'))
subset(Lehman, Date %in% as.Date(c('2001-09-10', '2001-09-17',#
		    '2008-09-12', '2008-09-16')), select=c('title', 'annotation')) <- data.frame(titles, annotations)
Lehman[Date %in% as.Date(c('2001-09-10', '2001-09-17',#
		    '2008-09-12', '2008-09-16')), c('title', 'annotation')]
Lehman[Lehman$Date %in% as.Date(c('2001-09-10', '2001-09-17',#
		    '2008-09-12', '2008-09-16')), c('title', 'annotation')]
events <- as.Date(c('2001-09-10', '2001-09-17',#
		    '2008-09-12', '2008-09-16'))#
#
Lehman[Lehman$Date %in% events, c('title', 'annotation')] <- data.frame(titles, annotions)
annotations
Lehman[Lehman$Date %in% events, c('title', 'annotation')] <- data.frame(titles, annotations)
A=gvisAnnotatedTimeLine(Lehman[c("Date", "Close", "title", "annotation")], datavar=Date, options=list(displayAnnotations=TRUE))
head(Lehman)
A=gvisAnnotatedTimeLine(Lehman[c("Date", "Close", "title", "annotation")],#
                        datevar=Date, options=list(displayAnnotations=TRUE))
plot(A)
str(Lehman)
Lehman[Lehman$Date %in% events]%title <- titles#
Lehman[Lehman$Date %in% events]%annotation <- annotations#
#
#
A=gvisAnnotatedTimeLine(Lehman[c("Date", "Close", "title", "annotation")],#
                        datevar=Date, options=list(displayAnnotations=TRUE))
str(Lehman)
#
Lehman$title <- NA#
Lehman$annotation <- NA#
#
events <- as.Date(c('2001-09-10', '2001-09-17',#
		    '2008-09-12', '2008-09-16'))#
#
Lehman[Lehman$Date %in% events]$title <- titles#
Lehman[Lehman$Date %in% events]$annotation <- annotations
Lehman$title <- NA#
Lehman$annotation <- NA#
#
events <- as.Date(c('2001-09-10', '2001-09-17',#
		    '2008-09-12', '2008-09-16'))#
#
Lehman[Lehman$Date %in% events]$title
head(Lehman)
Lehman[Lehman$Date %in% events]$title
Lehman[Lehman$Date %in% events]
events
class(events)
Lehman$Date %in% events
Lehman[Lehman$Date %in% events,]
Lehman[Lehman$Date %in% events,]$title <- titles#
Lehman[Lehman$Date %in% events,]$annotation <- annotations
Lehman[Lehman$Date %in% events,]
A=gvisAnnotatedTimeLine(Lehman[c("Date", "Close", "title", "annotation")],#
                        datevar=Date, options=list(displayAnnotations=TRUE))
plot(A)
A=gvisAnnotatedTimeLine(Lehman[c("Date", "Close", "title", "annotation")],#
                        datevar=Date, options=list(displayAnnotations=TRUE, width=800, height=600))
plot(A)
Lehman[Lehman$Date %in% events,]
Lehman[Lehman$Date %in% events,1:4]
Lehman[Lehman$Date %in% rev(events),1:4]
Lehman[order(Lehman$Date),]
Lehman=Lehman[order(Lehman$Date),]
Lehman[Lehman$Date %in% rev(events),1:4]
Lehman[Lehman$Date %in% events,]$title <- titles#
Lehman[Lehman$Date %in% events,]$annotation <- annotations
A=gvisAnnotatedTimeLine(Lehman[c("Date", "Close", "title", "annotation")],#
                        datevar=Date, options=list(displayAnnotations=TRUE, width=800, height=600))
plot(A)
A=gvisAnnotatedTimeLine(Lehman[c("Date", "Close", "title", "annotation", "Volume")],#
                        datevar=Date, options=list(displayAnnotations=TRUE, width=800, height=600, scaleColumns='[0,1]', scaleType='allmaximized'))
plot(A)
head(Lehman)
names(Lehman)
names(Lehman)[8:9]
names(Lehman)[8:9]=c("Title", "Annotation")
head(Lehman)
save(Lehman, file="~/Dropbox/google-motion-charts-with-r/data/Lehman.RData")
prompt(Lehman , file="~/Desktop/Lehman.Rd")
A1=gvisAnnotatedTimeLine(Lehman[c("Date", "Adj. Close", "Title", "Annotation")],#
                        datevar=Date, options=list(displayAnnotations=TRUE))
A1=gvisAnnotatedTimeLine(Lehman[c("Date", "Adj.Close", "Title", "Annotation")],#
                        datevar=Date, options=list(displayAnnotations=TRUE))
plot(A1)
?gvisAnnotationTimeLine
A1=gvisAnnotatedTimeLine(Lehman[c("Date", "Adj.Close", "Title", "Annotation")],#
                         datevar=Date,#
                         options=list(displayAnnotations=TRUE,#
                           width=800, height=600)#
                         )
plot(A1)
#
str(Lehman)
#
summary(Lehman)
A1=gvisAnnotatedTimeLine(Lehman[c("Date", "Adj.Close", "Title", "Annotation")],#
                         datevar="Date",#
                         options=list(displayAnnotations=TRUE,#
                           width=800, height=600)#
                         )
plot(A1)
library(googleVis)
demo(googleVis)
?gvisAnnotationTimeLine
Lehman[13,1]
toJSON(Lehman[13,1])
toJSON(Lehman[100,1])
toJSON(Lehman[200,1])
A1<-gvisAnnotatedTimeLine(Lehman[c("Date", "Adj.Close", "Volume")],#
                         datevar="Date",#
                         options=list(scaleColumns='[]',#
                           width=600, height=350,#
                           zoomStartTime=toJSON(Lehman[100,"Date"]),#
                           zoomEndTime=toJSON(Lehman[200,"Date"]) )#
                         )
plot(A1)
A1$html$chart
cat(A1$html$chart)
edit(A1$html$chart)
cat(A1$html$chart)
gsub("'new Date", "new Date",A1$html$chart)
A1$hrml$chart=gsub("'new Date", "new Date",A1$html$chart)
A1$html$chart=gsub("'new Date", "new Date",A1$html$chart)
cat(A1$html$chart)
A1<-gvisAnnotatedTimeLine(Lehman[c("Date", "Adj.Close", "Volume")],#
                         datevar="Date",#
                         options=list(scaleColumns='[]',#
                           width=600, height=350,#
                           zoomStartTime=toJSON(Lehman[100,"Date"]),#
                           zoomEndTime=toJSON(Lehman[200,"Date"]) )#
                         )
A1$html$chart=gsub("'new Date", "new Date",A1$html$chart)
A1$html$chart=gsub("05,25)'", "05,25)",A1$html$chart)
A1$html$chart=gsub("10,20)'", "10,20)",A1$html$chart)
plot(A1)
toJSON(TRUE)
toJSON(23)
toJSON("Hello")
cat(toJSON("Hello"))
cat(toJSON("[Hello]"))
toJSON("[Hello]")
gvisOptions <- function(options=list(gvis=list(width = 600, height=500))){#
    options <- options$gvis#
    # wipe out options with start with gvis.#
    options[grep("^gvis.",names(options))] <- NULL#
    .par <- sapply(names(options), function(x)#
                   paste("options[\"", x,"\"] = ",#
                         ifelse(is.numeric(options[[x]]) | is.logical(options[[x]]),#
                                ## options are numeric or logical#
                                ifelse(is.numeric(options[[x]]),#
                                       options[[x]],#
                                       ifelse(options[[x]],#
                                              "true", "false")#
                                       ),#
                                ## options are character or [-style, e.g. colours#
                                ifelse(checkSquareBracketOps(options[[x]]),#
                                       options[[x]],#
                                       paste("'", options[[x]],"'",sep="")#
                                       )#
                                ),#
                         ";",sep="" )#
                   )#
    return(.par)#
}#
#
checkSquareBracketOps <- function(char){#
#
  first <- substr(char, 1,1)#
  n <- nchar(char)#
  last <- substr(char, n, n)#
  ifelse(first == "[" & last == "]", TRUE, FALSE)#
}
gvisOptions(options=list(gvis=list(width=23, name="Hello", color='[2,3,2]', flag=TRUE)))
cat(gvisOptions(options=list(gvis=list(width=23, name="Hello", color='[2,3,2]', flag=TRUE))))
class(gvisOptions(options=list(gvis=list(width=23, name="Hello", color='[2,3,2]', flag=TRUE))))
cat(gvisOptions(options=list(gvis=list(width=23, name="Hello", color='[2,3,2]', flag=TRUE))))
toJSON("[2,3]")
cat(toJSON("[2,3]"))
cat(toJSON([2,3]))
cat(toJSON("[[2,3]]"))
toJSON(TRUE)
toJSON("Hello")
#
gvisOptions <- function(options=list(gvis=list(width = 600, height=500))){#
    options <- options$gvis#
    # wipe out options with start with gvis.#
    options[grep("^gvis.",names(options))] <- NULL#
    .par <- sapply(names(options), function(x)#
                   paste("options[\"", x,"\"] = ",#
                         toJSON(options[[x]]),#
                         ";",sep="" )#
                   )#
    return(.par)#
}
cat(gvisOptions(options=list(gvis=list(width=23, name="Hello", color='[2,3,2]', flag=TRUE))))
cat(gvisOptions(options=list(gvis=list(width=23, name="Hello", color='[2,3,2]', flag=TRUE, data=Lehman[200,"Date"]))))
#
gvisOptions <- function(options=list(gvis=list(width = 600, height=500))){#
    options <- options$gvis#
    # wipe out options with start with gvis.#
    options[grep("^gvis.",names(options))] <- NULL#
    .par <- sapply(names(options), function(x)#
                   paste("options[\"", x,"\"] = ",#
                                ifelse(checkSquareBracketOps(options[[x]]),#
                                       options[[x]],                                       #
                                       toJSON(options[[x]])#
                                       ),#
                         ";",sep="" )#
                   )#
    return(.par)#
}
cat(gvisOptions(options=list(gvis=list(width=23, name="Hello", color='[2,3,2]', flag=TRUE, data=Lehman[200,"Date"]))))
q()
library(googleVis)
A3<-gvisAnnotatedTimeLine(Lehman[c("Date", "Adj.Close", "Volume")],#
                         datevar="Date",#
                         options=list(scaleColumns='[]',#
                           width=600, height=350,#
                           zoomStartTime=toJSON(Lehman[100,"Date"]),#
                           zoomEndTime=toJSON(Lehman[200,"Date"]) )#
                         )
plot(A3)
cat(A3$html$chart)
A3<-gvisAnnotatedTimeLine(Lehman[c("Date", "Adj.Close", "Volume")],#
                         datevar="Date",#
                         options=list(scaleColumns='[]',#
                           width=600, height=350,#
                           zoomStartTime=as.Date("2006-04-01")),#
                           zoomEndTime=as.Date("2006-07-01")) )#
                         )
#
A3<-gvisAnnotatedTimeLine(Lehman[c("Date", "Adj.Close", "Volume")],#
                         datevar="Date",#
                         options=list(scaleColumns='[]',#
                           width=600, height=350,#
                           zoomStartTime=as.Date("2006-04-01"),#
                           zoomEndTime=as.Date("2006-07-01")) #
                         )
cat(A3$html$chart)
plot(A3)
A3<-gvisAnnotatedTimeLine(Lehman[c("Date", "Adj.Close", "Volume")],#
                         datevar="Date",#
                         options=list(scaleColumns='[]',#
                           scaleType='allmaximized',#
                           width=600, height=350,#
                           zoomStartTime=as.Date("2006-04-01"),#
                           zoomEndTime=as.Date("2006-07-01")) #
                         )
plot(A3)
demo(googleVis)
library(googleVis)
library(ChainLadder)
RAA
t(RAA)
R=t(RAA)
colnames(R)
paste(colnames(R), "-12-31", sep="")
as.Date(paste(colnames(R), "-12-31", sep=""))
Year=as.Date(paste(colnames(R), "-12-31", sep=""))
df=data.frame(Year, df)
df=data.frame(Year, R)
df
df=data.frame(Year, as.matrix(R))
df
R
as.matrix(R)
as.data.frame(as.matrix(R))
R
cbind(Year,R)
df=cbind(Year,R)
class(df)
as.data.frame(df)
df=as.data.frame(df)
df$Year=Year
df
A=gvisAnnotatedTimeLine(df, "Year")
plot(A)
?gvisAnnotatedTimeLind
?gvisAnnotatedTimeLine
A=gvisAnnotatedTimeLine(df, "Year", options=list(legendPosition='newRow', width=800, height=400))
plot(A)
names(df)
names(df)[1]="YearEnd"
df
RAA
as.data.frame(RAA, na.rm=TRUE )
lRAA=as.data.frame(RAA, na.rm=TRUE )
heaad(RAA)
head(lRAA)
RAA
cum2incr(RAA)
head(lRAA)
subset(lRAA, dev==7 & origin=1982)
subset(lRAA, dev==7 & origin==1982)
lRAA
lRAA[50,]
lRAA[47,]
lRAA[50,]
 lRAA=as.data.frame(RAA, na.rm=TRUE)#
 lRAA$title <- NA#
 lRAA$annotation <- NA#
 #
 lRAA$title[c(2,47)] <- c("Low first claim", "Negative development")#
 lRAA$annotation[c(2,47)] <- c("Change in underlying claims process resulted in delayed reporting", #
 							   "Joe Bloggs was on holiday and the person who covered for him mixed up the signs.")
lRAA
lRAAhead(lRAA)
head(lRAA)
example(reshape)
?reshape
head(lRAA)
 lRRA$cal.year.end <- as.Date(with(lRAA, paste(origin+dev-1,"-12-31", sep="")))
 lRAA$cal.year.end <- as.Date(with(lRAA, paste(origin+dev-1,"-12-31", sep="")))
lRAA
head(lRAA)
reshape(lRAA,  idvar="cal.year.end", v.names=c("value", "title", "annotation"), timevar="origin", direction="wide")
wRAA=reshape(lRAA,  idvar="cal.year.end", v.names=c("value", "title", "annotation"), timevar="origin", direction="wide")
A=gvisAnnotatedTimeLine(wRAA, "cal.year.end", options=list(legendPosition='newRow', width=800, height=400))
plot(A)
head(wRAA)
A=gvisAnnotatedTimeLine(wRAA[,-1], "cal.year.end", options=list(legendPosition='newRow', width=800, height=400))
plot(A)
RAA
t(RAA)
df
Year=as.Date(paste(colnames(R), "-12-31", sep=""))
R
A=gvisAnnotatedTimeLine(wRAA[,-1], "cal.year.end", options=list(legendPosition='newRow', width=800, height=400))
 lRAA=as.data.frame(RAA, na.rm=TRUE)#
 lRAA$dev.year.end <- as.Date(with(lRAA, paste(origin-1,"-12-31", sep="")))#
 lRAA$title <- NA#
 lRAA$annotation <- NA#
 #
 lRAA$title[c(2,47)] <- c("Low first claim", "Negative development")#
 lRAA$annotation[c(2,47)] <- c("Change in underlying claims process resulted in delayed reporting", #
 							   "Joe Bloggs was on holiday and the person who covered for him mixed up the signs.")#
 							   #
 wRAA=reshape(lRAA,  idvar="cal.year.end", v.names=c("value", "title", "annotation"), timevar="origin", direction="wide")#
 							   #
  							   #
A=gvisAnnotatedTimeLine(wRAA[,-1], "cal.year.end", options=list(legendPosition='newRow', width=800, height=400, displayAnnotations=TRUE))
 wRAA=reshape(lRAA,  idvar="dev.year.end", v.names=c("value", "title", "annotation"), timevar="origin", direction="wide")#
 							   #
  							   #
A=gvisAnnotatedTimeLine(wRAA[,-1], "cal.year.end", options=list(legendPosition='newRow', width=800, height=400, displayAnnotations=TRUE))
plot(A)
wRAA
 lRAA=as.data.frame(RAA, na.rm=TRUE)A#
 lRAA$dev.year.end <- as.Date(with(lRAA, paste(origin,"-12-31", sep="")))#
 lRAA$title <- NA#
 lRAA$annotation <- NA#
 #
 lRAA$title[c(2,47)] <- c("Low first claim", "Negative development")#
 lRAA$annotation[c(2,47)] <- c("Change in underlying claims process resulted in delayed reporting", #
 							   "Joe Bloggs was on holiday and the person who covered for him mixed up the signs.")#
 							   #
 wRAA=reshape(lRAA,  idvar="dev.year.end", v.names=c("value", "title", "annotation"), timevar="origin", direction="wide")
wRAA
 lRAA=as.data.frame(RAA, na.rm=TRUE)A#
 lRAA$dev.year.end <- as.Date(with(lRAA, paste(origin,"-12-31", sep="")))#
 lRAA$title <- NA#
 lRAA$annotation <- NA#
 #
 lRAA$title[c(2,47)] <- c("Low first claim", "Negative development")#
 lRAA$annotation[c(2,47)] <- c("Change in underlying claims process resulted in delayed reporting", #
 							   "Joe Bloggs was on holiday and the person who covered for him mixed up the signs.")#
 							   #
 wRAA=reshape(lRAA,  idvar="dev.year.end", v.names=c("value", "title", "annotation"), timevar="dev", direction="wide")
wRAA
RAA
t(RAA)
wRAA
 lRAA=as.data.frame(RAA, na.rm=TRUE)A#
 lRAA$dev.year.end <- as.Date(with(lRAA, paste(dev,"-12-31", sep="")))#
 lRAA$title <- NA#
 lRAA$annotation <- NA#
 #
 lRAA$title[c(2,47)] <- c("Low first claim", "Negative development")#
 lRAA$annotation[c(2,47)] <- c("Change in underlying claims process resulted in delayed reporting", #
 							   "Joe Bloggs was on holiday and the person who covered for him mixed up the signs.")#
 							   #
 wRAA=reshape(lRAA,  idvar="dev.year.end", v.names=c("value", "title", "annotation"), timevar="origin", direction="wide")#
 							   #
  							   #
A=gvisAnnotatedTimeLine(wRAA[,-1], "cal.year.end", options=list(legendPosition='newRow', width=800, height=400, displayAnnotations=TRUE))
 lRAA=as.data.frame(RAA, na.rm=TRUE)#
 lRAA$dev.year.end <- as.Date(with(lRAA, paste(dev,"-12-31", sep="")))#
 lRAA$title <- NA#
 lRAA$annotation <- NA#
 #
 lRAA$title[c(2,47)] <- c("Low first claim", "Negative development")#
 lRAA$annotation[c(2,47)] <- c("Change in underlying claims process resulted in delayed reporting", #
 							   "Joe Bloggs was on holiday and the person who covered for him mixed up the signs.")#
 							   #
 wRAA=reshape(lRAA,  idvar="dev.year.end", v.names=c("value", "title", "annotation"), timevar="origin", direction="wide")#
 							   #
  							   #
A=gvisAnnotatedTimeLine(wRAA[,-1], "cal.year.end", options=list(legendPosition='newRow', width=800, height=400, displayAnnotations=TRUE))
wRAA
plot(A)
?demo
system.file("demo", "google.R", package="googleVis")
system.file("demo", "googleVis.R", package="googleVis")
setwd("~/Dropbox/google-motion-charts-with-r/inst/doc/")
"../../demo/googleVis.R"
?lehman
?Lehman
qpaid
getLatestCumulative( qpaid)
getLatestCumulative <- function(cumulative.tri) {#
  y <- apply(cumulative.tri, 1L, function(x) ifelse(length(w <- which(!is.na(x))) > 0L, x[tail(w, 1L)], x[1L]))#
  if (any(is.na(y))) stop("Some year (row) has no available losses")#
  return(y)#
}
getLatestCumulative( qpaid)
#
getLatestCumulative <- function(cumulative.tri) {#
  y <- apply(cumulative.tri, 1L, function(x) ifelse(length(w <- which(!is.na(x))) > 0L, x[tail(w, 1L)], x[1L]))#
  if (any(is.na(y))) stop("Some year (row) has no available losses")#
#
  return(as.numeric(y))#
}
getLatestCumulative( qpaid)
?qpaid
## the triangle to a quarterly origin period.#
n <- ncol(qpaid)#
Paid <- matrix(NA, n, n)#
Paid[seq(1,n,4),] <- qpaid
PAid
Paid
getLatestCumulative( Paid)
getLatestCumulative2( Paid)
getLatestCumulative2 <- function(cumulative.tri) {#
  # Return the latest diagonal as a vector from a cumulative triangle#
  available.indicies <- apply(!is.na(cumulative.tri), 1, which)#
  latest.indicies <- sapply(available.indicies, function(x) ifelse(length(x)>0, max(x), 1) )#
  if (any(latest.indicies < 1))#
    stop("Some year (row) has no available losses")#
  return(cumulative.tri[cbind(1:nrow(cumulative.tri), latest.indicies)])#
}
getLatestCumulative2( Paid)
as.data.frame( Paid, na.rm=TRUE)
as.data.frame( as.triangle(Paid), na.rm=TRUE)
as.data.frame(RAA, na.rm=TRUE)
subset( as.data.frame(RAA, na.rm=TRUE), dev==max( as.data.frame(RAA, na.rm=TRUE)$dev)
)
subset( as.data.frame(RAA, na.rm=TRUE), origin+dev-1==max( as.data.frame(RAA, na.rm=TRUE)$dev))
subset( as.data.frame(RAA, na.rm=TRUE), ()origin+dev-1-min( as.data.frame(RAA, na.rm=TRUE)$origin))==max( as.data.frame(RAA, na.rm=TRUE)$dev))
