Re: [R-SIG-Finance] Formatting multiple charts on same window

2014-01-17 Thread R. Michael Weylandt
Take a look at xts::plot.xts. There's a type=candlestick option
pre-made for you and all the shared x-axis alignment should work out
of the box.

On Thu, Jan 2, 2014 at 7:52 AM,  manojit_...@comcast.net wrote:
 I am using layout=NULL to plot multiple charts on the same window, as follows:

  getSymbols(c('DJIA','NDX','^IXIC'),from='2013-01-01')
 par(mfrow=c(3,1))
 chartSeries(DJIA,type='candlesticks',TA=NULL,theme='white',layout=NULL)
 chartSeries(NDX,type='candlesticks',TA=NULL,theme='white',layout=NULL)
 chartSeries(IXIC,type='candlesticks',TA=NULL,theme='white',layout=NULL)

 I'd like to remove the x-labels (they are same for all plots) and stretch the 
 plots vertically to fill up space. With the usual R plot() function, I would 
 adjust 'oma=c()' and 'mar=c()' in 'par()' , but they do not seem to work 
 here. Is there an easy way to do this?

 Thanks.
 [[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@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] Formatting multiple charts on same window

2014-01-17 Thread R. Michael Weylandt
Bah, meant to say xtsExtra::plot.xts. Available off R-Forge.

Michael

On Sat, Jan 18, 2014 at 1:39 AM, R. Michael Weylandt
michael.weyla...@gmail.com wrote:
 Take a look at xts::plot.xts. There's a type=candlestick option
 pre-made for you and all the shared x-axis alignment should work out
 of the box.

 On Thu, Jan 2, 2014 at 7:52 AM,  manojit_...@comcast.net wrote:
 I am using layout=NULL to plot multiple charts on the same window, as 
 follows:

  getSymbols(c('DJIA','NDX','^IXIC'),from='2013-01-01')
 par(mfrow=c(3,1))
 chartSeries(DJIA,type='candlesticks',TA=NULL,theme='white',layout=NULL)
 chartSeries(NDX,type='candlesticks',TA=NULL,theme='white',layout=NULL)
 chartSeries(IXIC,type='candlesticks',TA=NULL,theme='white',layout=NULL)

 I'd like to remove the x-labels (they are same for all plots) and stretch 
 the plots vertically to fill up space. With the usual R plot() function, I 
 would adjust 'oma=c()' and 'mar=c()' in 'par()' , but they do not seem to 
 work here. Is there an easy way to do this?

 Thanks.
 [[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@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] AGARCH + rugarch

2013-11-19 Thread R. Michael Weylandt michael.weyla...@gmail.com
Just trying to replicate a bit of research which uses it. 

As to the value of it compared with GJR -- I'll defer to your expertise. 

Cheers,
MW

On Nov 19, 2013, at 19:57, alexios ghalanos alex...@4dscape.com wrote:

 Sentana (1995) actually worked out more thoroughly the details of this
 model which he called quadratic ARCH (QGARCH).
 
 This is not implemented in rugarch. For asymmetric response to shocks
 try the GJR (gjrGARCH), TGARCH (model=fGARCH, submodel=TGARCH)
 or NAGARCH (model=fGARCH, submodel=NAGARCH)...among others.
 If you provide compelling evidence why this model merits inclusion I
 will consider it.
 
 Regards,
 
 Alexios
 
 
 On 20/11/2013 00:34, R. Michael Weylandt michael.weyla...@gmail.com wrote:
 Is it possible to implement the AGARCH [1] of Engle 90 using rugarch? The 
 aparch models seem close, but don't allow for different powers of epsilon as 
 far as I can see. 
 
 Thanks, 
 Michael
 
 [1] I know GARCH terminology is a mess, so I'm using that given at 
 public.econ.duke.edu/~boller/Papers/glossary_arch.pdf (P.2 in my case)
 
 ___
 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] European options in r3

2013-11-05 Thread R. Michael Weylandt michael.weyla...@gmail.com
The greeks package seems a good place to start ;-)

www.rinfinance.com/agenda/2013/talk/JeffRyan.pdf

Michael

On Nov 5, 2013, at 8:48, Vishnu B vishnu.karth...@gmail.com wrote:

 Hi,
 
 Is there any package that works with r3.0.2 that can calculate option Greeks 
 for European options?
 
 Thanks
 Vishnu
 
 Sent from my iPhone
 ___
 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] How to interpret this formula?

2013-10-12 Thread R. Michael Weylandt michael.weyla...@gmail.com
I'll admit it seems rather fishy --
impossible perhaps to have something 'implied' by the option price without the 
option price in the formula -- but it's a hair off-topic for an _R_ finance 
list. 

Perhaps quant stackexchange would work? But unless you're willing to share your 
reference, I doubt folks there will be able to help you much. 

In general, if you want folks to help you understand what you are reading you 
should tell them what you are reading in the question. 

Michael

On Oct 12, 2013, at 15:53, Arun Kumar Saha arun25558...@gmail.com wrote:

 Hi,
 
 I have come across a formula to calculate the Option implied skewness which
 is calculated as (Strike/underlying's price - 1)
 
 Has anyone come across a similar type of formula?
 
 Can somebody please explain how can I derive that? Any online
 reference/paper is highly appreciated.
 
 Thanks and regards,
 
[[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@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] Reading MetaStock data format in R

2013-09-30 Thread R. Michael Weylandt michael.weyla...@gmail.com


On Sep 30, 2013, at 3:28, Peter Fertig pfer...@yahoo.de wrote:

 Hello,
 
 I am new at R and need some help because I am stuck in a project. I have 
 financial data, which is stored in the MetaStock data format and is updated 
 daily. For reading this data, I started to write a R-script. So far, I 
 managed to read the Master file, which contains the information about the 
 various securities in a directory, as well as reading the Fxxx.Dat data 
 files. The data is stored in the Microsoft Binary Format, which was used for 
 Basica under DOS. Thus, it has to be converted into the IEEE format for the 
 floating point numbers. But here my problems start.

Godspeed -- nothing quite like non-standard binary formats before the first 
morning coffee. 


 
 I have a DLL-file with functions to convert the 4byte MBF format into IEEE 
 format as well as from IEEE to MBF format. As recommended, this DLL is in the 
 Windows/System32 directory. I use this DLL with Visual Basic and it works 
 fine. In the R script, I included the following line
 
 dyn.load(MBFIEE32, DLLpath=C:/Windows/System32).

Don't think it works like that -- anything you want exposed within R will need 
to return R objects or wrapper classes (SEXP's generally) -- if your DLL works 
for / was written for VB, it won't work un-modified in R. 

 
 However, testing if the DLL had been loaded with is.loaded(MBFIEE32) 
 returns FALSE. I have read the manual, but have not figured out what went 
 wrong. Thus, my question is, what might I have overlooked, which could cause 
 this error?
 
 I also have a file with the functions for the format conversions in C. After 
 making slight modifications to ensure that the functions return void as 
 requested, I wanted to compile the file with the command (using the shell 
 feature of RStudio) R CMD SHLIB [-d] -o MBF2IEEE.DLL MBF2IEEE.c. I called 
 this command from the directory where the C-file is stored. However, the file 
 was not compiled. Does the C-file has to be stored in a particular directory? 
 After reading the online help, I can not figure out, what went wrong. 
 

Is your R development environment set up properly? R is not officially 
supported to build under VS and I'd imagine the same applies to packages. 

To test that, I'd try building the 'xts' package locally -- it's an easy 
(enough) build and relevant for finance work anyways. 

Depending on the scale of your data and the frequency you'll be doing this, it 
might be worth writing a standalone program which makes a csv file (or similar) 
and then just reading that into R so you can get on with your work. 

Cheers,
Michael


 Thanks for any help
 
 Peter  
[[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@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] Capital requirements as a cushion against risks, why?

2013-08-03 Thread R. Michael Weylandt michael.weyla...@gmail.com


On Aug 3, 2013, at 9:06, Copula Guy copula...@yahoo.de wrote:

Didn't Dirk ask you to use your real name?

 I am currently programming different VaR models with R and I often read about 
 the Basel framework. There the capital requirements are determinded by a 
 fomula which uses the VaR. Now I am wondering, why a bank needs to hold a 
 certain amount of capital? 
 
 
 In general, it says, the minimum capital requirements are used, to 
 determine the capital that banks must hold as an insurance against risk.
 E.g. if a Bank has invested in one equity asset, e.g. Microsoft stock (long). 
 If now the stock drops, the bank's asset looses value - so the 
 bank has a loss, but it does not have to actually PAY something? Why 
 should the bank hold extra money as an insurance against this drop in 
 the assets value?
 

But you're ignoring the bank's other side: where did the initial cash come 
from? In the simplest scenario, it originated in someone's deposit account and 
they can ask for it back. In normal times, the bank can sell part of their 
investment and give the cash back to the depositor.  If the bank has lost the 
cash on a failed investment, they can't fulfill their obligation to a customer 
which is considered, not surprisingly, a very bad thing. How would you feel if 
your bank lost the money in your savings account? 

In practice, this all gets more complicated when you look a modern financing 
and leverage techniques, but that's a bit of intuition. 

 Although this is not directly a question about R programming in finance I was 
 wondering about this, when I did my R project.
 

Indeed it isn't so direct your follow up questions to 1) some sort of financial 
discussion forum (money.stackexchange.com perhapd) or 2) me offlist if you must 
but 3) only after reading and making a valiant attempt to understand this on 
your own (perhaps by reading the Basel docs) -- it's certainly well explained 
across the net. 

If you're a 'real book' kind of guy check out Peter Bernstein's books. He's 
done some nice histories of finance. 

Michael

 Thanks a lot in advance!
 
 
 ___
 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] Range intersections

2013-07-26 Thread R. Michael Weylandt
On Fri, Jul 26, 2013 at 6:22 PM, Mark Knecht markkne...@gmail.com wrote:
 For the sake of asking here assume I have 5 models that attempt to
 predict a pair of future values like tomorrow's high  low. The
 predictions are placed in a matrix with the low prediction in column 1
 and the high prediction in column 2. _IF_ there is an intersection of
 all 5 predictions then I can test for that using the simple equation
 in Range1. However if there is a prediction that's a complete outlier
 as is Pred2[4,] then the simple equation fails and says the high is
 less than the low.

 Are there any R packages that automatically handle simple intersection
 problems like this? My real goals include things like probability
 distributions across the ranges, but for now I'm just looking for
 what's out there?


http://cran.r-project.org/web/packages/intervals/index.html
http://cran.r-project.org/web/packages/sets/index.html

would probably be the place to start.

Cheers,
MW

___
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] subset section of trading day from RBloomberg bar download

2013-07-25 Thread R. Michael Weylandt michael.weyla...@gmail.com


On Jul 25, 2013, at 14:40, Tim Meggs twme...@gmail.com wrote:

 Hi R finance people,
 
 I have downloaded some 15-min price Bar data across a number of days from
 Bloomberg for the March13 FTSE futures. 
 
 library(Rbbg)
 conn - blpConnect()
 ftse - Z H3 Index
 ftse_Bars - bar(conn, ftse, TRADE, 2013-01-04 07:00:00.000, 2013-02-01
 20:00:00.000, 15)
 ftse_Bars-as.xts(ftse_Bars)
 blpDisconnect(conn)
 
 The data looks like this:
 
   time   open   highlow  close
 numEvents volume
 2013-01-10T01:00:00.000 2013-01-10T01:00:00.000 6050.5 6050.5 6047.0 6048.0   
 
 12 12
 2013-01-10T01:15:00.000 2013-01-10T01:15:00.000 6046.5 6047.5 6046.5 6047.5   
  
 2  2
 2013-01-10T01:30:00.000 2013-01-10T01:30:00.000 6046.5 6046.5 6044.5 6045.0   
 
 12 21
 2013-01-10T01:45:00.000 2013-01-10T01:45:00.000 6044.5 6045.5 6044.5 6045.5   
  
 6  9
 2013-01-10T02:00:00.000 2013-01-10T02:00:00.000 6045.5 6049.0 6045.5 6047.5   
 
 11 13
 2013-01-10T02:15:00.000 2013-01-10T02:15:00.000 6053.0 6059.0 6049.0 6058.0   
 
 37 68
 
 I would like to remove those bars that fall outside the hours 07:00 UTC to
 15:30 UTC, to leave me with data just from the hours when the cash index is
 open.  Given the time column I receive from Bloomberg is in the slightly odd
 format format %Y-%m-%dT%H:%M:%S with the strange T in the middle how can
 subset out my desired data?

Assuming the as.xts call went properly, I believe you can just use the 
time-period form of ISO8601 subsetting. I'm not in a position to test, but I 
think it's 

CC['07:00/15:30']

There might be a T in there. Check ?[.xts and ?xts for details. 

Note that I'm assuming you got the as.xts call to work properly. If Bloomberg 
does put in that T, I'd have thought you'd need to pass an explicit format 
string. 

Michael

 
 Any help greatly appreciated.
 
 Thanks
 Tim
 
 
 
 --
 View this message in context: 
 http://r.789695.n4.nabble.com/subset-section-of-trading-day-from-RBloomberg-bar-download-tp4672338.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@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] nested matrices

2013-05-20 Thread R. Michael Weylandt
As best as I know the Matlab 'cell array', you might want to consider
adding dimensionality to a list object:

x - list(1:4, cow, lm, 0.25)
dim(x) - c(2,2)

Then you can do:

x[[2,2]] + 1

x[[1,2]](rnorm(25) ~ rexp(25))

None too financey

etc.

MW

On Mon, May 20, 2013 at 8:37 AM, Yana Roth yana.r...@yahoo.com wrote:
 Hello,I was reading the tread about R equivalent of cell array in Matlab and 
 still couldn't understand how can you systematically  organize large set of 
 data as cell arrays in R.
 would appreciate your help

 Yana
 [[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@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] Length of a curve?

2013-04-24 Thread R. Michael Weylandt
On Wed, Apr 24, 2013 at 4:32 PM, R. Michael Weylandt
michael.weyla...@gmail.com wrote:
 On Wed, Apr 24, 2013 at 12:26 PM, wlblount b...@easterngrain.com wrote:
 how would i calculate the length of this plot for a trading day?  i am using
 ibrokers data for stocks in 3 min. bars

 library(quantmod)
 load(~/R/UVXY)  #3 min xts  stock data

 reg10 - rollSFM(Cl(pricedata),seq(nrow(pricedata)),10)
 rma10 - reg10$alpha + reg10$beta*seq(nrow(pricedata))



 i am looking for the length of the rma10 plot for one trading day (ie. if it
 were a piece of string, the measurement once straightened out) .  i would
 like to compare this measurement to the same measurement for previous days
 (regular trading hours 9:30am-4:00pm).

 sorry for the non-technical language.  Bill



 I'd assume that, for regular data, you'd just add up the absolute
 values of the differences between observations.


Sorry -- that's not quite correct. But the idea's right: to be the
length of a curve, you just want to do

sum(sqrt((dx)^2 + (dy)^2))

If your dx is constant, it's an easy enough calculation but you'll
need to define a 'conversion' from 3 minutes to distance and from
price differences to distance.

 MW

___
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] help on smoothing volatility surface..

2013-04-13 Thread R. Michael Weylandt michael.weyla...@gmail.com
Moving to the relevant list. 

MW

On Apr 13, 2013, at 6:14 PM, C cdcave...@gmail.com wrote:

 This script below pulls yahoo data via a function in quantmod, then
 massages the data around to forumalate a 3D graph with RGL library,
 attached is a ggplot to show the data i'm trying to create a surface with
 in separate line geoms . the issue is that the 3D graph looks very ugly and
 cut up because of the limited quantities of points on the front month
 expirations.. can anyone tell me whats going on here , what i can do to fix
 this.. do i need to smooth each expiration's line then interpolate ??
 
 
 
 
 library(RQuantLib)
 library(quantmod)
 library(rgl)
 library(akima)
 library(ggplot2)
 library(plyr)
 
 GetIV - function(type, value,
  underlying, strike,dividendYield, riskFreeRate, maturity,
 volatility,
  timeSteps=150, gridPoints=151) {
 
AmericanOptionImpliedVolatility(type, value,
underlying, strike,dividendYield,
 riskFreeRate, maturity, volatility,
timeSteps=150,
 gridPoints=151)$impliedVol
 }
 
 
 GetDelta - function(type, underlying, strike,
 dividendYield, riskFreeRate, maturity, volatility,
 timeSteps=150, gridPoints=149, engine=CrankNicolson)
 {
 
AmericanOption(type,underlying, strike, dividendYield, riskFreeRate,
 maturity, volatility,
   timeSteps=150, gridPoints=149,
 engine=CrankNicolson)$delta
 }
 # set what symbol you want vol surface for
 underlying - 'GOOG'
 # set what your volatility forcast or assumption is
 volforcast - .25
 # Get symbols current price
 underlying.price - getQuote(underlying,what=yahooQF(Last Trade (Price
 Only)))$Last
 
 OC - getOptionChain(underlying, NULL)
 #check data
 head(OC)
 lputs - lapply(OC, FUN = function(x) x$puts[grep([A-Z]\\d{6}[CP]\\d{8}$,
 rownames(x$puts)), ])
 head(lputs) #check for NA values, yahoo returns all NA values sometimes
 puts - do.call('rbind', lputs )
 #check data
 head(puts,5)
 
 symbols - as.vector(unlist(lapply(lputs, rownames)))
 expiries - unlist(lapply(symbols, FUN = function(x) regmatches(x=x,
 regexpr('[0-9]{6}', x) )))
 puts$maturity - as.numeric((as.Date(expiries, %y%m%d) - Sys.Date())/365)
 
 puts$IV - mapply(GetIV, value = puts$Ask, strike = puts$Strike, maturity =
 puts$maturity,
  MoreArgs= list(type='put', underlying= underlying.price,
 dividendYield=0, riskFreeRate = 0.01,
 volatility = volforcast), SIMPLIFY=TRUE)
 
 puts$delta - mapply(GetDelta, strike =  puts$Strike, volatility = puts$IV,
 maturity = puts$maturity, MoreArgs= list(type='put',
 
 underlying=underlying.price, dividendYield=0,
  riskFreeRate
 = 0.01 ), SIMPLIFY=TRUE)
 
 # subset out itm puts
 puts - subset(puts, delta  -.09  delta  -.5 )
 
 expiries.formated - format(as.Date(levels(factor(expiries)), format =
 '%y%m%d'), %B %d, %Y)
 
 fractionofyear.levels - levels(factor(puts$maturity))
 
 xyz - with(puts, interp(x=maturity, y=delta*100, z=IV*100,
 xo=sort(unique(maturity)), extrap=FALSE ))
 
 with(xyz, persp3d(x,y,z, col=heat.colors(length(z))[rank(z)],
 xlab='maturity',
  ylab='delta', zlab='IV', main='IV Surface'))
 
 putsplot - ggplot(puts, aes(delta, IV, group = factor(maturity), color =
 factor(maturity))) +
labs(x = Delta, y = Implied Volatilty, title=Volatility Smile,
 color = GooG \nExpiration) +
scale_colour_discrete( breaks=c(fractionofyear.levels),
   labels=c(expiries.formated)) +
geom_line() +
geom_point()
 
 putsplot
 
[[alternative HTML version deleted]]
 
 __
 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.


Re: [R-SIG-Finance] Base R question on XTS object

2013-04-10 Thread R. Michael Weylandt
On Wed, Apr 10, 2013 at 5:17 AM, Brian G. Peterson br...@braverock.com wrote:
 On 04/10/2013 04:45 AM, wlblount wrote:

 before the days of all these great packages, how would one with base R
 access
 only find the following assuming i have an XTS object with normal OHLC
 price
 data for 100 periods.


 1 - change in price from yesterday to today.  close[today] -
 close[yesterday]


 ?diff
 (part of base)


 2 -rolling or moving simple ave. of close[last 30 periods]

 3 - rolling or moving sd of close[last 30 periods]


 ?apply
 (in base)

 ?rollapply
 (today)
 Rollapply is basically a loop that constructs the windowed index.


 i understand that this would all be done with quantmod /ttr etc today but
 would just like to stay within the bounds of base R for educational
 purposes.


'xts' is not part of base R, so if your students can get 'xts' they
should be able to get 'quantmod'. In fact, if you simply have them
install.packages(quantmod) that will get them zoo, TTR, and xts
automatically.


 Then read an old book on S.

 ?ts

 the 'ts' class has been part of the S language basically since inception.

 Alternatively, all this code is open source.  Look at the code.

 Cheers,

 Brian


 ___
 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] [R] Maximum likelihood estimation of ARMA(1, 1)-GARCH(1, 1)

