[R-SIG-Finance] PerformanceAnalytics issue

julien cuisinier j_cuisinier at hotmail.com
Wed Jul 25 11:16:46 CEST 2012


Bonjour Julien,



Just as  FYI, entering the dates in your first column as DD/MM/YYYY is not ideal - best to format them as YYYY-MM-DD as unambigous format R can understand

I can have the method "compound" work as it should personally but still have the simple method giving me zeros - ???

AFTER changing the csv first column dates with format YYYY-MM-DD

> dfPrices <- read.csv("Indices.csv",header=TRUE,row.names=1,as.is=TRUE)
> testSimple <- CalculateReturns(dfPrices,method="simple")
> write.csv(testSimple,"testSimple.csv")
> testCompound <- CalculateReturns(dfPrices,method="compound")
> write.csv(testCompound,"testCompound.csv")

attached the csv I got from that code - weirdly I have simple returns as zeros but compound returns OK? 


I am suspecting the second issue might be related? thhanks to report back to the list if it is the case



Rgds,
Julien



Just to confirm testing the below & I am getting the same... I am guessing we do not use it proprely although it should be simple - focusing ont he CalculateRetuurns() function: 

> dfPrices <- read.csv("Indices.csv",header=TRUE,row.names=1,as.is=TRUE)
test <- CalculateReturns(dfPrices,method="compound")
Warning message:
In data.row.names(row.names, rowsi, i) :
  some row.names duplicated: 3,6,9,11,13,16,20,23,25,27,30,33,37,40,45,49,51,54,56,58,60,62,64,66,68,73,78,84,86,89,91,93,95,98,100,102,104,106,112,115,118,124,126,130,133,136,138,140,143,147,150,152,154,157,160,164,167,172,176,178,181,183,185,187,189,191,193,195,200,205,211,213,216,218,220,222,225,227,229,231,233,239,242,245,251,253,257,260,263,265,267,270,274,277,279,281,284,287,291,294,299,303,305,308,310,312,314,316,318,320,322,327,332,338,340,343,345,347,349,352,354,356,358,360,366,369,372,378,380,384,387,390,392,394,397,401,404,406,408,411,414,418,421,426,430,432,435,437,439,441,443,445,447,449,454,459,465,467,470,472,474,476,479,481,483,486,492,495,498,504,506,512,515,517,519,522,526,528,530,532,535,538,542,549,551 --> row.names NOT used


Not sure what the warning is about as I do not have duplicated 

From: jdargent at dci.com
To: r-sig-finance at r-project.org
Date: Wed, 25 Jul 2012 03:52:09 +0000
Subject: [R-SIG-Finance] PerformanceAnalytics issue








Dear all:
 
I am facing a disconcerting issue with the functions CalculateReturns() and chart.CumReturns() of the PerformanceAnalytics package.
 
First, when I try to use CalculateReturns() to back out the returns from the total return indices values, the resulting returns do not add up:
 
Indices.ts <- as.timeSeries(CalculateReturns(indices, method = "compound"))
#Note that the method = “simple” option only returns zeros for me.
 
Running the code above on the data in the “indices” CSV file attached, I obtain suspicious returns (for instance the total return for S&P 500 is 17% while it is actually close to 40%).
 
Second, when I do the reverse and use chart.CumReturns() with the correct returns calculated manually in the “returns” CSV file attached, I also obtain wrong cumulative returns.

 
Returns.ts <-      chart.CumReturns(returns[,c(1:5), drop = FALSE],

                                                main="Cumulative Returns",

                                                begin="axis",
                                                 legend.loc = "topleft",

                                                 geometric = TRUE,
                                                 wealth.index = TRUE,
                                                colorset = rainbow6equal)
 
Running this code plots for instance the Barclays US Agg Corporate in my sample above the Barclays Global Agg whereas the later outperformed it.

 

 
I spent a fair amount of time trying to resolve this by myself but it appears that something is amiss.
 
