[R-SIG-Finance] Daily dividend yield

2012-10-13 Thread FJ M

I'm trying to calculate the current yield for MSFT using the most recent 
dividend and daily closing price of MSFT. I've tried a couple of approaches 
that don't work, any suggestions would be appreciated. 
 
1) I have downloaded both the dividends and the OHLCVAdjC data successfully. 
When I merge the data with fill=0.0 and export the merged data with write.csv, 
the date is replaced with the index from 1 to 52, first few lines:
 














MSFT.Open
MSFT.High
MSFT.Low
MSFT.Close
MSFT.Volume
MSFT.Adjusted
Divs

1
29.59
29.65
29.21
29.41
31721800
29.22
0

2
29.21
29.53
28.97
29.19
39520500
29
0
 
2) Divs contains the dividend date and the 1 dividend 0.20. Stock contains 
theOHLVAdjC data for Microsoft. I can print the dates using Divs[1,0] and 
Stock[1,0] but a comparison of those dates always results in an error:
 
> 
> for (j in 1:d) {
+ for (i in 1:n) {
+ print(c(Stock[i,0],Divs[j,0]))
+ if ((Stock[i,0]) == (Divs[j,0]))  Current_Div <- Divs[j,1]
+ Stock$MSFT.Adjusted[i]<-Current_Div * Divs_Per_Year
+ }
+ }
2012-08-01
2012-08-14
Error in if ((Stock[i, 0]) == (Divs[j, 0])) Current_Div <- Divs[j, 1] : 
  argument is of length zero
Execution halted

Code follows:
 
library(quantmod)
## Div frequency
Divs_Per_Year<-4
ticker<-"MSFT"
startDate=as.Date("2012-08-01")
endDate=as.Date("2012-10-13")
ticker
startDate
endDate
Divs<-getDividends(ticker, from = startDate, to = endDate)
d<-nrow(Divs)
d
Divs
Stock<-getSymbols.yahoo(ticker, from = startDate, to = endDate, src = "yahoo", 
verbose=TRUE, auto.assign=FALSE)
n<-nrow(Stock)
n
Stock_Divs<-merge(Stock,Divs,fill=0.0)
Stock_Divs
Divs_Per_Year
Current_Div<-Divs[1,1]
Current_Div
d<-nrow(Divs)
d
write.csv(Stock_Divs, file = "Stock_Divs.csv", append = FALSE, quote = TRUE, 
sep = " ")
for (j in 1:d) {
for (i in 1:n) {
print(c(Stock[i,0],Divs[j,0]))
if ((Stock[i,0]) == (Divs[j,0]))  Current_Div <- Divs[j,1]
Stock$MSFT.Adjusted[i]<-Current_Div * Divs_Per_Year
}
}
 
 
Frank
Chicago, IL   
[[alternative HTML version deleted]]

___
R-SIG-Finance@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.


[R-SIG-Finance] Errors with updatePortf in blotter package

2012-10-13 Thread Noah Silverman
Hello,

I'm attempting to develop a trade testing system using the blotter package.  
Following some of the demo examples included.

I'm looking at a specific set of assets using historical data provided to me.  
(I have to use these assets and data - not my choice.)

The issue is that an asset may skip a trading day occasionally.  I don't care, 
but the updatePortf function returns and error and the code stops.

The error is:

> updatePortf(Portfolio = port, Dates = tradeDay)

Error in lag.xts(TmpPeriods$Pos.Value, 1) : 
  abs(k) must be less than nrow(x)
In addition: Warning message:
In .updatePosPL(Portfolio = pname, Symbol = as.character(symbol),  :
  no Prices available for asst3 in 2000-01-02 23:59:59::2000-01-03 23:59:59 : 
using last available price and marking to 2000-01-03 23:59:59

Any suggestions on how to resolve this?

Thanks,

--
Noah Silverman, M.S.
UCLA Department of Statistics
8117 Math Sciences Building
Los Angeles, CA 90095




[[alternative HTML version deleted]]

___
R-SIG-Finance@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.


Re: [R-SIG-Finance] Slow data EOD

2012-10-13 Thread G See
And Jeff's already provided a quoteFormat (which I had forgotten
about) so that you don't have to rearrange columns.

