R> P <- PF(syms, prefer='Adjusted', silent=TRUE)
R> mP <- to.monthly(P, OHLC=FALSE)
R> # 6 month simple return of each Dow component
R> tail(ROC(mP, n=6, type='discrete'))
AA AXP BA BAC
May 2011 0.28407351 0.2035731077 0.23722861 0.0751604
Jun 2011 0.03464052 0.2186982249 0.14537514 -0.1766917
Jul 2011 -0.10800971 0.1623512946 0.02564103 -0.2914536
Aug 2011 -0.23718713 0.1495587552 -0.06029515 -0.4266667
Sep 2011 -0.45594088 0.0008954556 -0.17166324 -0.5398496
Oct 2011 -0.31659776 0.0698151951 -0.13522771 -0.4000000
CAT CSCO CVX DD
May 2011 0.2616811 -0.12031662 0.31547017 0.15129714
Jun 2011 0.1467261 -0.22550000 0.14423508 0.10002054
Jul 2011 0.0269677 -0.23912004 0.11244071 0.02991712
Aug 2011 -0.1084622 -0.14931880 -0.03230860 -0.10561423
Sep 2011 -0.3312995 -0.09283196 -0.12502363 -0.26077307
Oct 2011 -0.1525943 0.06789413 0.01763505 -0.11636233
DIS GE HD HPQ
May 2011 0.152866242 0.25913838 0.20906631 -0.1050471
Jun 2011 0.040789123 0.04708520 0.04779948 -0.1306122
Jul 2011 -0.006431695 -0.09720102 -0.03640912 -0.2262774
Aug 2011 -0.221307727 -0.21362530 -0.08971912 -0.4002780
Sep 2011 -0.300069622 -0.22741117 -0.09969871 -0.4471805
Oct 2011 -0.159860789 -0.14136386 -0.01311475 -0.3018491
IBM INTC JNJ JPM
May 2011 0.20426720 0.08098933 0.11277945 0.16361650
Jun 2011 0.17881297 0.07125427 0.09463722 -0.02866089
Jul 2011 0.13197874 0.05738881 0.10324686 -0.08946412
Aug 2011 0.07135735 -0.04597156 0.08994534 -0.18622951
Sep 2011 0.08184855 0.07614725 0.09395397 -0.33894178
Oct 2011 0.10864679 0.09802198 0.01579436 -0.18394128
KFT KO MCD MMM
May 2011 0.17773973 0.06532988 0.05772496 0.137328642
Jun 2011 0.13811075 0.03789408 0.11562542 0.112147326
Jul 2011 0.14472801 0.09783845 0.19239311 0.003012746
Aug 2011 0.11960026 0.11808885 0.21160547 -0.088932806
Sep 2011 0.08884565 0.03271171 0.17062117 -0.222462905
Oct 2011 0.07175295 0.03622971 0.20826318 -0.156162100
MRK MSFT PFE
May 2011 0.0901365706 0.0024203308 0.342405063
Jun 2011 0.0014359563 -0.0565899963 0.200353565
Jul 2011 0.0521060842 0.0003673769 0.078142695
Aug 2011 0.0394026057 0.0137195122 0.006896552
Sep 2011 0.0133250697 -0.0071798963 -0.111111111
Oct 2011 -0.0008537279 0.0543180930 -0.035053554
PG T TRV UTX
May 2011 0.114454776 0.16844512 0.16457143 0.17840249
Jun 2011 0.003691221 0.09985580 0.06161746 0.13621091
Jul 2011 -0.009902597 0.09332322 -0.00744507 0.02965465
Aug 2011 0.026820546 0.03200883 -0.14726436 -0.10032715
Sep 2011 0.042588588 -0.04195089 -0.16814612 -0.15867512
Oct 2011 0.013782302 -0.01620906 -0.04572437 -0.10158192
VZ WMT XOM
May 2011 0.183733948 0.040425128 0.2131675201
Jun 2011 0.067766647 -0.001135933 0.1252609603
Jul 2011 0.016647196 -0.047159505 -0.0001261352
Aug 2011 0.005071851 0.044784915 -0.1239199905
Sep 2011 -0.020248380 0.010907674 -0.1260979425
Oct 2011 0.023110386 0.053844735 -0.0624784260
On Sat, Oct 29, 2011 at 3:42 PM, Martin Bauer <Bauermartin at gmx.at> wrote:
-------- Original-Nachricht --------
Datum: Fri, 28 Oct 2011 18:13:14 +0200
Von: "Martina Bauer" <Bauermartin at gmx.at>
An: r-sig-finance at r-project.or
Betreff: runMult instead of runSum
Hello,
Maybe my approach is wrong from the beginning but I would like to
calculate from monthly data - one months and two months and lastly three
months return
I know that I have to multiply the monthly performance instead to sum up
but I dont know how to do in R. Finally I should also rank the result
according to n period performance (no clue how to archive this in R)
here my code
require(quantmod)
stock=c("DD","DIS","PFE")
DD.sp=Ad(DD)
dd.m=monthlyReturn(DD.sp)
dd1=runSum(dd.m,n=1)
dd2=runSum(dd.m,n=2)
dd3=runSum(dd.m,n=3)
DIS.sp=Ad(DIS)
dis.m=monthlyReturn(DIS.sp)
dis1=runSum(DIS.m,n=1)
dis2=runSum(DIS.m,n=2)
dis3=runSum(DIS.m,n=3)
PFE.sp=Ad(PFE)
pfe.m=monthlyReturn(PFE.sp)
pfe1=runSum(pfe.m,n=1)
pfe2=runSum(pfe.m,n=2)
pfe3=runSum(pfe.m,n=3)
I know that my R code is very poor any idea how to improve ?
THanks in advance
Best Regards
martin
--
--