Thanks in advance for your much appreciated help!
 
Julien
 





This e-mail and its attachments are intended only for the individual or entity to whom it is addressed and may contain information that is confidential, privileged, inside information, or subject to other restrictions on use or disclosure. If you have received
 this transmission in error, please notify the sender immediately by return e-mail, and permanently delete or destroy this e-mail, any attachments, and all copies. Any unauthorized use, dissemination or copying of this transmission or the information may be
 unlawful. This message is provided for informational purposes and should not be construed as an invitation or offer to buy or sell any securities or related financial instruments.



_______________________________________________
R-SIG-Finance at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance
-- Subscriber-posting only. If you want to post, subscribe first.
-- Also note that this is not the r-help list where general R questions should go. 		 	   		  
-------------- next part --------------
Content-Transfer-Encoding: quoted-printable

<html>
<head>
<style><!--
.hmmessage P
{
margin:0px=3B
padding:0px
}
body.hmmessage
{
font-size: 10pt=3B
font-family:Tahoma
}
--></style></head>
<body class=3D'hmmessage'><div dir=3D'ltr'>
Bonjour Julien=2C<br><br><br><br>Just as&nbsp=3B FYI=2C entering the dates =
in your first column as DD/MM/YYYY is not ideal - best to format them as YY=
YY-MM-DD as unambigous format R can understand<br><br>I can have the method=
 "compound" work as it should personally but still have the simple method g=
iving me zeros - ???<br><br>AFTER changing the csv first column dates with =
format YYYY-MM-DD<br><br>&gt=3B dfPrices &lt=3B- read.csv("Indices.csv"=2Ch=
eader=3DTRUE=2Crow.names=3D1=2Cas.is=3DTRUE)<br>&gt=3B testSimple &lt=3B- C=
alculateReturns(dfPrices=2Cmethod=3D"simple")<br>&gt=3B write.csv(testSimpl=
e=2C"testSimple.csv")<br>&gt=3B testCompound &lt=3B- CalculateReturns(dfPri=
ces=2Cmethod=3D"compound")<br>&gt=3B write.csv(testCompound=2C"testCompound=
.csv")<br><br>attached the csv I got from that code - weirdly I have simple=
 returns as zeros but compound returns OK? <br><br><br>I am suspecting the =
second issue might be related? thhanks to report back to the list if it is =
the case<br><br><br><br>Rgds=2C<br>Julien<br><br><br><br>Just to confirm te=
sting the below &amp=3B I am getting the same... I am guessing we do not us=
e it proprely although it should be simple - focusing ont he CalculateRetuu=
rns() function: <br><br>&gt=3B dfPrices &lt=3B- read.csv("Indices.csv"=2Che=
ader=3DTRUE=2Crow.names=3D1=2Cas.is=3DTRUE)<br>test &lt=3B- CalculateReturn=
s(dfPrices=2Cmethod=3D"compound")<br>Warning message:<br>In data.row.names(=
row.names=2C rowsi=2C i) :<br>&nbsp=3B some row.names duplicated: 3=2C6=2C9=
=2C11=2C13=2C16=2C20=2C23=2C25=2C27=2C30=2C33=2C37=2C40=2C45=2C49=2C51=2C54=
=2C56=2C58=2C60=2C62=2C64=2C66=2C68=2C73=2C78=2C84=2C86=2C89=2C91=2C93=2C95=
=2C98=2C100=2C102=2C104=2C106=2C112=2C115=2C118=2C124=2C126=2C130=2C133=2C1=
36=2C138=2C140=2C143=2C147=2C150=2C152=2C154=2C157=2C160=2C164=2C167=2C172=
=2C176=2C178=2C181=2C183=2C185=2C187=2C189=2C191=2C193=2C195=2C200=2C205=2C=
211=2C213=2C216=2C218=2C220=2C222=2C225=2C227=2C229=2C231=2C233=2C239=2C242=
=2C245=2C251=2C253=2C257=2C260=2C263=2C265=2C267=2C270=2C274=2C277=2C279=2C=
281=2C284=2C287=2C291=2C294=2C299=2C303=2C305=2C308=2C310=2C312=2C314=2C316=
=2C318=2C320=2C322=2C327=2C332=2C338=2C340=2C343=2C345=2C347=2C349=2C352=2C=
354=2C356=2C358=2C360=2C366=2C369=2C372=2C378=2C380=2C384=2C387=2C390=2C392=
=2C394=2C397=2C401=2C404=2C406=2C408=2C411=2C414=2C418=2C421=2C426=2C430=2C=
432=2C435=2C437=2C439=2C441=2C443=2C445=2C447=2C449=2C454=2C459=2C465=2C467=
=2C470=2C472=2C474=2C476=2C479=2C481=2C483=2C486=2C492=2C495=2C498=2C504=2C=
506=2C512=2C515=2C517=2C519=2C522=2C526=2C528=2C530=2C532=2C535=2C538=2C542=
=2C549=2C551 --&gt=3B row.names NOT used<br><br><br>Not sure what the warni=
ng is about as I do not have duplicated <br><br><div><div id=3D"SkyDrivePla=
ceholder"></div><hr id=3D"stopSpelling">From: jdargent at dci.com<br>To: r-sig=
-finance at r-project.org<br>Date: Wed=2C 25 Jul 2012 03:52:09 +0000<br>Subjec=
t: [R-SIG-Finance] PerformanceAnalytics issue<br><br>


<style><!--
.ExternalClass p.ecxMsoNormal=2C .ExternalClass li.ecxMsoNormal=2C .Externa=
lClass div.ecxMsoNormal
{margin-bottom:.0001pt=3Bfont-size:11.0pt=3Bfont-family:"Calibri"=2C"sans-s=
erif"=3B}
.ExternalClass a:link=2C .ExternalClass span.ecxMsoHyperlink
{color:blue=3Btext-decoration:underline=3B}
.ExternalClass a:visited=2C .ExternalClass span.ecxMsoHyperlinkFollowed
{color:purple=3Btext-decoration:underline=3B}
.ExternalClass p.ecxMsoAcetate=2C .ExternalClass li.ecxMsoAcetate=2C .Exter=
nalClass div.ecxMsoAcetate
{margin-bottom:.0001pt=3Bfont-size:8.0pt=3Bfont-family:"Tahoma"=2C"sans-ser=
if"=3B}
.ExternalClass span.ecxEmailStyle17
{font-family:"Calibri"=2C"sans-serif"=3Bcolor:windowtext=3B}
.ExternalClass span.ecxBalloonTextChar
{font-family:"Tahoma"=2C"sans-serif"=3B}
.ExternalClass .ecxMsoChpDefault
{=3B}
@page WordSection1
{=3B}
.ExternalClass div.ecxWordSection1
{=3B}

--></style>


<div class=3D"ecxWordSection1">
<p class=3D"ecxMsoNormal">Dear all:</p>
<p class=3D"ecxMsoNormal">&nbsp=3B</p>
<p class=3D"ecxMsoNormal">I am facing a disconcerting issue with the functi=
ons CalculateReturns() and chart.CumReturns() of the PerformanceAnalytics p=
ackage.</p>
<p class=3D"ecxMsoNormal">&nbsp=3B</p>
<p class=3D"ecxMsoNormal">First=2C when I try to use CalculateReturns() to =
back out the returns from the total return indices values=2C the resulting =
returns do not add up:</p>
<p class=3D"ecxMsoNormal">&nbsp=3B</p>
<p class=3D"ecxMsoNormal" style=3D"text-indent:.5in">Indices.ts &lt=3B- as.=
timeSeries(CalculateReturns(indices=2C method =3D "compound"))</p>
<p class=3D"ecxMsoNormal" style=3D"text-indent:.5in">#Note that the method =
=3D =93simple=94 option only returns zeros for me.</p>
<p class=3D"ecxMsoNormal">&nbsp=3B</p>
<p class=3D"ecxMsoNormal">Running the code above on the data in the =93indi=
ces=94 CSV file attached=2C I obtain suspicious returns (for instance the t=
otal return for S&amp=3BP 500 is 17% while it is actually close to 40%).</p=
>
<p class=3D"ecxMsoNormal">&nbsp=3B</p>
<p class=3D"ecxMsoNormal">Second=2C when I do the reverse and use chart.Cum=
Returns() with the correct returns calculated manually in the =93returns=94=
 CSV file attached=2C I also obtain wrong cumulative returns.
</p>
<p class=3D"ecxMsoNormal">&nbsp=3B</p>
<p class=3D"ecxMsoNormal" style=3D"text-indent:.5in">Returns.ts &lt=3B- &nb=
sp=3B&nbsp=3B&nbsp=3B&nbsp=3B chart.CumReturns(returns[=2Cc(1:5)=2C drop =
=3D FALSE]=2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3B&nbsp=3B&nb=
sp=3B&nbsp=3B&nbsp=3B &nbsp=3Bwealth.index =3D TRUE=2C</p>
<p class=3D"ecxMsoNormal">&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&=
nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbs=
p=3B &nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=
=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B=
&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nb=
sp=3B&nbsp=3B&nbsp=3B colorset =3D rainbow6equal)</p>
<p class=3D"ecxMsoNormal">&nbsp=3B</p>
<p class=3D"ecxMsoNormal">Running this code plots for instance the Barclays=
 US Agg Corporate in my sample above the Barclays Global Agg whereas the la=
ter outperformed it.
</p>
<p class=3D"ecxMsoNormal">&nbsp=3B</p>
<p class=3D"ecxMsoNormal"><img id=3D"ecxPicture_x0020_1" src=3D"cid:image00=
1.png at 01CD69DE.3138E1C0" width=3D"550" height=3D"450"></p>
<p class=3D"ecxMsoNormal">&nbsp=3B</p>
<p class=3D"ecxMsoNormal">I spent a fair amount of time trying to resolve t=
his by myself but it appears that something is amiss.</p>
<p class=3D"ecxMsoNormal">&nbsp=3B</p>
<p class=3D"ecxMsoNormal">Thanks in advance for your much appreciated help!=
</p>
<p class=3D"ecxMsoNormal">&nbsp=3B</p>
<p class=3D"ecxMsoNormal">Julien</p>
<p class=3D"ecxMsoNormal">&nbsp=3B</p>
</div>
<br>
<br>
This e-mail and its attachments are intended only for the individual or ent=
ity to whom it is addressed and may contain information that is confidentia=
l=2C privileged=2C inside information=2C or subject to other restrictions o=
n use or disclosure. If you have received
 this transmission in error=2C please notify the sender immediately by retu=
rn e-mail=2C and permanently delete or destroy this e-mail=2C any attachmen=
ts=2C and all copies. Any unauthorized use=2C dissemination or copying of t=
his transmission or the information may be
 unlawful. This message is provided for informational purposes and should n=
ot be construed as an invitation or offer to buy or sell any securities or =
related financial instruments.


<br>_______________________________________________
R-SIG-Finance at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance
-- Subscriber-posting only. If you want to post=2C subscribe first.
-- Also note that this is not the r-help list where general R questions sho=
uld go.</div> 		 	   		  </div></body>
</html>=
-------------- next part --------------
A non-text attachment was scrubbed...
Name: testSimple.csv
Type: application/octet-stream
Size: 19544 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20120725/ee844f53/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: testCompound.csv
Type: application/octet-stream
Size: 158011 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20120725/ee844f53/attachment-0001.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.png
Type: image/png
Size: 21224 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20120725/ee844f53/attachment.png>


More information about the R-SIG-Finance mailing list