> getQuote("SPY", what=yahooQuote.EOD)
 Trade Time   Open   HighLow  CloseVolume
SPY 2012-10-12 04:00:00 143.46 143.95 142.58 142.89 124181904


On Tue, Oct 9, 2012 at 12:04 PM, Ralph Vince  wrote:
> Ah, okthen I can create a function to perhaps append it onto the
> file I am downloading entirely end of day or something like that.
>
> On Tue, Oct 9, 2012 at 1:02 PM, G See  wrote:
>> On Tue, Oct 9, 2012 at 11:58 AM, Ralph Vince  wrote:
>>> Thanks Garrett, Im really just looking for timely end-of-day data on
>>> this though. Ralph
>>
>> For example, getQuote("SPY"), will return end of day data if you call
>> it late in the afternoon ;-)

___
R-SIG-Finance@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.


Re: [R-SIG-Finance] [R] RTAQ - convert function: warning causes incorrect loading of data

2012-10-13 Thread Jeff Ryan
FWIW %m is the proper conversion for months. %M is minutes. 

Looks like a bug. 

Jeffrey Ryan|Founder|jeffrey.r...@lemnica.com

www.lemnica.com

On Oct 13, 2012, at 10:33 AM, Nicolae Caprarescu  wrote:

> Hi Michael,
> 
> Thank you for pointing me in the right direction, I'm now using an email
> client rather than Nabble.
> 
> Related to the issue I described below, it's resolved now, I have managed
> to fix it myself. However, I believe this might be a bug, or at least
> something that needs improving; I have described both how to reproduce this
> issue and its solution in the below 4 steps:
> 1) library(RTAQ)
> 2) Create XXX_trades.csv file with the contents below using a relative
> path like [somewhere]/TAQData/2010-11-01/XXX_trades.csv
> SYMBOL,DATE,TIME,PRICE,SIZE,G127,CORR,COND,EX
> XXX,20101101,10:30:00,11.49,500,0,0,@,B
> XXX,20101101,10:30:02,11.49,322,0,0,0,B
> XXX,20101101,10:30:02,11.49,178,0,0,@,B
> XXX,20101101,10:30:03,11.49,500,0,0,@,B
> XXX,20101101,10:30:03,11.49,187,0,0,@,D
> 3) 
> #convert does not generate any errors/warnings, however it does not work
> properly
> convert(from="2010-11-01",
> to="2010-11-01",datasource="[somewhere]/TAQData/",
> datadestination="[somewhere]/TAQDataRData/",trades=T,quotes=F,ticker="XXX",dir=T,
> extention="csv", header=T, tradecolnames=c("SYMBOL", "DATE", "TIME",
> "PRICE", "SIZE", "G127", "CORR", "COND", "EX"))
> #loading the RData created by convert
> TAQLoad("XXX",from="2010-11-01",to="2010-11-01",datasource="[somewhere]TAQDataRData/",
> trades=T,quotes=F)
> #output of TAQLoad 
> SYMBOL EX  PRICE   SIZE  COND CORR G127
>  "XXX"  "B" "11.49" "500" "@"  "0"  "0" 
>  "XXX"  "B" "11.49" "322" "0"  "0"  "0" 
>  "XXX"  "B" "11.49" "178" "@"  "0"  "0" 
>  "XXX"  "B" "11.49" "500" "@"  "0"  "0" 
>  "XXX"  "D" "11.49" "187" "@"  "0"  "0" 
> Warning message:
> timezone of object (GMT) is different than current timezone (). 
> 
> Problem are the s. If one does not supply the format of date and time
> to the convert function, it is assumed that the standard NYSE format is
> used, and therefore RTAQ internally (convert_to_RData.r line 32) represents
> this as "Y%M%D %H:%M:%S". Whilst this works fine for some things, when a
> timeDate is initialised using this format (convert_to_RData.r line 102), it
> does not work. timeDate expects a correct format like "%Y%m%d %H:%M:%S"
> format rather than "Y%M%D %H:%M:%S".
> Run the below two to confirm: 
> tdobject=timeDate:::timeDate(paste(as.vector("2010-10-11"),
> as.vector("10:30:30")), format="%Y%M%D
> %H:%M:%S",FinCenter="GMT",zone="GMT")
> #tdobject is GMT [1] [NA]
> tdobject=timeDate:::timeDate(paste(as.vector("20101011"),
> as.vector("10:30:30")), format="%Y%m%d
> %H:%M:%S",FinCenter="GMT",zone="GMT")
> #tdobject is now GMT [1] [2010-10-11 10:30:30]
> 
> Therefore, if one explicitly includes format="%Y%m%d %H:%M:%S" in the
> convert function, everything works fine and the  problem above is
> solved; this is my solution. Can I please suggest that, once you
> investigate this and provided that you confirm my understanding,
> convert_to_RData.r is changed in order to use "%Y%m%d %H:%M:%S" as the
> default format? 
> 
> 4) My environment:
> R version 2.15.1 (2012-06-22)
> Platform: i686-pc-linux-gnu (32-bit)
> 
> locale:
> [1] LC_CTYPE=en_GB   LC_NUMERIC=C LC_TIME=en_GB   
> [4] LC_COLLATE=C LC_MONETARY=en_GBLC_MESSAGES=en_GB   
> [7] LC_PAPER=C   LC_NAME=CLC_ADDRESS=C
> [10] LC_TELEPHONE=C   LC_MEASUREMENT=en_GB LC_IDENTIFICATION=C 
> 
> attached base packages:
> [1] stats graphics  grDevices utils datasets  methods   base 
> 
> other attached packages:
> [1] RTAQ_0.2 timeDate_2160.97 xts_0.8-6zoo_1.7-8   
> 
> loaded via a namespace (and not attached):
> [1] grid_2.15.1lattice_0.20-6
> 
> 
> Best wishes,
> Nicolae
> 
> 
> 
> On Fri, 12 Oct 2012 21:52:22 +0100, "R. Michael Weylandt"
>  wrote:
>> I'm forwarding this to the R-SIG-Finance list, where ou'll have a more
>> specialized audience.
>> 
>> In the meanwhile, you may wish to look at
>> 
> http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example
>> 
>> Finally, I note you're posting from Nabble. Please do include context in
>> your reply -- I don't believe Nabble does this automatically, so
>> you'll need to manually include it. Most of the regular respondents on
>> these lists don't use Nabble -- it is a _mailing list_ after all -- so
>> we don't get the forum view you do, only emails of the individual
>> posts. Combine that with the high volume of posts, and it's quite
>> difficult to trace a discussion if we all don't make sure to include
>> context.
>> 
>> Cheers,
>> Michael
>> 
>> On Fri, Oct 12, 2012 at 7:01 PM, caprarn9  wrote:
>>> Hello,
>>> 
>>> I am closely following the RTAQ documentation in order to load my
> dataset
>>> into R, however I get this warning when running the convert function in
>>> the
>>> followi

Re: [R-SIG-Finance] [R] RTAQ - convert function: warning causes incorrect loading of data

2012-10-13 Thread Nicolae Caprarescu
Hi Michael,

Thank you for pointing me in the right direction, I'm now using an email
client rather than Nabble.

Related to the issue I described below, it's resolved now, I have managed
to fix it myself. However, I believe this might be a bug, or at least
something that needs improving; I have described both how to reproduce this
issue and its solution in the below 4 steps:
1) library(RTAQ)
2) Create XXX_trades.csv file with the contents below using a relative
path like [somewhere]/TAQData/2010-11-01/XXX_trades.csv
SYMBOL,DATE,TIME,PRICE,SIZE,G127,CORR,COND,EX
XXX,20101101,10:30:00,11.49,500,0,0,@,B
XXX,20101101,10:30:02,11.49,322,0,0,0,B
XXX,20101101,10:30:02,11.49,178,0,0,@,B
XXX,20101101,10:30:03,11.49,500,0,0,@,B
XXX,20101101,10:30:03,11.49,187,0,0,@,D
3) 
#convert does not generate any errors/warnings, however it does not work
properly
convert(from="2010-11-01",
to="2010-11-01",datasource="[somewhere]/TAQData/",
datadestination="[somewhere]/TAQDataRData/",trades=T,quotes=F,ticker="XXX",dir=T,
extention="csv", header=T, tradecolnames=c("SYMBOL", "DATE", "TIME",
"PRICE", "SIZE", "G127", "CORR", "COND", "EX"))
#loading the RData created by convert
TAQLoad("XXX",from="2010-11-01",to="2010-11-01",datasource="[somewhere]TAQDataRData/",
trades=T,quotes=F)
#output of TAQLoad 
 SYMBOL EX  PRICE   SIZE  COND CORR G127
 "XXX"  "B" "11.49" "500" "@"  "0"  "0" 
 "XXX"  "B" "11.49" "322" "0"  "0"  "0" 
 "XXX"  "B" "11.49" "178" "@"  "0"  "0" 
 "XXX"  "B" "11.49" "500" "@"  "0"  "0" 
 "XXX"  "D" "11.49" "187" "@"  "0"  "0" 
