I am trying to set a graph to show the value of the equity of an investment based on whether the portfolio is invested or in cash. I tried using the ColorFunction
, but was not successful. Here is the sample data.
colorCash = RGBColor[90/255, 180/255, 172/255];
colorInvested = RGBColor[216/255, 179/255, 101/255];
invested = {0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
0, 1, 0, 0, 0, 0};
period = {
{2005, 7, 1}, {2005, 8, 1}, {2005, 9, 1}, {2005, 10, 3}, {2005, 11, 1}, {2005, 12, 1},
{2006, 1, 3}, {2006, 2, 1}, {2006, 3, 1}, {2006, 4, 3}, {2006, 5, 1}, {2006, 6, 1},
{2006, 7, 3}, {2006, 8, 1}, {2006, 9, 1}, {2006, 10, 2}, {2006, 11, 1}, {2006, 12, 1},
{2007, 1, 3}, {2007, 2, 1}, {2007, 3, 1}, {2007, 4, 2}, {2007, 5, 1}, {2007, 6, 1},
{2007, 7, 2}, {2007, 8, 1}, {2007, 9, 4}, {2007, 10, 1}, {2007, 11, 1}, {2007, 12, 3},
{2008, 1, 2}, {2008, 2, 1}, {2008, 3, 3}, {2008, 4, 1}, {2008, 5, 1}, {2008, 6, 2},
{2008, 7, 1}, {2008, 8, 1}, {2008, 9, 2}, {2008, 10, 1}, {2008, 11, 3}, {2008, 12, 1},
{2009, 1, 2}, {2009, 2, 2}, {2009, 3, 2}, {2009, 4, 1}, {2009, 5, 1}, {2009, 6, 1},
{2009, 7, 1}, {2009, 8, 3}, {2009, 9, 1}, {2009, 10, 1}, {2009, 11, 2}, {2009, 12, 1},
{2010, 1, 4}, {2010, 2, 1}, {2010, 3, 1}, {2010, 4, 1}, {2010, 5, 3}, {2010, 6, 1},
{2010, 7, 1}, {2010, 8, 2}, {2010, 9, 1}, {2010, 10, 1}, {2010, 11, 1}, {2010, 12, 1},
{2011, 1, 3}, {2011, 2, 1}, {2011, 3, 1}, {2011, 4, 1}, {2011, 5, 2}, {2011, 6, 1},
{2011, 7, 1}, {2011, 8, 1}, {2011, 9, 1}, {2011, 10, 3}, {2011, 11, 1}, {2011, 12, 1},
{2012, 1, 3}, {2012, 2, 1}, {2012, 3, 1}, {2012, 4, 2}, {2012, 5, 1}, {2012, 6, 1}};
equity = {100, 100, 100, 107.60368663594471, 106.91244239631337, 113.13364055299542,
118.84792626728114, 130.6451612903226, 129.19354838709677, 133.8709677419355,
149.97695852534562, 147.99539170506912, 141.08294930875573, 145.52995391705065,
143.52534562211977, 137.02764976958522, 137.02764976958522, 137.02764976958522,
134.51650476681908, 137.964008923159, 141.4753557490608, 139.9005698998685,
142.77349003015175, 139.47495210278947, 136.77227909133777, 136.77227909133777,
138.2898921592307, 152.82155701480832, 163.44484849005894, 160.74224987600297,
171.42790901157795, 190.01347178823949, 199.95071899992203, 187.95533899753534,
180.13859223688132, 181.8017298455311, 190.01347178823949, 187.2692947339673,
187.2692947339673, 187.2692947339673, 187.2692947339673, 187.2692947339673,
187.2692947339673, 197.63707006655756, 200.49416055487052, 195.407673700677,
188.89264160232702, 208.22129164826242, 197.3556899427086, 202.0525735484958,
202.16079667305314, 213.9571172497998, 221.92233921721777, 250.29844247614417,
232.26846992489646, 229.34644556184912, 236.85713040612634, 235.8181884103762,
249.69239297862313, 257.3113009474577, 263.37179592266705, 249.97377310247217,
264.2375809191255, 276.85639724250774, 287.0510155758062, 293.1115105510154,
300.2542367717978, 281.0987437251542, 297.95990653118287, 302.7217240117045,
329.79914977594314, 323.8901671751141, 316.011523707342, 342.6127677235285,
384.66827392649884, 342.11494135056495, 362.2011532684015, 368.24000361869935,
328.9766540293077, 328.9766540293077, 319.22257687363395, 319.22257687363395,
319.22257687363395, 319.22257687363395};
The following charts show the value of the portfolio and whether I am an investor or not:
Column[{
DateListPlot[Transpose[{period, equity}], Filling -> Axis,
Joined -> True, ImageSize -> Large],
DateListPlot[Transpose[{period, invested}], Filling -> Axis,
ImageSize -> Large]
}]
This is what I tried to change the color, but it is not the correct thing to do as the period painted does not coincide with the investment period:
myColor = If[# == 1, colorInvested, colorCash] & /@ invested;
DateListPlot[Transpose[{period, equity}], Filling -> Axis,
Joined -> True, ColorFunction -> myColor, ImageSize -> Large]