Re: [R-SIG-Finance] adjustOHLC discrepancy
On 19 September 2012 04:00, Jim Green student.northwest...@gmail.com wrote: Thanks Josh. I'll dig a little more with your clues and post back if I find anything. Checked Bloomberg, many of the cacs from are wrong before 2009... some even don't make sense.. Nasdaq, on the other hand, seems to have correct historical dividend data http://www.nasdaq.com/symbol/c/dividend-history adjusted close provided by yahoo seems reasonable. but need more time to test. Thanks to Josh again for looking into the issue! Hope this post answers some potential questions regarding adjustOHLC. Jim. ___ 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] adjustOHLC discrepancy
Dear List: I expect that use.Adjusted=TRUE or FALSE wouldn't affect the adjusted close. But running the following code proved I was wrong. getSymbols('C',src='yahoo') [1] C head(adjustOHLC(C)) C.Open C.HighC.Low C.Close C.Volume C.Adjusted 2007-01-03 190.8698 192.9960 187.6464 189.4639 2282100 498.66 2007-01-04 189.4639 192.5502 187.6464 188.8123 1658700 496.94 2007-01-05 188.6066 188.7780 186.7548 187.8179 1317900 494.32 2007-01-08 187.2349 189.1210 186.2061 188.7780 1236900 496.85 2007-01-09 188.6409 189.1210 185.8289 187.1320 1963000 492.52 2007-01-10 186.1032 186.8577 185.0059 185.6232 1744900 488.55 head(adjustOHLC(C,use.Adjusted=TRUE)) C.Open C.HighC.Low C.Close C.Volume C.Adjusted 2007-01-03 502.3605 507.9563 493.8765 498.66 2282100 498.66 2007-01-04 498.6548 506. 493.8714 496.94 1658700 496.94 2007-01-05 496.3958 496.8471 491.5221 494.32 1317900 494.32 2007-01-08 492.7886 497.7525 490.0809 496.85 1236900 496.85 2007-01-09 496.4912 497.7548 489.0903 492.52 1963000 492.52 2007-01-10 489.8136 491.7992 486.9254 488.55 1744900 488.55 by using adjustOHLC, the C.close value is not the same as C.Adjusted provided directly by yahoo. C.Open C.HighC.Low C.Close C.Volume C.Adjusted 2007-01-03 190.8698 192.9960 187.6464 189.4639 2282100 498.66 I think adjustOHLC and adjRatios are theoretically correct and I wonder where this discrepancy comes from. Is it possible Yahoo uses a different method to calculate its adjusted close. Which adjusted close would everyone recommend? the raw close adjusted by adjustOHLC or the adjusted close provided by yahoo? Thanks! Jim. ___ 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] adjustOHLC discrepancy
On 19 September 2012 03:54, Joshua Ulrich josh.m.ulr...@gmail.com wrote: I hope that helps a bit, though I realize I probably created more questions for you than I answered. Thanks Josh. I'll dig a little more with your clues and post back if I find anything. Jim. ___ 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] Help with getSymbols from csv data file
On 27 January 2012 20:58, Joshua Ulrich josh.m.ulr...@gmail.com wrote: Hi Jun, Specifying the date format via setSymbolLookup fixes it. I'm not sure if there is a more general solution. setSymbolLookup(test=list(src=csv,format=%Y-%m-%d)) getSymbols('test',src='csv') I had the same problem, it seems to be to make more sense if I can set the format via setDefaults('getSymbols.csv' having to set set the setSymbolLookup for each symbol is too much. Jim. ___ 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] moving averages on specific interval and merge
Thanks Garret, it worked correctly. I found a similar question here at http://r.789695.n4.nabble.com/Speed-optimization-on-minutes-distribution-calculation-td929537.html and Jeff gave a very fast solution. Just for the reference. Now I am attempting to write a custom indicator doing what you showed to be used in quantstrat. Jim. On 12 May 2012 12:54, G See gsee...@gmail.com wrote: Hi Jim, We prefer if you share with us what you tried and what you've done to attempt to solve the problem yourself. Anyway here's one way to start. library(quantmod) # for the Vo function as well as xts and zoo load(~/Downloads/a.rda) CalcMinuteVolume - function(x) { # This function will calculate the average of the volume for a given minute #of every day mvolm - aggregate(Vo(x), format(index(x), %H:%M), mean) xts(coredata(mvolm), as.POSIXct(paste(as.Date(end(x)), index(mvolm)), format=%Y-%m-%d %H:%M)) } dtemp - to.daily(temp) index(dtemp) - as.Date(index(dtemp)) # in case you have an old version of xts # make strings to use to subset the data by 10 day periods subsets - rollapplyr(index(dtemp), 10, function(x) paste0(first(x), /, last(x))) out - lapply(subsets, function(ss) { CalcMinuteVolume(temp[ss]) }) names(out) - index(dtemp)[-c(1:9)] # days 1:9 were burned to calculate 1st mean # Now you have a list of days. e.g. out[[2012-02-15]] # Now merge temp$Average.Volume.at.current.interval - do.call(rbind, out) temp Things to consider: - You almost certainly want to throw a lag in there. - You have a different number of rows for different days. Also, see ?agrregate.zoo or ?tapply, ?rollapply, ?period.apply, and ?do.call HTH, Garrett On Thu, May 10, 2012 at 8:11 PM, Jim Green student.northwest...@gmail.com wrote: Greetings! I am using quantstrat and xts to do some intraday work and come up with this problem. the xts object temp in the following example is attached as and rda file. head(temp) A.Open A.High A.Low A.Close A.Volume 2012-02-01 08:29:00 42.47 43.76 41.410 43.76 2071 2012-02-01 09:30:00 43.38 43.38 42.970 43.15 40300 2012-02-01 09:31:00 43.14 43.28 43.130 43.28 14990 2012-02-01 09:32:00 43.27 43.37 43.270 43.37 3300 2012-02-01 09:33:00 43.37 43.50 43.370 43.48 3056 2012-02-01 09:34:00 43.49 43.50 43.396 43.44 10968 tail(temp) A.Open A.High A.Low A.Close A.Volume 2012-03-27 16:07:00 45.6650 45.6650 45.6650 45.6650 170 2012-03-27 16:08:00 45.6710 45.6710 45.6710 45.6710 474 2012-03-27 16:10:00 45.9131 45.9131 45.9131 45.9131 1800 2012-03-27 16:13:00 45.6952 45.6952 45.6952 45.6952 300 2012-03-27 16:15:00 45.9368 45.9368 45.9368 45.9368 791 2012-03-27 16:21:00 45.7000 45.7000 45.7000 45.7000 22000 I would like to calculate moving averages of minute volume for specific interval and merge with the original minute ohlc data. take 09:40:00 for example, calculate the average previous 10 days volume between 09:39:00 to 09:40:00 and merge with exiting data. ultimately I want to get an xts object with columns Open High Low Close Volume Average.Volume.at.current.interval 2012-03-27 16:07:00 45.6650 45.6650 45.6650 45.6650 170 177 2012-03-27 16:08:00 45.6710 45.6710 45.6710 45.6710 474 500 ... ... .. 2012-03-27 16:21:00 45.7000 45.7000 45.7000 45.7000 22000 1000 any pointers are appreciated! Jim. ___ 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@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] moving averages on specific interval and merge
the question is more of r-help on second thought. I'll post on r-help. sorry. Jim. On 10 May 2012 21:11, Jim Green student.northwest...@gmail.com wrote: Greetings! I am using quantstrat and xts to do some intraday work and come up with this problem. the xts object temp in the following example is attached as and rda file. head(temp) A.Open A.High A.Low A.Close A.Volume 2012-02-01 08:29:00 42.47 43.76 41.410 43.76 2071 2012-02-01 09:30:00 43.38 43.38 42.970 43.15 40300 2012-02-01 09:31:00 43.14 43.28 43.130 43.28 14990 2012-02-01 09:32:00 43.27 43.37 43.270 43.37 3300 2012-02-01 09:33:00 43.37 43.50 43.370 43.48 3056 2012-02-01 09:34:00 43.49 43.50 43.396 43.44 10968 tail(temp) A.Open A.High A.Low A.Close A.Volume 2012-03-27 16:07:00 45.6650 45.6650 45.6650 45.6650 170 2012-03-27 16:08:00 45.6710 45.6710 45.6710 45.6710 474 2012-03-27 16:10:00 45.9131 45.9131 45.9131 45.9131 1800 2012-03-27 16:13:00 45.6952 45.6952 45.6952 45.6952 300 2012-03-27 16:15:00 45.9368 45.9368 45.9368 45.9368 791 2012-03-27 16:21:00 45.7000 45.7000 45.7000 45.7000 22000 I would like to calculate moving averages of minute volume for specific interval and merge with the original minute ohlc data. take 09:40:00 for example, calculate the average previous 10 days volume between 09:39:00 to 09:40:00 and merge with exiting data. ultimately I want to get an xts object with columns Open High Low Close Volume Average.Volume.at.current.interval 2012-03-27 16:07:00 45.6650 45.6650 45.6650 45.6650 170 177 2012-03-27 16:08:00 45.6710 45.6710 45.6710 45.6710 474 500 ... ... .. 2012-03-27 16:21:00 45.7000 45.7000 45.7000 45.7000 22000 1000 any pointers are appreciated! Jim. ___ 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] quantstrat with intraday data
On 3 May 2012 00:07, G See gsee...@gmail.com wrote: If a stock splits in half, don't you think you should adjust for that before performing technical analysis? You'd treat that big jump in price the same as a real price jump even though if you had a position in the stock, your PnL would be unaffected by the split? sorry I was unclear... that would generate wrong signals.. I think the correct way to use split/dividend adjusted daily data for technical analysis is: 1, for each day, generate signals using adjusted data till before that day, in a walking forward fashion. 2, for pnl logistics, use trade based adjustments or position adjustments. the above are not currently supported by quantstrat and underlying blotter but is really a nice to have. is qmao addressing the them in some way? Jim. ___ 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] Handling half hourly data from electricity markets
Hi, I came across this message and found: the years function doesn't work, actuall in zoo docomentation there is no years function.. aggregate(cbind(X1, X2, X3) ~ peak + years(Date), DF, mean) I tried aggregate(cbind(X1, X2, X3) ~ peak + as.numeric(format(Date,format='%Y')), DF, mean) aggregate(cbind(X1, X2, X3) ~ peak + as.POSIXlt(Date)$year+1900, DF, mean) but both don't work either.. Could someone pls advise? Thanks! Jim. -- View this message in context: http://r.789695.n4.nabble.com/Handling-half-hourly-data-from-electricity-markets-tp3616106p4600106.html Sent from the Rmetrics mailing list archive at Nabble.com. ___ 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] quantstrat with intraday data
Greetings! Pls forgive me if this is an old topic. I have searched through list archives extensively but I am just not sure if I am using quantstrat correctly with intraday data. I've attached sample minute ohlc data. after loading it, an xts object spy.test would be populated as shown below: nrow(spy.test) [1] 1074 head(spy.test) spy.Open spy.High spy.Low spy.Close spy.Volume 2012-03-29 07:32:00 140.14 140.15 140.14140.15800 2012-03-29 07:33:00 140.15 140.15 140.14140.14 2700 2012-03-29 07:36:00 140.16 140.16 140.12140.12 5105 2012-03-29 07:40:00 140.17 140.17 140.17140.17200 2012-03-29 07:41:00 140.15 140.16 140.15140.16 1798 2012-03-29 07:42:00 140.16 140.16 140.16140.16 2052 tail(spy.test) spy.Open spy.High spy.Low spy.Close spy.Volume 2012-03-30 16:26:00 140.86 140.87 140.85140.87 10900 2012-03-30 16:27:00 140.86 140.86 140.79140.79 27770 2012-03-30 16:28:00 140.84 140.86 140.84140.86 20400 2012-03-30 16:29:00 140.85 140.86 140.84140.86 18500 2012-03-30 16:30:00 140.86 140.86 140.85140.85 11035 2012-03-30 16:31:00 140.85 140.86 140.85140.85 1100 Currently I use something similar to attached test.R to do intraday work. in the code I liquidate everything before close so that I don't need to worry about splits and dividends. Is what I am doing the correct way of using quantstrat with intraday data? Also if in future I will hold overnight positions, How would I make sure dividends and splits are correctly adjusted for pnl and summary statistics? would underlying blotter be smart enough to handle all the housekeeping? Thanks! Jim. spy.test.Rdata Description: Binary data test.R Description: Binary data ___ 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] Historical data for single dates
your best bet would be beancounter package http://dirk.eddelbuettel.com/code/beancounter.html from Dirk. It can store yahoo data in database. Jim. -- View this message in context: http://r.789695.n4.nabble.com/Historical-data-for-single-dates-tp4598678p4598701.html Sent from the Rmetrics mailing list archive at Nabble.com. ___ 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-sig-Finance] Rolling correlations with zoo object
Thanks Gabor, it works great now! Jim. -- View this message in context: http://r.789695.n4.nabble.com/Rolling-correlations-with-zoo-object-tp926073p4599489.html Sent from the Rmetrics mailing list archive at Nabble.com. ___ 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] Strange results from Quantstrat
I was testing the attached code and I found that in the testSymbols file, it contains duplicate timestamp rows, after I removed them, the strange behavior goes away. Jim. -- View this message in context: http://r.789695.n4.nabble.com/Strange-results-from-Quantstrat-tp4230979p4591150.html Sent from the Rmetrics mailing list archive at Nabble.com. ___ 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] how to save the quantstrat performance chart
Good Evening! in maCross.R in the demo folder of quantstrat, chart.Posn(Portfolio='macross',Symbol=stock.str) is called to generate the performance chart. internally it calls chart_Series in quantmod. the chart it produced is very nice, the only thing that bothers me is the font of the label is too small and looks like there is no easy way to zoom in an out interactively. Could anyone advise how to save that chart to some image format on the hard drive so I can zoom in and out without much loss of definition? I tried quantmod documentation and came across saveChart command but still don't know how to integrate to maCross.R for example. Thanks! Jim. ___ 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] how to save the quantstrat performance chart
On 27 March 2012 21:34, Brian G. Peterson br...@braverock.com wrote: On Tue, 2012-03-27 at 21:20 -0400, Jim Green wrote: Good Evening! in maCross.R in the demo folder of quantstrat, chart.Posn(Portfolio='macross',Symbol=stock.str) is called to generate the performance chart. internally it calls chart_Series in quantmod. the chart it produced is very nice, the only thing that bothers me is the font of the label is too small and looks like there is no easy way to zoom in an out interactively. Could anyone advise how to save that chart to some image format on the hard drive so I can zoom in and out without much loss of definition? I tried quantmod documentation and came across saveChart command but still don't know how to integrate to maCross.R for example. After it has already been created, see ?dev.copy2pdf it worked beautifully. Thanks Brian! Jim. otherwise, see ?pdf I tend to not spend too much time messing about with font sizes and such, preferring rather to see the information and move on, but patches are always welcome. Regards, - Brian -- Brian G. Peterson http://braverock.com/brian/ Ph: 773-459-4973 IM: bgpbraverock ___ 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] quantstrat package
Good Morning! Could anyone do a favor and attach a latest copyof quantstrat http://r-forge.r-project.org/R/?group_id=316, it failed build and can't be downloaded from the link. Thanks, Jim. ___ 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] quantstrat package
On 24 March 2012 09:45, Joshua Ulrich josh.m.ulr...@gmail.com wrote: Jim, Just checkout the source yourself: svn checkout svn://svn.r-forge.r-project.org/svnroot/blotter/ from: http://r-forge.r-project.org/scm/?group_id=316 Best, -- Thank you! Jim. Joshua Ulrich | FOSS Trading: www.fosstrading.com R/Finance 2012: Applied Finance with R www.RinFinance.com On Sat, Mar 24, 2012 at 8:38 AM, Jim Green student.northwest...@gmail.com wrote: Good Morning! Could anyone do a favor and attach a latest copyof quantstrat http://r-forge.r-project.org/R/?group_id=316, it failed build and can't be downloaded from the link. Thanks, Jim. ___ 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@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.