2013-04-09 Thread R. Michael Weylandt
Forwarding to r-sig-finance where you might get a better response.

MW

On Mon, Apr 8, 2013 at 5:30 AM, Andy Yeh rochefort2...@gmail.com wrote:
 Hello

 Following some standard textbooks on ARMA(1,1)-GARCH(1,1) (e.g. Ruey
 Tsay's Analysis of Financial Time Series), I try to write an R program
 to estimate the key parameters of an ARMA(1,1)-GARCH(1,1) model for
 Intel's stock returns. For some random reason, I cannot decipher what
 is wrong with my R program. The R package fGarch already gives me the
 answer, but my customized function does not seem to produce the same
 result.

 I would like to build an R program that helps estimate the baseline
 ARMA(1,1)-GARCH(1,1) model. Then I would like to adapt this baseline
 script to fit different GARCH variants (e.g. EGARCH, NGARCH, and
 TGARCH). It would be much appreciated if you could provide some
 guidance in this case. The code below is the R script for estimating
 the 6 parameters of an ARMA(1,1)-GARCH(1,1) model for Intel's stock
 returns. At any rate, I would be glad to know your thoughts and
 insights. If you have a similar example, please feel free to share
 your extant code in R. Many thanks in advance.

 Emily



 # This R script offers a suite of functions for estimating  the
 volatility dynamics based on the standard ARMA(1,1)-GARCH(1,1) model
 and its variants.
 # The baseline ARMA(1,1) model characterizes the dynamic evolution of
 the return generating process.
 # The baseline GARCH(1,1) model depicts the the return volatility
 dynamics over time.
 # We can extend the GARCH(1,1) volatility model to a variety of
 alternative specifications to capture the potential asymmetry for a
 better comparison:
 # GARCH(1,1), EGARCH(1,1),  NGARCH(1,1), and TGARCH(1,1).

 options(scipen=10)

 intel= read.csv(file=intel.csv)
 summary(intel)

 raw_data= as.matrix(intel$logret)

 library(fGarch)
 garchFit(~arma(1,1)+garch(1,1), data=raw_data, trace=FALSE)


 negative_log_likelihood_arma11_garch11=
 function(theta, data)
 {mean =theta[1]
  delta=theta[2]
  gamma=theta[3]
  omega=theta[4]
  alpha=theta[5]
  beta= theta[6]

  r= ts(data)
  n= length(r)

  u= vector(length=n)
  u= ts(u)
  u[1]= r[1]- mean

  for (t in 2:n)
  {u[t]= r[t]- mean- delta*r[t-1]- gamma*u[t-1]}

  h= vector(length=n)
  h= ts(h)
  h[1]= omega/(1-alpha-beta)

  for (t in 2:n)
  {h[t]= omega+ alpha*(u[t-1]^2)+ beta*h[t-1]}

  #return(-sum(dnorm(u[2:n], mean=mean, sd=sqrt(h[2:n]), log=TRUE)))
  pi=3.141592653589793238462643383279502884197169399375105820974944592
  return(-sum(-0.5*log(2*pi) -0.5*log(h[2:n]) -0.5*(u[2:n]^2)/h[2:n]))
 }


 #theta0=c(0, +0.78, -0.79, +0.018, +0.06, +0.93, 0.01)
 theta0=rep(0.01,6)
 negative_log_likelihood_arma11_garch11(theta=theta0, data=raw_data)


 alpha= proc.time()
 maximum_likelihood_fit_arma11_garch11=
 nlm(negative_log_likelihood_arma11_garch11,
 p=theta0,
 data=raw_data,
 hessian=TRUE,
 iterlim=500)
 #optim(theta0,
 #  negative_log_likelihood_arma11_garch11,
 #  data=raw_data,
 #  method=L-BFGS-B,
 #  
 upper=c(+0.,+0.,+0.,0.,0.,0.),
 #  
 lower=c(-0.,-0.,-0.,0.0001,0.0001,0.0001),
 #  hessian=TRUE)

 # We record the end time and calculate the total runtime for the above work.
 omega= proc.time()
 runtime= omega-alpha
 zhours = floor(runtime/60/60)
 zminutes=floor(runtime/60- zhours*60)
 zseconds=floor(runtime- zhours*60*60- zminutes*60)
 print(paste(It takes ,zhours,hour(s), zminutes, minute(s) ,and
 , zseconds,second(s) to finish running this R program,sep=))


 maximum_likelihood_fit_arma11_garch11

 sqrt(diag(solve(maximum_likelihood_fit_arma11_garch11$hessian)))

 __
 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.


Re: [R-SIG-Finance] [R] Fitting distributions to financial data using volatility model to estimate VaR

2013-04-09 Thread R. Michael Weylandt
Moving to R-SIG-Finance which seems to be the correct mailing list.

On Sun, Apr 7, 2013 at 8:41 AM, Stat Tistician
statisticiangerm...@gmail.com wrote:
 Ok,
 I try it again with plain text, with a simple R code example and just
 sending it to the r list and you move it to sig finance if it is
 necessary.

 I try to be as detailed as possible.

 I want to fit a distribution to my financial data using a volatility
 model to estimate the VaR. So in case of a normal distribution, this
 would be very easy, I assume the returns to follow a normal
 distribution and calculate a volatility forecast for each day, so I
 have sigma_1,sigma_2,...,sigma_n,. I can calculate the VaR via (mu
 constant, z_alpha quantile of standard normal):
 VaR_(alpha,t)=mu+sigma_t * z_alpha. This is in case, I have losses, so
 I look at the right tail. So for each day I have a normal density with
 a constant mu but a different sigma corrensponding to the volatility
 model. Let's assume a very simple volatility model, e.g. (empirical)
 standard deviation of the last 10 days and the mu is set to zero. The
 R code could look like (data):

 volatility-0
 quantile-0
 for(i in 11:length(dat)){
 volatility[i]-sd(dat[(i-10):(i-1)])
 }


Let's clean this up:

library(xts)
# Load data into an xts object called dat here.

library(TTR)
vola - runSD(dat, 10) # volatility is a ttr function name, so not using that

 for(i in 1:length(dat)){
 quantile[i]-qnorm(0.975,mean=0,sd=volatility[i])
 }

# Similarly, quantile is a function name and not a good idea to override

quan - qnorm(0.975, mean = 0, sd = vola)

 # the first quantile value is the VaR for the 11th date

 #plot the volatility
 plot(c(1:length(volatility)),volatility,type=l)

Can just do
plot(vola) # if vola is an xts object. Also, the c() is superfluous
(and arguably dangerous) there


 #add VaR
 lines(quantile,type=l,col=red)

library(PerformanceAnalytics)
chart.BarVaR(dat) # is probably easier.



 Now, I want to change the volatility model to a more advanced model
 (EWMA, ARCH, GARCH) and the distribution to a more sophisticated
 distribution (student, generalized hyperbolic distribution). My main
 question is now, how can I combine the volatility model and the
 distribution, since in case e.g. of a Student's-t distribution with
 parameters mu (location), v (df), beta (scale) I cannot just plug the
 sigma in, because the distribution has no sigma?

Be careful here -- it certainly has a standard deviation, just not a
parameter called sigma. Keeping those two ideas distinct is important
here. They only coincide for the normal distribution. (Among the major
ones)

You're also using something other than the classical t-distribution
(as defined by the all-hallowed Wikipedia) if it's a three parameter
distribution.


 One solution I already know is, that I take the variance formula of
 the corresponding distribution - in case of a Student's-t distribution
 this would be sigma=beta v/(v-2). I have an estimate for sigma. So for
 each day I do the ML estimation with a modified log-likelihood where I
 insert for the scale parameter: beta=sigma * (v-2)/v and do the
 estimation.

 First of all, is this correct?

No -- I believe that the t-distribution has sigma^2 = v / (v-2).

But even with that correction, it's not what I would do.

I would first fit beta, nu, and mu by ML and then estimate sigma from there.

Without checking, I'm not positive that sample standard deviation
gives a particularly good estimator for the df of a t-distribution. It
wouldn't surprise me if it did though.

In that same vein, I'm not sure this process gives an estimate that's
much superior to the rolling empirical standard deviation. Though it
might be useful for forward looking predictions...

Bigger question -- have you looked at TTR::volatility or
PerformanceAnalytics::VaR. There's a lot of useful stuff in there.

I'll try to read through the rest of this later -- about to have
dinner with the family,
Michael


 I looked at several papers, but I did not understand, how they did
 this? No matter what volatility model they use, I cannot understand
 the connection of distribution and volatility model. For example,
 consider this paper:
 http://www.math.chalmers.se/~palbin/mattiasviktor.pdf

 On page 50 they are showing the hyperbolical distribution with
 different volatility models, how did they do this?

 Also, I do not understand table 6.2 on page 49: If they have estimated
 several distributions over the time, they have lots of estimates, but
 they just show one distribution? I mean, where does it come from? The
 3d picture clearly differnt distributions over time, so they have
 estimated the distribution after 5 days (page 48), but in the table is
 just one specific distribution with specific parameters? And they give
 the volatility models in the rows?

 A second famous paper is the Technial Document by JPMorgan:
 RiskMetrics Technical Document - Fourth Edition 1996, December:

 

Re: [R-SIG-Finance] high frequency italian market data

2013-01-11 Thread R. Michael Weylandt
Backtesting we can do; historical intraday data, not so much (to the
best of my knowledge) -- sorry...

MW

On Fri, Jan 11, 2013 at 10:40 PM, singletonthebest
singletontheb...@msn.com wrote:
 Thanks for the answers!
 Michael: no particular source in mind. Actually I was hoping to find
 something for free even if I knew it would have been not much likely.
 The purpose of my request was due to the fact that I was willing to backtest
 with R some strategy that requires intraday data.





 Michael Weylandt michael.weyla...@gmail.com ha scritto:

 Intraday data usually requires a paid data subscription. Do you have any
 particular source in mind?

 MW

 On Jan 11, 2013, at 8:34 PM, Simone Gogna singletontheb...@msn.com
 wrote:

 Dear R users,
 I hope this is not an already discussed topic. I tried with
 RSiteSearch(“high frequency italian market data”) but I was not successful
 in the research.
 I need to download data of the price of italian stocks with the highest
 possible frequency.
 I know that, for example, in the library tseries

 get.hist.quote(,start=())

 would give me Open-High-Low-Close price but, as fas as get.hist.quote is
 concerned this gives me only data at daily frequency at most.
 I wonder if there is something similar that allows to import data of the
 italian stock market with frequencies of, at least, one hour.

 thanks and best regards,
 Simone Gogna
[[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@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] TSCov function from RTAQ package

2012-11-30 Thread R. Michael Weylandt
Forwarding to the correct mailing list.

MW

On Fri, Nov 30, 2012 at 9:30 AM, billycorg candi...@gmail.com wrote:
 Hi R Users!

 I am having some difficulties in using the TSCov function from RTAQ package
 that should calculate the two time scale realized volatility (Zhang et al,
 2005).

 Let's suppose I have tick by tick data, let's say aaa and bbb.

 If I write in R:

 /stock1=aaa$PRICE
 stock2=bbb$PRICE

 TSCov(list(stock1,stock2))/

 The result is: /Error in var[i] : object of type 'closure' is not
 subsettable/

 Instead, if I write:

 /TSCov(stock1,stock2)/

 I obtain a single value and not a 2X2 matrix (one for each day).

 I would only want to obtain a 2x2 matrix per day.

 Where is my error? It would be sufficient an example of correct syntax! :)

 Thank you,
 Vincent





 --
 View this message in context: 
 http://r.789695.n4.nabble.com/TSCov-function-from-RTAQ-package-tp4651402.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.


Re: [R-SIG-Finance] [R] (no subject)

2012-11-09 Thread R. Michael Weylandt
Forwarding to the relevant list.

MW

On Fri, Nov 9, 2012 at 9:01 AM, Manasvi Dobhal manasvidob...@gmail.com wrote:
 Hi all,
 The TWS on my system is unable to connect to my R session. Here is the
 error that I'm getting:

 * tws-twsConnect()
 Error in socketConnection(host = host, port = port, open = ab, blocking =
 blocking) :
 cannot open the connection
 In addition: Warning message:
 In socketConnection(host = host, port = port, open = ab, blocking =
 blocking) :
 localhost:7496 cannot be opened*

 Here is the session info for the R session:

 *R version 2.15.1 (2012-06-22)*
 **

 *Platform: x86_64-pc-linux-gnu (64-bit)*

 **

 *locale:*

 * [1] LC_CTYPE=en_IN.UTF-8LC_NUMERIC=C*

 * [3] LC_TIME=en_IN.UTF-8LC_COLLATE=en_IN.UTF-8*

 * [5] LC_MONETARY=en_IN.UTF-8LC_MESSAGES=en_IN.UTF-8*

 * [7] LC_PAPER=CLC_NAME=C*

 * [9] LC_ADDRESS=CLC_TELEPHONE=C*

 *[11] LC_MEASUREMENT=en_IN.UTF-8 LC_IDENTIFICATION=C*

 * *

 *attached base packages:*

 *[1] statsgraphicsgrDevices utilsdatasets *

 *[6] methodsbase*

 * *

 *other attached packages:*

 *[1] IBrokers_0.9-10 xts_0.8-6zoo_1.7-8*

 * *

 *loaded via a namespace (and not attached):*

 *[1] grid_2.15.1lattice_0.20-0 tools_2.15.1*

 **



 I have checked the Enable Activex and Socket clients  but it hasn't
 helped. Since I'm running on an Ubuntu machine, I even tried changing the
 parameter *blocking *in the command *twsConnect() *to

 1. *blocking = FALSE*

 2. According to the one mentioned here
 http://code.google.com/p/ibrokers/source/detail?r=84path=/trunk/R/twsConnect.R

 but nothing has helped.



 Please let me know what I should do.



 Thanks.

 [[alternative HTML version deleted]]

 __
 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.


Re: [R-SIG-Finance] [R] (no subject)

2012-11-09 Thread R. Michael Weylandt
Hi Manasvi,

Please keep your replies on the mailing list, or at least direct them
to the person with whom you're conversing should you have a good
reason to go off list.

It's also good form to include context in emails, so I've reassembled
your discussion with G.

When in doubt, use the reply all feature of your mail client.

Michael

On Sat, Nov 10, 2012 at 6:33 AM, Manasvi Dobhal manasvidob...@gmail.com wrote:
 Yes, I did.

On Fri, Nov 9, 2012 at 3:34 PM, G See gsee...@gmail.com wrote:
 Manasvi,

 Did you add 127.0.0.1 to Trusted IP Addresses?

 -Garrett



 On Fri, Nov 9, 2012 at 9:01 AM, Manasvi Dobhal manasvidob...@gmail.com
 wrote:
  Hi all,
  The TWS on my system is unable to connect to my R session. Here is the
  error that I'm getting:
 
  * tws-twsConnect()
  Error in socketConnection(host = host, port = port, open = ab,
  blocking =
  blocking) :
  cannot open the connection
  In addition: Warning message:
  In socketConnection(host = host, port = port, open = ab, blocking =
  blocking) :
  localhost:7496 cannot be opened*
 
  Here is the session info for the R session:
 
  *R version 2.15.1 (2012-06-22)*
  **
 
  *Platform: x86_64-pc-linux-gnu (64-bit)*
 
  **
 
  *locale:*
 
  * [1] LC_CTYPE=en_IN.UTF-8LC_NUMERIC=C*
 
  * [3] LC_TIME=en_IN.UTF-8LC_COLLATE=en_IN.UTF-8*
 
  * [5] LC_MONETARY=en_IN.UTF-8LC_MESSAGES=en_IN.UTF-8*
 
  * [7] LC_PAPER=CLC_NAME=C*
 
  * [9] LC_ADDRESS=CLC_TELEPHONE=C*
 
  *[11] LC_MEASUREMENT=en_IN.UTF-8 LC_IDENTIFICATION=C*
 
  * *
 
  *attached base packages:*
 
  *[1] statsgraphicsgrDevices utilsdatasets *
 
  *[6] methodsbase*
 
  * *
 
  *other attached packages:*
 
  *[1] IBrokers_0.9-10 xts_0.8-6zoo_1.7-8*
 
  * *
 
  *loaded via a namespace (and not attached):*
 
  *[1] grid_2.15.1lattice_0.20-0 tools_2.15.1*
 
  **
 
 
 
  I have checked the Enable Activex and Socket clients  but it hasn't
  helped. Since I'm running on an Ubuntu machine, I even tried changing
  the
  parameter *blocking *in the command *twsConnect() *to
 
  1. *blocking = FALSE*
 
  2. According to the one mentioned here
 
  http://code.google.com/p/ibrokers/source/detail?r=84path=/trunk/R/twsConnect.R
 
  but nothing has helped.

___
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] To Dr. Eric Zivot: Coursera servers went down.

2012-10-22 Thread R. Michael Weylandt
Hi Ilya,

I think this is rather off-topic for this list. While Dr Zivot is an
occasional and valued poster to this forum, this is not his personal
email and you've just spammed a large number of subscribers who have
little to do with Dr Zivot or his teaching. His email is, however,
readily accessible with a simple googling should you need to reach him
again.

Best,
Michael

On Mon, Oct 22, 2012 at 8:48 PM, Ilya Kipnis ilya.kip...@gmail.com wrote:
 Exam deadline may need to be extended.

 [[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@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] A good backtesting package ??

2012-10-20 Thread R. Michael Weylandt
On Sat, Oct 20, 2012 at 4:04 PM, jaimie villanueva
jaimie.villanu...@gmail.com wrote:

 Could anyone recommend me a good backtesting function (or package) ??


Google around for quanstrat

RMW

___
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] 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
martin.d...@student.adelaide.edu.au 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.


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

2012-10-12 Thread R. Michael Weylandt
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 capra...@cs.man.ac.uk 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`(`*tmp*`, is.na(tdata$G127), value = c(1L, 1L, 1L,  :
   invalid factor level, NAs generated

 As it is a warning, the .RData files still get created and I can use TAQLoad
 to load them:

 x -
 TAQLoad(BAC,from=2010-11-01,to=2010-11-01,datasource=datadestination,
 trades=T,quotes=T)

 The PROBLEM:
 head(x)
  SYMBOL EX  PRICE SIZECOND CORR G127
 NA BAC  B 11.4900   500 @  0  0
 ...

 This is the same for the quotes objects, but different headers obviously. I
 get a NA instead of the expected YYY-MM-DD HH:MM:SS format for each
 observation.

 I've spent a fair number of hours on trying to get this right, no success.
 Can you please provide me with some guidance?

 Thank you.

 A sample from the CSV files I use:

 SYMBOL,DATE,TIME,BID,OFR,BIDSIZ,OFRSIZ,MODE,EX
 BAC,20101101,9:30:00,11.5,11.51,5,116,12,P
 ...

 SYMBOL,DATE,TIME,PRICE,SIZE,G127,CORR,COND,EX
 BAC,20101101,10:30:00,11.49,500,0,0,@,B
 ...




 --
 View this message in context: 
 http://r.789695.n4.nabble.com/RTAQ-convert-function-warning-causes-incorrect-loading-of-data-tp4646025.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.


Re: [R-SIG-Finance] Optimx help

2012-10-10 Thread R. Michael Weylandt
Please don't cross-post to both R-SIG-Finance and the general R-help
list, where you've already received a response.

Michael

On Wed, Oct 10, 2012 at 8:54 AM, nserdar snes1...@hotmail.com wrote:
 Error Message:

 fn is  Linn
 Function has  10  arguments
 par[ 1 ]:  0   ? 0   ? 1 In Bounds
 par[ 2 ]:  0   ? 0   ? 1 In Bounds   In Bounds
 par[ 3 ]:  0   ? 0   ? 1 In Bounds   In Bounds   In Bounds
 par[ 4 ]:  -Inf   ? 1.001   ? Inf In Bounds   In Bounds   In Bounds
 In Bounds
 par[ 5 ]:  -Inf   ? 1.001   ? Inf In Bounds   In Bounds   In Bounds
 In Bounds   In Bounds
 par[ 6 ]:  -Inf   ? 1.001   ? Inf In Bounds   In Bounds   In Bounds
 In Bounds   In Bounds   In Bounds
 par[ 7 ]:  -Inf   ? 1.001   ? Inf In Bounds   In Bounds   In Bounds
 In Bounds   In Bounds   In Bounds   In Bounds
 par[ 8 ]:  -Inf   ? 1   ? Inf In Bounds   In Bounds   In Bounds   In
 Bounds   In Bounds   In Bounds   In Bounds   In Bounds
 par[ 9 ]:  -Inf   ? 1   ? Inf In Bounds   In Bounds   In Bounds   In
 Bounds   In Bounds   In Bounds   In Bounds   In Bounds   In Bounds
 par[ 10 ]:  -Inf   ? 1   ? Inf In Bounds   In Bounds   In Bounds   In
 Bounds   In Bounds   In Bounds   In Bounds   In Bounds   In Bounds   In
 Bounds
 Error in optimx(init.par, Linn, gr = NULL, method = L-BFGS-B, hessian =
 TRUE,  :
   Cannot evaluate function at initial parameters

 My function:
  optimx(init.par,Linn,gr=NULL,method= L-BFGS-B, hessian=TRUE, control =
 list(trace=1,factr=1e3),lower=c(0,0,0,-Inf,-Inf,-Inf,-Inf,-Inf,-Inf,-Inf),upper=c(1,1,1,Inf,Inf,Inf,Inf,Inf,Inf,Inf))

 How to solve this problem ?

 Regards,
 Serdar



 --
 View this message in context: 
 http://r.789695.n4.nabble.com/Optimx-help-tp4645666.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@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] NA When Setting Options to See Fractions of Seconds

2012-10-10 Thread R. Michael Weylandt
I've moved this to R-SIG-Finance thinking there might be a more
relevant audience.

RMW

On Tue, Oct 9, 2012 at 7:49 PM, Alex Zhang alex.zh...@ymail.com wrote:
 Dear all,

 I just found a weird behavior of the timeDate related functions 
 Sys.timeDate() and as.timeDate().
 Both of them take place when showing fractions of seconds and I think they 
 might have the same source.

 Do you know if it should be considered a bug of Sys.timeDate()? Also, what is 
 a good way to generate timeDate with fractions of seconds from strings? I 
 know I can just get the whole part of seconds and add fractions to it. That 
 is a little bit unnecessarily awkward IMO. Thanks!

 - Alex

 Below is my whole session:

 R version 2.15.1 (2012-06-22) -- Roasted Marshmallows
 Platform: i386-pc-mingw32/i386 (32-bit)

 require(timeDate)
 Sys.timeDate()
 New_York
 [1] [2012-10-09 14:35:21]
 options(digits.secs=3)
 Sys.timeDate()
 New_York
 [1] [NA]
 Warning message
 Sys.time()
 [1] 2012-10-09 14:43:45.303 EDT
 as.timeDate(2012-10-09 14:43:45.303 EDT)
 New_York
 [1] [NA]
 Warning message
 as.timeDate(2012-10-09 14:43:45.303)
 New_York
 [1] [NA]
 Warning message
 [[alternative HTML version deleted]]

 __
 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.


Re: [R-SIG-Finance] Test for new event and save data in new data.frame

2012-10-04 Thread R. Michael Weylandt
On Thu, Oct 4, 2012 at 12:12 AM, Mark Knecht markkne...@gmail.com wrote:
 Hi again,
Again, I haven't touched R in a couple of years and am just getting
 going on a little idea. Thanks in advance.

If you all think this is better done somewhere else like
 StackOverflow let me know and I'll post there instead.

The following very simplified code is meant to represent reading
 through price data (PriceData) to extract what is happening with
 prices after a trade has started and as it progresses. The column MP
 (MarketPosition) is lagged. When MP switches from 0 to 1 a new long
 trade is entered. I'd like to collect the next 5 bars of data for that
 trade in a data.frame called TradeData. Each new trade gets a new
 column. In this example there are 4 trades occurring at bars 3, 8, 11
  15. The results for this data are a data.frame with 5 rows and 4
 columns. (The real one will be much larger...)

 QUESTIONS:

 1) How do I do a logical test something like ((c3 = 1) AND (c4 = 0))
 for each row in PriceData to determine when a trade started?

 2) If the test above is true, how do I copy c2[row:(row+4)] into a
 element an add it to TradeData?

 I'm guessing this might be a job for one of the apply functions but
 I'm not sure which one or how to do it. The couple of R books I've got
 aren't making it clear yet,

In the code below EVERYTHING below the comment block is only to
 show what I want to create.  It will all go away when the questions
 above turn into R code.

I hope this is reasonably clear. Let me know if it isn't.

 Thanks,
 Mark




 MyLag - function(x, k) c(rep(NA, k), x[1:(length(x)-k)] )

 c1 = 1:20
 c2 = c(5,6,7,8,1,2,3,4,7,2,3,4,5,7,8,9,1,2,1,1)
 c3 = c(0,0,1,1,1,0,0,1,0,0,1,1,0,0,1,1,1,0,0,0)
 c4 = MyLag(c3, 1)


 PriceData = data.frame(cbind(c1,c2,c3,c4))
 colnames(PriceData) = c(BarNum,Price, MP,LagMP)

 PriceData

 # This represents the data.frame I'd like to create - (TradeData)
 #
 # When ((c3 = 1) AND (c4 = 0)) then copy c2[row:row+4] and
 # put it in a new column in the data frame
 # Eventually there is one column in the data.frame for
 # each trade

 t1 = c(7,8,1,2,3)
 t2 = c(4,7,2,3,4)
 t3 = c(3,4,5,7,8)
 t4 = c(8,9,1,2,1)

 TradeData = data.frame(cbind(t1,t2,t3,t4))

This is a terrible awful and altogether wretched idiom. Instead just
do data.frame(t1, t2, t3, t4). cbind()-ing completely invalidates the
entire point of a data.frame() by coercing all its inputs to a common
class.  [Don't take it personally: we've just been working to stamp it
out every where we see it on the main R-help list for a few months
now]


 TradeData


Best advice: don't use a data.frame() for this sort of data. Instead,
use a proper time series object, like xts or zoo. These also provide a
lag function for you:

library(xts)

PriceData - xts(cbind(BarNum = 1:20, Price =
c(5,6,7,8,1,2,3,4,7,2,3,4,5,7,8,9,1,2,1,1), MP =
c(0,0,1,1,1,0,0,1,0,0,1,1,0,0,1,1,1,0,0,0)), Sys.Date() + 1:20)

print(PriceData)

# Now we can add on the lag column:

PriceData - cbind(PriceData, LagMP = lag(PriceData[,3], 3))

with(PriceData, (MP == 1)  (MP.1== 0)) # Gives you the rows you want
to manipulate

Cheers,
Michael

___
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] Calculating FV of a Uniform Stream using TVM

2012-10-02 Thread R. Michael Weylandt
On Wed, Oct 3, 2012 at 12:21 AM, Nitin Juneja nitin.jun...@gmail.com wrote:
 I am perplexed. The problem I am working is,

 Question : How much money must Carol deposit every year starting 1 year
 from now at 5.5 % per year in order to accumulate $6000 seven years from
 now?

 My correct solution is :

 6000/usfv(5.5,7)
 [1] 725.7865

 I think this should also work... but does not:
 tvm(i=5.5,n=7,fv=-6000,pmt=NA,pyr=1)

 Time Value of Money model

I% #N PVFVPMT Days #Adv P/YR C/YR
 1 5.5  7  0 -6000 687.95  360011

 I am getting a difference PMT amount. Does anyone have an insight in why I
 a getting the difference


Hi Nitin,

This is the feel of a homework assignment and this --  and all the
R-help lists -- have a no homework policy (too many academics involved
I suppose! R was, after all, originally teaching software) so we can't
really give you too much help here.

To answer your question properly, we'd need to see a reproducible example

http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example

In particular giving the origin of the functions tvm() and usfv().

Without those, things which immediately come to mind: i) simple vs.
compounding; ii) frequency of compounding; iii) arithmetic vs
geometric returns. (These are all of course related in some sense)
I've played with the numbers a bit and the discrepancy is likely in
that vein.

Cheers,
Michael

___
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 on creating 5 minutes bars

2012-09-24 Thread R. Michael Weylandt
On Mon, Sep 24, 2012 at 9:57 AM, Chris de Bleu blue2b...@yahoo.fr wrote:
 I would like to convert a 1 minute xts data to 5 minutes bars using 
 to.minutes5.

 library(xts)

 N = 20
 s = xts(1:N, order.by =  seq.POSIXt(ISOdate(2012, 9, 1), by = min, length 
 = N))
 s
 [,1]
 2012-09-01 12:00:001
 2012-09-01 12:01:002
 2012-09-01 12:02:003
 2012-09-01 12:03:004
 2012-09-01 12:04:005
 2012-09-01 12:05:006
 2012-09-01 12:06:007
 2012-09-01 12:07:008
 2012-09-01 12:08:009
 2012-09-01 12:09:00   10
 2012-09-01 12:10:00   11
 2012-09-01 12:11:00   12
 2012-09-01 12:12:00   13
 2012-09-01 12:13:00   14
 2012-09-01 12:14:00   15
 2012-09-01 12:15:00   16
 2012-09-01 12:16:00   17
 2012-09-01 12:17:00   18
 2012-09-01 12:18:00   19
 2012-09-01 12:19:00   20
 Warning message:
 timezone of object (GMT) is different than current timezone ().
 to.minutes5(s)
 s.Open s.High s.Low s.Close
 2012-09-01 12:04:00  1  5 1   5
 2012-09-01 12:09:00  6 10 6  10
 2012-09-01 12:14:00 11 1511  15
 2012-09-01 12:19:00 16 2016  20
 Warning message:
 timezone of object (GMT) is different than current timezone ().


 Why I haven't data at the 5 minutes with these timestamps?

Merely convention: to.period() goes to the _end_ of the unit being
aggregated rather than the beginning. This seems reasonable if you
consider a time stamp as when something can be known. (I.e., if you
marked periods as the beginning, use of  Hi and Lo would introduce
a small but non-negligible look ahead into the simulation)

Cheers,
Michael


 2012-09-01 12:00:00
 2012-09-01 12:05:00
 2012-09-01 12:10:00
 2012-09-01 12:15:00


 Thank you,
 [[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@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 on creating 5 minutes bars

2012-09-24 Thread R. Michael Weylandt
On Mon, Sep 24, 2012 at 1:00 PM, Chris de Bleu blue2b...@yahoo.fr wrote:

 Ok, let set N = 21, so the last timestamp is 2012-09-01 12:20:00

 N = 21
  s = xts(cbind(1:N, 1:N, 1:N, 1:N), order.by =  seq.POSIXt(ISOdate(2012, 9, 
 1), by = min, length = N))
 colnames(s) = c(Open, High, Low, Close)
 s
 Open High Low Close
 2012-09-01 12:00:0011   1 1
 2012-09-01 12:01:0022   2 2
 2012-09-01 12:02:0033   3 3
 2012-09-01 12:03:0044   4 4
 2012-09-01 12:04:0055   5 5
 2012-09-01 12:05:0066   6 6
 2012-09-01 12:06:0077   7 7
 2012-09-01 12:07:0088   8 8
 2012-09-01 12:08:0099   9 9
 2012-09-01 12:09:00   10   10  1010
 2012-09-01 12:10:00   11   11  1111
 2012-09-01 12:11:00   12   12  1212
 2012-09-01 12:12:00   13   13  1313
 2012-09-01 12:13:00   14   14  1414
 2012-09-01 12:14:00   15   15  1515
 2012-09-01 12:15:00   16   16  1616
 2012-09-01 12:16:00   17   17  1717
 2012-09-01 12:17:00   18   18  1818
 2012-09-01 12:18:00   19   19  1919
 2012-09-01 12:19:00   20   20  2020
 2012-09-01 12:20:00   21   21  2121

 to.minutes5(s)
   s.Open s.High s.Low s.Close
 2012-09-01 12:04:00  1  5 1   5
 2012-09-01 12:09:00  6 10 6  10
 2012-09-01 12:14:00 11 1511  15
 2012-09-01 12:19:00 16 2016  20
 2012-09-01 12:20:00 21 2121  21

 align.time(to.minutes5(s), 5*60)
   s.Open s.High s.Low s.Close
 2012-09-01 12:05:00  1  5 1   5
 2012-09-01 12:10:00  6 10 6  10
 2012-09-01 12:15:00 11 1511  15
 2012-09-01 12:20:00 16 2016  20
 2012-09-01 12:25:00 21 2121  21

 We remark also that there is a lag in the values.


Is there a question in this? It's consistent with your earlier
example: aligning with the end of the grouped period.

Michael

 [[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@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] Aggregating tick-by-tick data to seconds

2012-09-15 Thread R. Michael Weylandt
If you have a column labelled Volume, to.period will sum it: e.g.,

library(xts)
data(sample_matrix)

s - as.xts(sample_matrix)

s - cbind(s, Volume = round(exp(runif(NROW(s),2,3))*1))

head(s)
head(to.weekly(s))

Cheers,
Michael

On Sat, Sep 15, 2012 at 4:57 PM, Costas Vorlow costas.vor...@gmail.com wrote:
 Hello,

 I have the following data (xts) (last two columns refer to up and down
 volumes).

 head(test,20)
   [,1] [,2] [,3]
 2012-09-12 16:30:00 144.39  3000
 2012-09-12 16:30:00 144.39  5000
 2012-09-12 16:30:00 144.39  3000
 2012-09-12 16:30:00 144.39  4000
 2012-09-12 16:30:00 144.39  3000
 2012-09-12 16:30:00 144.39  3000
 2012-09-12 16:30:00 144.39  1000
 2012-09-12 16:30:00 144.39  9000
 2012-09-12 16:30:00 144.39  2000
 2012-09-12 16:30:00 144.39  1030
 2012-09-12 16:30:00 144.39  1970
 2012-09-12 16:30:00 144.39  2000
 2012-09-12 16:30:00 144.39  5000
 2012-09-12 16:30:00 144.39  4000
 2012-09-12 16:30:00 144.39  1000
 2012-09-12 16:30:00 144.39  5000
 2012-09-12 16:30:00 144.39  3000
 2012-09-12 16:30:00 144.39  2000
 2012-09-12 16:30:00 144.39  1030
 2012-09-12 16:30:00 144.380  100


 I can use the to.period to aggregate the above data to seconds

 test.Open test.High test.Low test.Close
 2012-09-12 16:30:00144.39144.47   144.37 144.38
 2012-09-12 16:31:00144.39144.40   144.33 144.37
 2012-09-12 16:32:00144.37144.45   144.37 144.45
 2012-09-12 16:33:00144.45144.47   144.42 144.47


  but I am not sure how to do this for the volume columns. I would need to
 retrieve the volume sums per second.

 Is this functionality built into the xts package? Is there any other
 function that could be used to do something like that?

 Thanks  best regards,
 Costas
 ___

 [[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@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] plot.xts

2012-08-14 Thread R. Michael Weylandt
Readers of R-SIG-Finance,

As the community which makes the most heavy use of xts, I would like
to draw your attention to a new set of plotting functions for xts
objects available as part of Google Summer of Code 2012. This work
represents a major overhaul of previously existing plot.xts and should
provide you with the most comprehensive and flexible time series
plotting available in R. Features include:

 -- automagic layout construction and axis alignment
 -- smart argument recycling
 -- panel function abilities
 -- more attractive candle and bar plots for OHLC objects
 -- scatterplots to view the co-evolution of multiple series
 -- event markers
 -- regime highlighting
 -- time-oriented barplots via barplot.xts [based on code by Peter Carl]
 -- interoperability with all known R time series classes using the
xts try/reclass paradigm

while retaining the same smart axis formatting and gridlines that
plot.xts provided. We have made every effort to maintain complete
compatibility with documented usages of the old plot.xts and to be 95%
compatible with plot.zoo. My goal has been to craft a design which
uses smart defaults to put attractive and informative graphics ever at
your fingertips, while remaining flexible enough for power-users to
craft every detail as they desire.

Now that this work is approaching production-quality, I would like to
promote it to the community and to request your impressions, feedback,
and, most importantly, bug reports. These can be returned to me
off-list, but I welcome any examples of power charting from those
who may wish to show off their work in public.

In that vein, I include code for a rather nifty graphic derived from
code of Peter Carl and Timely Portfolio's klr, both of whom have
provided invaluable feedback in development.

# Expected Shortfall of EDHEC Data ###

# install.packages(xtsExtra, source = http://r-forge.r-project.org;)

require(xtsExtra)
require(PerformanceAnalytics)
data(edhec)

p=0.95
FUN=ES
method=gaussian

my.panel - function(x, y, lwd, ..., pf = parent.frame()) {
   # Reference axis
   abline(h = 0, col = grey, lty = 2, lwd = 2)

   #get VaR for overlay similar to chart.BarVaR
   risk = apply.rolling(na.omit(y), width = 36, FUN = FUN, p = p,
method = method) #hVaR = quantile(x,probs=.01)
   lines(x = .index(risk),y = coredata(risk), type=l, col=gray60)

   #print bar style chart of returns
   plus.minus.colors - ifelse(y  0, ifelse(coredata(y) 
coredata(risk), red, gray) ,green4)
   lines(x, y, type=h, col=plus.minus.colors, lwd = lwd)
}

plot(edhec[,c(13, 2:8)], panel = my.panel,
 layout = matrix(c(1, 1, 1, 1, 1, 1:8, 8), byrow = TRUE, ncol = 2),
 yax.loc = flip, lwd = c(3, rep(1,6), 2), main = ES Chart,
   blocks = list(start.time = c(2001-03-01, 2007-12-01),
 end.time = c(2001-11-01, 2009-06-01),
 col = lightblue1), cex.lab = 0.8)

###


Currently, the code is available in a testing package known as
xtsExtra containing both plot.xts and barplot.xts. The code is
currently available in source form from r-forge and should be
available in binary form shortly via the usual incantations. I do
stress once again that this is not quite yet frozen code and minor
changes may occur over the next week in response to bug reports and
feature requests. We are, as always, particularly sensitive to any
unforseen regressions.

Happy charting and, perhaps more importantly, happy trading,

Michael Weylandt
http://r-forge.r-project.org/projects/xts/

___
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] XTS plot of intra-daily stock prices

2012-07-13 Thread R. Michael Weylandt
Hi Costas,

Unfortunately, I think this isn't exactly a trivial thing to do: R
doesn't by default support broken axis plots (which I think is more or
less what you are looking for). I'm interested in helping you out with
this, but just to make sure I understand what you are looking for,
your data is something like

tm - as.POSIXct(1342207451, origin = 1970-01-01)
x - xts(rnorm(100), tm+ 100*c(0:49, 0:49 + 5e2))
plot(x)

and you want that long flat bit omitted?

Here's a cheap hack to work around if I understand the problem:

plot.by.day - function(x, ...){
ti - deparse(substitute(x))
x2 - split(x, as.Date(index(x), tz = ))
op - par(no.readonly = TRUE)
par(mfrow = c(1, length(x2)), mar = c(5.1, 0, 4.1, 0), oma = c(0,
4.1, 1, 2.1))
for(x3 in x2) xts::plot.xts(as.xts(x3), yaxt = n, main = ,
ylim = range(x), ...)
mtext(ti, outer = TRUE, cex = 2, line = -2)
}

It could use some more work though. (and I just wipped it up, so it
will probably break in all sorts of unpleasant ways) Lemme know how it
goes for you and I might start polishing it.

Best,
Michael


On Fri, Jul 13, 2012 at 1:50 PM, Costas Vorlow costas.vor...@gmail.com wrote:
 Hello,

 When I plot more than a day's xts time series data on a stock (intra-daily
 frequency) I get gaps during the non-trading hours.

 I placed some examples here:

 http://users.hol.gr/~laurarvc/Costas/R/


 Can I homogenize the plots i.e., skip those gaps so I have more continuous
 plots of high frequency prices?
 I can't find something on the help page of the relevant plot command...

 Best regards,
 Costas

 --

 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 |c|o|s|t|a|s|@|v|o|r|l|o|w|.|o|r|g|
 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

 [[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@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] TSE ticker problems

2012-07-11 Thread R. Michael Weylandt
Hi Paul,

Are you sure you're not looking for the src= argument of getSymbols()?

Best,
Michael

On Wed, Jul 11, 2012 at 12:49 PM, Paul Gilbert pgilbert...@gmail.com wrote:
 I have been having trouble retrieving some TSE series from yahoo:

 require(quantmod)
 getSymbols(BMO.TO, dbname=yahoo)

 works but

 getSymbols(COS.TO, dbname=yahoo)

 appears to have worked but has actually failed:

 str(COS.TO)
 An 'xts' object of zero-width

 It seems to be getting the header, but no data. I have also tried with
 Google Finance:

 getSymbols(TSE:COS, dbname=google)
  Error in download.file(paste(yahoo.URL, s=, Symbols.name, a=, from.m,
 :
   cannot open URL
 'http://chart.yahoo.com/table.csv?s=TSE:COSa=0b=01c=2007d=6e=11f=2012g=dq=qy=0z=TSE:COSx=.csv'
 In addition: Warning message:
 In download.file(paste(yahoo.URL, s=, Symbols.name, a=, from.m,  :
   cannot open: HTTP status was '404 Not Found'

 I'm not sure if I have the syntax correct for indicating an exchange on
 google. Does anyone have suggestions?

 Thanks,
 Paul

 ___
 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] RUGARCH variance targeting issue

2012-06-27 Thread R. Michael Weylandt michael.weyla...@gmail.com
It's on R-forge: googling r-forge and rugarch should get you there, but you 
might need to build from source to get the bleeding edge. It usually takes 
r-forge about a day to build, but it can be unpredictable. Details in another 
recent thread on this list. 

Best,
Michael

On Jun 27, 2012, at 10:32 AM, stoyan.stoyanov s.n.stoya...@gmail.com wrote:

 No worries. Does this mean that I should just not use variance targeting
 until the revision is out? I am actually trying to build something quite
 applied using the package, so I would be very happy if I could get my hands
 on a recent revision. Is one available anywhere?
 
 Thank you,
 Stoyan
 
 -
 Stoyan Stoyanov
 The University of Chicago Booth School of Business
 MBA Class of 2013
 (312) 532-0120 | stoya...@chicagobooth.edu
 --
 View this message in context: 
 http://r.789695.n4.nabble.com/RUGARCH-variance-targeting-issue-tp4634631p4634643.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@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] xts objects and speed

2012-06-18 Thread R. Michael Weylandt michael.weyla...@gmail.com
If I understand you, it might take a little jerry-rigging (sp?) but I think you 
could use the to.period() functions and pull out the Highs and Lows. 

Hope this gets you going in the right direction,

Michael

On Jun 18, 2012, at 9:40 PM, E D e065c8515d206cb0e...@gmail.com wrote:

 Hi everyone,
 
 I'm trying to use R to do some analysis of intraday data.
 Currently I have quotes for one symbol (every 1 min, from 930am to 4pm) and
 about a month and a half of data, and I'm computing things such as the
 trailing 1 hour and 3 hour maximums and minimums for that ticker.
 I'm making use of commands such as max(last(myXTS[1:t],'3 hours')) for
 every t, and I'm finding it rather slow as it takes about 60s to run for
 12500 observations on a modern workstation.
 
 Am I making improper or unoptimized use of the xts functions? Could someone
 give me a few points to speed up that kind of calculation? (If the answer
 is I know this great time series library in C... that's ok.)
 
 Thanks in advance.
 
 ED
 
[[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@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] RQuantLib possible bug in yearFraction and dayCount

2012-06-08 Thread R. Michael Weylandt
Well, I don't really know what you're doing wrong: it works just fine
to give me a vector so please provide a reproducible example of it not
doing so:

# From the examples
startDates - structure(c(14341, 14342, 14343, 14344, 14345, 14346, 14347,
14348), class = Date)

endDates structure(c(14555, 14556, 14557, 14558, 14559, 14560, 14561,
14562), class = Date)

dayCounters - c(0,1,2,3,4,5,6,1)

print(yearFraction(startDates, endDates, dayCounters))
print(yearFraction(startDates[1:4], endDates[rep(1,4)], rep(0, 4)))

I haven't really played with it, but it seems that you'll only get as
many outputs as you provide dayCounters so that might be part of
your problem.

Best,
Michael

On Fri, Jun 8, 2012 at 9:38 AM, Guillaume Horel
guillaume.ho...@gmail.com wrote:
 Ok thanks, this makes sense. Any way to make it work with a vector?
 The example from the doc with startDates, endDates makes clear that it
 should return a vector but I can only get a single value.

 Guillaume

 On Thu, Jun 7, 2012 at 10:57 PM, R. Michael Weylandt
 michael.weyla...@gmail.com wrote:
 H... looking at the source code, you see the return value is
 wrapped in invisible() so it won't auto-print but it is returned
 --it's not a bug, but I don't know exactly why Dirk would have done
 that. There are other functions that return invisibly (e.g., most plot
 functions) but those are usually side-effect functions.

 The invisible() was added not too long ago in r322 it seems, but the
 log doesn't quite explain why. Perhaps Dirk can chime in?

 Michael

 On Thu, Jun 7, 2012 at 5:07 PM, Guillaume Horel
 guillaume.ho...@gmail.com wrote:
 Hello,

 I'm trying to use the yearFraction function from the RQuantLib
 library. However the function behaves strangely. This small example
 should make the problem clear:

 yearFraction(Sys.Date(),Sys.Date()+10,0)
 dt - yearFraction(Sys.Date(),Sys.Date()+10,0)
 dt
 [1] 0.0278
 dtvec - yearFraction(Sys.Date(),Sys.Date()+10:20,0)
 dtvec
 [1] 0.0278

 The first issue is that just calling yearFraction alone doesn't return
 anything. However the output is just hidden, because if I store the
 result to a variable it works fine.
 However this trick doesn't work if you want to apply it to a vector as
 shown with the dtvec variable.

 This is the output from example(yearFraction), which shows that
 dayCount also exhibits the same issue (no output).

 yrFrct   startDates - seq(from=as.Date(2009-04-07),
 to=as.Date(2009-04-14),by=1)

 yrFrct   endDates - seq(from=as.Date(2009-11-07),
 to=as.Date(2009-11-14), by=1)

 yrFrct   dayCounters - c(0,1,2,3,4,5,6,1)

 yrFrct   dayCount(startDates, endDates, dayCounters)

 yrFrct   yearFraction(startDates, endDates, dayCounters)


 Can anybody else reproduce this? I'm trying to figure out if there is
 something wrong with my setup or if it's an actual bug in
 yearFraction.

 Thanks,
 Guillaume

 ___
 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] RQuantLib possible bug in yearFraction and dayCount

2012-06-07 Thread R. Michael Weylandt
H... looking at the source code, you see the return value is
wrapped in invisible() so it won't auto-print but it is returned
--it's not a bug, but I don't know exactly why Dirk would have done
that. There are other functions that return invisibly (e.g., most plot
functions) but those are usually side-effect functions.

The invisible() was added not too long ago in r322 it seems, but the
log doesn't quite explain why. Perhaps Dirk can chime in?

Michael

On Thu, Jun 7, 2012 at 5:07 PM, Guillaume Horel
guillaume.ho...@gmail.com wrote:
 Hello,

 I'm trying to use the yearFraction function from the RQuantLib
 library. However the function behaves strangely. This small example
 should make the problem clear:

 yearFraction(Sys.Date(),Sys.Date()+10,0)
 dt - yearFraction(Sys.Date(),Sys.Date()+10,0)
 dt
 [1] 0.0278
 dtvec - yearFraction(Sys.Date(),Sys.Date()+10:20,0)
 dtvec
 [1] 0.0278

 The first issue is that just calling yearFraction alone doesn't return
 anything. However the output is just hidden, because if I store the
 result to a variable it works fine.
 However this trick doesn't work if you want to apply it to a vector as
 shown with the dtvec variable.

 This is the output from example(yearFraction), which shows that
 dayCount also exhibits the same issue (no output).

 yrFrct   startDates - seq(from=as.Date(2009-04-07),
 to=as.Date(2009-04-14),by=1)

 yrFrct   endDates - seq(from=as.Date(2009-11-07),
 to=as.Date(2009-11-14), by=1)

 yrFrct   dayCounters - c(0,1,2,3,4,5,6,1)

 yrFrct   dayCount(startDates, endDates, dayCounters)

 yrFrct   yearFraction(startDates, endDates, dayCounters)


 Can anybody else reproduce this? I'm trying to figure out if there is
 something wrong with my setup or if it's an actual bug in
 yearFraction.

 Thanks,
 Guillaume

 ___
 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] 2 time/date columns to one

2012-05-25 Thread R. Michael Weylandt
Oh my mistake... parenthesis in the wrong spot -- format should be
an argument to as.POSIXct, not paste -- try this:

xts(dat[,3], as.POSIXct(paste(dat[,1], dat[,2]), format = %m/%d/%Y %H%M))

Best,
Michael

On Fri, May 25, 2012 at 1:00 PM, Costas Vorlow costas.vor...@gmail.com wrote:
 Hi,

 I am getting:

 Error in as.POSIXlt.character(x, tz, ...) :
  character string is not in a standard unambiguous format

 I am also using:

 Sys.setenv(TZ=GMT)

 just in case.

 Any thoughts?

 On 25 May 2012 19:49, R. Michael Weylandt michael.weyla...@gmail.com wrote:
 Use xts (always use xts!) and do something like this:

 Suppose your data is in three columns called dat

 xts(dat[,3], as.POSIXct(paste(dat[,1], dat[,2], format = %m/%d/%Y %H%M))

 This will make an xts of your data taking the third column as the
 data-bit and using the first two to make a POSIXct (time) object
 converting them using the format specification.

 Hope that helps,

 Michael

 On Fri, May 25, 2012 at 12:35 PM, Costas Vorlow costas.vor...@gmail.com 
 wrote:
 Hello,

 I have trouble connecting times with dates to create a proper time 
 sequence:

 5/22/2012       1640    318295
 5/22/2012       1641    432517
 5/22/2012       1642    328233
 5/22/2012       1643    444692
 5/22/2012       1644    217440
 5/22/2012       1645    650593
 5/22/2012       1646    207366
 5/22/2012       1647    334881
 5/22/2012       1648    133929
 5/22/2012       1649    267117
 5/22/2012       1650    179423
 5/22/2012       1651    259668
 5/22/2012       1652    341661


 The table above is a time sequence. The 1st column on the left is the
 date and the next column contains the time of day (1640= 4:40pm). The
 3rd column is the price of a variable at that point in time. Hence, I
 want to convert the above table to a time series variable (xts, zoo,
 etc) of some sort. Any pointer extremely welcome ( I know this is a
 lame question)...

 Many thanks in advance,

 Costas

 --

 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 |c|o|s|t|a|s|@|v|o|r|l|o|w|.|o|r|g|
 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

 ___
 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.



 --

 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 |c|o|s|t|a|s|@|v|o|r|l|o|w|.|o|r|g|
 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

___
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] Can't addMACD(). Is it a bug?

2012-05-22 Thread R. Michael Weylandt
Not runnable exactly as is where does the for loop have its close brace?

This works fine for me:

getSymbols(SPY, from = 1990-01-01)
y - to.weekly(SPY)
chartSeries(y, type = candlesticks, multi.col = TRUE, theme =
white, subset = 'last 54 months', name = SPY)
addMACD(fast = 12, slow = 26, signal = 9, type = EMA, histogram = TRUE)
saveChart('pdf',width=25,height=13)

so try it for you.

Your data seems to work for me if I close the loop after MACD. Can you
display the error message or say more about why you think it doesn't
work?

Michael

On Tue, May 22, 2012 at 10:58 PM, Sávio M. Ramos savio.deb...@gmail.com wrote:
 Hi,

 addMACD don't work. I am doing something wrong or it is a bug.

 The code:

 require(quantmod)
 lista - c(PETR4.csv, VALE3.csv)
 for (i in lista){
 x - as.xts(read.zoo(i, sep=,, format=%Y-%m-%d, header=TRUE))
 y - to.weekly(x)
 chartSeries(y, type=candlesticks, multi.col=TRUE, theme=white, 
 subset='last 54 months', name=i)
 addMACD(fast = 12, slow = 26, signal = 9, type = EMA, histogram = TRUE)
 saveChart('pdf',width=25,height=13)


 The two files is attached.

 []'s
 --
 Sávio M Ramos
 Arquiteto, Rio, RJ
 Só uso Linux desde 2000
 www.debian.org


 ___
 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] Time indexation after selection in an xts object

2012-05-01 Thread R. Michael Weylandt
Your xts is a little out of date, I doubt that that's relevant but it
might not hurt to just go ahead and update.

But yes, sending the file (just a small sample thereof) would help --
the easiest way to do so would be to type

dput(head(x, 30)) # x is name of your object

and send us the textual output produced.

Michael

On Tue, May 1, 2012 at 11:40 AM, Karim kktras...@gmail.com wrote:
 I could send the file itself, but maybe that's because the index is not
 unique? (yours is unique)
 sessionInfo()
 R version 2.14.1 (2011-12-22)
 Platform: i386-pc-mingw32/i386 (32-bit)

 locale:
 [1] LC_COLLATE=French_France.1252  LC_CTYPE=French_France.1252
 LC_MONETARY=French_France.1252 LC_NUMERIC=C
 [5] LC_TIME=French_France.1252

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

 other attached packages:
  [1] RTAQ_0.1                   timeDate_2131.00           quantstrat_0.6.4
 blotter_0.8.4
  [5] FinancialInstrument_0.13.6 quantmod_0.3-17            TTR_0.21-0
 xts_0.8-2
  [9] zoo_1.7-7                  Defaults_1.1-1
 randomForest_4.6-6         RRF_1.1
 [13] fractal_1.1-1              scatterplot3d_0.3-33       akima_0.5-7
 wmtsa_1.1-1
 [17] sapa_1.1-0                 ifultools_1.1-2            MASS_7.3-16
 splus2R_1.1-0
 [21] RODBC_1.3-4

 loaded via a namespace (and not attached):
 [1] grid_2.14.1    lattice_0.20-0 tools_2.14.1

 -Message d'origine-
 De : Joshua Ulrich [mailto:josh.m.ulr...@gmail.com]
 Envoyé : mardi 1 mai 2012 15:41
 À : Karim
 Cc : r-sig-finance@r-project.org
 Objet : Re: [R-SIG-Finance] Time indexation after selection in an xts object

 I cannot replicate this behavior.  Please provide a reproducible example.

 library(xts)
 set.seed(21)
 x - .xts(trunc(runif(1e4)*10), 1:1e4, dimnames=list(NULL,SIZE))
 s - cumsum(x$SIZE['1969-12-31'])
 head(s)
                    SIZE
 1969-12-31 18:00:01    7
 1969-12-31 18:00:02    9
 1969-12-31 18:00:03   15
 1969-12-31 18:00:04   16
 1969-12-31 18:00:05   25
 1969-12-31 18:00:06   34
 sessionInfo()
 R version 2.15.0 (2012-03-30)
 Platform: i386-pc-mingw32/i386 (32-bit)

 locale:
 [1] LC_COLLATE=English_United States.1252
 [2] LC_CTYPE=English_United States.1252
 [3] LC_MONETARY=English_United States.1252
 [4] LC_NUMERIC=C
 [5] LC_TIME=English_United States.1252

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

 other attached packages:
 [1] xts_0.8-6 zoo_1.7-7

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

 Best,
 --
 Joshua Ulrich  |  FOSS Trading: www.fosstrading.com

 R/Finance 2012: Applied Finance with R
 www.RinFinance.com


 On Tue, May 1, 2012 at 6:04 AM, Karim kktras...@gmail.com wrote:

 Hi,

 My xts object : SP500TiSa

  head(SP500TiSa)

     BID  OFR   PRICE SIZE
 2012-01-23 06:00:58 1306.75 1307 1307.00    2
 2012-01-23 06:00:58 1306.75 1307 1306.75    6
 2012-01-23 06:00:58 1306.75 1307 1307.00    1
 2012-01-23 06:00:58 1306.75 1307 1307.00    2
 2012-01-23 06:00:59 1306.75 1307 1307.00    1
 2012-01-23 06:00:59 1306.75 1307 1307.00    1

 What I want to do is to calculate the cumulated sum of the column SIZE of
 the records of day 2012-01-24 but I want the resulting selection to keep the
 time information

  s=cumsum(SP500TiSa$SIZE['2012-01-24'])


 When I plot s, that’s ok, I have the time information on the x-axis of the
 graph :

  plot(s,type=l)


 But when I display s on the console :

  head(s)
    SIZE
 2012-01-24    4
 2012-01-24    5
 2012-01-24    6
 2012-01-24   16
 2012-01-24   17
 2012-01-24   32

 We have only the day information on the index. The time info is lost, how
 to keep it ?

 Thank you

 ___
 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.
 -
 Aucun virus trouvé dans ce message.
 Analyse effectuée par AVG - www.avg.fr
 Version: 2012.0.1913 / Base de données virale: 2411/4971 - Date: 01/05/2012

 ___
 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] to make the finance package running

2012-04-25 Thread R. Michael Weylandt michael.weyla...@gmail.com
This isn't really a finance question, but do you have the source code? If you 
do, just use install.packages() with type = source and point to the 
appropriate tarball. 

The only somewhat difficult step might be if you need to add a namespace. 

Michael 

On Apr 25, 2012, at 10:00 PM, Wei-han Liu weihanliu2...@yahoo.com wrote:

 Hi R users:
 
 I tried to install a R finance package in its beta version. I believe it was 
 developed several years ago and no longer maintained. The error message I got 
 is listed below:
 library(XXX)
 Error: package 'XXX' was built before R
 2.10.0: please re-install it
 
 Could somebody share some advice to make the package running under the 
 current version of R?
 
 Thanks.
 
 Wei-han
[[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@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] Information

2012-04-25 Thread R. Michael Weylandt
Please reply to the list and not just me so others can benefit/help.

http://cran.r-project.org/web/packages/RBerkeley/index.html (the
install link) suggests RBerkeley is not supported for Windows so
unless you're willing to help with the port (or someone has done it
without publishing it) I think you may be out of luck.

Michael

On Thu, Apr 26, 2012 at 1:12 AM, Karim kktras...@gmail.com wrote:
 Thank you for your reply.

 1) My session info :

 R version 2.14.1 (2011-12-22)
 Platform: i386-pc-mingw32/i386 (32-bit)

 locale:
 [1] LC_COLLATE=French_France.1252  LC_CTYPE=French_France.1252
 LC_MONETARY=French_France.1252
 [4] LC_NUMERIC=C                   LC_TIME=French_France.1252

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

 other attached packages:
  [1] Hmisc_3.9-3                  survival_2.36-10             igraph_0.5.54

  [4] fGarch_2110.80               fBasics_2110.79
 timeSeries_2130.92
  [7] PerformanceAnalytics_1.0.4.4 RTAQ_0.1
 timeDate_2131.00
 [10] quantstrat_0.6.4             blotter_0.8.4
 FinancialInstrument_0.13.6
 [13] quantmod_0.3-17              TTR_0.21-0                   xts_0.8-2

 [16] zoo_1.7-7                    Defaults_1.1-1
 randomForest_4.6-6
 [19] RRF_1.1                      fractal_1.1-1
 scatterplot3d_0.3-33
 [22] akima_0.5-7                  wmtsa_1.1-1                  sapa_1.1-0

 [25] ifultools_1.1-2              MASS_7.3-16                  splus2R_1.1-0

 [28] RODBC_1.3-4

 loaded via a namespace (and not attached):
 [1] cluster_1.14.1 grid_2.14.1    lattice_0.20-0 tools_2.14.1

 2) The command I use for installing RBerkeley (and the subsequent warning
 message) :
 install.packages(RBerkeley)
 Installing package(s) into ‘C:/Users/Karim/Documents/R/win-library/2.14’
 (as ‘lib’ is unspecified)
 Warning in install.packages :
  package ‘RBerkeley’ is not available (for R version 2.14.1)

 I've installed Berkeley DB11gR2

 Thank you to tell me how to install RBerkeley if you have some information.



 -Message d'origine-
 De : R. Michael Weylandt [mailto:michael.weyla...@gmail.com]
 Envoyé : mercredi 25 avril 2012 05:16
 À : Karim
 Cc : r-sig-finance@r-project.org
 Objet : Re: [R-SIG-Finance] Information

 I'm no Jeff Ryan, but I'd be willing to put money on him wanting to
 ask what you've tried and what error message(s) you got? (As well as
 system config details you get from sessionInfo() )

 I just installed it with no problems (well, none that I can check
 since i don't have Berkeley DB) straight from CRAN.

 Michael

 On Tue, Apr 24, 2012 at 11:08 PM, Karim kktras...@gmail.com wrote:
 Hello,



 I’m an R user and I’ve a problem installing package RBerkeley from
 Jefferey
 Ryan.

 I’ve subscribed to the mailing list (I have an email and a password)
 https://stat.ethz.ch/mailman/listinfo/r-sig-finance

 And I’d like to post a message to the mailing list in order to get a
 response from Jeffrey Ryan.



 Exactly as did M. Golam Sakline below :



 -Message d'origine-

 De : r-sig-finance-boun...@r-project.org
 [mailto:r-sig-finance-boun...@r-project.org] De la part de Jeffrey Ryan
 Envoyé : lundi 26 mars 2012 16:25 À : Golam Sakline;
 r-sig-finance@r-project.org Objet : Re: [R-SIG-Finance] Numeric to
 timeSeries help



 ?merge.xts is what you need.



 It will behave like you'd expect in R - requiring a vector of length ==
 nrow
 of your object, or will be recycled as needed. e.g. cbind(x, NA) will
 recycle NA accordingly



 HTH

 Jeff



 On 3/26/12 7:59 AM, Golam Sakline golam.sakl...@gmail.com wrote:



Hi,



Can someone quickly help me with few lines of code or point me to a

site that shows how to merge a numeric class object column with time

column of getSymbol object and plot it in quantmod chartSeries.

Much appreciated.



Thanks in advance



 Could you tell me how to send (should I send it to
 r-sig-finance@r-project.org ?) a question and how to be sure that M.
 Jeffrey
 Ryan will get it?



 Thank you very much.



 Karim Kanoun




        [[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.
 -
 Aucun virus trouvé dans ce message.
 Analyse effectuée par AVG - www.avg.fr
 Version: 2012.0.1913 / Base de données virale: 2411/4957 - Date: 24/04/2012


___
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] about an error of xts

2012-04-23 Thread R. Michael Weylandt
In addition to what's been said, you could much more easily write:

GSPC - getSymbols(^GSPC, from = 2000-01-01, auto.assign = F)

which will give names that are (directly) compatible with other
quantmod functions and would seem to avoid your problem in the first
place.

Michael


On Mon, Apr 23, 2012 at 4:50 AM, Haiping LAN haiping...@gmail.com wrote:
 *Hallo, lists:*
 *
 *
 *  I came to an error for xts package : * order.by requires an appropriate
 time-based object.
 * It seems there is no explicit solution to this problem, so would you
 please do me a favor and give me some further advice ?*
 *My current version for R is 2.14.0, and relevant codes are as follows :*

 library(tseries)

 library(quantmod)

 GSPC - as.xts(get.hist.quote(^GSPC,start=2000-01-02,
          quote=c(Open, High, Low, Close,Volume,AdjClose)))

 T.ind - function(quotes,tgt.margin=0.025,n.days=10) {
  v - apply(HLC(quotes),1,mean)

  r - matrix(NA,ncol=n.days,nrow=NROW(quotes))
  for(x in 1:n.days) r[,x] - Next(Delt(v,k=x),x)

  x - apply(r,1,function(x) sum(x[x  tgt.margin | x  -tgt.margin]))
  if (is.xts(quotes)) xts(x,time(quotes)) else x
 }

 ex.model - specifyModel(T.ind(GSPC) ~ Delt(Cl(GSPC),k=1:3))

 *
 *
 *Best,*
 *Haiping Lan /Guosen Securities Co.*

 *
 *

 --
  Haiping LAN

        [[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@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] timeSeries 2 zoo convert

2012-04-17 Thread R. Michael Weylandt
Following up on what Josh said, does it work with the built-in data
set MSFT provided by timeSeries?

library(xts)
library(timeSeries)

data(MSFT)

head(MSFT)
head(as.xts(MSFT))
head(as.zoo(MSFT))

all give the same dates for me.

Michael

On Tue, Apr 17, 2012 at 1:39 PM, Joshua Ulrich josh.m.ulr...@gmail.com wrote:
 On Tue, Apr 17, 2012 at 12:27 PM, Costas Vorlow costas.vor...@gmail.com 
 wrote:
 Hello,

 What is the best   way to convert an timeSeries object to .zoo?

 Generally, as.zoo is preferred.

 Say I have  the following timeSeries object:

 is(x)
 [1] timeSeries structure  vector
 head(x)
 GMT
            DAAA
 1983-01-03 11.77
 1983-01-04 11.79
 1983-01-05 11.79
 1983-01-06 11.74
 1983-01-07 11.74
 1983-01-10 11.75


 When I try to convert it to zoo, I can not retain the dates info. I tried:

        a-as.Date(index( x ))
        xz-as.zoo(x)
        index(xz)-a

 but dates change.

  head(xz)
            DAAA
 1970-01-02 11.77
 1970-01-03 11.79
 1970-01-04 11.79
 1970-01-05 11.74
 1970-01-06 11.74
 1970-01-07 11.75

 That's because you changed the dates.  Look at the output of:

 R index(x)
  [1] 1 2 3 4 5 6 7 8 9 10

 There's no index.timeSeries method, so index.default is dispatched.
 xz - as.zoo(x) should be sufficient.


 This used to work with last year's libraries but it seems it doesn't anymore:

                a-index(as.zoo(x))
                xz-as.zoo(x)
                xnew-aggregate(xz, as.Date, identity)

 Error in as.Date.default(index(x)) :
  do not know how to convert 'index(x)' to class Date

 This is different from your example above.  Further, this works for me
 on R-2.15.0 with timeSeries_2130.92, timeDate_2131.00, and zoo_1.7-7.
 Your R version is a year old and timeDate and zoo are a couple minor
 versions behind.  Maybe updating will solve your problem?


 Any help, extremely welcome.

 thanks in advance,
 Costas


 sessionInfo()
 R version 2.13.0 (2011-04-13)
 Platform: i386-pc-mingw32/i386 (32-bit)

 locale:
 [1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United
 States.1252
 [3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
 [5] LC_TIME=English_United States.1252

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

 other attached packages:
  [1] fImport_2110.79              timeSeries_2130.92
  [3] timeDate_2130.93             fMarkovSwitching_1.0
  [5] Rdonlp2_0.3-1                rcom_2.2-3.1
  [7] rscproxy_1.3-1               quantmod_0.3-17
  [9] TTR_0.21-0                   Defaults_1.1-1
 [11] PerformanceAnalytics_1.0.3.2 xts_0.8-2
 [13] zoo_1.7-4

 loaded via a namespace (and not attached):
 [1] grid_2.13.0     lattice_0.19-33 tools_2.13.0



 --

 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 |c|o|s|t|a|s|@|v|o|r|l|o|w|.|o|r|g|
 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+



 --
 Joshua Ulrich  |  FOSS Trading: www.fosstrading.com

 R/Finance 2012: Applied Finance with R
 www.RinFinance.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@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] Data to start with?

2012-04-04 Thread R. Michael Weylandt
I know IBrokers is reasonable and it has top-notch R integration
thanks to Jeff Ryan
(http://cran.r-project.org/web/packages/IBrokers/index.html) -- here's
some of their pricing data:
http://individuals.interactivebrokers.com/en/p.php?f=marketData

Michael

On Wed, Apr 4, 2012 at 3:52 AM, Sebastian Steins
sebastian.ste...@gmail.com wrote:
 Hi there,

 does anybody know a reliable and affordable data stream for current
 (delayed) and historical market data? Budget is, approx. 100 €/$ per
 month and as I am currently only trying to do some research I would
 have non-professional status.
 Would be nice, if Xetra was included.


 Thanks for your hints!
 Sebastian

 ___
 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] Quick question: the parameter K in the Johansen Procedure for VAR?

2012-04-02 Thread R. Michael Weylandt
As I said to you before, ca.jo is in the urca package.

It's defined in arguments: to wit,

K: The lag order of the series (levels) in the VAR.

It's also used in that manner throughout the details section.

Michael Weylandt

On Mon, Apr 2, 2012 at 5:33 PM, Michael comtech@gmail.com wrote:
 Hi all,

 I have a quick question:

 In using ca.jo in vars...


 ca.jo(x, type = c(eigen, trace), ecdet = c(none, const, trend), K = 
 2,
 spec=c(longrun, transitory), season = NULL, dumvar = NULL)



 There is a parameter K.

 What does this K correspond to in the Details section? It doesn't
 appear anywhere in the fomulars...

 When I read into the book by Dr. Bernhard Pfaff, I couldn't find a
 corresponding one either...

 Please help me!



 Thank you!

        [[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@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] xts and sapply

2012-04-01 Thread R. Michael Weylandt
Just a guess, but you are missing a comma in the GSPC part of the y -  line.

Your bigger problem is that you don't need sapply() in the first place
here (best I remember): I think this works:

y - merge(Ad(FNMIX), Ad(DBLTX), Ad(AGG), Ad(GSPC))
ROC(y) # Note that you don't need sapply() because ROC handles
everything nicely for you.

Michael

On Sun, Apr 1, 2012 at 2:24 PM, Eric Thungstom
eric.thungst...@gmail.com wrote:
 I have prices for several securities in a data frame. I'm wondering how to
 calculate returns for each of them in a vectorized fashion.

 require(quantmod)
 group -c('FNMIX','DBLTX','AGG','^GSPC')
 getSymbols(group, src=yahoo, from=2012-01-01, to=Sys.Date())
 y - merge(FNMIX[,4],DBLTX[,4],AGG[,4],GSPC[4])
 x -sapply(y[,1:4], dailyReturn)

 When I execute the above code I get an error in arrary message that
 indicates that the length of dim names [1] not equal to array extent.

 What am I doing wrong ?

        [[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@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 automatically extract test result from Johansen test?

2012-03-30 Thread R. Michael Weylandt
Actually, it looks like ca.jo objects are S4 so it's a little bit
harder: take a look at ?`ca.jo-class` (note the backticks) to see the
26 slots available. I'm not sure if the ones you want have dedicated
extractor methods but you can get them with ?slot directly. There's
not an absolute pass/fail (like most other statistical tests) so you
have to pick your desired significance threshold, but that's not hard.
As Brian said though, it makes most sense to do this inside your loop
construction.

Hope this helps,

Michael Weylandt

On Fri, Mar 30, 2012 at 12:00 PM, Brian G. Peterson br...@braverock.com wrote:
 On Fri, 2012-03-30 at 10:53 -0500, Michael wrote:
 How to automatically extract test result from Johansen test?

 Hi all,

 I am using the ca.jo function to do the Johansen test.

 It's outputting a lot of results.

 If I am running this on a large number of assets, is there a way to
 automatically extract and condense the test outputs to just pass/fail and
 residuals?

 Thanks a lot!

 Like all R objects, it is a list internally. Extract what you need in
 the same loop that's doing the test.

 Please at least try before posting.

 --
 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@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] xts to timeSeries conversion

2012-03-24 Thread R. Michael Weylandt
I'm not sure I understand. PerformanceAnalytics is part of the
xts-family (as opposed to the Rmetrics family) of finance packages.
Your problem may be that it requires returns, but consider this
(somewhat opaque) one liner.

charts.PerformanceSummary(ROC(Cl(to.weekly(Ad(getSymbols(IBM,auto.assign
= F))

which works just fine (using 3 packages explicitly and two major dependencies!)

Michael

On Sat, Mar 24, 2012 at 9:01 AM, Golam Sakline golam.sakl...@gmail.com wrote:
 How is it possible to get getSymbol object like IBM stock converted to 
 timeSeries object so that it can be plotted in charts.PerformanceSummary() of 
 PerformanceAnalytics in few lines of code. The problem I am having is with 
 the Date column. Please help.

 Thanks

 Riskmaverick

 Sent from my iPhone
 ___
 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] xts to timeSeries conversion

2012-03-24 Thread R. Michael Weylandt
Is as.timeSeries not sufficient? (It will dispatch to as.timeSeries.xts)

Michael

On Sat, Mar 24, 2012 at 9:58 AM, Golam Sakline golam.sakl...@gmail.com wrote:
 Hi Michael,

 Thank you for you reply, but in general are you aware of any ways to convert 
 xts date to timeSeries date using intermediate data.frame conversion in 
 between.

 Thank you in advance.

 Golam

 Sent from my iPhone

 On 24 Mar 2012, at 13:13, R. Michael Weylandt michael.weyla...@gmail.com 
 wrote:

 I'm not sure I understand. PerformanceAnalytics is part of the
 xts-family (as opposed to the Rmetrics family) of finance packages.
 Your problem may be that it requires returns, but consider this
 (somewhat opaque) one liner.

 charts.PerformanceSummary(ROC(Cl(to.weekly(Ad(getSymbols(IBM,auto.assign
 = F))

 which works just fine (using 3 packages explicitly and two major 
 dependencies!)

 Michael

 On Sat, Mar 24, 2012 at 9:01 AM, Golam Sakline golam.sakl...@gmail.com 
 wrote:
 How is it possible to get getSymbol object like IBM stock converted to 
 timeSeries object so that it can be plotted in charts.PerformanceSummary() 
 of PerformanceAnalytics in few lines of code. The problem I am having is 
 with the Date column. Please help.

 Thanks

 Riskmaverick

 Sent from my iPhone
 ___
 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] hourly time series

2012-03-22 Thread R. Michael Weylandt
Well, simply, your problem is that the thing are providing is not
cut()-able in that no specific cut() method is provided. If you want
to cut on the start date, you can simply use cut(test$Start) or, for
the end date, cut(test$End). Though there may be better extractor
functions availablefor the other stuff, you might be able to get
some help from the lubridate package.

And this won't work for ts objects because they don't store their
timestamps the same what at all.

Michael

On Thu, Mar 22, 2012 at 4:13 AM, Advait Godbole advaitgodb...@gmail.com wrote:
 thanks Michael, that worked.

 I now want to perform monthly and weekly decomposition. In a one-on-one
 conversation with fellow member Vlad, I was suggested to do the following.
 I'm posting it here for the forum and for other pointers.

 # define hourly data with monthly frequency
 wind.ts.monthbase - ts(wind.MH, start=1, frequency=8760/12)    #wind.MH is
 8760 x 1 vector
 wind.ts.monthbase.decompose - decompose(wind.ts.monthbase)

 # define hourly data with weekly frequency
 wind.ts.weekbase - ts(wind.MH,start=1, frequency=8760/52.14286)
 #52.14286=8760/168
 wind.ts.weekbase.decompose - decompose(wind.ts.weekbase)

 Vlad also suggested I could try using the timetools package to better
 preserve the time properties. Following on his lead, I was able to create a
 test time series:

 #use of timetools package
 # create an hourly time series starting on 1st April 2010, ending on 31st
 March 2011
 test - RegularTimeIntervalDataFrame('2010-04-01','2011-03-31
 23:00','hour',timezone=GMT,data=data.frame(test=1:8760))

 If anyone is familiar with this package, I would like to know how to
 extract
 1. a particular month/group of months
 2. the first day/first week etc of each month
 3. all mondays, all tuesdays etc of the year

 I tried doing the above using the cut function with the following errors:
 wind.ttools.weekly.data - cut(test, breaks=week, start.on.monday=TRUE)
 Error in cut.default(test, breaks = week, start.on.monday = TRUE) :
   'x' must be numeric
 wind.ttools.weekly.data - cut(as.numeric(test), breaks=week,
 start.on.monday=TRUE)
 Error in as.numeric(test) :
   cannot coerce type 'S4' to vector of type 'double'

 I havent yet been able to identify the cause of this issue.

 It will also be good to know if the same extraction can be performed on the
 ts object. Thanks in advance for your responses.

 Regards,
 Advait

 On Wed, Mar 14, 2012 at 6:41 PM, R. Michael Weylandt
 michael.weyla...@gmail.com wrote:

 I think you are interpreting your frequency argument incorrectly and
 thus R is giving you an error message because you are asking for
 seasonal trends but giving only one observation per season -- it's
 rather subtle: as the help page says,

 frequency -- the number of observations per unit of time.

 Note that this works,

 wind_ts - ts(cumsum(rnorm(8760)), start = 1, frequency = 24) # E.g.,
 the relevant time scale is daily and you have 24 obs per day
 (hourly)
 decompose(wind_ts)

 This would be for a phenomenon that reoccurs daily: I'm not sure if a
 single monsoon season (I think there's only one a year but I don't
 really know Indian climatology so well) will give you sufficient power
 for a statistically significant result, but you can cross that bridge
 when you get to it.

 Hope this helps,

 Michael

 PS -- The ts class is generally considered a necessary evil around
 here because of things like that ;-)

 On Wed, Mar 14, 2012 at 5:45 AM, Advait Godbole advaitgodb...@gmail.com
 wrote:
  Dear all,
 
  I am new to this list and I first posted this query on the r-sig-geo
  forum,
  apologies for the cross-post. My question is not related to finance,
  however I am sure many users here will have experience with time series
  analysis and would be able to provide insight.
 
  I have one year's worth of hourly data, starting from 1st April 2010 and
  ending on 31st March 2011. I would like to perform time series analysis
  on
  it. New to time series analysis and not having used ts before, I am
  having trouble setting it up to correctly represent the data. I have R
  reading in the time series via:
  *wind_ts - ts(wind.MH,start=1,frequency=1)*
 
  where wind.MH is a 8760x1 matrix object. I then tried to decompose the
  time series with the following error:
  *wind_ts_components - decompose(wind_ts)*
  *Error in decompose(wind_ts) : time series has no or less than 2
  periods*
 
  The dataset is the hourly wind generation for Maharashtra, India and has
  some seasonality associated with the Indian monsoon. Ultimately, this is
  what I would like to identify. I imagine that correctly setting the
  start
  and frequency parameters is necessary to be able to parse the dataset
   into months and seasons. Someone suggested I use the timetools
  package
  instead but I havent had the chance to do so.
 
  I would greatly appreciate help on how to handle this and any leads on
  time
  series analysis for hourly data in general.
 
  Regards

Re: [R-SIG-Finance] using getQuote with subscription to yahoo real-time data?

2012-03-02 Thread R. Michael Weylandt michael.weyla...@gmail.com
You can write your own getQuote method and use the Defaults package to change 
from src=yahoo to yahoopaid or whatever you decide to call it. I don't have 
a paid subscription so I can't really help with writing it. 

Michael

On Mar 2, 2012, at 3:01 PM, Andre Zege az...@yahoo.com wrote:

 Sorry, my bad. I was looking for sources in package installation directory, 
 used to finding them there. In any case, what's your take on my main 
 question. It doesn't seem easy to me to hack getQuote.yahoo to get real-time. 
 It seems it just loads a csv file. Does anyone know if there is maybe a 
 similar page for non-delayed real-time or it all involves reading and writing 
 to sockets? I don't care about a couple of seconds of latency, i just don't 
 want to have 15 minutes latency and using getQuote would be uber nice.
[[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@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] really puzzled by this R script

2012-02-25 Thread R. Michael Weylandt
This isn't really a finance question...

Your problem is that you use names() instead of just getting the row
numbers from outlierTest but then, when you convert the names to an
integer, your attempts to remove the row by that number and so doesn't
actually get the right row, then an outlier remains and the infinite
loop is triggered.

To put it concretely, add a browser() at the top of the while loop and
note this:

x - 1:20
y - x; y[c(3, 14)] - 1000*c(1, 1.05); y - jitter(y);

dat - data.frame(x = x, y = y)

rmOutlier(y ~ x, dat[-1,])


## Once in browser note this:
ret # should give 14 because the 14th spot is a problem by construction
fullData[ - ret, ] # Still has the outlier at 14 because it's not in
the 14th row!

If you just use the names and index appropriately, you should be fine.
Further help is more suited to R-help though as this isn't very
financial...just a heads up though: you'll also probably get told off
for mentioning outlier removal on R-help: it's something of a rite of
passage

Michael

On Sat, Feb 25, 2012 at 1:27 AM,  john...@comcast.net wrote:
 Dear all,

 I wrote a R script that basically trying to identify outliers, and returns a 
 non-empty vector containing the index to the outliers or a NULL object if 
 there is no outliers.
 I have been puzzled by the strange behavior of this function. Let's say we 
 have 10 outliers in a data frame of 1000 row samples.
 1) If I run rmOutlier(y ~ x1 + x2, xyData), where xyData is a data frame with 
 column names y, x1, x2. The program runs fine, and returns the indices 
 of those 10 outliers.
 2) If I run rmOutlier(y ~ x1 + x2, xyData[1:200, ]), or any subset starts 
 from the first row (i.e., 1:xx), the program runs fine.
 3) If I run the script start from subsets of data not starting from the first 
 row, e.g., rumOutlier
 (y ~ x1 + x2, xyData[100:1000, ] ), if there is no outlier falls within 
 xyData[100:1000, ], the program runs fine.

 However, in case 3), if there is any outlier falls within xyData[100:1000, ], 
 the program runs in infinite loop (the while loop in the script). Trouble 
 shooting indicates that outlierTest( lm(lm_form, data = fullData[-ret, ]) 
 will always return the same set of outliers index, and fullData[-ret, ] seems 
 have no effects.

 What went wrong here? Any help will be greatly appreciated.

 Thank you.


 John Li


 This is the script:


  rmOutlier - function(lm_form, fullData) {
 # Find and return Outliers indices based on Bonferroni Outlier Test
 # The program returns a non-empty vector or a NULL object


 # AUTHOR:
 # John Li
 # Date: Feb 17, 2012
 # Revised: Feb 24, 2012
 #

  require(car, quietly = TRUE)

  #sanity check
  stopifnot(is.data.frame(fullData), ncol(fullData)  1, 
 length(names(fullData)) == ncol(fullData))

  outlier - outlierTest( lm(lm_form, data = fullData), n.max = Inf)
  if ( outlier$signif ) {
    ex - c(as.numeric(names(outlier$rstudent)))
    ret - ex
  }
  else {
    ret - NULL
    return(ret)
  }

  while( outlier$signif ) {
    outlier - outlierTest( lm(lm_form, data = fullData[-ret, ]), n.max = Inf) 
 # fullData[-ret, ] seems not work
    if ( outlier$signif ) {
      ex - as.numeric(names(outlier$rstudent))
      ret - c(ret, ex)
    }
  }
  return(ret)
  }

        [[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@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] Stock Total Returns?

2012-02-18 Thread R. Michael Weylandt
I think you're over-thinking this: if you have adjusted prices, they
already incorporate splits+dividends --- so the return in adjusted
price *is* the total return. (Up to some fuzziness in how that
adjustment should be done)

Michael

On Sat, Feb 18, 2012 at 5:20 PM, SW kry...@yahoo.com wrote:
 Hello All,


 I am relatively new to R and I am still not very comfortable with syntactic 
 and libraries. Is there are any nice way to calculate and plot total returns 
 for stocks which I would define as change in price and paid dividends? I made 
 a code to do that but the loop that constructs prices+dividends looks 
 ugly(see code below). Any suggestions to do it more efficiently? Thanks. 
 Sergey

 ##  CODE  ##
 library(quantmod)
 library(PerformanceAnalytics)

 #Time frame
 dt.end = 2010-01-01
 dt.start =  2007-01-01

 tickers = c('SPY',
            'XLY',
            'XLP',
            'XLE',
            'XLF',
            'XLV',
            'XLI',
            'XLB',
            'XLK',
            'XLU')
 tickers.desc = c('SNP500',
                 'ConsumerCyclicals',
                 'ConsumerStaples',
                 'Energy',
                 'Financials',
                 'HealthCare',
                 'Industrials',
                 'Materials',
                 'Technology',
                 'Utilities')

               Get prices        ###
 setDefaults(getSymbols, warnings=FALSE,auto.assign=FALSE)
 fnPx - function(i) { return(Ad(getSymbols(tickers[i], 
 from=dt.start,to=dt.end))) }
 ts = lapply(1:length(tickers), fnPx)
 ###

               Get Dividends     
 fnDiv- function(i) { return(getDividends(tickers[i], 
 from=dt.start,to=dt.end,auto.assign=FALSE)) }
 div = lapply(1:length(tickers), fnDiv)
 ###

 ###    Create Prices + Dividends (UGLY )  #
 fnTotPx - function(i)
  {
    ret = ts[[i]]
    for(j in 1:length(div[[i]]))
    {
      row  = div[[i]][j,]
      tm   = time(row)
      val  = as.double(row[1,1])
      iFwd = paste(tm,::,sep='')
      iBk  = paste(::,tm-1,sep='')
      unch = ret[iBk]
      chg  = ret[iFwd]+val
      ret = rbind(unch,chg)
    }
    return(ret)
  }
 totPx = lapply(1:length(tickers), fnTotPx)
 


           Calc Total Returns     ##
 fnRet - function(i) { return(periodReturn(totPx[[i]],period='daily')) }
 ts.ret = lapply(1:length(tickers), fnRet)

           Plot Total Returns     ##
 ts.ret.df = as.data.frame(ts.ret)
 colnames(ts.ret.df)=tickers.desc
 chart.CumReturns(ts.ret.df, main=Cumulative 
 Returns,geometric=FALSE,legend.loc=bottomleft)
 

 ___
 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] using findPeaks in designing railing-stops?

2012-02-16 Thread R. Michael Weylandt
You'll get more if you lower your threshold value (the 5)

Michael

On Thu, Feb 16, 2012 at 10:13 AM, Luna lunamoonm...@gmail.com wrote:
 Hi friends,

 Thanks for your help!

 I just did a new test:

 aa=100:1
 bb=sin(aa/3)
 cc=aa*bb
 plot(cc, type=l)
 p=findPeaks(cc, 5)
 points(p, cc[p])
 points(p, cc[p])



 p

 [1] 3 22 41



 It only picks up 3 peaks, which is obviously wrong, am I correct?

 Thanks a lot!

 On Thu, Feb 9, 2012 at 9:55 PM, R. Michael Weylandt
 michael.weyla...@gmail.com wrote:

 Happy to follow procedure.

 Thanks for jumping on it so quickly.

 Michael Weylandt

 On Thu, Feb 9, 2012 at 10:40 PM, Jeffrey Ryan jeffrey.r...@lemnica.com
 wrote:
  On Thu, Feb 9, 2012 at 9:00 PM, R. Michael Weylandt
  michael.weyla...@gmail.com wrote:
  It looks like you need to wrap coredata() because some funny
  arithmetic is happening when the xts-ness is preserved.
 
  e.g.
 
  findPeaks(coredata(Ad(SPY)), 5)
 
  But this is perhaps a less-than-desirable feature. I'll patch it and
  send it to Josh.
 
  Proper procedure is indeed to blame Josh for all undesirable
  functionality, even in code he didn't write ;-)
 
  Patched in R-forge rev 577. Thanks.
 
  Jeff
 
  Michael
 
  On Thu, Feb 9, 2012 at 9:56 PM, Michael comtech@gmail.com wrote:
   Hi all,
 
  I am having trouble using the function findPeaks:
 
  tickers=SPY
 
  data *-* new.env()
 
  getSymbols(tickers, src = 'yahoo', from = '1970-01-01', env = data,
  auto.assign = T)
 
  p=findPeaks(data$SPY[, 6], 5)
 
  plot(data$SPY[, 6], type=l)
 
  points(p, data$SPY[, 6][p])
 
  My goal is to implement a trailing-stop on a buy-and-hold strategy
  using
  findPeaks...
 
  I wanted to detect whenever SPY falls 5 points from the local peak...
 
  The above example failed in finding the peaks (p == NULL).
 
  Am I missing anything here?
 
  Thanks a lot!
 
         [[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@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.
 
 
 
  --
  Jeffrey Ryan
  jeffrey.r...@lemnica.com
 
  www.lemnica.com
  www.esotericR.com
 
  R/Finance 2012: Applied Finance with R
  www.RinFinance.com
 
  See you in Chicago

 ___
 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] using findPeaks in designing railing-stops?

2012-02-16 Thread R. Michael Weylandt
Noperhaps you misunderstand what the threshold means? It means
the point of interest has to be x greater than its neighbor, not the
amount by which it has to exceed the valley. If you look in the
neighborhood of ~55:65 (the next peak on your graph) you'll see no
point is that far above its predecessor so there's no peak (so to
speak). Type findPeaks without parentheses and try to understand the
code used and the implicit definition of what a peak is. There's also
a lag convention you should be aware of.

What do you mean you cannot change the number 5?

Michael

On Thu, Feb 16, 2012 at 10:18 AM, Luna lunamoonm...@gmail.com wrote:
 But using my eye from the plot it should have more local peaks even with
 tolerance 5... no?

 I cannot change the number 5

 On Thu, Feb 16, 2012 at 9:17 AM, R. Michael Weylandt
 michael.weyla...@gmail.com wrote:

 You'll get more if you lower your threshold value (the 5)

 Michael

 On Thu, Feb 16, 2012 at 10:13 AM, Luna lunamoonm...@gmail.com wrote:
  Hi friends,
 
  Thanks for your help!
 
  I just did a new test:
 
  aa=100:1
  bb=sin(aa/3)
  cc=aa*bb
  plot(cc, type=l)
  p=findPeaks(cc, 5)
  points(p, cc[p])
  points(p, cc[p])
 
 
 
  p
 
  [1] 3 22 41
 
 
 
  It only picks up 3 peaks, which is obviously wrong, am I correct?
 
  Thanks a lot!
 
  On Thu, Feb 9, 2012 at 9:55 PM, R. Michael Weylandt
  michael.weyla...@gmail.com wrote:
 
  Happy to follow procedure.
 
  Thanks for jumping on it so quickly.
 
  Michael Weylandt
 
  On Thu, Feb 9, 2012 at 10:40 PM, Jeffrey Ryan
  jeffrey.r...@lemnica.com
  wrote:
   On Thu, Feb 9, 2012 at 9:00 PM, R. Michael Weylandt
   michael.weyla...@gmail.com wrote:
   It looks like you need to wrap coredata() because some funny
   arithmetic is happening when the xts-ness is preserved.
  
   e.g.
  
   findPeaks(coredata(Ad(SPY)), 5)
  
   But this is perhaps a less-than-desirable feature. I'll patch it and
   send it to Josh.
  
   Proper procedure is indeed to blame Josh for all undesirable
   functionality, even in code he didn't write ;-)
  
   Patched in R-forge rev 577. Thanks.
  
   Jeff
  
   Michael
  
   On Thu, Feb 9, 2012 at 9:56 PM, Michael comtech@gmail.com
   wrote:
    Hi all,
  
   I am having trouble using the function findPeaks:
  
   tickers=SPY
  
   data *-* new.env()
  
   getSymbols(tickers, src = 'yahoo', from = '1970-01-01', env = data,
   auto.assign = T)
  
   p=findPeaks(data$SPY[, 6], 5)
  
   plot(data$SPY[, 6], type=l)
  
   points(p, data$SPY[, 6][p])
  
   My goal is to implement a trailing-stop on a buy-and-hold strategy
   using
   findPeaks...
  
   I wanted to detect whenever SPY falls 5 points from the local
   peak...
  
   The above example failed in finding the peaks (p == NULL).
  
   Am I missing anything here?
  
   Thanks a lot!
  
          [[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@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.
  
  
  
   --
   Jeffrey Ryan
   jeffrey.r...@lemnica.com
  
   www.lemnica.com
   www.esotericR.com
  
   R/Finance 2012: Applied Finance with R
   www.RinFinance.com
  
   See you in Chicago
 
  ___
  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] using findPeaks in designing railing-stops?

2012-02-09 Thread R. Michael Weylandt
It looks like you need to wrap coredata() because some funny
arithmetic is happening when the xts-ness is preserved.

e.g.

findPeaks(coredata(Ad(SPY)), 5)

But this is perhaps a less-than-desirable feature. I'll patch it and
send it to Josh.

Michael

On Thu, Feb 9, 2012 at 9:56 PM, Michael comtech@gmail.com wrote:
  Hi all,

 I am having trouble using the function findPeaks:

 tickers=SPY

 data *-* new.env()

 getSymbols(tickers, src = 'yahoo', from = '1970-01-01', env = data,
 auto.assign = T)

 p=findPeaks(data$SPY[, 6], 5)

 plot(data$SPY[, 6], type=l)

 points(p, data$SPY[, 6][p])

 My goal is to implement a trailing-stop on a buy-and-hold strategy using
 findPeaks...

 I wanted to detect whenever SPY falls 5 points from the local peak...

 The above example failed in finding the peaks (p == NULL).

 Am I missing anything here?

 Thanks a lot!

        [[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@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] using findPeaks in designing railing-stops?

2012-02-09 Thread R. Michael Weylandt
Happy to follow procedure.

Thanks for jumping on it so quickly.

Michael Weylandt

On Thu, Feb 9, 2012 at 10:40 PM, Jeffrey Ryan jeffrey.r...@lemnica.com wrote:
 On Thu, Feb 9, 2012 at 9:00 PM, R. Michael Weylandt
 michael.weyla...@gmail.com wrote:
 It looks like you need to wrap coredata() because some funny
 arithmetic is happening when the xts-ness is preserved.

 e.g.

 findPeaks(coredata(Ad(SPY)), 5)

 But this is perhaps a less-than-desirable feature. I'll patch it and
 send it to Josh.

 Proper procedure is indeed to blame Josh for all undesirable
 functionality, even in code he didn't write ;-)

 Patched in R-forge rev 577. Thanks.

 Jeff

 Michael

 On Thu, Feb 9, 2012 at 9:56 PM, Michael comtech@gmail.com wrote:
  Hi all,

 I am having trouble using the function findPeaks:

 tickers=SPY

 data *-* new.env()

 getSymbols(tickers, src = 'yahoo', from = '1970-01-01', env = data,
 auto.assign = T)

 p=findPeaks(data$SPY[, 6], 5)

 plot(data$SPY[, 6], type=l)

 points(p, data$SPY[, 6][p])

 My goal is to implement a trailing-stop on a buy-and-hold strategy using
 findPeaks...

 I wanted to detect whenever SPY falls 5 points from the local peak...

 The above example failed in finding the peaks (p == NULL).

 Am I missing anything here?

 Thanks a lot!

        [[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@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.



 --
 Jeffrey Ryan
 jeffrey.r...@lemnica.com

 www.lemnica.com
 www.esotericR.com

 R/Finance 2012: Applied Finance with R
 www.RinFinance.com

 See you in Chicago

___
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 do I intersecttwo time series?

2012-01-24 Thread R. Michael Weylandt
The OP's confusion might also stem from the fact that

?merge

doesn't actually lead to

 ?merge.xts

which would have been much more helpful here.

I think it's a suboptimal consequence of method dispatch that there
are no pointers to documented methods...I'll try to work up a small
patch to `?` and put it on Rd to see if it gets any traction.

Perhaps something like

 ?merge # pops up merge's help page, but also cat()s
There are documented methods for:
merge.xts
merge.dendrogram
merge.zoo
You may wish to check these as well.

Or something like that. Feel free to send me thoughts off-list

Michael

On Tue, Jan 24, 2012 at 10:10 AM, G See gsee...@gmail.com wrote:
 Well, it was just a guess since it seemed as if you didn't try it.
 Maybe next time you could show us what you tried and why it didn't do
 what you wanted.  Then, provide a sample dataset and desired outcome.
 Those types of questions are much easier for us to answer, which is
 why it is suggested here: http://www.r-project.org/posting-guide.html

 Thanks for your understanding,
 Garrett

 On Tue, Jan 24, 2012 at 8:55 AM, Michael comtech@gmail.com wrote:
 Hi G See,

 Thanks but I have been watching ?merge hundreds of times...

 It's very terse and there are lots of hidden tricks...

 Thanks a lot any way!

 And thanks a lot for all the help folks!

 On Tue, Jan 24, 2012 at 2:53 AM, G See gsee...@gmail.com wrote:

 Michael,

 Maybe you do not realize that when someone writes a word with a
 question mark in front of it, it means that you should look at the
 help page for that function.  For example, if you type ?merge in an
 R terminal (without the quotes) it will open the help page for that
 function.  Another option is to type help(merge)

 Hope this makes it easier for you to find answers in the future,
 Garrett

 On Mon, Jan 23, 2012 at 5:53 PM, Michael comtech@gmail.com wrote:
  Oh I forgot one thing:
 
  xts_one and xts_two are not neccessarily the same length...
 
  In effect, I was looking for a time series set-operation intersect
 
  Thank you!
 
  On Mon, Jan 23, 2012 at 12:35 PM, Jun Zhu junzh...@yahoo.com wrote:
 
    Assume you are testing the first column
 
  l_result - ifelse(l_xts_one[,1] == l_xts_two[,1], l_xts_one[,1],NA)
 
 
 
 
  --- On *Mon, 1/23/12, Brian G. Peterson br...@braverock.com* wrote:
 
 
  From: Brian G. Peterson br...@braverock.com
  Subject: Re: [R-SIG-Finance] How do I intersecttwo time series?
  To: Michael comtech@gmail.com
  Cc: r-sig-finance r-sig-fina...@stat.math.ethz.ch
  Date: Monday, January 23, 2012, 8:25 AM
 
    On Mon, 2012-01-23 at 08:06 -0600, Michael wrote:
   I have two xts objects...and they have coulmns with the same names.ie
   their column represent the same variables.
  
   The only difference is that the values in the rows may be different.
   At
   precisely the same timestamps the observations can be exactly the
   same.
  
   How do I find the intersection of these two time series ie the rows
   where
   the observations are identical including the time stamps?
  
   How do I find intersection where a few specified coulmns are
   identical
   including the time stamps?
  
   Thanks a lot!
 
  ?merge
 
  ?ifelse
 
  merge is amply covered in the xts documentation, and ifelse is covered
  in many write-ups on vectorized operations in R.
 
  ___
 
  R-SIG-Finance@r-project.orghttp://mc/compose?to=R-SIG-Finance@r-project.orgmailing
  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.
 
 
 
         [[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@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] Removing a row in an xts object in place?

2012-01-21 Thread R. Michael Weylandt
Short answer: I'm pretty sure it's impossible to remove elements in place.

Medium answer: If you are worried about memory usage, I might suggest
using the data.table() package. It's pretty efficient for most things,
though you'll loose xts specific time-functionality. You might be able
to wedge time stamps in though smart use of the keys. (I'm not
familiar enough with the package to say for sure.) Pondering aloud,
merging data.table and xts functionalities sounds like an
exceptionally fun project and a new package idea. I might do that when
life gets 80% less busy

Long answer: it *may* be possible using the .Call() interface and
playing very deeply with the internals (I haven't looked at them
recently enough to say one way or the other) but it's exceptionally
dangerous since R uses copy-on-change semantics. If you are determined
enough, I think I can see a way that it's doable, but it's such a
non-R thing to do that I don't think you'll get much help.

Michael

On Sat, Jan 21, 2012 at 7:13 PM, Michael comtech@gmail.com wrote:
 I hope I can do:

 x[ !Conditions, ] = NULL

 or something like this...

 On Sat, Jan 21, 2012 at 6:13 PM, Michael comtech@gmail.com wrote:

 Hi all,

 How do I remove a row in an xts object and the operation has to be in
 place?

 I knew I can do

 y=x[ Conditions, ]

 where x is the original time series xts object...

 But if x and y both are huge,

 this operation can consume a lot of memory...

 Any thoughts?

 Thanks a lot!




        [[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@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] question about time-stamp comparison?

2012-01-20 Thread R. Michael Weylandt
storage.mode(as.POSIXct(123757, origin = 1970-01-01)) # POSIXct
sapply(strptime(1970-01-01 03:43:32.345, format = %Y-%m-%d
%H:%M:%OS), storage.mode) #POSIXlt

They are numeric, not character.

Michael Weylandt

On Fri, Jan 20, 2012 at 10:49 AM, Michael comtech@gmail.com wrote:
  Good morning all!

 Just wanted to confirm - how do I compare two date-time stamps in the
 following format?

 I tried the following and they seem to work fine...

 But I am not so sure whether these comparisons are treated as char strings
 and based on alphabetic ordering, or actually R is smart enough to
 auto-recognize these strings and compare based on calendar ordering?

 Or maybe calendar ordering is coincidental with alphabetic ordering? I am
 trying to conceive a counter-example...


 To make it absolutely correct, maybe I should use


 strptime(date-time-stamp1, %Y-%m-%d %H:%M:%OS)

 vs.

 strptime(date-time-stamp2, %Y-%m-%d %H:%M:%OS)

 ? Will that be definitely correct?

 Thanks a lot!

 2011-09-20 12:01:33.386168 2011-09-20 12:01:33.386169

 [1] TRUE

 2011-09-20 12:01:33.386168 2012-09-20 12:01:32.386169

 [1] TRUE

        [[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@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] question about time-stamp comparison?

2012-01-20 Thread R. Michael Weylandt
I can't immediately come up with an counter-example where lexical
ordering and calendar ordering are different if you have a consistent
amount of digits, but wouldn't it just be easier (and more
computationally efficient) to convert your character to a POSIXct
before doing the comparison?

Or (if you actually read the xts documentation!) there's a (much) better trick:

? `[.xts`
tmp1[::20110920 12:01:33.386168]

Michael Weylandt

On Fri, Jan 20, 2012 at 11:32 AM, Michael comtech@gmail.com wrote:
 These are char strings:
 2011-09-20 12:01:33.386168
 In fact,
 I want to do subsetting of xts objects:
 lets say tmp1 is an xts object:
 tmp2 = tmp1[index(tmp1) 2011-09-20 12:01:33.386168]
 Will it work?
 Thanks again!

 On Fri, Jan 20, 2012 at 10:02 AM, Brian G. Peterson 
 br...@braverock.comwrote:

 On Fri, 2012-01-20 at 09:49 -0600, Michael wrote:
  Good morning all!
 
  Just wanted to confirm - how do I compare two date-time stamps in the
  following format?

   2011-09-20 12:01:33.386168 2011-09-20 12:01:33.386169
 
  [1] TRUE

 You don't tell us what class those timestamps are.

 Assuming you're using xts objects for your time series (which you should
 be), then the index is POSIXct, and   = , etc are defined for the
 POSIXct class.

 It won't care about the string format.

 --
 Brian G. Peterson
 http://braverock.com/brian/
 Ph: 773-459-4973
 IM: bgpbraverock



        [[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@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] question about time-stamp comparison?

2012-01-20 Thread R. Michael Weylandt
In addition to what Brian said:

But converting to POSIXct I need to supply an origin something like
1970-01-01 which is weird and unintuitive...

Simply not true...
as.POSIXct(1985-01-01, format = %Y-%m-%d) # Works just fine

Going out on a limb, it sounds like your troubles are coming from not
understanding what factors are or how they are stored internally in R.

Michael

On Fri, Jan 20, 2012 at 3:17 PM, Michael comtech@gmail.com wrote:
 But converting to POSIXct I need to supply an origin something like
 1970-01-01 which is weird and unintuitive...

 And what if I am not dealing with xts/zoo objects?

 For example,


 ss=tt

 [with(tt, order(DateTimeStamps)),]


 where tt is a data.frame read from csv file.

 My goal was to order the rows of the data.frame based on the DateTimeStamps
 (in the previously discussed formatting)... I found the tt$DateTimeStamps is
 actually factor ...

 So my question is: ordering them like the one I did above,

 is it correct?

 Thanks a lot!




 On Fri, Jan 20, 2012 at 10:44 AM, R. Michael Weylandt
 michael.weyla...@gmail.com wrote:

 I can't immediately come up with an counter-example where lexical
 ordering and calendar ordering are different if you have a consistent
 amount of digits, but wouldn't it just be easier (and more
 computationally efficient) to convert your character to a POSIXct
 before doing the comparison?

 Or (if you actually read the xts documentation!) there's a (much) better
 trick:

 ? `[.xts`
 tmp1[::20110920 12:01:33.386168]

 Michael Weylandt

 On Fri, Jan 20, 2012 at 11:32 AM, Michael comtech@gmail.com wrote:
  These are char strings:
  2011-09-20 12:01:33.386168
  In fact,
  I want to do subsetting of xts objects:
  lets say tmp1 is an xts object:
  tmp2 = tmp1[index(tmp1) 2011-09-20 12:01:33.386168]
  Will it work?
  Thanks again!
 
  On Fri, Jan 20, 2012 at 10:02 AM, Brian G. Peterson
  br...@braverock.comwrote:
 
  On Fri, 2012-01-20 at 09:49 -0600, Michael wrote:
   Good morning all!
  
   Just wanted to confirm - how do I compare two date-time stamps in the
   following format?
 
2011-09-20 12:01:33.386168 2011-09-20 12:01:33.386169
  
   [1] TRUE
 
  You don't tell us what class those timestamps are.
 
  Assuming you're using xts objects for your time series (which you
  should
  be), then the index is POSIXct, and   = , etc are defined for the
  POSIXct class.
 
  It won't care about the string format.
 
  --
  Brian G. Peterson
  http://braverock.com/brian/
  Ph: 773-459-4973
  IM: bgpbraverock
 
 
 
         [[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@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 do I bin data into 5 min bins and compute the medians in the bins?

2012-01-19 Thread R. Michael Weylandt
Use something like:

period.apply(X, endpoints(X, minutes, 5), median)

Michael Weylandt


On Thu, Jan 19, 2012 at 1:54 PM, Michael comtech@gmail.com wrote:
 I have also searched crazily... and read into both xts and zoo... but
 couldn't find a solution...

 My questions are:

 1. How to handle the .082225 part in xts and zoo?

 2. The xts/zoo interval arithmatic only handles OHLC of an interval, not
 median of an interval, right?

 Thanks a lot!

 On Thu, Jan 19, 2012 at 12:51 PM, Jeffrey Ryan 
 jeffrey.r...@lemnica.comwrote:

 Use a time series class.  This has all been solved thousands of times
 before in private and on the lists.

 Jeff

 On Thu, Jan 19, 2012 at 12:43 PM, Michael comtech@gmail.com wrote:
  Hi all,
 
  I have data in the following format:
 
  How do I bucket the data into 5 min bins and then compute the median of
  quotes in the bins?
 
  Currently the DateTimeStamps are factors in the data frame and I
  ordered the rows according to these DateTimeStamps
 
  Thanks a lot!
 
  Bid           Offer      DateTimeStamps
 
  46.00       46.10     2006-06-16 12:12:00.082225
 
         [[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.



 --
 Jeffrey Ryan
 jeffrey.r...@lemnica.com

 www.lemnica.com
 www.esotericR.com http://www.esotericr.com/


        [[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@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] data manipulation to for quantmod function

2012-01-11 Thread R. Michael Weylandt michael.weyla...@gmail.com
If you have tick/high(-ish) frequency data, you'll have to transform it to 
OHLC; there's no way to keep the frequency you have and to make an OHLC object 
out of it, since those metrics are by definition aggregates. The easiest way to 
do so is to read it in as an xts object then use one of the to.period() 
functions. 

Michael

On Jan 11, 2012, at 4:22 AM, julien cuisinier j_cuisin...@hotmail.com wrote:

 
 Hi,
 
 
 Always nice to have a name on those email. 
 
 quantmod format is xts format, you might try as.xts but i guess you will 
 need to give it all the needed columns to fit the XTS object
 
 OR use quantmod getSymbols function to download the data straight into the 
 right format if possible
 
 
 HTH,
 Julien
 
 
 
 From: ktdservice...@gmail.com
 To: r-sig-finance@r-project.org
 Date: Tue, 10 Jan 2012 22:30:33 -0600
 Subject: [R-SIG-Finance] data manipulation to for quantmod function
 
 I need some help with data manipulation so I can use quantmod.
 
 I have a data frame with three columns: time, price, volume.  This  
 data frame is all the trades of a product for about 15 days.  What I  
 want to do is modify the data so that it is in a format that quantmod  
 can read.  Quantmod needs data to be in columns: Open, High, Low,  
 Close, and Volume.
 
 I wanted to see if anyone had some suggestions to easily modify the  
 data into the quantmod format.
 
 Quantmod: http://www.quantmod.com/
 Data (.csv, 21.67KB) can be downloaded at 
 http://www.mediafire.com/?fyunce685ekuyo3
[[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.
 
[[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@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] data manipulation to for quantmod function

2012-01-11 Thread R. Michael Weylandt michael.weyla...@gmail.com
Brian,

You are (of course) absolutely right about quantmod/quantstrat functionality - 
and you, Jeff, Josh, Dirk  anyone else I'm forgetting can't be thanked enough 
for your work. I was only directing the OP on how to get OHLC as he asked but 
he should be rightly informed that quantmod easily handles tick data. 

Michael

On Jan 11, 2012, at 10:10 AM, Brian G. Peterson br...@braverock.com wrote:

 On Wed, 2012-01-11 at 09:49 -0500, R. Michael Weylandt wrote:
 If you have tick/high(-ish) frequency data, you'll have to 
 transform it to OHLC; there's no way to keep the frequency 
 you have and to make an OHLC object out of it, since those 
 metrics are by definition aggregates. The easiest way to 
 do so is to read it in as an xts object then use one of the to.period() 
 functions. 
 
 
 Whoa.  Not (Completely) True.
 
 getSymbols, xts, and quantmod are perfectly comfortable with tick data
 of millions and even billions of rows.
 
 chart_Series and chartSeries have built-in charting mechanisms for OHLC
 data, and you may wish to transform higher freqency data to lower
 frequency OHLC before charting, but this is by no means required.
 
 Some indicator/TA methods also require OHLC data or equivalent, but many
 will work fine on univariate series or on tick.
 
 To the original poster's question, I usually use read.table or read.csv
 and then as.xts to convert to an xts object.  How to do these steps has
 been covered many times on this list, so please search the archives.
 
 With the linked csv file in the original poster's messages,
 see ?strftime and the list archives for information on formatting.
 
 Regards,
 
   - Brian
 
 
 -- 
 Brian G. Peterson
 http://braverock.com/brian/
 Ph: 773-459-4973
 IM: bgpbraverock
 
 On Jan 11, 2012, at 4:22 AM, julien cuisinier j_cuisin...@hotmail.com 
 wrote:
 
 
 Hi,
 
 
 Always nice to have a name on those email. 
 
 quantmod format is xts format, you might try as.xts but i guess you will 
 need to give it all the needed columns to fit the XTS object
 
 OR use quantmod getSymbols function to download the data straight into the 
 right format if possible
 
 
 HTH,
 Julien
 
 
 
 From: ktdservice...@gmail.com
 To: r-sig-finance@r-project.org
 Date: Tue, 10 Jan 2012 22:30:33 -0600
 Subject: [R-SIG-Finance] data manipulation to for quantmod function
 
 I need some help with data manipulation so I can use quantmod.
 
 I have a data frame with three columns: time, price, volume.  This  
 data frame is all the trades of a product for about 15 days.  What I  
 want to do is modify the data so that it is in a format that quantmod  
 can read.  Quantmod needs data to be in columns: Open, High, Low,  
 Close, and Volume.
 
 I wanted to see if anyone had some suggestions to easily modify the  
 data into the quantmod format.
 
 Quantmod: http://www.quantmod.com/
 Data (.csv, 21.67KB) can be downloaded at 
 http://www.mediafire.com/?fyunce685ekuyo3
   [[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] Where is my hedge ratio when testing for cointegration with Phillips-Ouliaris test?

2012-01-06 Thread R. Michael Weylandt
Slightly beyond the scope of your question, but this might be of
interest: http://quanttrader.info/public/betterHedgeRatios.pdf

Michael

On Fri, Jan 6, 2012 at 2:08 PM, Mark Breman breman.m...@gmail.com wrote:
 Hello List,

 I'm testing multivariate timeseries for cointegration using the
 Phillips-Ouliaris test from package urca (ca.po) i.e:

 # start example
 
 library(quantmod)
 library(urca)

 getSymbols(c('GLD', 'GDX'), from=2006-01-01)
 [1] GLD GDX

 prices=na.omit(cbind(Ad(GLD), Ad(GDX)))

 summary(ca.po(coredata(prices), type='Pz'))

 
 # Phillips and Ouliaris Unit Root Test #
 

 Test of type Pz
 detrending of series none

 Response GLD.Adjusted :

 Call:
 lm(formula = GLD.Adjusted ~ zr - 1)

 Residuals:
    Min      1Q  Median      3Q     Max
 -9.3422 -0.6212  0.0540  0.7783  8.6275

 Coefficients:
                Estimate Std. Error t value Pr(|t|)
 zrGLD.Adjusted 1.0004786  0.0020531 487.295   2e-16 ***
 zrGDX.Adjusted 0.0001917  0.0047246   0.041    0.968
 ---
 Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

 Residual standard error: 1.44 on 1414 degrees of freedom
 Multiple R-squared: 0.9998, Adjusted R-squared: 0.9998
 F-statistic: 3.78e+06 on 2 and 1414 DF,  p-value:  2.2e-16


 Response GDX.Adjusted :

 Call:
 lm(formula = GDX.Adjusted ~ zr - 1)

 Residuals:
    Min      1Q  Median      3Q     Max
 -5.0164 -0.6497  0.0160  0.7325  4.7142

 Coefficients:
               Estimate Std. Error t value Pr(|t|)
 zrGLD.Adjusted 0.001727   0.001608   1.074    0.283
 zrGDX.Adjusted 0.996047   0.003701 269.116   2e-16 ***
 ---
 Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

 Residual standard error: 1.128 on 1414 degrees of freedom
 Multiple R-squared: 0.9994, Adjusted R-squared: 0.9994
 F-statistic: 1.162e+06 on 2 and 1414 DF,  p-value:  2.2e-16



 Value of test-statistic is: 11.1864

 Critical values of Pz are:
                  10pct    5pct    1pct
 critical values 33.9267 40.8217 55.1911

 ## end example 

 Now my question is where is my hedge ratio? The estimates (coefficients)
 don't look at all usable.
 Do i have to do a manual OLS regression to get the hedge ratio or is it
 hidden somewhere in the ca.po test results?

 Thanks,

 -Mark-

        [[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@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] msts command in the forecast package?

2011-12-12 Thread R. Michael Weylandt
What version of forecast do you have loaded (use sessionInfo() after
library(forecast) to check)? If it was only uploaded very very
recently, it might not have propagated to your mirror. It should be
3.14.

If your mirrors don't have it built, you might have to download a
source package and do a command line install so you can make sure you
have the right version.

Michael

On Mon, Dec 12, 2011 at 1:40 PM, Michael comtech@gmail.com wrote:
 Oh thx a lot Zachary!

 I would have thought since I just installed the package on Sunday, it
 should be very freshly new/recent!
 But even after I used update.packages() following your advice,

 I am still getting:


 library(forecast)

 ?msts

 No documentation for 'msts' in specified packages and libraries:

 you could try '??msts'




 On Mon, Dec 12, 2011 at 12:30 PM, Zachary Mayer zach.ma...@gmail.comwrote:

 msts was just added to the forecast 
 packagehttp://cran.r-project.org/web/packages/forecast/ChangeLog.
  Make sure you are using version 3.14 by running update.packages()


 2011/12/12 Michael comtech@gmail.com

 Of course loaded...

 I can do auto.arima, etc...

 But just couldn't do msts...

  fit1=auto.arima(as.vector(dDiffPrices))

  msts

 Error: object 'msts' not found


 2011/12/12 Daniel Cegiełka daniel.cegie...@gmail.com

 
 
   2011/12/12 Michael comtech@gmail.com
 
  Hi all,
 
  When I tried to use the msts command in the Forecast package...
 
 
   fcast - msts(as.vector(my data), c(4, 40))
 
  Error: could not find function msts
 
 
  Have you loaded the forecast package?
 
   library(forecast)
 
 
 
 
 
 
 
  What could be the problem? I had made sure that the library(forecast)
  has
  been used...
 
  Thank you!
 
         [[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.
 
 
 

        [[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.




        [[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@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] repeating regression

2011-11-21 Thread R. Michael Weylandt
You can probably specify the problem with model.matrix and use lm.fit
directly, but what's probably even better is to remember that the
slope can be calculated as correlation * std_y / std_x for this simple
case of one independent variable and implement directly . E.g.,
something like

apply(Data, 1, function(x) std(x[6:10])/std(x[1:5]) * cor(x[1:5],x[6:10]))

You can do this even faster by taking x and y to big vectors, taking a
rolling std and cor with length 5, and sampling each 5 steps as well,
but it's after midnight and I'm doing a disastrous OJ project (don't
ask) for school so I can't really think right now.

Michael

On Mon, Nov 21, 2011 at 10:52 PM, Robert A'gata rhelp...@gmail.com wrote:
 Hi,

 I think my problem is a bit mundane but it's quite intriguing. Imagine
 I have a matrix of 10 by 2 million. The first 5 columns are x and the
 last 5 are y values. I have to regress y on x (assume 0 intercept) for
 each row to observe time series of the slope. I am wondering if there
 is any way to speed this calculation up? I tried with apply. But it is
 still slow. Is there any trick I should know? Thank you.

 Robert

 ___
 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] Output of vars package impulse response function

2011-11-08 Thread R. Michael Weylandt
If no one here knows, it may be worth it to contact the package
maintainer directly. See maintainer(vars)

Michael

On Tue, Nov 8, 2011 at 9:44 AM, Richard Saba saba...@charter.net wrote:
 Does anyone know if the  bootstrap  CI intervals generated by the irf()
 function in the  vars  package are bias corrected?



 I posted this on the R-Help website but the only response I got was a
 suggestion to post on this site.

 Thanks,

 Richard Saba


        [[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@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] 3d implied volatility surface

2011-10-26 Thread R. Michael Weylandt
This isn't specifically financial so any follow up is perhaps better
done on the general R-help list, but try demo(persp) to see some
example code that's built in. If I remember correctly, demo(lattice)
also has at least one 3d example.

Michael

On Wed, Oct 26, 2011 at 1:43 PM, financial engineer
fin_e...@hotmail.com wrote:

 hi,

 I'd like to be able to plot a 3-d vol surface using option strike vs. 
 expiration(as yrs to maturity) vs. implied volatility.

 I have the historical trade-date, expiration-date, strike, option price, 
 option symbol, option type, implied vol. etc. data for each option,
 so I ran the following query:
 OpQuotes - dbGetQuery(con,SELECT strike,iv,ytm FROM greeks WHERE 
 trade_date='2011-10-07' AND symbol like 'MCO%'and type='C';)

 I am trying to figure out if I need to convert the above into a list or have 
 individual matrices, or set it up as a seq. Would appreciate some 
 help/direction/suggestion/example code on that.

 I'd like to be able to use persp or lattice to plot this.

 thanks!

        [[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@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] 3d implied volatility surface

2011-10-26 Thread R. Michael Weylandt
Perhaps you should load the lattice package first with
library(lattice)I just confirmed it has 2 3d examples in it.

As to specific formatting advice, I'd usually prefer delta/moneyness
than straight strike if you were preparing the graph for me. Otherwise
there's one very large source of variance unaccounted for in your
graph should you start to compare over different points in time.

Other than that, I don't think there's too much to know beyond the
usual caveats for financial data: smoothing only if appropriate, make
sure prices are clean and correspond to something actionable (i.e.,
make sure you aren't using prints that are just old and discovering
arbitrages).

Michael

On Wed, Oct 26, 2011 at 3:38 PM, financial engineer
fin_e...@hotmail.com wrote:
 thanks for your response, Michael

 I didn't find any demo(lattice) but I did look at the demo(persp). however,
 being new to R, I was trying to get a better understanding of how to
 organize the data.

 I can post to the general list, but I figured since the folks on the
 financial side would understand the implied vol reference, I could get some
 good guidance faster  and perhaps any additional suggestions, if similar
 stuff has been done by the others :-)

 Best,
 BA

 From: michael.weyla...@gmail.com
 Date: Wed, 26 Oct 2011 15:26:53 -0400
 Subject: Re: [R-SIG-Finance] 3d implied volatility surface
 To: fin_e...@hotmail.com
 CC: r-sig-finance@r-project.org

 This isn't specifically financial so any follow up is perhaps better
 done on the general R-help list, but try demo(persp) to see some
 example code that's built in. If I remember correctly, demo(lattice)
 also has at least one 3d example.

 Michael

 On Wed, Oct 26, 2011 at 1:43 PM, financial engineer
 fin_e...@hotmail.com wrote:
 
  hi,
 
  I'd like to be able to plot a 3-d vol surface using option strike vs.
  expiration(as yrs to maturity) vs. implied volatility.
 
  I have the historical trade-date, expiration-date, strike, option price,
  option symbol, option type, implied vol. etc. data for each option,
  so I ran the following query:
  OpQuotes - dbGetQuery(con,SELECT strike,iv,ytm FROM greeks WHERE
  trade_date='2011-10-07' AND symbol like 'MCO%'and type='C';)
 
  I am trying to figure out if I need to convert the above into a list or
  have individual matrices, or set it up as a seq. Would appreciate some
  help/direction/suggestion/example code on that.
 
  I'd like to be able to use persp or lattice to plot this.
 
  thanks!
 
         [[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@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] 3d implied volatility surface

2011-10-26 Thread R. Michael Weylandt
Another thought, you might want to look at the rgl package: it allows
for interactive 3d graphics (though with a little bit of work) which
can add a potentially useful level of exploratory power. I haven't
used it much but would also be interested in learning more: if you'd
be interested, I'd love to do a little off-list back and forth to work
something up -- perhaps using freely available data from
quantmod::getOptionChain(, NULL) -- which we could open-source.

M

On Wed, Oct 26, 2011 at 4:35 PM, financial engineer
fin_e...@hotmail.com wrote:
 thanks Michael,

 ...appreciate the suggestions.

 cheers,
 BA

 From: michael.weyla...@gmail.com
 Date: Wed, 26 Oct 2011 16:21:40 -0400
 Subject: Re: [R-SIG-Finance] 3d implied volatility surface
 To: fin_e...@hotmail.com
 CC: r-sig-finance@r-project.org

 Perhaps you should load the lattice package first with
 library(lattice)I just confirmed it has 2 3d examples in it.

 As to specific formatting advice, I'd usually prefer delta/moneyness
 than straight strike if you were preparing the graph for me. Otherwise
 there's one very large source of variance unaccounted for in your
 graph should you start to compare over different points in time.

 Other than that, I don't think there's too much to know beyond the
 usual caveats for financial data: smoothing only if appropriate, make
 sure prices are clean and correspond to something actionable (i.e.,
 make sure you aren't using prints that are just old and discovering
 arbitrages).

 Michael

 On Wed, Oct 26, 2011 at 3:38 PM, financial engineer
 fin_e...@hotmail.com wrote:
  thanks for your response, Michael
 
  I didn't find any demo(lattice) but I did look at the demo(persp).
  however,
  being new to R, I was trying to get a better understanding of how to
  organize the data.
 
  I can post to the general list, but I figured since the folks on the
  financial side would understand the implied vol reference, I could get
  some
  good guidance faster  and perhaps any additional suggestions, if similar
  stuff has been done by the others :-)
 
  Best,
  BA
 
  From: michael.weyla...@gmail.com
  Date: Wed, 26 Oct 2011 15:26:53 -0400
  Subject: Re: [R-SIG-Finance] 3d implied volatility surface
  To: fin_e...@hotmail.com
  CC: r-sig-finance@r-project.org
 
  This isn't specifically financial so any follow up is perhaps better
  done on the general R-help list, but try demo(persp) to see some
  example code that's built in. If I remember correctly, demo(lattice)
  also has at least one 3d example.
 
  Michael
 
  On Wed, Oct 26, 2011 at 1:43 PM, financial engineer
  fin_e...@hotmail.com wrote:
  
   hi,
  
   I'd like to be able to plot a 3-d vol surface using option strike vs.
   expiration(as yrs to maturity) vs. implied volatility.
  
   I have the historical trade-date, expiration-date, strike, option
   price,
   option symbol, option type, implied vol. etc. data for each option,
   so I ran the following query:
   OpQuotes - dbGetQuery(con,SELECT strike,iv,ytm FROM greeks WHERE
   trade_date='2011-10-07' AND symbol like 'MCO%'and type='C';)
  
   I am trying to figure out if I need to convert the above into a list
   or
   have individual matrices, or set it up as a seq. Would appreciate
   some
   help/direction/suggestion/example code on that.
  
   I'd like to be able to use persp or lattice to plot this.
  
   thanks!
  
          [[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@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] getSymbols {quantmod}: load data from world markets

2011-10-25 Thread R. Michael Weylandt
library(quantmod)
getSymbols(CBA.AX)

Hope that helps,

Michael

On Tue, Oct 25, 2011 at 6:13 AM, Fan sfan.st...@gmail.com wrote:
 Hi there,
 I am trying to load data using getSymbols {quantmod}, however, it looks to
 me this function can only load data from US exchange, since I trade stocks
 in ASX, so I tried to use symbols like ASX:CBA and also tried to set up an
 exchange, but all failed, so I wonder if it is possible to use this function
 to load data from world markets? If not, any other functions existing to do
 the work?
 Thanks, Fan

        [[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@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] PerformanceAnalytics package

2011-10-24 Thread R. Michael Weylandt
I don't know if Josh/Brian/Jeff got you an answer on this, but on my
version of PerformanceAnalytics (1.0.3.2), these different VaR methods
seem to have been collapsed into VaR with different methods available.
Perhaps your reference is for an older version of the package in which
these have been deprecated.

I also don't see table.MonthlyReturns() only table.AnnualizedReturns()
available. I believe I read somewhere that the package is designed
with monthly data in mind (though most of the analytical techniques
are scale invariant) so it's perhaps not surprising that there's no
aggregation tool to monthly.

Michael

On Sun, Oct 23, 2011 at 3:56 PM, financial engineer
fin_e...@hotmail.com wrote:

 hi,

 As I continue working through the functions with my time series of daily 
 returns(R.MCO), most of the functions have been working fine, except the 
 following(so far):

 VaR.mean.MCO=VaR.mean(R.MCO,p=0.95)
 Error: could not find function VaR.mean
 VaR.traditional.MCO=VaR.traditional(R.MCO,p=0.95)
 Error: could not find function VaR.traditional
 modifiedVaR.MCO=modifiedVaR(R.MCO,p=0.99)
 Error: could not find function modifiedVaR
 table.MonthlyReturns(R.MCO,ci=0.95,digits=4)
 Error: could not find function table.MonthlyReturns

 Can you please let me know how I can fix these errors, as I am keen to use 
 these functions for computing the daily VaR and also generate tables of 
 monthly returns.

 Thanks!

 Date: Sat, 22 Oct 2011 17:20:04 -0500
 From: br...@braverock.com
 To: fin_e...@hotmail.com
 CC: r-sig-finance@r-project.org
 Subject: Re: [R-SIG-Finance] PerformanceAnalytics package

 This is most likely a conflict between xts/zoo and the various f* Rmetrics
 packages
 (or possibly the timeSeries package from Rmetrics).  You'll like see a
 warning that function 'time' is being masked.

 the zoo/xts and Rmetrics teams are aware of the issue, and are trying to
 sort out a modle that will avoid trhe conflict.

 For now, the most likely way for you to avoid this issue is to not load
 the Rmetrics packages, or to load zoo/xts *after* you've loaded any
 Rmetrics packages you need.

 On Sat, 22 Oct 2011 18:10:15 -0400, financial engineer
 fin_e...@hotmail.com wrote:
  hi,
 
 
 
  I've been trying to familiarize myself with the PerformanceAnalytics
  package.
 
 
 
  As I go through the examples (in the attached file), I faced a hiccup.
 
  When I run the following code, it only prints the first chart
 
 
 
  charts.PerformanceSummary(managers[, c(manager.col,
 
  indexes.cols)],colorset = rich6equal, lwd = 2, ylog = TRUE)
 
 
 
  and gives me the following error:
 
 
  Error in UseMethod(time-) :
 
    no applicable method for 'time-' applied to an object of class
 
  c('xts', 'zoo')
 
 
 
  Can you please let me know how I can fix it.
 
 
 
  Thanks!

 --
 Brian G. Peterson
 http://braverock.com/brian/
 Ph: 773-459-4973
 IM: bgpbraverock

        [[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@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] VaR and ES in PerformanceAnalytics

2011-10-24 Thread R. Michael Weylandt
I don't have the OP's data, but, just for the record, the same
phenomenon can be seen with SPY returns.

library(quantmod)
getSymbols(SPY)
R = na.omit(ROC(Ad(SPY)))

identical((ES(R, p = 0.99)-VaR(R, p = 0.99))[1,1],0)
TRUE

And thanks for the insightful explanation. Do you happen to have the
Jorion reference handy? If not, no worries, I can hunt it down.

Michael

On Mon, Oct 24, 2011 at 2:11 PM, Brian G. Peterson br...@braverock.com wrote:
 On Mon, 2011-10-24 at 11:49 -0400, financial engineer wrote:
 I ran the VaR and ES using the below, and am trying to understand why the 
 VaR(99%)
 is exactly equal to ES(99%). Is that how it is supposed to be.

 You didn't include your data to make this reproducible, so I need to
 speak in generalities.

 From the documentation:

  Modified expected shortfall should always be higher than modified
  Value at Risk. Due to estimation problems, this might not always
  be the case. Set operational = TRUE to replace modified ES with
  modified VaR in the (exceptional) case where the modified ES is
  smaller than modified VaR.

 If you're seeing this, I expect your data is highly skewed and/or
 kurtotic.

 Cornish Fisher Modified VaR can exhibit what Jorion referred to as
 'wrong tailed  behavior', migrating rapidly to zero or infinity.  While
 this is a problem, it is only a problem if you aren't paying attention.
 I use this as an indicator that I either don't have enough data or that
 my data is likely unreliable.  It is also often an indication that your
 preferred probability (99%) is too high for a reliable answer.

 Look at function chart.VaRSensitivity to see how the VaR and ES play out
 at different probability thresholds.

 The good news is that it's really obvious when this happens, you can
 easily see it in the chart, and tell where you don't and probably
 shouldn't have confidence in your estimating powers.

 Just because some other methodologies will give you an answer that
 claims to be precise doesn't mean that they are truly doing so.  Many
 many people have written about the pitfalls of looking for too high a
 precision in VaR/ES estimates.  I, for example, find 95% to be a good
 number on daily return data, as this indicates a 1 in 20 'bad day', so
 you can interpret the 95% ES as approximately your 'average one really
 bad day a month' on daily return data.  I have a colleague who uses 92%
 on monthly return data to estimate the 'average really bad month once a
 year' on his portfolios.

 I prefer 'approximately correct' to 'precisely wrong' statistics.

 I could speak in more specifics about the characteristics of your data
 with a reproducible example.

 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@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] Open to Close to Open data transformation (quantmod, xts and possibly zoo)

2011-09-23 Thread R. Michael Weylandt
There's no automatic function for this sort of request that I know of, but
it shouldn't be hard to write one:

require(quantmod)
getSymbols('^GSPC',from='1990-01-01')

CollapseOpCl - function(P){
stopifnot(all(has.Op(P),has.Cl(P)))
O - Op(P); time(O) - as.POSIXlt(time(O)); time(O)$hour - 9;
time(O)$min - 30
C - Cl(P); time(C) - as.POSIXlt(time(C)); time(C)$hour - 16;
time(C)$min - 00
ans - rbind(O,C);
names(ans) - unlist(strsplit(names(O),\\.))[1]
ans
}
plot(Out - CollapseOpCl(GSPC))

It's a little brute force, but it seems to work. More generally, if you just
use rbind(Op(P),Cl(P)) you can get an xts with non-unique time stamps, but
you loose some info that way.

Hope this helps,

Michael

On Fri, Sep 23, 2011 at 5:50 AM, Costas Vorlow costas.vor...@gmail.comwrote:

 Hello,

 I want to put in order (preferably as a zoo or xts object with a suitable
 timestamp)
 the open anc closing prices of an (say) index downloaded from YAHOO
 finance:

 require(quantmod)
 getSymbols('^GSPC',from='1990-**01-01')

 medata- tail((GSPC),400)
 opens-Op(medata)
 closes-Cl(medata)

 i.e., I want  asingle sequence of  1095.89,1105.24 , 1101.24 ,
 1102.94, and so on ... preferably with a timestamp (morning - evening of
 same day as for daily prices zoo does not like the same date in two
 consecutive prices...

  head(merge(opens,closes))
   GSPC.Open GSPC.Close
 2010-02-24   1095.891105.24
 2010-02-25   1101.241102.94
 2010-02-26   1103.101104.49
 2010-03-01   1105.361115.71
 2010-03-02   1117.011118.31
 2010-03-03   1119.361118.79
 
 
 Probably I could use the OpCl in quantmod and caclulate the Cl price from
 Op, though Is there any easy way using some implicit zoo/xts function for
 this? I have problems in puting the timestamps in the xts vobject.

 Thanks,
 Costas

 __**_
 R-SIG-Finance@r-project.org mailing list
 https://stat.ethz.ch/mailman/**listinfo/r-sig-financehttps://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.


[[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] Help needed for accessing factor data,

2011-09-16 Thread R. Michael Weylandt
The following (admittedly inelegant) code worked for me to get the data in:

D = readLines(test.txt)
D = sapply(D,strsplit,,)
D = t(simplify2array(D))
rownames(D) - NULL

D = as.data.frame(D)

for (i in 3:9){
D[,i] - as.double(as.character(D[,i]))
}
D[,10] - (D$V10 == true)

Columns 1 and 2 are still factors and probably require some additional
processing.

Hope this helps,

Michael

On Fri, Sep 16, 2011 at 6:57 PM, Bharat Kherwa bharatram.m...@gmail.comwrote:

 Hi Micheal

 Thanks for the quick reply, but I tried your solution, and still
 doesn't work  (it gives error for the dimension).
 apply(as.character(data$V2),1,strsplit,,)
 Error in apply(as.character(data$V2), 1, strsplit, ,) :
  dim(X) must have a positive length
 
 I tried the above with all the data too: still got similar error.

 I am attaching a file here whose data I need to access,

 when we read the data using read.table('test'), it's read in as data
 frame and using str(data) gives this :

 str(data)
 'data.frame':   23399 obs. of  2 variables:
  $ V1: Factor w/ 1 level spy,20110815: 1 1 1 1 1 1 1 1 1 1 ...
  $ V2: Factor w/ 23399 levels
 01:00:00,119.92,119.92,119.92,119.92,0,0,0.0 , ...

 I need to access the individual elements of each row of V2.

 Please let me know,
 It's a great help,

 Thanks a lot
 Bharat

 On Fri, Sep 16, 2011 at 3:42 PM, R. Michael Weylandt
 michael.weyla...@gmail.com wrote:
  I'd guess that the data frame could be easily converted to strings
 without
  loosing any information, so why don't you try something like
 
  apply(as.character(V),1,strsplit,,)
 
  and then coerce the columns to their appropriate types and recombine them
  into a big data frame?
 
  If this doesn't work, I'd happily take a closer look at the problem, but
  please use dput() so I can just copy it directly into my console and make
  sure I get just the right sort of thing.
 
  Hope this helps,
 
  Michael Weylandt
 
  On Fri, Sep 16, 2011 at 6:18 PM, Bharat Kherwa bharatram.m...@gmail.com
 
  wrote:
 
  Hi Guys,
 
  I have some daily tick data like this,
 V1
  V2
  1 spy,20110815 09:30:00,119.18,119.19,119.18,119.19,0,0,0.0,false
  2 spy,20110815 09:30:01,119.21,119.21,119.19,119.21,0,0,0.0,false
  3 spy,20110815 09:30:02,119.22,119.27,119.21,119.27,0,0,0.0,false
  4 spy,20110815 09:30:03,119.26,119.27,119.18,119.18,0,0,0.0,false
  5 spy,2011081509:30:04,119.2,119.2,119.18,119.2,0,0,0.0,false
  6 spy,20110815 09:30:05,119.21,119.21,119.18,119.18,0,0,0.0,false
 
  The structure of the data is as follows:
 
  'data.frame':   23399 obs. of  2 variables:
   $ V1: Factor w/ 1 level spy,20110815: 1 1 1 1 1 1 1 1 1 1 ...
   $ V2: Factor w/ 23399 levels
  01:00:00,119.92,119.92,119.92,119.92,0,0,0.0,false,..: 10800 10801
  10802 10803 10804 10805 10806 10807 10808 10809 ...
 
  Now I want to access the individual elements of data[1,2]  which is
  09:30:00,119.18,119.19,119.18,119.19,0,0,0.0,false,
  i.e. access 119.18 separately, and similarly for other entries in the
  row...
  How do I do that? I tried all combinations to access the individual
  elements with no success,
 
  Any help will be greatly appreciated.
 
  Thanks a lot
  Bharat
 
  ___
  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.
 
 


[[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] RBLOOMBERG

2011-09-12 Thread R. Michael Weylandt
You might try resending this message while actually including the error
message if you want a more substantial reply...

Michael Weylandt

On Mon, Sep 12, 2011 at 4:18 AM, krisan haria krisanha...@gmail.com wrote:

 Hi

 Basic Question

 I havev R .2.13.1. Im trying to use RBLOOMBERG for the first time.

 However, I get an error saying the following



 Any diea what is gonig wrong. To be clear this is the first time Im trying
 this.

[[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.


[[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] Moving averages etcetera over time periods on ragged data

2011-08-28 Thread R. Michael Weylandt
na.locf() will handle the second part of your question. I've not been super
successful with the maxlag optional argument, however, so do be wary if you
use that one.

Michael

On Sun, Aug 28, 2011 at 9:42 PM, Worik Stanton worik.stan...@gmail.comwrote:

 Forgive me if this has been asked/answered.

 I have some data that has values only when data changes.  I would like to
 be able to use a moving average (or similar) from TTR but specify the time
 period not the number of steps.

 Is there a way to do this without rebuilding my data to be regular?

 Off topic, but if I have to rebuild my data is there a function like
 na.approx that I can use to make all NAs take on the preceding non-NA value?

 cheers
 Worik

 --
 The hippies were right

 __**_
 R-SIG-Finance@r-project.org mailing list
 https://stat.ethz.ch/mailman/**listinfo/r-sig-financehttps://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.


[[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.