Hi all, I am trying to make a plot based on stock market prices and the library quantmod, imagine BatchGetSymbols(?^IBEX?, first.date = ?1999-12-31?, last.date = ?2020-12-07?) The thing is I want to plot a plot that for each year on 31/12/year tthe base is 100 and each day calvulate the cumulative returns so if on 01/01/year t+1 in one day stock climbs a 3% the Index values 103. I want to plot for each day off the year to the end of the year a line (in fact would be 20 lines) in the example from year 2000 to actual 2020. Aditionally on the current year I want to plot the line more thig (dar) to clearly distinguish It. Do you know if there is some predefinited function to construct It. Many thanks in advance [[alternative HTML version deleted]]
On 7/19/20 11:18 AM, Pedro p?ramo wrote:> Hi all, > > I am trying to make a plot based on stock market prices and the library > quantmod, imagine > > BatchGetSymbols(?^IBEX?, first.date = ?1999-12-31?, > last.date = ?2020-12-07?) > > The thing is I want to plot a plot that for each year on 31/12/year tthe > base is 100 and each day calvulate the cumulative returns so if on > 01/01/year t+1 in one day stock climbs a 3% the Index values 103. I want to > plot for each day off the year to the end of the year a line (in fact would > be 20 lines) in the example from year 2000 to actual 2020. > > Aditionally on the current year I want to plot the line more thig (dar) to > clearly distinguish It. > > Do you know if there is some predefinited function to construct It. > > Many thanks in advance > > [[alternative HTML version deleted]]Rhelp is a plain text mailing list. It is not a project server. We don't exist to deliver code on command. We do exist to help with efforts at R coding. First you need to use an editor that does not create "smart quotes" by default. You should also start your code with library calls to load all necessary packages. I note this because GetBatchSymbols is not in package:quantmod. You should then show all the code from your efforts at investigation of objects' structure and properties and your efforts at plotting. Then describe what sort of problems you seem to be having in understanding the results and modifying them. -- David> > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.
I understand. I Will send my Code tomorrow, I am outside home now. Many thanks David, sorry about all. El dom., 19 jul. 2020 21:13, David Winsemius <dwinsemius at comcast.net> escribi?:> > On 7/19/20 11:18 AM, Pedro p?ramo wrote: > > Hi all, > > > > I am trying to make a plot based on stock market prices and the library > > quantmod, imagine > > > > BatchGetSymbols(?^IBEX?, first.date = ?1999-12-31?, > > last.date = ?2020-12-07?) > > > > The thing is I want to plot a plot that for each year on 31/12/year tthe > > base is 100 and each day calvulate the cumulative returns so if on > > 01/01/year t+1 in one day stock climbs a 3% the Index values 103. I want > to > > plot for each day off the year to the end of the year a line (in fact > would > > be 20 lines) in the example from year 2000 to actual 2020. > > > > Aditionally on the current year I want to plot the line more thig (dar) > to > > clearly distinguish It. > > > > Do you know if there is some predefinited function to construct It. > > > > Many thanks in advance > > > > [[alternative HTML version deleted]] > > > Rhelp is a plain text mailing list. It is not a project server. We don't > exist to deliver code on command. We do exist to help with efforts at R > coding. First you need to use an editor that does not create "smart > quotes" by default. You should also start your code with library calls > to load all necessary packages. I note this because GetBatchSymbols is > not in package:quantmod. You should then show all the code from your > efforts at investigation of objects' structure and properties and your > efforts at plotting. Then describe what sort of problems you seem to be > having in understanding the results and modifying them. > > > -- > > David > > > > > ______________________________________________ > > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]
Hi Pedro, Assuming that you get a vector of daily percentage changes: dpc<-c(+3.1, -2.8, +1.7, +2.1) get the cumulative change and add 100: cumsum(dpc)+100 [1] 103.1 100.3 102.0 104.1 You can then plot that. As Rui noted, your mail client is inserting invisible characters that prevent cutting and pasting into R. Jim On Mon, Jul 20, 2020 at 4:46 AM Pedro p?ramo <percentil101 at gmail.com> wrote:> > Hi all, > > I am trying to make a plot based on stock market prices and the library > quantmod, imagine > > BatchGetSymbols(?^IBEX?, first.date = ?1999-12-31?, > last.date = ?2020-12-07?) > > The thing is I want to plot a plot that for each year on 31/12/year tthe > base is 100 and each day calvulate the cumulative returns so if on > 01/01/year t+1 in one day stock climbs a 3% the Index values 103. I want to > plot for each day off the year to the end of the year a line (in fact would > be 20 lines) in the example from year 2000 to actual 2020. > > Aditionally on the current year I want to plot the line more thig (dar) to > clearly distinguish It. > > Do you know if there is some predefinited function to construct It. > > Many thanks in advance > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.
You can do this with PerformanceAnalytics. library(PerformanceAnalytics) data(edhec) chart.RelativePerformance(edhec, 0, legend = "topleft") Also note that there's a finance-specific mailing list: R-SIG-Finance. Best, Josh On Sun, Jul 19, 2020 at 1:46 PM Pedro p?ramo <percentil101 at gmail.com> wrote:> > Hi all, > > I am trying to make a plot based on stock market prices and the library > quantmod, imagine > > BatchGetSymbols(?^IBEX?, first.date = ?1999-12-31?, > last.date = ?2020-12-07?) > > The thing is I want to plot a plot that for each year on 31/12/year tthe > base is 100 and each day calvulate the cumulative returns so if on > 01/01/year t+1 in one day stock climbs a 3% the Index values 103. I want to > plot for each day off the year to the end of the year a line (in fact would > be 20 lines) in the example from year 2000 to actual 2020. > > Aditionally on the current year I want to plot the line more thig (dar) to > clearly distinguish It. > > Do you know if there is some predefinited function to construct It. > > Many thanks in advance > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.-- Joshua Ulrich | about.me/joshuaulrich FOSS Trading | www.fosstrading.com