I have a shapefile (US) and a list of counties (biz) with data that I'd like to convert to a choropleth map. There is data missing, so not every county FIPS is present in the biz dataframe. I've filtered both the shapefile and the biz R dataframe so that each contain the same countyfips, but I am still getting the following error when I try to merge the two to create a spatial dataframe.
ERROR while rich displaying an object: Error in sp::SpatialPolygonsDataFrame(polys, data = input#data): row.names of data and Polygons IDs do not match
I've tried:
library(rgdal)
merge(US, biz, by = "FIPS", match.ID = FALSE, duplicateGeoms = T)
and
sp::merge(US, biz, by = "FIPS")
What am I missing here?
Below is how I loaded the shapefile:
# download shape (a little less detail than in the other scripts)
f <- tempfile()
download.file("http://www2.census.gov/geo/tiger/GENZ2010/gz_2010_us_050_00_20m.zip", destfile = f)
unzip(f, exdir = ".")
US <- shapefile("gz_2010_us_050_00_20m.shp")
# leave out AK, HI, and PR (state FIPS: 02, 15, and 72)
US <- US[!(US$STATE %in% c("02","15","72")),]
# create key column
US$FIPS <- paste0(US$STATE, US$COUNTY)
And the following is the first 100 rows of my biz data:
structure(list(FIPS = c(10001, 10003, 10005, 11001, 12001, 12003,
12005, 12007, 12009, 12011, 12013, 12015, 12017, 12019, 12021,
12023, 12027, 12031, 12033, 12035, 12037, 12039, 12041, 12045,
12049, 12051, 12053, 12055, 12057, 12061, 12063, 12065, 12069,
12071, 12073, 12075, 12081, 12083, 12085, 12086, 12087, 12089,
12091, 12093, 12095, 12097, 12099, 12101, 12103, 12105, 12107,
12109, 12111, 12113, 12115, 12117, 12119, 12121, 12123, 12127,
12129, 12131, 12133, 13001, 13009, 13013, 13015, 13021, 13029,
13031, 13033, 13035, 13039, 13045, 13047, 13051, 13055, 13057,
13059, 13063, 13067, 13069, 13071, 13073, 13075, 13077, 13081,
13083, 13085, 13087, 13089, 13095, 13097, 13103, 13105, 13107,
13109, 13111, 13113, 13115), merch_perc_change = c(-0.999999997419426,
-0.999999960099927, -0.999999463606016, -0.999999999992747, -0.999999589415816,
-0.999776694518714, -0.999998139171249, -0.923691427414423, -0.999962755064437,
-0.999999297609172, 6.86356300955509, -0.999796407354303, -0.999999920342331,
-0.999989017442108, -0.999999987828828, -0.999687144654275, -0.999809854633837,
-0.999994022173781, -0.999997564726118, -0.999991074764553, -0.999978132819644,
-0.999048191581644, -0.999816255794303, -0.99999999999953, -0.999998368294174,
-0.999983530324202, -0.999999959737609, -0.999999999915238, -0.9999998961883,
-0.999997217365727, -0.999999486649557, -0.998247739967963, -0.999998585480854,
-0.99999734246251, -0.99998316042666, -0.999997698874625, -0.999999749503321,
-0.999999812749288, -0.999935448837586, -0.999999220586342, -0.99999956646977,
-0.999999999979337, -0.999999311106202, -0.99798206258435, -0.999999372093591,
-0.999999923772396, -0.999995867853803, -0.999997734665119, -0.999999905345573,
-0.999998463559358, -0.99999999205029, -0.999999991820707, -0.99990638439578,
-0.999999312175056, -0.999999978238681, -0.999999607559491, -0.999997940723336,
-0.999965827464078, -0.99987412039642, -0.999998284179988, -0.999788909786871,
-0.999999999391236, -0.999558269566805, -0.999999999991671, -0.999999896605606,
-0.999999811038711, -0.99957117015121, -0.999997531666568, -0.999891490436958,
-0.99996557149293, -0.999997779404573, -0.999999995034784, -0.999999862415467,
-0.999984320487476, -0.999998471029504, -0.999999475141075, -0.999989299298126,
-0.99999700303135, -0.999999983041563, -0.999976248756212, -0.999997959804029,
-0.999906120208879, -0.974494760294364, -0.999996351284903, -0.999999987539243,
-0.999314090769117, -0.999999999937565, -0.999999999996, -0.999227737065879,
-0.999999894274373, -0.999999275234666, -0.99999972998535, -0.999989925844005,
-0.999980780315507, 11.9726427425268, -0.999999845161106, -0.999985089588605,
-0.99999999506689, -0.999997272506931, -0.999999600943781), rev_perc_change = c(-0.999999868770726,
-0.999999990632098, -0.999978350417758, -1, -0.999999977063738,
-0.999999557925536, 2.96734401473508, -0.999999978115999, -0.999999876658537,
-0.999998644384056, -0.999999948925146, -0.999957383116217, -0.999999999202153,
-0.799103739676736, -0.999999999730313, 52.5419769811163, -0.989897752573793,
-0.999990771638404, -0.999999097277337, -0.999999056612073, -0.999999999997651,
-0.791258306382895, -0.835408375403338, -0.999999949255092, -0.999999995917852,
-0.995526573454658, -0.999980744495764, -0.999999999999523, -0.999999967084492,
-0.999999795346701, -0.865997270001737, -0.998547105111494, -0.999999994311607,
-0.999999986040664, -0.999991969242583, -0.999644160435803, -0.999999761949245,
-0.999999615053214, -0.439117774567191, -0.999999973586027, -0.999999999999614,
-0.999997934384089, -0.999999490767057, -0.904747175661281, -0.999999996424736,
-0.999999995884735, -0.999999970209871, -0.999993644951214, -0.999999928595513,
-0.999997760171338, -0.999999999201456, -0.999999998546284, -0.999996541137073,
-0.999999998767801, -0.999999999803137, -0.999999882081287, -0.999998232474645,
-0.999999998321198, -0.999999999134723, -0.999999877739019, -0.999938452181625,
-0.999999999696075, -0.999971062558217, -1, -0.999999999998913,
-0.999999936705897, -0.999999972777953, -0.999993970088101, -0.767994542540064,
-0.999997956578155, -0.999999999999991, -0.999999999504284, -0.999999988489851,
-0.999998275694059, -0.999978229417813, -0.999999893084442, -0.99999998787768,
-0.999974986845167, -0.999999999116068, -0.999998633242769, -0.999998804829792,
-0.982278889848666, -0.364341840741643, -0.999999997786457, -0.999999976614482,
-0.998382508964322, -0.999999999999671, -0.999999196325065, -0.999975011497777,
-0.998599571268165, -0.999999979094997, -0.997753198487314, -0.999999926318692,
-0.154416470074132, -0.928951601468295, -0.994011394007064, -0.999999999462366,
-0.999999999998392, -0.999999919376053, -0.99999990340994), religion = c(0.041286647,
0.02607471, 0.066732876, 0.044134054, 0.05952625, 0.06738507,
0.059015673, 0.111649066, 0.025701044, 0.01340009, 0.15596099,
0.020686807, 0.041033328, 0.028240733, 0.017688353, 0.10048646,
0.09002863, 0.045010816, 0.0599233, 0.023459796, 0.18008809,
0.15380068, 0.10875068, 0.16463679, 0.12366201, 0.08062692, 0.020737456,
0.072489396, 0.02980364, 0.03522147, 0.18431833, 0.2241213, 0.04967877,
0.020767821, 0.042845365, 0.114026226, 0.025252016, 0.050515506,
0.028480459, 0.011976497, 0.051216464, 0.071065746, 0.060021035,
0.0671975, 0.022543803, 0.026054224, 0.012819406, 0.012850202,
0.019244831, 0.052286506, 0.104308784, 0.021517357, 0.026059527,
0.04549559, 0.026263602, 0.018891444, 0.04764373, 0.14865479,
0.17848434, 0.032876275, 0.074900545, 0.13018908, 0.14712808,
0.22409584, 0.06142032, 0.04922596, 0.058575258, 0.080876544,
0.054859933, 0.05560649, 0.14968075, 0.09415126, 0.076041564,
0.07222162, 0.04100541, 0.059602886, 0.19613168, 0.022500644,
0.035217304, 0.023242751, 0.01764376, 0.12785666, 0.1234028,
0.03073952, 0.13650659, 0.060998723, 0.12673242, 0.11131127,
0.10484315, 0.20243417, 0.024939083, 0.07396702, 0.03522846,
0.07814219, 0.21069641, 0.14236231, 0.14371029, 0.15000819, 0.050455987,
0.099605545), civic = c(0.09236666, 0.10866666, 0.08693332, 0.10866666,
0.10323332, 0.048899993, 0.09779999, 0.048899993, 0.10866666,
0.10866666, 0.02173333, 0.081499994, 0.081499994, 0.09779999,
0.09779999, 0.05433333, 0.05976666, 0.10866666, 0.10866666, 0.081499994,
0.06519999, 0.06519999, 0.02173333, 0.06519999, 0.05976666, 0.08693332,
0.10323332, 0.08693332, 0.10866666, 0.09779999, 0.06519999, 0.03803333,
0.09236666, 0.10866666, 0.10866666, 0.05976666, 0.09779999, 0.09779999,
0.09779999, 0.10866666, 0.09779999, 0.09236666, 0.09236666, 0.07063332,
0.10866666, 0.09236666, 0.10866666, 0.09779999, 0.10866666, 0.10866666,
0.07606666, 0.09779999, 0.07606666, 0.08693332, 0.10866666, 0.10866666,
0.08693332, 0.05976666, 0.048899993, 0.09779999, 0.06519999,
0.07063332, 0.05976666, 0.05433333, 0.07606666, 0.06519999, 0.07063332,
0.10866666, 0.06519999, 0.081499994, 0.032599997, 0.02173333,
0.081499994, 0.05976666, 0.048899993, 0.10866666, 0.03803333,
0.08693332, 0.10866666, 0.09236666, 0.10866666, 0.07063332, 0.07063332,
0.07606666, 0.03803333, 0.07606666, 0.05433333, 0.05433333, 0.05433333,
0.05433333, 0.09779999, 0.081499994, 0.08693332, 0.06519999,
0.03803333, 0.05976666, 0.02173333, 0.048899993, 0.10323332,
0.081499994), ethnic = c(0.3970396, 0.37897056, 0.5357585, 0.24768388,
0.40286815, 0.6357579, 0.6016036, 0.5114627, 0.6255658, 0.3186922,
0.5825614, 0.7621388, 0.8317045, 0.6124228, 0.6632664, 0.52478975,
0.49357843, 0.30896062, 0.39672756, 0.6146619, 0.662264, 0.283978,
0.79085565, 0.5306848, 0.6103033, 0.35079825, 0.7638138, 0.64863324,
0.44819558, 0.6953889, 0.40650934, 0.3398254, 0.61111623, 0.6295637,
0.3380776, 0.67512846, 0.61698794, 0.5896463, 0.721169, 0.4455908,
0.7558898, 0.75864416, 0.5891671, 0.65199465, 0.29523754, 0.43643963,
0.46105385, 0.7583519, 0.62372357, 0.50434506, 0.53839517, 0.74449384,
0.45155495, 0.7162366, 0.7817946, 0.5408662, 0.68203306, 0.6332905,
0.49937886, 0.6118857, 0.626454, 0.6951653, 0.5778341, 0.41941065,
0.32683736, 0.5616461, 0.5903009, 0.28805655, 0.5589603, 0.38802063,
0.33231544, 0.43056065, 0.47309256, 0.5226548, 0.8516469, 0.29380715,
0.66506696, 0.6927326, 0.33732903, 0.3049189, 0.29078054, 0.35410964,
0.32911754, 0.5134419, 0.37947673, 0.51836216, 0.3146671, 0.8988029,
0.89620274, 0.29536778, 0.24357241, 0.38732207, 0.308964, 0.61849403,
0.39014798, 0.3550223, 0.30616927, 0.91790694, 0.43637908, 0.5408756
), language = c(0.9028321, 0.8534756, 0.9003864, 0.8477236, 0.85861427,
0.9763271, 0.91966915, 0.96824694, 0.89786947, 0.6191133, 0.9333193,
0.9033248, 0.9319655, 0.9029625, 0.6809509, 0.93964654, 0.70345926,
0.86834, 0.91468996, 0.8441426, 0.92808974, 0.9063144, 0.9645202,
0.9443971, 0.5804937, 0.56604165, 0.8854753, 0.81346387, 0.7352802,
0.8515354, 0.94880205, 0.93205106, 0.877309, 0.7811706, 0.9077789,
0.9318178, 0.8326978, 0.8790868, 0.8538892, 0.25064504, 0.7663783,
0.9555273, 0.907167, 0.7620087, 0.66066307, 0.5361982, 0.72005004,
0.8630133, 0.8662945, 0.81044525, 0.9097693, 0.9163808, 0.7922232,
0.92694986, 0.8709022, 0.81088173, 0.90886694, 0.92950064, 0.9560861,
0.8681097, 0.96221495, 0.92667896, 0.9416113, 0.8984488, 0.9538415,
0.8885773, 0.9254957, 0.94662046, 0.9305949, 0.9372623, 0.98557174,
0.96830726, 0.94496214, 0.923303, 0.9672361, 0.9219519, 0.96036005,
0.87589335, 0.8607454, 0.7873163, 0.7968753, 0.89746803, 0.83082134,
0.8995851, 0.9295714, 0.9215403, 0.96248287, 0.9729186, 0.955991,
0.9710674, 0.8113927, 0.9619904, 0.8924399, 0.96472365, 0.9513764,
0.94352907, 0.86856884, 0.9584267, 0.88784045, 0.9044569), voteage = c(0.5415052,
0.5250972, 0.5858911, 0.57861066, 0.60942423, 0.558716, 0.5892219,
0.6370349, 0.6141516, 0.3952495, 0.5966508, 0.69935966, 0.70640314,
0.52056634, 0.43017876, 0.59642285, 0.37977982, 0.53641015, 0.5947154,
0.59636533, 0.68313015, 0.524484, 0.60493284, 0.6814822, 0.26147988,
0.24641654, 0.62900823, 0.60015863, 0.4710629, 0.59511346, 0.6425276,
0.66375273, 0.5933129, 0.52887684, 0.6171358, 0.60419106, 0.53888094,
0.620374, 0.614735, 0.24189119, 0.6001134, 0.6118948, 0.57089466,
0.43977982, 0.44113994, 0.39214894, 0.4736451, 0.58449423, 0.6172989,
0.5052691, 0.56155217, 0.5756319, 0.5006779, 0.56436056, 0.64906085,
0.53386456, 0.79360616, 0.5629912, 0.64399046, 0.6279944, 0.61143416,
0.6120734, 0.6178282, 0.51169556, 0.63740486, 0.46528107, 0.49653965,
0.5406704, 0.49688926, 0.6171718, 0.51588005, 0.60201925, 0.540264,
0.52046335, 0.5638834, 0.55689573, 0.5832646, 0.45817313, 0.58187026,
0.37612963, 0.4259325, 0.49137145, 0.39633512, 0.49645153, 0.49827608,
0.48816267, 0.5490801, 0.61691815, 0.58953744, 0.5359645, 0.43509322,
0.54484385, 0.44624743, 0.5085251, 0.5765146, 0.53727007, 0.45505175,
0.6727599, 0.493701, 0.52082986), local = c(0.11346269, 0.0821763,
0.09865325, 0.13039602, 0.16706811, 0.1925357, 0.18262136, 0.20276488,
0.16904168, 0.18558133, 0.23628975, 0.19656563, 0.22064485, 0.19406708,
0.13554244, 0.18911618, 0.1964137, 0.1288788, 0.1642498, 0.2320314,
0.2406299, 0.23134439, 0.2193604, 0.21352763, 0.18684117, 0.2663458,
0.18552017, 0.1936251, 0.15774018, 0.16654506, 0.2464689, 0.2213913,
0.19595641, 0.17701498, 0.16920264, 0.18539564, 0.19038261, 0.18990363,
0.17630382, 0.16714683, 0.16716042, 0.18136276, 0.14041798, 0.21676183,
0.13718824, 0.1693134, 0.16400187, 0.19431508, 0.15682065, 0.20015918,
0.22922051, 0.15314136, 0.20060387, 0.17444389, 0.17039652, 0.1454538,
0.234232, 0.16478789, 0.1899709, 0.18571664, 0.26345906, 0.2111755,
0.27364796, 0.16966473, 0.16955985, 0.21253699, 0.22058052, 0.15532793,
0.15032071, 0.15741009, 0.2304608, 0.250423, 0.20964451, 0.17636389,
0.16328937, 0.16403592, 0.16296567, 0.1623544, 0.17546876, 0.17806159,
0.13644126, 0.23888248, 0.1776321, 0.15040636, 0.16471201, 0.17668277,
0.24506003, 0.14990062, 0.19695675, 0.20724353, 0.15140234, 0.19517402,
0.18235727, 0.19484001, 0.18699574, 0.16355312, 0.121629976,
0.21160316, 0.1918851, 0.16756512), education = c(0.6537678,
0.6364562, 0.5315682, 0.6130346, 0.72199595, 0.45010185, 0.68533605,
0.51221997, 0.6629328, 0.6099796, 0.4124236, 0.65784115, 0.56619143,
0.67209774, 0.52138495, 0.57331973, 0.1934827, 0.66496944, 0.700611,
0.67413443, 0.45112014, 0.43380857, 0.50610995, 0.37576377, 0.24847251,
0.3940937, 0.6252546, 0.47352344, 0.6262729, 0.5875764, 0.55906314,
0.5366599, 0.59063137, 0.59572303, 0.7443992, 0.55397147, 0.55906314,
0.59979635, 0.58350307, 0.56109977, 0.5682281, 0.62729126, 0.7209776,
0.44093686, 0.6405295, 0.62118125, 0.5712831, 0.6099796, 0.65478617,
0.5549898, 0.50814664, 0.65478617, 0.57026476, 0.65580446, 0.62729126,
0.68329936, 0.4857434, 0.4562118, 0.42260695, 0.6863544, 0.51221997,
0.54887986, 0.4154786, 0.49694502, 0.5875764, 0.5641548, 0.49083507,
0.5397149, 0.6201629, 0.7739307, 0.49694502, 0.33604884, 0.70162934,
0.59063137, 0.63441956, 0.62729126, 0.48472506, 0.6120163, 0.71588594,
0.598778, 0.6171079, 0.49083507, 0.48472506, 0.5916497, 0.58655804,
0.59775966, 0.54276985, 0.6822811, 0.65173113, 0.4582485, 0.6120163,
0.62729126, 0.5967413, 0.55600816, 0.36863542, 0.45723015, 0.401222,
0.6466395, 0.65784115, 0.5875764), employ = c(0.5028835, 0.57900804,
0.47750866, 0.5213379, 0.5121107, 0.4463668, 0.5074971, 0.32987314,
0.449827, 0.5397924, 0.28950405, 0.2802768, 0.23644753, 0.5374856,
0.44059977, 0.33679354, 0.35178775, 0.5363322, 0.4152249, 0.37600923,
0.37139562, 0.32064593, 0.34256056, 0.3252595, 0.37831604, 0.37600923,
0.30449826, 0.28835064, 0.5432526, 0.3690888, 0.30680507, 0.34256056,
0.42214534, 0.4152249, 0.5432526, 0.3656286, 0.43367937, 0.3287197,
0.39792386, 0.49942333, 0.57324106, 0.49019605, 0.5098039, 0.38523644,
0.56747407, 0.5224914, 0.46597463, 0.4106113, 0.48212227, 0.44059977,
0.32641295, 0.5374856, 0.38985008, 0.46251443, 0.37946942, 0.5859285,
0.118800454, 0.4083045, 0.34371397, 0.44059977, 0.49250287, 0.4544406,
0.36678204, 0.5340254, 0.38177624, 0.5201846, 0.5363322, 0.42791235,
0.5940023, 0.46251443, 0.39677048, 0.43137255, 0.44059977, 0.47866204,
0.5524798, 0.5098039, 0.37024224, 0.61937714, 0.4913495, 0.4948097,
0.6297578, 0.4394464, 0.4936563, 0.55709344, 0.4544406, 0.5870819,
0.38292962, 0.48096886, 0.54094577, 0.461361, 0.5282584, 0.37024224,
0.5340254, 0.5524798, 0.4175317, 0.38869664, 0.48096886, 0.40138412,
0.5928489, 0.46943483), socialcap = c(1.2465897, 1.1796607, 0.99583554,
1.213838, 1.2140356, 1.0433682, 1.1867946, 1.0998459, 1.1968888,
0.9863519, 1.0743337, 1.2542336, 1.2588876, 1.167894, 1.0432669,
1.0626454, 0.88172776, 1.0901438, 1.1371455, 1.1487094, 1.0707088,
1.1323296, 1.0424548, 1.3017348, 0.7089147, 0.99225324, 1.006372,
1.0797297, 1.0777289, 1.0685663, 1.1497757, 1.0380225, 1.1510758,
1.0681523, 1.1533836, 1.1480858, 1.109215, 1.0647533, 1.108393,
0.86751366, 1.1352568, 1.250612, 1.1412742, 0.9820876, 1.0141772,
0.9327179, 0.9930749, 1.0881922, 1.2074403, 1.0714755, 1.1362286,
1.1118767, 0.96056145, 1.2471367, 1.2069551, 0.9745213, 1.0848411,
1.1748116, 1.166508, 1.1300496, 1.1630167, 1.1959319, 1.1653817,
1.0205215, 1.0896816, 1.0423381, 1.0528433, 1.1218456, 1.1675899,
1.1556351, 1.0114185, 1.0285435, 1.2299659, 1.0582013, 1.1651775,
1.124054, 1.0567757, 1.1237862, 1.135855, 0.9389708, 1.0796958,
0.9262693, 0.8858328, 1.1860313, 0.9620687, 1.1273029, 1.0348538,
1.1883315, 1.1845229, 1.0326669, 1.0741078, 1.1087412, 1.0355263,
1.1264266, 1.0276779, 0.95914507, 0.9550716, 1.1294575, 1.1779915,
1.1125866)), row.names = c(NA, -100L), class = c("tbl_df", "tbl",
"data.frame"))
This is how I filtered the two dataframes to have the same county fips:
US <- US[which(US$FIPS %in% c(test$FIPS)),]
biz <- biz[which(biz$FIPS %in% c(US$FIPS)),]
Any help would be greatly appreciated!
Related
I am having some trouble with visualizing cumulative returns in R. For some reason I can't change the axis labels and line type in chart.TimeSeries or chart.CumReturns from the PerformanceAnalytics package. Changes in the line type do appear in the legend.
My code:
ret_compare <- cbind(conventional.scaled.returns.monthly, conditional.scaled.returns.monthly, unscaled.returns.monthly)
cum_ret_compare <- cumprod(ret_compare+1)
chart.TimeSeries(cum_ret_compare, ylab = "Cumulatief rendement", colorset= c(2,3,1),lty = 2, legend.loc = "topleft")
The plot I get:
A screenshot of the data I used (below is the full dput() output):
The data I used (dput(ret_compare)):
structure(c(0.0565939990771869, -0.0347482427707391, -0.0277900457059636,
0.0429234080870222, -0.0718787783241953, -0.016863029966348,
0.059355733239068, 0.037562234119064, -0.0677988560026864, 0.0600705787852096,
-0.0517080807079698, 0.00180517117961099, -0.0209223756892264,
0.0272845085630986, 0.0837601002893609, 0.0359655556488165, 0.0289223567394459,
0.00786503568014307, 0.0613306520140755, -0.0691778150018606,
0.0326380403566631, -0.0133417659847783, 0.0124121161628492,
0.0642708816666793, 0.00507849967404161, 0.0261052878209909,
0.0151493267776062, 0.00676515233437147, 0.00653446817356351,
0.0150714363479285, -0.050143190382553, 0.0345058557122753, 0.0441645265494663,
0.0330199447063566, 0.080567937081057, 0.0316571988327838, 0.000198181362019767,
0.0208690458801075, 0.0504761702266239, -0.00550425517164699,
0.0399051303505815, 0.0599723999392408, 0.0568078556781997, -0.047301231431996,
0.0883885279858534, -0.0511316915459871, 0.00804493275737861,
0.0299441033050929, 0.0334788931639478, 0.0582014365192993, 0.0678197532602445,
0.0159992998095304, 0.0125443303556689, 0.00819301763612046,
0.00991755318616083, -0.120605712811205, -0.0262409920857444,
0.040946793757588, 0.0164392980283827, 0.0306621368418329, -0.0238640140220965,
-0.0156901113780832, 0.0101061236361657, 0.0280945470081029,
-0.0493498768067187, 0.0158476544516308, -0.0130536804845046,
0.00928507222402164, -0.0174652889946849, 0.0415549564151227,
0.00501328628644071, 0.141989003051248, -0.0684962605913843,
0.0476352610219926, 0.0161558138743416, -0.0288967250807524,
-0.0136524963030579, 0.013609536698864, -0.0101217287483828,
-0.0158427614092369, -0.0659110431281645, -0.00361214051470649,
-0.0339148683510243, 0.0549197973662541, 0.00351817414237154,
-0.0836247487330098, -0.0660975163205073, 0.0304100958405675,
-0.0433097428906102, -0.0363928303567407, 0.0106002084863943,
-0.027020033384645, -0.0291214507902441, 0.013711263904689, 0.0191434464401923,
0.0249660315555751, -0.0360122263475078, 0.00687569978857283,
0.0574596331980592, -0.0114262145986058, -0.00694415263166959,
-0.0519113175679171, -0.092809259472171, -0.000240961580031951,
-0.0573097859137003, 0.0476330153045359, 0.0158596707003653,
-0.0261396384934428, -0.0286505239756832, -0.0366692368775817,
-0.0127341035075788, 0.0669385878663209, 0.0465027267386504,
0.00704423441903423, 0.0217546431041822, -0.00582565417712289,
0.0130023382378637, 0.10511251526633, 0.0518522334205838, 0.107127520905078,
0.0178719315683786, 0.0278267973953032, -0.0485503100189258,
-0.0108659147438031, 0.0109666518413147, 0.0154645672337712,
-0.0338505700478167, -0.00436219527802972, 0.05104724595336,
0.0541549024268144, 0.0873384487014046, 0.0628186392725139, -0.0288161017299512,
0.0950492127308722, -0.0491296716777756, -0.0444532289596897,
-0.00216600237045717, 0.0190268040149375, 0.067817072016372,
0.0146918057312835, 0.0295514071747491, -0.0435830986730233,
0.0215714644357461, 0.0494583026657589, 0.0913329109870025, -0.0053448319045083,
0.0601557176652443, 0.0568172510761795, -0.0485426969753849,
0.00175302828494006, 0.00984938190559648, 0.0240502738702311,
-0.00118579262163876, 0.0561485994364315, 0.0685148593157117,
0.04683955790033, -0.0574638736286489, -0.0138207306792366, 0.0355299071029838,
0.0531266681464893, 0.0117742011764304, -0.00525222583312346,
-0.0293812846037232, -0.0131594446545449, 0.0289964530305211,
0.0360588122490606, -0.0445991604911897, -0.0133107604099818,
-0.038145829508777, -0.000486060215306838, 0.00104676175588558,
0.0208886233797061, -0.00263583111403876, -0.12338493810393,
-0.0166803342153315, -0.0297568741980336, -0.112338323364713,
-0.0693713119660443, -0.0180597800314281, 0.0134278508097088,
-0.0330598180720567, -0.0366483220489359, 0.0339417580345724,
0.0509050678267557, 0.0528878066096272, -0.018266616997294, 0.0677991301131817,
0.0413170767588944, 0.0179821345844948, -0.0120530476718976,
0.0506564243990657, 0.0108111883471529, -0.0607609892616301,
-0.0245384465619248, 0.0513624569791613, -0.0375362970369394,
-0.108672749280212, -0.00337217907778453, 0.087093380777213,
-0.0338856992001196, 0.0840213297383585, 0.0404836319184165,
-0.0844650405081253, 0.0619874075245053, 0.0504278836336267,
0.0415781344576631, -0.0167132483670377, 0.076801882730787, -0.0369574751565279,
-0.0206697388445634, -0.0328788588005816, -0.083383558090487,
-0.0323162584368404, 0.051610493839749, -0.0220809995437766,
-0.00870937103673219, 0.0225163266689465, 0.0397241319702022,
-0.0102895797305198, -0.0281284547507554, -0.0991696936611708,
0.0636541757418483, 0.0179711424415336, 0.0333173103972026, 0.0225887202551132,
0.00443860666159801, 0.014806760557537, 0.0310237163003237, 0.144376590041557,
-0.0448055417930532, -0.00513324649717639, 0.0537257308063575,
-0.00999221359281199, -0.0819189957530423, 0.0476018428802933,
-0.0214364641397353, 0.0918599937028983, 0.068148748800128, 0.00803440955796253,
0.0397444044913302, -0.0552739603600437, 0.10420213043066, -0.0215270370205893,
0.0249963705701839, -0.0093007099097957, -0.00944183950206712,
-0.0971704450184838, 0.00264470427302532, -0.0723146624220592,
-0.0604005470589978, 0.0267660599545763, -0.0809302399859423,
-0.0155073183470853, 0.0664580522537737, -0.0536551996227884,
0.0468841220908309, -0.0208428453992652, -0.0416561940283499,
0.0333869121623922, -0.0710574857344434, -0.0493355477841083,
0.0574454161378841, -0.0413939958360005, -0.0361717353766919,
-0.0730611841593626, -0.0306524518642073, 0.0448704347638376,
0.0189138798885842, -0.019112690070504, -0.0607784992411501,
0.0200647095833417, 4.64025545323654e-05, 0.0167228957527705,
-0.0399352463740604, -0.0533583100515406, 0.0922371375755624,
0.0469543874397995, 0.0130431580117298, 0.0904898600303281, 0.0657425429880596,
0.0499463961351239, -0.0261922592092307, 0.065751610214466, -0.00621555863424983,
0.0832799329468406, 0.00866941466260029, -0.017688747365096,
0.0449778523037858, 0.0954877576723518, -0.118831287262529, -0.0142308642932637,
0.0385103238081386, -0.064183870293033, -0.0142310862314927,
0.046099549894892, -0.0550393421312394, 0.00274530215199009,
-0.156434752199699, -0.00708826723870748, -0.0462880814806087,
0.059565753901339, 0.0316103424635057, 0.00219296046281703, 0.0485668880949881,
-0.16121577788262, 0.0851533099681305, -0.0386176257065057, -0.0712227636357597,
0.0312116344677249, 0.0527030336009604, 0.016990538618856, 0.0943310408154399,
-0.0417768266816103, -0.167029346552333, -0.136573394710224,
0.0151856742327374, 0.0150795243191497, 0.0256024944818467, 0.0319573321526792,
0.0423101107019896, -0.060681262543504, -0.0516425733035891,
0.160387164752116, 0.0380848238199503, -0.0206859096083852, 0.0113327971407688,
0.0582468900635822, 0.0619978730333017, 0.077263516690542, -0.0171388878765958,
0.0199810159760507, 0.0158023347139837, -0.103334180665634, 0.0549659271604657,
-0.0893066705987667, 0.101606771360827, 0.0492865186589087, -0.0238877039788714,
-0.0277900457059636, 0.0404617408226444, -0.0718787783241953,
-0.0123575474841724, 0.059355733239068, 0.029908291943469, -0.0677988560026864,
0.0600705787852096, -0.0437493069001588, 0.00180517117961099,
-0.0209223756892264, 0.0272845085630986, 0.0837601002893609,
0.0299074232605328, 0.0240446051441223, 0.00748096094707074,
0.0613306520140755, -0.0691778150018606, 0.0246049232880761,
-0.0133417659847783, 0.0124121161628492, 0.0642708816666793,
0.00507849967404161, 0.0261052878209909, 0.0151493267776062,
0.00676515233437147, 0.00653446817356351, 0.0150714363479285,
-0.050143190382553, 0.0277659888972834, 0.0441645265494663, 0.0330199447063566,
0.080567937081057, 0.0316571988327838, 0.00111260813987357, 0.016406229113636,
0.0504761702266239, -0.00550425517164699, 0.0395917385160307,
0.048456257520995, 0.0430035722547741, -0.047301231431996, 0.087565977773425,
-0.050604038742966, 0.00804493275737861, 0.0299441033050929,
0.0357934879374062, 0.0582014365192993, 0.0698786365111124, 0.0171741022871303,
0.0125443303556689, 0.00819301763612046, 0.00991755318616083,
-0.127008834727823, -0.0262409920857444, 0.040946793757588, 0.0164392980283827,
0.0306621368418329, -0.0238640140220965, -0.0156901113780832,
0.00959306152476125, 0.030309665786747, -0.0520373515064326,
0.0155414686264252, -0.00868280688491285, 0.00882165631942744,
-0.0152414835528486, 0.0354479986139713, 0.00495367631225263,
0.0958858811432524, -0.0684962605913843, 0.0476352610219926,
0.0161558138743416, -0.0288967250807524, -0.0136524963030579,
0.013609536698864, -0.0101217287483828, -0.0129056749640298,
-0.0561043848567603, -0.00361214051470649, -0.0339148683510243,
0.0549197973662541, 0.00352545246358327, -0.0908929634017446,
-0.0766867551408712, 0.0304100958405675, -0.0433097428906102,
-0.0395849516878581, 0.00961086344015882, -0.0281887998980271,
-0.0277864019559111, 0.013711263904689, 0.0191434464401923, 0.0254260098579855,
-0.0360122263475078, 0.00713376835505675, 0.0515609918115263,
-0.0104156632309022, -0.00554941806867115, -0.0366770391324845,
-0.092809259472171, -0.000240961580031951, -0.0573097859137003,
0.0476330153045359, 0.0158596707003653, -0.0261396384934428,
-0.0286505239756832, -0.0366692368775817, -0.0127341035075788,
0.0669385878663209, 0.0465027267386504, 0.00697103541730559,
0.0240759738135028, -0.00499995833368028, 0.0130023382378637,
0.0660819187835711, 0.0381905638254254, 0.081864083562877, 0.0178719315683786,
0.0253466261092197, -0.0349542847267367, -0.0123113683808378,
0.00922796120595493, 0.0154645672337712, -0.0256621847300804,
-0.00257097347471802, 0.0339067339228674, 0.0356102024265696,
0.0571472869544005, 0.0628186392725139, -0.0221911881645702,
0.0950492127308722, -0.0491296716777756, -0.0304308647089176,
-0.00105025749743581, 0.0190268040149375, 0.067817072016372,
0.0118702126988408, 0.02056060572427, -0.0320256986349159, 0.0173034620187353,
0.0348383376789623, 0.0913329109870025, -0.00508049371248243,
0.0601557176652443, 0.0474269701349554, -0.0362187348642155,
0.00175302828494006, 0.00984938190559648, 0.0240502738702311,
-0.000928072811158587, 0.0422905855543541, 0.0685148593157117,
0.031757030973413, -0.0574638736286489, -0.00959417435537924,
0.0325380097149295, 0.0597952080195425, 0.00944188854178352,
-0.00229856160324715, -0.0271236735291358, -0.0137710545829336,
0.0289964530305211, 0.0360588122490606, -0.0427573578511865,
-0.0133107604099818, -0.0413350154935502, -0.000486060215306838,
0.00104676175588558, 0.0208886233797061, -0.00267336295134479,
-0.0885860511912184, -0.0161029691326237, -0.0297568741980336,
-0.112338323364713, -0.0693713119660443, -0.0180597800314281,
0.0134278508097088, -0.0330598180720567, -0.0366483220489359,
0.0339417580345724, 0.0509050678267557, 0.0528878066096272, -0.018266616997294,
0.0677991301131817, 0.0413170767588944, 0.0179821345844948, -0.0121888968895034,
0.0506564243990657, 0.0108111883471529, -0.0607609892616301,
-0.0247113973468298, 0.0513624569791613, -0.0309923310770995,
-0.108672749280212, -0.00337217907778453, 0.087093380777213,
-0.0338856992001196, 0.0840213297383585, 0.0424971554686477,
-0.081464070989248, 0.0619874075245053, 0.0430698737989899, 0.0421349243533173,
-0.0109533653241958, 0.0742378263228765, -0.0369574751565279,
-0.0212240452296111, -0.0328788588005816, -0.083383558090487,
-0.0323162584368404, 0.051610493839749, -0.0220809995437766,
-0.00870937103673219, 0.0225163266689465, 0.0438734449744449,
-0.00892210665440751, -0.0293707722982393, -0.0991696936611708,
0.0636541757418483, 0.0181589135552847, 0.0333173103972026, 0.0210622227911781,
0.00487335405251677, 0.0131356170394468, 0.0273537483318715,
0.144376590041557, -0.02796259796409, -0.00522582776545444, 0.0364354414456791,
-0.00837134854176702, -0.0502137264472271, 0.0476018428802933,
-0.0153208746756319, 0.0513742248497895, 0.0421405589892034,
0.00465956984288418, 0.0215903415755918, -0.0388077343572576,
0.0657724728057736, -0.0132884344984379, 0.0201092644054153,
-0.0051175163129672, -0.00944183950206712, -0.0971704450184838,
0.0016192925508538, -0.0723146624220592, -0.0604005470589978,
0.0258782226065151, -0.0433891880670063, -0.0141086652162496,
0.0625300971761347, -0.0301628728287874, 0.0385126964933498,
-0.0112984784610625, -0.0323098915386699, 0.0365004974846537,
-0.0737970611899815, -0.0493355477841083, 0.0574454161378841,
-0.0306092896219177, -0.0262257339374732, -0.0569910029244357,
-0.0306524518642073, 0.0448704347638376, 0.0185695069363463,
-0.0155548984204991, -0.0467627599243856, 0.0200647095833417,
8.29964155073526e-05, 0.0167228957527705, -0.0335972446871899,
-0.0294344648848727, 0.0518143754361482, 0.0257859588754956,
0.00824571243269778, 0.0904898600303281, 0.0657425429880596,
0.0415235900563797, -0.0261922592092307, 0.065751610214466, -0.00621555863424983,
0.0832799329468406, 0.00866941466260029, -0.017688747365096,
0.0449778523037858, 0.0954877576723518, -0.118831287262529, -0.0153069547305189,
0.0218515179870005, -0.0342686779423506, -0.00850677257427712,
0.0325477383763988, -0.0306141018335595, 0.00243501209588759,
-0.156434752199699, -0.005029743685798, -0.0345290845779366,
0.059565753901339, 0.0252512069665196, 0.00207064965943626, 0.0302923006737879,
-0.16121577788262, 0.0654457174010914, -0.0209269433762712, -0.0712227636357597,
0.0269825779272959, 0.0307477365084228, 0.0141733437604381, 0.0943310408154399,
-0.023119978605681, -0.0967380201240571, -0.147305013179531,
0.0151856742327374, 0.0150795243191497, 0.0256024944818467, 0.0319573321526792,
0.0389645831394516, -0.0516711678172406, -0.057263622404775,
0.17035185335458, 0.0380848238199503, -0.014964951245554, 0.00815821494412972,
0.0582468900635822, 0.0410152743642858, 0.077263516690542, -0.014889383359691,
0.0128841652906317, 0.0126255977120013, -0.103334180665634, 0.0438272536940851,
-0.0576089770159162, 0.0647885069687177, 0.0492865186589087,
-0.0238877039788714, -0.0300054599177805, 0.0404617408226444,
-0.0429596698815269, -0.0123575474841724, 0.0417189496432033,
0.029908291943469, -0.0409145877912638, 0.0416155635440896, -0.0437493069001588,
0.00282867922883168, -0.00940990309615575, 0.0190579142175993,
0.0443042237259872, 0.0299074232605328, 0.0240446051441223, 0.00748096094707074,
0.0443570938433033, -0.0404571419085026, 0.0246049232880761,
-0.0066025249154531, 0.00954964988443341, 0.0298053972087278,
0.00476107372301793, 0.0175757232170388, 0.0101068360663179,
0.00609368513738762, 0.00540196687039063, 0.00917053509817412,
-0.0216215093591073, 0.0277659888972834, 0.0226023268044275,
0.0213902871313327, 0.0443373040422519, 0.0176332357221722, 0.00111260813987357,
0.016406229113636, 0.0298863069339816, -0.006561222645037, 0.0395917385160307,
0.048456257520995, 0.0430035722547741, -0.0585570779808038, 0.087565977773425,
-0.050604038742966, 0.0108699498782903, 0.0350978073788761, 0.0357934879374062,
0.0665716262589837, 0.0698786365111124, 0.0171741022871303, 0.0148956336813075,
0.00971692648248834, 0.0118976448527714, -0.127008834727823,
-0.0643807858901128, 0.0785395421983646, 0.0341359119905573,
0.0424124006976598, -0.0297507849081639, -0.0284978431148246,
0.00959306152476125, 0.030309665786747, -0.0520373515064326,
0.0155414686264252, -0.00868280688491285, 0.00882165631942744,
-0.0152414835528486, 0.0354479986139713, 0.00495367631225263,
0.0958858811432524, -0.0754119883858065, 0.0605889700089284,
0.0230055503982476, -0.0452346298784714, -0.0199167187040488,
0.0202669563997153, -0.0151015261797287, -0.0129056749640298,
-0.0561043848567603, -0.00874332327370753, -0.0450463176390838,
0.0676450859834781, 0.00352545246358327, -0.0908929634017446,
-0.0766867551408712, 0.0683714108587556, -0.0562536535683003,
-0.0395849516878581, 0.00961086344015882, -0.0281887998980271,
-0.0277864019559111, 0.0315316866110831, 0.0278566332045715,
0.0254260098579855, -0.0478119064346871, 0.00713376835505675,
0.0515609918115263, -0.0104156632309022, -0.00554941806867115,
-0.0366770391324845, -0.128540218463314, -0.00333101415653492,
-0.120107648833262, 0.0958295457008402, 0.0354990847462275, -0.0370024578753033,
-0.035961013075631, -0.0473812313231093, -0.0190728925526511,
0.129179809515038, 0.0580707168491923, 0.00697103541730559, 0.0240759738135028,
-0.00499995833368028, 0.00801345581575896, 0.0660819187835711,
0.0381905638254254, 0.081864083562877, 0.0102074178146554, 0.0253466261092197,
-0.0349542847267367, -0.0123113683808378, 0.00922796120595493,
0.0190388963276953, -0.0256621847300804, -0.00257097347471802,
0.0339067339228674, 0.0356102024265696, 0.0571472869544005, 0.037933876312189,
-0.0221911881645702, 0.04867790190674, -0.0284893707600057, -0.0304308647089176,
-0.00105025749743581, 0.0113296046090396, 0.0384517691761184,
0.0118702126988408, 0.02056060572427, -0.0320256986349159, 0.0173034620187353,
0.0348383376789623, 0.055078009042417, -0.00508049371248243,
0.0349324182903621, 0.0474269701349554, -0.0362187348642155,
0.000731944005366358, 0.0126588629475626, 0.0284200411474285,
-0.000928072811158587, 0.0422905855543541, 0.0344914231782354,
0.031757030973413, -0.0204446138767127, -0.00959417435537924,
0.0325380097149295, 0.0597952080195425, 0.00944188854178352,
-0.00229856160324715, -0.0271236735291358, -0.0137710545829336,
0.048844176339206, 0.0455008063339308, -0.0427573578511865, -0.0178282872713298,
-0.0413350154935502, -0.00251312075281451, 0.000392568409978589,
0.038867708087317, -0.00267336295134479, -0.0885860511912184,
-0.0161029691326237, -0.0420241198590325, -0.140933679398404,
-0.213182576299088, -0.092462713370572, 0.0518406558167939, -0.0897576490474823,
-0.0843476608722317, 0.0665382076070802, 0.131582448235168, 0.107795304196951,
-0.0220904436860068, 0.105306956007685, 0.0603934116278224, 0.0236136189048726,
-0.0121888968895034, 0.0658652385210567, 0.0143138180286164,
-0.0670856183281777, -0.0247113973468298, 0.0618092509209986,
-0.0309923310770995, -0.128803242463851, -0.00934578652654638,
0.12464789947184, -0.0389238136806155, 0.105292759441438, 0.0424971554686477,
-0.081464070989248, 0.0801304884170133, 0.0430698737989899, 0.0421349243533173,
-0.0109533653241958, 0.0742378263228765, -0.0412233371318413,
-0.0212240452296111, -0.038721073177811, -0.102593285857173,
-0.0660128643244059, 0.120312560041835, -0.0445404035530143,
-0.0160245207220792, 0.0264519215884826, 0.0438734449744449,
-0.00892210665440751, -0.0293707722982393, -0.131667864804966,
0.0765524648247053, 0.0181589135552847, 0.0410867753199928, 0.0210622227911781,
0.00487335405251677, 0.0131356170394468, 0.0273537483318715,
0.0525736688028997, -0.02796259796409, -0.00522582776545444,
0.0364354414456791, -0.00837134854176702, -0.0502137264472271,
0.0532240511918611, -0.0153208746756319, 0.0513742248497895,
0.0421405589892034, 0.00465956984288418, 0.0215903415755918,
-0.0388077343572576, 0.0657724728057736, -0.0132884344984379,
0.0201092644054153, -0.0051175163129672, -0.00294532574721995,
-0.0342077361930025, 0.0016192925508538, -0.0379594485162568,
-0.0270255520457952, 0.0258782226065151, -0.0433891880670063,
-0.0141086652162496, 0.0625300971761347, -0.0301628728287874,
0.0385126964933498, -0.0112984784610625, -0.0323098915386699,
0.0365004974846537, -0.0737970611899815, -0.0556600639245958,
0.0705786039020948, -0.0306092896219177, -0.0262257339374732,
-0.0569910029244357, -0.0405411931490601, 0.0592431057525111,
0.0185695069363463, -0.0155548984204991, -0.0467627599243856,
0.0477649909637343, 8.29964155073526e-05, 0.00912820625534794,
-0.0335972446871899, -0.0294344648848727, 0.0518143754361482,
0.0257859588754956, 0.00824571243269778, 0.0364118589045417,
0.0311793838385637, 0.0415235900563797, -0.0130142562807395,
0.0340778557667032, -0.00227377328383616, 0.0347900685331286,
0.00384546460879642, -0.00418305832682986, 0.0144009024701055,
0.0443595078891013, -0.0509816485786232, -0.0153069547305189,
0.0218515179870005, -0.0342686779423506, -0.00850677257427712,
0.0325477383763988, -0.0306141018335595, 0.00243501209588759,
-0.0772496207460813, -0.005029743685798, -0.0345290845779366,
0.0670034415430896, 0.0252512069665196, 0.00207064965943626,
0.0302923006737879, -0.0635789495123614, 0.0654457174010914,
-0.0209269433762712, -0.0282304959937522, 0.0269825779272959,
0.0307477365084228, 0.0141733437604381, 0.0384548002293232, -0.023119978605681,
-0.0967380201240571, -0.147305013179531, 0.0566080914066258,
0.0267254767970793, 0.0387793305132154, 0.0441493507889792, 0.0389645831394516,
-0.0516711678172406, -0.057263622404775, 0.17035185335458, 0.0462477698800481,
-0.014964951245554, 0.00815821494412972, 0.0272545550529284,
0.0410152743642858, 0.0388027775914868, -0.014889383359691, 0.0128841652906317,
0.0126255977120013, -0.0535302063156535, 0.0438272536940851,
-0.0576089770159162, 0.0647885069687177), .Dim = c(336L, 3L), .Dimnames = list(
NULL, c("Conventionele.strategie", "Conditionele.strategie",
"Niet.geschaald")), index = structure(c(759974400, 762393600,
765072000, 767577600, 770342400, 772934400, 775440000, 778291200,
780883200, 783561600, 786153600, 788745600, 791510400, 793929600,
796608000, 799027200, 801878400, 804470400, 807148800, 809827200,
812332800, 815097600, 817689600, 820195200, 823046400, 825552000,
828057600, 830822400, 833500800, 835920000, 838771200, 841363200,
844041600, 846720000, 849225600, 851990400, 854668800, 857088000,
859766400, 862358400, 864950400, 867628800, 870307200, 872812800,
875577600, 878256000, 880675200, 883526400, 886118400, 888537600,
891302400, 893894400, 896400000, 899164800, 901843200, 904521600,
907113600, 909705600, 912384000, 915062400, 917568000, 919987200,
922838400, 925430400, 927849600, 930700800, 933292800, 936057600,
938649600, 941155200, 943920000, 946598400, 949276800, 951782400,
954460800, 956880000, 959731200, 962323200, 965001600, 967680000,
970185600, 972950400, 975542400, 978048000, 980899200, 983318400,
985910400, 988588800, 991267200, 993772800, 996537600, 999216000,
1001635200, 1004486400, 1007078400, 1009756800, 1012435200, 1014854400,
1017273600, 1020124800, 1022803200, 1025222400, 1028073600, 1030665600,
1033344000, 1036022400, 1038528000, 1041292800, 1043971200, 1046390400,
1049068800, 1051660800, 1054252800, 1056931200, 1059609600, 1062115200,
1064880000, 1067558400, 1069977600, 1072828800, 1075420800, 1077840000,
1080691200, 1083283200, 1085702400, 1088553600, 1091145600, 1093910400,
1096502400, 1099008000, 1101772800, 1104451200, 1107129600, 1109548800,
1112227200, 1114732800, 1117497600, 1120089600, 1122595200, 1125446400,
1128038400, 1130716800, 1133308800, 1135900800, 1138665600, 1141084800,
1143763200, 1146182400, 1149033600, 1151625600, 1154304000, 1156982400,
1159488000, 1162252800, 1164844800, 1167350400, 1170201600, 1172620800,
1175212800, 1177891200, 1180569600, 1183075200, 1185840000, 1188518400,
1190937600, 1193788800, 1196380800, 1199059200, 1201737600, 1204243200,
1206921600, 1209513600, 1212105600, 1214784000, 1217462400, 1219968000,
1222732800, 1225411200, 1227830400, 1230681600, 1233273600, 1235692800,
1238457600, 1241049600, 1243555200, 1246320000, 1248998400, 1251676800,
1254268800, 1256860800, 1259539200, 1262217600, 1264723200, 1267142400,
1269993600, 1272585600, 1275004800, 1277856000, 1280448000, 1283212800,
1285804800, 1288310400, 1291075200, 1293753600, 1296432000, 1298851200,
1301529600, 1304035200, 1306800000, 1309392000, 1311897600, 1314748800,
1317340800, 1320019200, 1322611200, 1325203200, 1327968000, 1330473600,
1333065600, 1335744000, 1338422400, 1340928000, 1343692800, 1346371200,
1348790400, 1351641600, 1354233600, 1356912000, 1359590400, 1362009600,
1364428800, 1367280000, 1369958400, 1372377600, 1375228800, 1377820800,
1380499200, 1383177600, 1385683200, 1388448000, 1391126400, 1393545600,
1396224000, 1398816000, 1401408000, 1404086400, 1406764800, 1409270400,
1412035200, 1414713600, 1417132800, 1419984000, 1422576000, 1424995200,
1427760000, 1430352000, 1432857600, 1435622400, 1438300800, 1440979200,
1443571200, 1446163200, 1448841600, 1451520000, 1454025600, 1456704000,
1459382400, 1461888000, 1464652800, 1467244800, 1469750400, 1472601600,
1475193600, 1477872000, 1480464000, 1483056000, 1485820800, 1488240000,
1490918400, 1493337600, 1496188800, 1498780800, 1501459200, 1504137600,
1506643200, 1509408000, 1.512e+09, 1514505600, 1517356800, 1519776000,
1522281600, 1525046400, 1527724800, 1530230400, 1532995200, 1535673600,
1538092800, 1540944000, 1543536000, 1546214400, 1548892800, 1551312000,
1553817600, 1556582400, 1559260800, 1561680000, 1564531200, 1567123200,
1569801600, 1572480000, 1574985600, 1577750400, 1580428800, 1582848000,
1585612800, 1588204800, 1590710400, 1593475200, 1596153600, 1598832000,
1601424000, 1604016000, 1606694400, 1609372800, 1611878400, 1614297600,
1617148800, 1619740800, 1622160000, 1625011200, 1627603200, 1630368000,
1632960000, 1635465600, 1638230400, 1640908800), tzone = "UTC", tclass = c("POSIXct",
"POSIXt")), class = c("xts", "zoo"))
Similar to you, I could only affect the legend by changing lty or lwd parameters. The package authors state that
"This function is intended to be used inside other charting functions."
— ?chart.TimeSeries
Indeed, you can select a plot.engine by passing it a function argument: plot.engine = "ggplot2" will return and plot a ggplot graph, "plotly" an interactive plotly-plot and so on. Then again you'll need the corresponding libraries installed and some basic aquaintance with each package (so I wonder why to use chart.TimeSeries as a wrapper anyway).
Edit - two alternatives to plot your data with library(ggplot2)
Fast and simple:
cum_ret_compare %>% autoplot.zoo
with basic dplyr and ggplot operations:
my_plot <-
cum_ret_compare %>%
as.data.frame %>%
mutate(Date = as.Date(time(cum_ret_compare))) %>% ## extract date to column Date
## stack variables instead of side-by-side
## to easier apply variable-wise color further down:
pivot_longer(cols = -Date,
names_to = 'strategy_type',
values_to = 'value'
) %>%
## construct ggplot
ggplot(aes(Date, value)) +
## add lines per strategy_type
geom_line(aes(col = strategy_type),
lty = 1, ## linetype
lwd = .1 ## linewidth
) +
labs(x = 'Date', y = 'cum. return')
## plot it:
my_plot
## make it look impressive ;-)
library(ggthemes)
my_plot + theme_economist()
My first data frame (df) contains Entrydate and ExitDate columns. Another dataframe (n1) has all trading dates. I need a new column in first dataframe calculated as number of days as calculated from the second dataframe. How do I call this dayCount function for each row of df. When I try to use mapply, I am unable to pass n1 as a parameter.
dayCount <- function (startDate, endDate, n1) {
return (nrow(subset(n1, Date >= startDate & Date <= endDate)))
}
df<- structure(list(EntryDate = structure(c(11355, 11418, 11436, 11449,
11520, 11523, 11548, 11620, 11768, 11773), class = "Date"), ExitDate = structure(c(11360,
11422, 11438, 11457, 11522, 11526, 11554, 11625, 11772, 11778
), class = "Date")), row.names = c(22L, 65L, 76L, 84L, 135L,
138L, 155L, 204L, 305L, 307L), class = "data.frame")
n1<- structure(c(11354, 11355, 11358, 11359, 11360, 11361, 11362,
11365, 11366, 11367, 11368, 11369, 11372, 11373, 11374, 11375,
11376, 11379, 11380, 11381, 11382, 11383, 11386, 11388, 11389,
11390, 11393, 11394, 11395, 11396, 11397, 11400, 11401, 11402,
11403, 11404, 11407, 11408, 11409, 11410, 11411, 11414, 11415,
11416, 11418, 11421, 11422, 11423, 11424, 11428, 11429, 11430,
11431, 11432, 11435, 11436, 11437, 11438, 11439, 11442, 11444,
11445, 11446, 11449, 11450, 11451, 11452, 11453, 11456, 11457,
11458, 11459, 11460, 11463, 11464, 11465, 11466, 11467, 11470,
11471, 11472, 11473, 11474, 11477, 11478, 11479, 11480, 11481,
11484, 11485, 11486, 11487, 11488, 11491, 11492, 11493, 11494,
11495, 11498, 11499, 11500, 11501, 11502, 11505, 11506, 11507,
11508, 11509, 11512, 11513, 11514, 11515, 11516, 11519, 11520,
11521, 11522, 11523, 11526, 11527, 11528, 11529, 11530, 11533,
11534, 11535, 11536, 11537, 11540, 11541, 11542, 11543, 11544,
11547, 11548, 11550, 11551, 11554, 11555, 11557, 11558, 11561,
11562, 11563, 11564, 11565, 11568, 11569, 11570, 11571, 11572,
11575, 11576, 11577, 11578, 11579, 11582, 11583, 11584, 11585,
11586, 11589, 11590, 11591, 11592, 11593, 11596, 11598, 11599,
11600, 11603, 11604, 11605, 11606, 11607, 11610, 11611, 11612,
11613, 11614, 11617, 11618, 11619, 11620, 11624, 11625, 11626,
11627, 11628, 11631, 11632, 11633, 11634, 11635, 11638, 11639,
11640, 11641, 11645, 11646, 11647, 11648, 11649, 11652, 11653,
11654, 11655, 11659, 11660, 11661, 11662, 11663, 11666, 11667,
11668, 11669, 11670, 11674, 11675, 11676, 11677, 11680, 11682,
11683, 11684, 11687, 11688, 11689, 11690, 11691, 11694, 11695,
11696, 11697, 11698, 11701, 11702, 11703, 11704, 11705, 11708,
11709, 11710, 11711, 11712, 11715, 11716, 11717, 11718, 11719,
11722, 11723, 11724, 11725, 11726, 11729, 11730, 11731, 11732,
11733, 11736, 11737, 11738, 11739, 11740, 11743, 11744, 11745,
11746, 11747, 11750, 11751, 11752, 11753, 11754, 11757, 11758,
11759, 11760, 11761, 11764, 11765, 11766, 11767, 11768, 11772,
11773, 11774, 11778), class = "Date")
You can use %in% to count number of days in n1 between each EntryDate and ExitDate.
df$dayCount <- colSums(mapply(function(x, y) n1 %in% seq(x, y, by = '1 day'),
df$EntryDate, df$ExitDate))
df
# EntryDate ExitDate dayCount
#22 2001-02-02 2001-02-07 4
#65 2001-04-06 2001-04-10 3
#76 2001-04-24 2001-04-26 3
#84 2001-05-07 2001-05-15 7
#135 2001-07-17 2001-07-19 3
#138 2001-07-20 2001-07-23 2
#155 2001-08-14 2001-08-20 4
#204 2001-10-25 2001-10-30 3
#305 2002-03-22 2002-03-26 2
#307 2002-03-27 2002-04-01 3
I have the following format, please advise how to convert it to a list in R?
"{1948, 2507, 2510, 7030, 7110, 9009, 00027, 00206, 00399, 00717, 00814, 00828, 00848, 00917, 01050, 01105, 01144, 02130, 02768, 03037, 03752, 03754, 04070, 04110, 05050, 05255, 05289, 05564, 05595, 06100, 06330, 06671, 07041, 07119, 07137, 07273, 07313, 07454, 07871, 08104, 08714, 08726, 08995, 09059, 09073, 09525, 09949, 09981, 10092, 10439, 10782, 11185, 11507, 11712, 11806, 11858, 11980, 12067, 12113, 12139, 12643, 13820, 14534, 15007, 15014, 15549, 15953, 16151, 16174, 16634, 16733, 16888, 17111, 17207, 17377, 17721, 17900, 18118, 18400, 18686, 18880, 19080, 19342, 19444, 19772, 19790, 19891, 20091, 20245, 20402, 20811, 21114, 21345, 21811, 21881, 22222, 22311, 22320, 22831, 22969, 23251, 23572, 23734, 23862, 23889, 24034, 24463, 25172, 25688, 26143, 26221, 26803, 26850, 26898, 27497, 28291, 28343, 29411, 29419, 30024, 30561, 30923, 31345, 31351, 31555, 31927, 32198, 32861, 33020, 33040, 33095, 33188, 33311, 33368, 33377, 33475, 33519, 33574, 33592, 34207, 34235, 34272, 34484, 34854, 34872, 34875, 34876, 34880, 35222, 35292, 35344, 36177, 36266, 37038, 37060, 37548, 37686, 37700, 38139, 39368, 39369, 39633, 40132, 40698, 40704, 40744, 40819, 41311, 41971, 42102, 42616, 43055, 43211, 43234, 43428, 43494, 43934, 44117, 44252, 44272, 44301, 44336, 44619, 44866, 44888, 45049, 45197, 45412, 45718, 46694, 46736, 47000, 48046, 48540, 49078, 49109, 49216, 49388, 49464, 50056, 50155, 50217, 50477, 50692, 51122, 51445, 51946, 52475, 52537, 52982, 54011, 54031, 54160, 54963, 55000, 55537, 56080, 56163, 56282, 56760, 56787, 57102, 57727, 57871, 58101, 58558, 58882, 59902, 60225, 60397, 60501, 60619, 60703, 60890, 61075, 61894, 61944, 62322, 62337, 62380, 62413, 62729, 62766, 62923, 63010, 63234, 63977, 64127, 65359, 65428, 65542, 65750, 65863, 66184, 66636, 66712, 67201, 67439, 67953, 68133, 68854, 69251, 69959, 70107, 70725, 70768, 71081, 71099, 71948, 72013, 72377, 72400, 72420, 72735, 73000, 73015, 73142, 73223, 73455, 73717, 74049, 74492, 74854, 74941, 75142, 75399, 75464, 75587, 75618, 75642, 75887, 76357, 76651, 77199, 77302, 77456, 77579, 77601, 77649, 77668, 77694, 77745, 78006, 78010, 78178, 78335, 78656, 78729, 78808, 78824, 78844, 78945, 79416, 79471, 79915, 80077, 80111, 80189, 80262, 80409, 80470, 80529, 80539, 80838, 81272, 81513, 81658, 81740, 81743, 81762, 81843, 82001, 82070, 82106, 82342, 82472, 82719, 83670, 84009, 84151, 84299, 84430, 84450, 84460, 84945, 86411, 86443, 86446, 86668, 86942, 87286, 87317, 87624, 87785, 88023, 88517, 88696, 88787, 88868, 88977, 89206, 90108, 90440, 90734, 90802, 90849, 90920, 90931, 91011, 91031, 91133, 91777, 91949, 92162, 92494, 93012, 93172, 94300, 94517, 95142, 95410, 95559, 95859, 96112, 97255, 97787, 97986, 98240, 98817, 99050, 99198, 99222, 99241, 99295, 99326, 99335, 99503, 99603, 99643, 99803, 99968}"
THIS IS NOT A DUPLICATE OF convert json to list in a vectorized way in R
IT'S COMPLETELY DIFFERENT BECAUSE THE FORMAT IS ABSOLUTELY DIFFERENT.
Try this one line code:
as.numeric(sapply(strsplit(substr(j,2,nchar(j)-1),split = ","),trimws))
[1] 1948 2507 2510 7030 7110 9009 27 206 399 717 814 828 848 917 1050 1105 1144
[18] 2130 2768 3037 3752 3754 4070 4110 5050 5255 5289 5564 5595 6100 6330 6671 7041 7119
[35] 7137 7273 7313 7454 7871 8104 8714 8726 8995 9059 9073 9525 9949 9981 10092 10439 10782
[52] 11185 11507 11712 11806 11858 11980 12067 12113 1213 ..
Your input:
j<-"{1948, 2507, 2510, 7030, 7110, 9009, 00027, 00206, 00399, 00717, 00814, 00828, 00848, 00917, 01050, 01105, 01144, 02130, 02768, 03037, 03752, 03754, 04070, 04110, 05050, 05255, 05289, 05564, 05595, 06100, 06330, 06671, 07041, 07119, 07137, 07273, 07313, 07454, 07871, 08104, 08714, 08726, 08995, 09059, 09073, 09525, 09949, 09981, 10092, 10439, 10782, 11185, 11507, 11712, 11806, 11858, 11980, 12067, 12113, 12139, 12643, 13820, 14534, 15007, 15014, 15549, 15953, 16151, 16174, 16634, 16733, 16888, 17111, 17207, 17377, 17721, 17900, 18118, 18400, 18686, 18880, 19080, 19342, 19444, 19772, 19790, 19891, 20091, 20245, 20402, 20811, 21114, 21345, 21811, 21881, 22222, 22311, 22320, 22831, 22969, 23251, 23572, 23734, 23862, 23889, 24034, 24463, 25172, 25688, 26143, 26221, 26803, 26850, 26898, 27497, 28291, 28343, 29411, 29419, 30024, 30561, 30923, 31345, 31351, 31555, 31927, 32198, 32861, 33020, 33040, 33095, 33188, 33311, 33368, 33377, 33475, 33519, 33574, 33592, 34207, 34235, 34272, 34484, 34854, 34872, 34875, 34876, 34880, 35222, 35292, 35344, 36177, 36266, 37038, 37060, 37548, 37686, 37700, 38139, 39368, 39369, 39633, 40132, 40698, 40704, 40744, 40819, 41311, 41971, 42102, 42616, 43055, 43211, 43234, 43428, 43494, 43934, 44117, 44252, 44272, 44301, 44336, 44619, 44866, 44888, 45049, 45197, 45412, 45718, 46694, 46736, 47000, 48046, 48540, 49078, 49109, 49216, 49388, 49464, 50056, 50155, 50217, 50477, 50692, 51122, 51445, 51946, 52475, 52537, 52982, 54011, 54031, 54160, 54963, 55000, 55537, 56080, 56163, 56282, 56760, 56787, 57102, 57727, 57871, 58101, 58558, 58882, 59902, 60225, 60397, 60501, 60619, 60703, 60890, 61075, 61894, 61944, 62322, 62337, 62380, 62413, 62729, 62766, 62923, 63010, 63234, 63977, 64127, 65359, 65428, 65542, 65750, 65863, 66184, 66636, 66712, 67201, 67439, 67953, 68133, 68854, 69251, 69959, 70107, 70725, 70768, 71081, 71099, 71948, 72013, 72377, 72400, 72420, 72735, 73000, 73015, 73142, 73223, 73455, 73717, 74049, 74492, 74854, 74941, 75142, 75399, 75464, 75587, 75618, 75642, 75887, 76357, 76651, 77199, 77302, 77456, 77579, 77601, 77649, 77668, 77694, 77745, 78006, 78010, 78178, 78335, 78656, 78729, 78808, 78824, 78844, 78945, 79416, 79471, 79915, 80077, 80111, 80189, 80262, 80409, 80470, 80529, 80539, 80838, 81272, 81513, 81658, 81740, 81743, 81762, 81843, 82001, 82070, 82106, 82342, 82472, 82719, 83670, 84009, 84151, 84299, 84430, 84450, 84460, 84945, 86411, 86443, 86446, 86668, 86942, 87286, 87317, 87624, 87785, 88023, 88517, 88696, 88787, 88868, 88977, 89206, 90108, 90440, 90734, 90802, 90849, 90920, 90931, 91011, 91031, 91133, 91777, 91949, 92162, 92494, 93012, 93172, 94300, 94517, 95142, 95410, 95559, 95859, 96112, 97255, 97787, 97986, 98240, 98817, 99050, 99198, 99222, 99241, 99295, 99326, 99335, 99503, 99603, 99643, 99803, 99968}"
This code removes first and last character of the string ("{" and "}" characters), splits values by "," and removes whitespaces using trimws. After that it moves the format to number.
If it happens your data actually is json, stick with the rjson package. This answer is assuming your data is not json (since rjson::fromjson throws an error on your data)
Try:
string <- "{1948, 2507, 2510, 7030, 7110, 9009, 00027, 00206, 00399, 00717, 00814, 00828, 00848, 00917, 01050, 01105, 01144, 02130, 02768, 03037, 03752, 03754, 04070, 04110, 05050, 05255, 05289, 05564, 05595, 06100, 06330, 06671, 07041, 07119, 07137, 07273, 07313, 07454, 07871, 08104, 08714, 08726, 08995, 09059, 09073, 09525, 09949, 09981, 10092, 10439, 10782, 11185, 11507, 11712, 11806, 11858, 11980, 12067, 12113, 12139, 12643, 13820, 14534, 15007, 15014, 15549, 15953, 16151, 16174, 16634, 16733, 16888, 17111, 17207, 17377, 17721, 17900, 18118, 18400, 18686, 18880, 19080, 19342, 19444, 19772, 19790, 19891, 20091, 20245, 20402, 20811, 21114, 21345, 21811, 21881, 22222, 22311, 22320, 22831, 22969, 23251, 23572, 23734, 23862, 23889, 24034, 24463, 25172, 25688, 26143, 26221, 26803, 26850, 26898, 27497, 28291, 28343, 29411, 29419, 30024, 30561, 30923, 31345, 31351, 31555, 31927, 32198, 32861, 33020, 33040, 33095, 33188, 33311, 33368, 33377, 33475, 33519, 33574, 33592, 34207, 34235, 34272, 34484, 34854, 34872, 34875, 34876, 34880, 35222, 35292, 35344, 36177, 36266, 37038, 37060, 37548, 37686, 37700, 38139, 39368, 39369, 39633, 40132, 40698, 40704, 40744, 40819, 41311, 41971, 42102, 42616, 43055, 43211, 43234, 43428, 43494, 43934, 44117, 44252, 44272, 44301, 44336, 44619, 44866, 44888, 45049, 45197, 45412, 45718, 46694, 46736, 47000, 48046, 48540, 49078, 49109, 49216, 49388, 49464, 50056, 50155, 50217, 50477, 50692, 51122, 51445, 51946, 52475, 52537, 52982, 54011, 54031, 54160, 54963, 55000, 55537, 56080, 56163, 56282, 56760, 56787, 57102, 57727, 57871, 58101, 58558, 58882, 59902, 60225, 60397, 60501, 60619, 60703, 60890, 61075, 61894, 61944, 62322, 62337, 62380, 62413, 62729, 62766, 62923, 63010, 63234, 63977, 64127, 65359, 65428, 65542, 65750, 65863, 66184, 66636, 66712, 67201, 67439, 67953, 68133, 68854, 69251, 69959, 70107, 70725, 70768, 71081, 71099, 71948, 72013, 72377, 72400, 72420, 72735, 73000, 73015, 73142, 73223, 73455, 73717, 74049, 74492, 74854, 74941, 75142, 75399, 75464, 75587, 75618, 75642, 75887, 76357, 76651, 77199, 77302, 77456, 77579, 77601, 77649, 77668, 77694, 77745, 78006, 78010, 78178, 78335, 78656, 78729, 78808, 78824, 78844, 78945, 79416, 79471, 79915, 80077, 80111, 80189, 80262, 80409, 80470, 80529, 80539, 80838, 81272, 81513, 81658, 81740, 81743, 81762, 81843, 82001, 82070, 82106, 82342, 82472, 82719, 83670, 84009, 84151, 84299, 84430, 84450, 84460, 84945, 86411, 86443, 86446, 86668, 86942, 87286, 87317, 87624, 87785, 88023, 88517, 88696, 88787, 88868, 88977, 89206, 90108, 90440, 90734, 90802, 90849, 90920, 90931, 91011, 91031, 91133, 91777, 91949, 92162, 92494, 93012, 93172, 94300, 94517, 95142, 95410, 95559, 95859, 96112, 97255, 97787, 97986, 98240, 98817, 99050, 99198, 99222, 99241, 99295, 99326, 99335, 99503, 99603, 99643, 99803, 99968}"
string as list of characters:
string_as_list_char <- as.list(strsplit(gsub('\\{|\\}', '', string), ", "))[[1]]
or converted to numeric:
string_as_list_num <- as.list(as.numeric(strsplit(gsub('\\{|\\}', '', string), ", ")[[1]]))
I'm trying to replicate with R a chart I made on Excel, which should represent a 95% Confidence Interval (CI) around a time series forecast. The Excel chart looks like this:
So, basically, the original historical time series and from a certain point in time the forecast of what it could be with its respective CI.
They way it's done on Excel is a bit inefficient:
I have four time series which overlap much of the time;
The actual/historical time series (blue line above) simply stops when the forecast begins;
The forecast (dotted red above) is simply hidden below the blue one until the forecast period begins;
Then I have a time series representing the difference between the the upper bound and the lower bound of the CI, which playing around with Excel Stacked Areas charts, becomes the shaded area in the chart above.
Obviously, the computation to generate the forecast and the CIs is much faster and easier to generalize and use with R, and while I could complete the task on R and then simply copy the output on Excel to draw the chart, doing everything in R would be much nicer.
At the end of the question I provided the raw data with dput() as suggested by #MLavoie.
Here the packages I loaded (not sure you need them all here, but they are the ones I usually work with):
require(zoo)
require(xts)
require(lattice)
require(latticeExtra)
My data looks like this for the first 100 rows:
> head(data)
fifth_percentile Median nintyfifth_percentile
2017-06-18 1.146267 1.146267 1.146267
2017-06-19 1.134643 1.134643 1.134643
2017-06-20 1.125664 1.125664 1.125664
2017-06-21 1.129037 1.129037 1.129037
2017-06-22 1.147542 1.147542 1.147542
2017-06-23 1.159989 1.159989 1.159989
Then after the 100 data point, the time series start to diverge and at the end they look like this:
> tail(data)
fifth_percentile Median nintyfifth_percentile
2017-12-30 0.9430930 1.125844 1.341603
2017-12-31 0.9435227 1.127391 1.354928
2018-01-01 0.9417235 1.124625 1.355527
2018-01-02 0.9470077 1.124088 1.361420
2018-01-03 0.9571596 1.127299 1.364005
2018-01-04 0.9515535 1.127978 1.369536
Solution provided by DaveTurek
Thanks to DaveTurek I've found the answer. However, only difference is that for my xts dataframe, apparently, I need first to convert each column to numbers (with as.numeric()). No idea if that stems from me doing something wrong with xts and lattice, or it is the only way to achieve it using DaveTurek suggestion. Will try to investigate it further.
Here is the code to generate the chart:
x = index(data[1:100,2])
y = as.numeric(data[1:100,2])
ex.x = index(data[101:200,2])
ex.y = as.numeric(data[101:200,2])
ex.lo = as.numeric(data[101:200,1])
ex.hi = as.numeric(data[101:200,3])
xyplot(y~x, ylim = c(0.9,1.4),
panel=function(x,y,...) {
panel.lines(x,y,lwd=2,col=4)
panel.polygon(c(ex.x,rev(ex.x)),c(ex.lo,rev(ex.hi)),border=NA,col=5)
panel.lines(ex.x,ex.y,lwd=2,col=2)
})
And here the final result:
Here is the final dataset, from dput(), that I'm trying to plot:
> dput(data)
structure(c(1.14626724930899, 1.13464279067717, 1.12566420479952,
1.12903662366847, 1.14754211999921, 1.15998855701439, 1.15274364578958,
1.16226441955745, 1.16169992687419, 1.16520028734587, 1.16823402018407,
1.19832130049664, 1.18411773220697, 1.18531274215286, 1.16421444455115,
1.17108139956539, 1.18392357740377, 1.20103911352579, 1.17791736605905,
1.18277944964829, 1.20162550199013, 1.19665058179752, 1.19411188122108,
1.19367558590966, 1.19803272562951, 1.20600155861871, 1.22189449901607,
1.22072774140118, 1.22312376195254, 1.25355505518571, 1.25895911759195,
1.2613354420716, 1.24440525381363, 1.24444079462029, 1.24168652168112,
1.24154936710117, 1.23440527301777, 1.22592718438811, 1.21709102449773,
1.21448030929365, 1.23109601090898, 1.24401127451953, 1.23953314346685,
1.21863565024168, 1.20834325548551, 1.20281193695583, 1.20405850724191,
1.19608032796923, 1.22008184095742, 1.21675995421116, 1.20198916403093,
1.20029121301547, 1.18822375424598, 1.19007923345344, 1.19285965857709,
1.1971013197471, 1.1776860331227, 1.18028531916998, 1.18394951589397,
1.16712430930941, 1.17827461393349, 1.18751430033172, 1.21482260909863,
1.2167262724184, 1.21729489152574, 1.21847062594996, 1.21932070698031,
1.19678189566773, 1.17678214957629, 1.17586968485613, 1.16903708967946,
1.16967697995898, 1.14498266161799, 1.12782282645368, 1.11540004479973,
1.12639853863918, 1.11402516325222, 1.10511837662567, 1.10600107687395,
1.10243149863659, 1.10404564773364, 1.12949458422398, 1.11679224666313,
1.11338078540871, 1.10762728498848, 1.12437898939299, 1.11572706259347,
1.1148111967932, 1.12358625045939, 1.11169207274881, 1.13009253108247,
1.13772927166761, 1.12550770863279, 1.13062401691547, 1.12821231512428,
1.13174620070443, 1.13072790983063, 1.1428325334377, 1.12739171867048,
1.1214997813059, 1.11870510839984, 1.096148222775, 1.08805136310032,
1.08701594286129, 1.08047984136855, 1.07939438148434, 1.0684082570972,
1.06497159411023, 1.05820047926833, 1.06322519359802, 1.06234781015662,
1.05431808916504, 1.054405104791, 1.05330182895869, 1.04787681441803,
1.041698698458, 1.03870702538097, 1.03300007904201, 1.02741553353049,
1.03525701392318, 1.0339774223954, 1.0328464056954, 1.03100871401712,
1.03348765946373, 1.03473218333386, 1.02942612874379, 1.02109481188296,
1.02301597272716, 1.01553904377803, 1.0031650628692, 1.00779708136199,
1.01322764666693, 1.01964272925677, 1.02125480865504, 1.02300342204156,
1.02563993245866, 1.02972111884963, 1.02048756192688, 1.00481457379443,
1.00512607721887, 1.01094340128446, 1.01377432300649, 1.01170553705668,
1.00551128145228, 1.00612634442438, 1.00735643866839, 1.0080606590012,
0.985706701720841, 0.982234200010558, 0.975314534071082, 0.973611418201841,
0.968118612511537, 0.973092829667201, 0.975599110408158, 0.967214930243667,
0.968569928969912, 0.963572085616274, 0.964901787179726, 0.957782708788541,
0.951868416101986, 0.956694066411684, 0.956937537219092, 0.956303331651844,
0.947880835881923, 0.956308493824626, 0.948146077843001, 0.945939091828748,
0.945082701640947, 0.937222489932819, 0.937989843132858, 0.948712728941467,
0.939050882255992, 0.946264846068344, 0.944926693194716, 0.946825914432391,
0.939070104432721, 0.950666108330947, 0.949365988007735, 0.943616625744159,
0.946600795357699, 0.941276090147603, 0.939957902451166, 0.941523527816784,
0.946611480333791, 0.959236316317354, 0.96165367272139, 0.957508302724503,
0.954774123925477, 0.960811125123549, 0.956525507301749, 0.948237690612711,
0.951299123137395, 0.945212566792479, 0.94507842203255, 0.942735006048921,
0.943093032220433, 0.943522672031737, 0.941723495992432, 0.947007713852018,
0.95715960245335, 0.951553478810637, 1.14626724930899, 1.13464279067717,
1.12566420479952, 1.12903662366847, 1.14754211999921, 1.15998855701439,
1.15274364578958, 1.16226441955745, 1.16169992687419, 1.16520028734587,
1.16823402018407, 1.19832130049664, 1.18411773220697, 1.18531274215286,
1.16421444455115, 1.17108139956539, 1.18392357740377, 1.20103911352579,
1.17791736605905, 1.18277944964829, 1.20162550199013, 1.19665058179752,
1.19411188122108, 1.19367558590966, 1.19803272562951, 1.20600155861871,
1.22189449901607, 1.22072774140118, 1.22312376195254, 1.25355505518571,
1.25895911759195, 1.2613354420716, 1.24440525381363, 1.24444079462029,
1.24168652168112, 1.24154936710117, 1.23440527301777, 1.22592718438811,
1.21709102449773, 1.21448030929365, 1.23109601090898, 1.24401127451953,
1.23953314346685, 1.21863565024168, 1.20834325548551, 1.20281193695583,
1.20405850724191, 1.19608032796923, 1.22008184095742, 1.21675995421116,
1.20198916403093, 1.20029121301547, 1.18822375424598, 1.19007923345344,
1.19285965857709, 1.1971013197471, 1.1776860331227, 1.18028531916998,
1.18394951589397, 1.16712430930941, 1.17827461393349, 1.18751430033172,
1.21482260909863, 1.2167262724184, 1.21729489152574, 1.21847062594996,
1.21932070698031, 1.19678189566773, 1.17678214957629, 1.17586968485613,
1.16903708967946, 1.16967697995898, 1.14498266161799, 1.12782282645368,
1.11540004479973, 1.12639853863918, 1.11402516325222, 1.10511837662567,
1.10600107687395, 1.10243149863659, 1.10404564773364, 1.12949458422398,
1.11679224666313, 1.11338078540871, 1.10762728498848, 1.12437898939299,
1.11572706259347, 1.1148111967932, 1.12358625045939, 1.11169207274881,
1.13009253108247, 1.13772927166761, 1.12550770863279, 1.13062401691547,
1.12821231512428, 1.13174620070443, 1.13072790983063, 1.1428325334377,
1.12739171867048, 1.1214997813059, 1.11870510839984, 1.11811303551412,
1.11855383782522, 1.11981261957516, 1.12096887905804, 1.12162710713999,
1.12015553029278, 1.12189306008921, 1.1236834173899, 1.12204149206779,
1.12075809542535, 1.12116672935174, 1.12216772364685, 1.11821915571021,
1.12117719223463, 1.11896003906963, 1.11563621625852, 1.1183625095638,
1.12053072892388, 1.1216348268255, 1.12317377733957, 1.11873136428952,
1.12267083202989, 1.12642930089215, 1.13027646770951, 1.13129632891931,
1.12700346009603, 1.12060488827701, 1.12390899402613, 1.13129350591169,
1.12786650327192, 1.1274201121913, 1.13101906643359, 1.12727135093377,
1.12458327192256, 1.12259738972645, 1.12097982776572, 1.12073621452193,
1.12364872830763, 1.12644326299714, 1.12556263098661, 1.12797963752343,
1.12734519199847, 1.1261793072762, 1.12911407446825, 1.12754878937943,
1.12777579027467, 1.12554965831588, 1.12324469267853, 1.12231558194992,
1.12135908710208, 1.11923353817423, 1.12345300992675, 1.12186883237389,
1.12173652640663, 1.12488148969114, 1.12664301925369, 1.12294230775256,
1.12393650688095, 1.13038044949978, 1.12822226676967, 1.12934384230215,
1.1217648908055, 1.12218158739803, 1.12302651609468, 1.12682187689922,
1.13537701046932, 1.13172108462183, 1.1374053505525, 1.13498257452656,
1.12692005654471, 1.13210629725645, 1.12868775509168, 1.13073909215368,
1.13098804355869, 1.13353301668386, 1.13336476594698, 1.13233873705211,
1.12667020676157, 1.12133152301322, 1.12418759586717, 1.12048022460741,
1.12798162212357, 1.13053093896994, 1.12019367019997, 1.12422483586498,
1.11303086301782, 1.11986711815552, 1.12504718249418, 1.11341517044014,
1.12495096618792, 1.12995127061511, 1.13538401552385, 1.13145536081928,
1.1264465959783, 1.12584386458867, 1.1273908895838, 1.12462482614994,
1.1240880626286, 1.12729907535003, 1.12797751377714, 1.14626724930899,
1.13464279067717, 1.12566420479952, 1.12903662366847, 1.14754211999921,
1.15998855701439, 1.15274364578958, 1.16226441955745, 1.16169992687419,
1.16520028734587, 1.16823402018407, 1.19832130049664, 1.18411773220697,
1.18531274215286, 1.16421444455115, 1.17108139956539, 1.18392357740377,
1.20103911352579, 1.17791736605905, 1.18277944964829, 1.20162550199013,
1.19665058179752, 1.19411188122108, 1.19367558590966, 1.19803272562951,
1.20600155861871, 1.22189449901607, 1.22072774140118, 1.22312376195254,
1.25355505518571, 1.25895911759195, 1.2613354420716, 1.24440525381363,
1.24444079462029, 1.24168652168112, 1.24154936710117, 1.23440527301777,
1.22592718438811, 1.21709102449773, 1.21448030929365, 1.23109601090898,
1.24401127451953, 1.23953314346685, 1.21863565024168, 1.20834325548551,
1.20281193695583, 1.20405850724191, 1.19608032796923, 1.22008184095742,
1.21675995421116, 1.20198916403093, 1.20029121301547, 1.18822375424598,
1.19007923345344, 1.19285965857709, 1.1971013197471, 1.1776860331227,
1.18028531916998, 1.18394951589397, 1.16712430930941, 1.17827461393349,
1.18751430033172, 1.21482260909863, 1.2167262724184, 1.21729489152574,
1.21847062594996, 1.21932070698031, 1.19678189566773, 1.17678214957629,
1.17586968485613, 1.16903708967946, 1.16967697995898, 1.14498266161799,
1.12782282645368, 1.11540004479973, 1.12639853863918, 1.11402516325222,
1.10511837662567, 1.10600107687395, 1.10243149863659, 1.10404564773364,
1.12949458422398, 1.11679224666313, 1.11338078540871, 1.10762728498848,
1.12437898939299, 1.11572706259347, 1.1148111967932, 1.12358625045939,
1.11169207274881, 1.13009253108247, 1.13772927166761, 1.12550770863279,
1.13062401691547, 1.12821231512428, 1.13174620070443, 1.13072790983063,
1.1428325334377, 1.12739171867048, 1.1214997813059, 1.11870510839984,
1.14162401974592, 1.15630966411729, 1.15992199767135, 1.16683144867851,
1.16928280999155, 1.17287782220285, 1.18184525262982, 1.17555305757354,
1.18031492211593, 1.18142628277888, 1.18307577052783, 1.18257404220722,
1.19421117710041, 1.19403330560815, 1.19510080390052, 1.2058940348108,
1.19848571699109, 1.20138771250604, 1.20660682710938, 1.20790011589089,
1.20963951875753, 1.21572259411602, 1.21379678812156, 1.220302087399,
1.22062959185172, 1.22743877731977, 1.23135277550334, 1.24075667733246,
1.24169498945046, 1.23529301399753, 1.2399941777708, 1.24823732280171,
1.23861121958778, 1.24816319854615, 1.25252933549084, 1.25133386983018,
1.24512546001264, 1.2617641352045, 1.25486018976211, 1.25424601859098,
1.25820538036104, 1.25968528498312, 1.26939611029084, 1.27883933177157,
1.27926882841012, 1.27951234203094, 1.28997494816278, 1.29391898267335,
1.2971442938215, 1.29733541086814, 1.30376525837809, 1.31025722802128,
1.29718190520268, 1.27919305871102, 1.28685138548374, 1.28594279969497,
1.28695233433419, 1.30277136510213, 1.29178316107299, 1.29586799884087,
1.30076586308517, 1.30881154838964, 1.32171887794143, 1.3197588324899,
1.3121332301804, 1.31744410759858, 1.31402945919721, 1.30926303329755,
1.32019231597949, 1.31449633135152, 1.31730801686101, 1.31834557852015,
1.3175761022299, 1.33430488507454, 1.34091614601639, 1.33606628597812,
1.33180446732765, 1.33630738683041, 1.33449101077219, 1.32521028784732,
1.32241490851887, 1.31488015995544, 1.31913131799656, 1.32901121011698,
1.33177659436063, 1.32577077582349, 1.31960627618725, 1.31307169067904,
1.32148403094167, 1.33104893196281, 1.33491831741272, 1.3386091981919,
1.35730874062825, 1.3460340606746, 1.34160318929376, 1.35492848895938,
1.35552729646417, 1.36141957863605, 1.36400538435282, 1.369536167295),
.indexCLASS = "Date", tclass = "Date", .indexTZ = "UTC", tzone = "UTC",
class = c("xts", "zoo"), index = structure(c(1497744000, 1497830400, 1497916800,
1498003200, 1498089600, 1498176000, 1498262400, 1498348800, 1498435200,
1498521600, 1498608000, 1498694400, 1498780800, 1498867200, 1498953600,
1499040000, 1499126400, 1499212800, 1499299200, 1499385600, 1499472000,
1499558400, 1499644800, 1499731200, 1499817600, 1499904000, 1499990400,
1500076800, 1500163200, 1500249600, 1500336000, 1500422400, 1500508800,
1500595200, 1500681600, 1500768000, 1500854400, 1500940800, 1501027200,
1501113600, 1501200000, 1501286400, 1501372800, 1501459200, 1501545600,
1501632000, 1501718400, 1501804800, 1501891200, 1501977600, 1502064000,
1502150400, 1502236800, 1502323200, 1502409600, 1502496000, 1502582400,
1502668800, 1502755200, 1502841600, 1502928000, 1503014400, 1503100800,
1503187200, 1503273600, 1503360000, 1503446400, 1503532800, 1503619200,
1503705600, 1503792000, 1503878400, 1503964800, 1504051200, 1504137600,
1504224000, 1504310400, 1504396800, 1504483200, 1504569600, 1504656000,
1504742400, 1504828800, 1504915200, 1505001600, 1505088000, 1505174400,
1505260800, 1505347200, 1505433600, 1505520000, 1505606400, 1505692800,
1505779200, 1505865600, 1505952000, 1506038400, 1506124800, 1506211200,
1506297600, 1506384000, 1506470400, 1506556800, 1506643200, 1506729600,
1506816000, 1506902400, 1506988800, 1507075200, 1507161600, 1507248000,
1507334400, 1507420800, 1507507200, 1507593600, 1507680000, 1507766400,
1507852800, 1507939200, 1508025600, 1508112000, 1508198400, 1508284800,
1508371200, 1508457600, 1508544000, 1508630400, 1508716800, 1508803200,
1508889600, 1508976000, 1509062400, 1509148800, 1509235200, 1509321600,
1509408000, 1509494400, 1509580800, 1509667200, 1509753600, 1509840000,
1509926400, 1510012800, 1510099200, 1510185600, 1510272000, 1510358400,
1510444800, 1510531200, 1510617600, 1510704000, 1510790400, 1510876800,
1510963200, 1511049600, 1511136000, 1511222400, 1511308800, 1511395200,
1511481600, 1511568000, 1511654400, 1511740800, 1511827200, 1511913600,
1.512e+09, 1512086400, 1512172800, 1512259200, 1512345600, 1512432000,
1512518400, 1512604800, 1512691200, 1512777600, 1512864000, 1512950400,
1513036800, 1513123200, 1513209600, 1513296000, 1513382400, 1513468800,
1513555200, 1513641600, 1513728000, 1513814400, 1513900800, 1513987200,
1514073600, 1514160000, 1514246400, 1514332800, 1514419200, 1514505600,
1514592000, 1514678400, 1514764800, 1514851200, 1514937600, 1515024000
), tzone = "UTC", tclass = "Date"), .Dim = c(201L, 3L), .Dimnames = list(
NULL, c("fifth_percentile", "Median", "nintyfifth_percentile"
)))
I haven't tried with your data, but if the question is how to shade the forecast area, maybe this simple example will help.
library(lattice)
x = 1:12 # base data
y = x
ex.x = 12:16 # extrapolated data
ex.y = 12:16
ex.lo = 12+0:4*.3 # lower bound
ex.hi = 12+0:4*1.6 # upper bound
xyplot(y~x,xlim=c(0:18),ylim=c(0:20),
panel=function(x,y,...) {
panel.lines(x,y,lwd=2,col=4)
panel.polygon(c(ex.x,rev(ex.x)),c(ex.lo,rev(ex.hi)),border=NA,col=5)
panel.lines(ex.x,ex.y,lwd=2,col=2)
})
You can add the shaded polygon to the lattice plot in a panel function. I used c(ex.x,rev(ex.x)) and c(ex.lo,rev(ex.hi)) to construct the polygon boundary.
Is there an R function or library that will give me the monthly (or any other specified timeframe) time weighted rate of return (twrr) for my portfolio?
I am including a dput dump of sample data below of the date and portfolio ending balance below. Not sure why the dates were dput'ed the way they were, but the first date 12053 is '2003-01-01' and the last date 12195 is '2003-05-23'.
portfolio.df <- structure(
list(
Date = structure(c(12053, 12054, 12055, 12058,
12059, 12060, 12061, 12062, 12065, 12066, 12067, 12068, 12069,
12073, 12074, 12075, 12076, 12079, 12080, 12081, 12082, 12083,
12086, 12087, 12088, 12089, 12090, 12093, 12094, 12095, 12096,
12097, 12101, 12102, 12103, 12104, 12107, 12108, 12109, 12110,
12111, 12114, 12115, 12116, 12117, 12118, 12121, 12122, 12123,
12124, 12125, 12128, 12129, 12130, 12131, 12132, 12135, 12136,
12137, 12138, 12139, 12142, 12143, 12144, 12145, 12146, 12149,
12150, 12151, 12152, 12153, 12156, 12157, 12158, 12159, 12163,
12164, 12165, 12166, 12167, 12170, 12171, 12172, 12173, 12174,
12177, 12178, 12179, 12180, 12181, 12184, 12185, 12186, 12187,
12188, 12191, 12192, 12193, 12194, 12195),
class = "Date"),
Ending_Balance = c(56250000L,
56852500L, 57080000L, 57355000L, 57477500L, 56817500L, 57885000L,
57810000L, 57732500L, 57670000L, 57520000L, 57285000L, 57270000L,
56655000L, 55802500L, 56337500L, 55642500L, 54510000L, 54987500L,
55802500L, 56065000L, 56865000L, 56635000L, 56497500L, 56640000L,
56155000L, 55757500L, 55972500L, 55865000L, 55535000L, 55885000L,
56840000L, 56902500L, 56945000L, 56622500L, 57012500L, 57200000L,
58072500L, 57612500L, 57447500L, 57157500L, 57032500L, 57405000L,
57502500L, 56785000L, 57007500L, 56342500L, 55697500L, 56655000L,
56900000L, 57002500L, 57465000L, 57467500L, 57382500L, 57982500L,
56562500L, 58065000L, 58935000L, 58502500L, 58200000L, 57767500L,
57757500L, 58055000L, 58305000L, 58277500L, 58295000L, 59047500L,
58907500L, 59125000L, 59072500L, 59107500L, 59315000L, 59690000L,
58957500L, 59407500L, 59385000L, 59965000L, 60297500L, 59890000L,
59822500L, 60367500L, 60407500L, 60380000L, 60815000L, 61155000L,
61080000L, 61132500L, 61265000L, 60912500L, 61107500L, 61445000L,
61345000L, 61137500L, 61035000L, 60707500L, 61340000L, 61365000L,
61402500L, 61640000L, 61675000L)),
.Names = c("Date", "Ending_Balance"),
row.names = c(NA, 100L),
class = "data.frame")