Warning message:
timezone of object (GMT) is different than current timezone (). 

Problem are the s. If one does not supply the format of date and time
to the convert function, it is assumed that the standard NYSE format is
used, and therefore RTAQ internally (convert_to_RData.r line 32) represents
this as "Y%M%D %H:%M:%S". Whilst this works fine for some things, when a
timeDate is initialised using this format (convert_to_RData.r line 102), it
does not work. timeDate expects a correct format like "%Y%m%d %H:%M:%S"
format rather than "Y%M%D %H:%M:%S".
Run the below two to confirm: 
tdobject=timeDate:::timeDate(paste(as.vector("2010-10-11"),
as.vector("10:30:30")), format="%Y%M%D
%H:%M:%S",FinCenter="GMT",zone="GMT")
#tdobject is GMT [1] [NA]
tdobject=timeDate:::timeDate(paste(as.vector("20101011"),
as.vector("10:30:30")), format="%Y%m%d
%H:%M:%S",FinCenter="GMT",zone="GMT")
#tdobject is now GMT [1] [2010-10-11 10:30:30]

Therefore, if one explicitly includes format="%Y%m%d %H:%M:%S" in the
convert function, everything works fine and the  problem above is
solved; this is my solution. Can I please suggest that, once you
investigate this and provided that you confirm my understanding,
convert_to_RData.r is changed in order to use "%Y%m%d %H:%M:%S" as the
default format? 

4) My environment:
R version 2.15.1 (2012-06-22)
Platform: i686-pc-linux-gnu (32-bit)

locale:
 [1] LC_CTYPE=en_GB   LC_NUMERIC=C LC_TIME=en_GB   
 [4] LC_COLLATE=C LC_MONETARY=en_GBLC_MESSAGES=en_GB   
 [7] LC_PAPER=C   LC_NAME=CLC_ADDRESS=C
[10] LC_TELEPHONE=C   LC_MEASUREMENT=en_GB LC_IDENTIFICATION=C 

attached base packages:
[1] stats graphics  grDevices utils datasets  methods   base 

other attached packages:
[1] RTAQ_0.2 timeDate_2160.97 xts_0.8-6zoo_1.7-8   

loaded via a namespace (and not attached):
[1] grid_2.15.1lattice_0.20-6


Best wishes,
Nicolae



On Fri, 12 Oct 2012 21:52:22 +0100, "R. Michael Weylandt"
 wrote:
> I'm forwarding this to the R-SIG-Finance list, where ou'll have a more
> specialized audience.
> 
> In the meanwhile, you may wish to look at
>
http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example
> 
> Finally, I note you're posting from Nabble. Please do include context in
> your reply -- I don't believe Nabble does this automatically, so
> you'll need to manually include it. Most of the regular respondents on
> these lists don't use Nabble -- it is a _mailing list_ after all -- so
> we don't get the forum view you do, only emails of the individual
> posts. Combine that with the high volume of posts, and it's quite
> difficult to trace a discussion if we all don't make sure to include
> context.
> 
> Cheers,
> Michael
> 
> On Fri, Oct 12, 2012 at 7:01 PM, caprarn9  wrote:
>> Hello,
>>
>> I am closely following the RTAQ documentation in order to load my
dataset
>> into R, however I get this warning when running the convert function in
>> the
>> following way:
>>
>> convert(from="2010-11-01", to="2010-11-01",datasource=datasource,
>> datadestination=datadestination,trades=T,quotes=T,ticker="BAC",dir=T,
>> extention="csv", header=T, tradecolnames=c("SYMBOL", "DATE", "TIME",
>> "PRICE", "SIZE", "G127", "CORR", "COND", "EX"),
quotecolnames=c("SYMBOL",
>> "DATE", "TIME", "BID", "OFR", "BIDSIZ", "OFRSIZ", "MODE", "EX"))
>>
>> The only warning returned is:
>> In `[<-.factor`(`*

Re: [R-SIG-Finance] [R] DCC help

2012-10-13 Thread R. Michael Weylandt
Forwarding to R-SIG-Finance where I believe you're likely to get more help:

In the meanwhile, I think you may wish to look at
http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example

Finally, I note you're posting from Nabble. Please include context in
your follow-ups -- I don't believe Nabble does this automatically, so
you'll need to manually include it. Most of the regular respondents on
these lists don't use Nabble -- it is a _mailing list_ after all -- so
we don't get the forum view you do, only emails of the individual
posts. Combine that with the high volume of posts, and it's quite
difficult to trace a discussion if we all don't make sure to include
context.

Cheers,
Michael

On Sat, Oct 13, 2012 at 5:36 AM, australiastudent
 wrote:
> hi all,
>
> i am using a dcc model for my senior thesis, it looks at stock returns
> during times of market uncertainty.
>
> my current rfile is below.
>
> library(SparseM)
> library(quantreg)
> library(zoo)
> library(nortest)
> library(MASS)
> library(fEcofin)
> library(mvtnorm)
> library(ccgarch)
> library(stats)
> library(foreign)
>
> #dataset<-read.csv(file="",header=FALSE)
> attach(dataset);
>
> vardata=data.frame(dataset[,2],dataset[,4])
>
> ### DCC ###
>
> #initial values
> a1 <- c(0.003, 0.001, 0.001)
> A1 <- diag(c(0.1,0.1,0.1))
> B1 <- diag(c(0.1, 0.1, 0.1))
> dcc.para <- c(0.01,0.98)
>
> # Estimating a DCC-GARCH(1,1) model
> dcc.results <- dcc.estimation(inia=a, iniA=A, iniB=B, ini.dcc=dcc.para,
> dvar=vardata, model="diagonal")
> # Parameter estimates and their robust standard errors
> dcc.results$out
>
> DCC_corr<-dcc.results$DCC[,2]
>
> plot(DCC_corr)
>
> this gives me the output results and a plot.
>
> the questions i have are
>
> 1. how do i get a plot with lines instead of dots
>
> 2. in my file i have two types of dummy variables - the first are quantiles
> where it is 1 if stock returns are in the lowest 5% quantile and the second
> dummy variable are specific events in the world economy where it is 1 if the
> stock return for that day happens to lie within the date range i specified
> for each event.
>
> i have fun the dcc without my dummy variables, but how can i incorporate my
> dummies into my results as i cannot find a user guide to help me
>
> any help would be greatly appreciated!
>
> thank you all!
>
>
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/DCC-help-tp4646061.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> r-h...@r-project.org mailing list
> 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.

___
R-SIG-Finance@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.