Created
July 4, 2012 17:32
-
-
Save felixjung/3048496 to your computer and use it in GitHub Desktop.
R code for Alex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
flush.console() | |
# Set working directory | |
setwd("/Users/Felix/Documents/University/Maastricht University/Master Thesis/") | |
# Include spreadPlotter code | |
source("Code/R/Main/DataPlotting.R") | |
source("Code/R/Library/additionalFunctions.R") | |
# Tranche configuration | |
correlationType <- "Compound" | |
attachmentPoints <- c(0, 0.03, 0.06, 0.09, 0.12, 0.22) | |
maturity <- 10 | |
startDate <- as.Date("2008-05-07") | |
endDate <- as.Date("2008-10-07") | |
plotData <- list() | |
trancheColors <- c( | |
"#4D545B", | |
"#8F4834", | |
"#614875", | |
"#008249", | |
"#0097B6", | |
"#174059", | |
"#6C625E", | |
"#A03482", | |
"#FF5C19", | |
"#A03482", | |
"#6E8138" | |
) | |
# Loop through tranches | |
for(at in 1:(length(attachmentPoints) - 1)){ | |
# Load correlation time series for tranche | |
correlation.ts <- corrTimeSeries(correlationType, maturity, c(attachmentPoints[at], attachmentPoints[at + 1])) | |
# Convert correlation time series into binary time series indicating, | |
# if the calibration worked or not | |
invertibility.ts <- | |
# Write CSV for further investigation | |
fileName <- paste( | |
"correlation_invertibility/", | |
correlationType, | |
"_Correlation_Invertibility_", | |
maturity, | |
"Y_", | |
attachmentPoints[at], | |
"_", | |
attachmentPoints[at + 1], | |
"_", | |
startDate, | |
"_", | |
endDate, | |
".csv", | |
sep = "" | |
) | |
write.csv(spreadSeries.diff, file = paste("Results/", maturity, "Y/", correlationType,"/", fileName, sep = "")) | |
# Save plot | |
p <- genericBarPlot(spreadSeries.diff, FALSE, colors = c(trancheColors[at]), yLabel = "Percent") | |
# Display plot | |
p | |
# Generate file name | |
fileName <- paste( | |
"Compound_Spread_Differences_", | |
maturity, | |
"Y_", | |
attachmentPoints[at], | |
"_", | |
attachmentPoints[at + 1], | |
"_", | |
startDate, | |
"_", | |
endDate, | |
sep = "" | |
) | |
# Save plot | |
ggsave( | |
filename = paste("Latex/Images/difference_plots/", fileName, ".pdf", sep = ""), | |
plot = p, | |
unit = "cm", | |
width = 15, | |
height = 5, | |
dpi = 180 | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment