Skip to content

Calculating Returns : (Extremely sorry for earlier incomplete mail)

2 messages · Amelia Vettori, PIKAL Petr

#
Hi

Your code is quite complicated and I get an error

spot_returns_table <- lapply(1:nrow(trans), function(z) with(trans[z, ], 
spot_trans(currency_trans=trans$currency_transacted)))
Error in if (currency_trans == "USD") { : argument is of length zero

It seems to me that you do not know what is your code doing.

The warnings are from the fact that the currency_trans value you feed to 
spot_trans function is longer than one and if function needs an input of 
only one logical value.

Maybe you could use debug and see what are values of your variables during 
computation but I believe that better is to use more convenient input 
objects together with *apply or aggregate or basic math could be better 
solution.

rate1
      USD    GBP  EURO   CHF    AUD
1  112.05 171.52 42.71 41.50 109.55
2  112.90 168.27 42.68 41.47 102.52
3  110.85 169.03 41.86 42.84 114.91
4  109.63 169.64 44.71 43.44 122.48
5  108.08 169.29 44.14 43.69 122.12
6  111.23 169.47 44.58 42.30 123.96
7  112.49 170.90 41.07 42.05 100.36
8  108.87 168.69 42.23 41.23 110.19
9  109.33 170.90 44.55 42.76 121.58
10 111.88 169.96 41.12 43.79 103.46

log(rate1[-1,]/rate1[-nrow(rate1),])

Is this what you want?

Regards
Petr




r-help-bounces at r-project.org napsal dne 07.01.2011 07:36:28:
There
through my
am
apologize
"AUD"),
"12/27/
"12/20/2010")
109.33, 111.88)
170.9, 169.96)
41.12)
43.79)
110.19, 121.
am
portfolio.
constant.
exchange rates.
data is
returns = 9
there are
only
first
only
caused.
http://www.R-project.org/posting-guide.html