how to use xts in setClass()

9 messages Options
Embed this post
Permalink
Wind2

how to use xts in setClass()

Reply Threaded More More options
Print post
Permalink
I wonder how to  use xts in setClass().   It seems that zoo is OK.
Thanks.

Wind


> library(quantmod)
Loading required package: xts
Loading required package: zoo

Attaching package: 'zoo'


The following object(s) are masked from package:base :

 as.Date.numeric

xts now requires a valid TZ environment variable to be set
 your current TZ:CST-8
Loading required package: Defaults
Loading required package: TTR
> setClass("trader",representation(prices="zoo",indicator="zoo"))
[1] "trader"
> setClass("trader",representation(prices="xts",indicator="xts"))
[1] "trader"
Warning message:
In .completeClassSlots(ClassDef, where) :
  undefined slot classes in definition of "trader": prices(class "xts"),
indicator(class "xts")

> sessionInfo()
R version 2.9.2 (2009-08-24)
i386-pc-mingw32

locale:
LC_COLLATE=Chinese (Simplified)_People's Republic of
China.936;LC_CTYPE=Chinese (Simplified)_People's Republic of
China.936;LC_MONETARY=Chinese (Simplified)_People's Republic of
China.936;LC_NUMERIC=C;LC_TIME=English_United States.1252

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

other attached packages:
[1] quantmod_0.3-11 TTR_0.20-1      Defaults_1.1-1  xts_0.6-7
[5] zoo_1.5-8

loaded via a namespace (and not attached):
[1] grid_2.9.2      lattice_0.17-25
>

        [[alternative HTML version deleted]]

_______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance
-- Subscriber-posting only.
-- If you want to post, subscribe first.
Wind2

Re: how to use xts in setClass()

Reply Threaded More More options
Print post
Permalink
It is strange that the new class could be used OK with xts slots.   It seems
that the warning appeared while defining the class with xts could be just
ignored.


On Tue, Oct 27, 2009 at 6:22 PM, Wind <[hidden email]> wrote:

> I wonder how to  use xts in setClass().   It seems that zoo is OK.
> Thanks.
>
> Wind
>
>
> > library(quantmod)
> Loading required package: xts
> Loading required package: zoo
>
> Attaching package: 'zoo'
>
>
> The following object(s) are masked from package:base :
>
>  as.Date.numeric
>
> xts now requires a valid TZ environment variable to be set
>  your current TZ:CST-8
> Loading required package: Defaults
> Loading required package: TTR
> > setClass("trader",representation(prices="zoo",indicator="zoo"))
> [1] "trader"
> > setClass("trader",representation(prices="xts",indicator="xts"))
> [1] "trader"
> Warning message:
> In .completeClassSlots(ClassDef, where) :
>   undefined slot classes in definition of "trader": prices(class "xts"),
> indicator(class "xts")
>
> > sessionInfo()
> R version 2.9.2 (2009-08-24)
> i386-pc-mingw32
>
> locale:
> LC_COLLATE=Chinese (Simplified)_People's Republic of
> China.936;LC_CTYPE=Chinese (Simplified)_People's Republic of
> China.936;LC_MONETARY=Chinese (Simplified)_People's Republic of
> China.936;LC_NUMERIC=C;LC_TIME=English_United States.1252
>
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods   base
>
> other attached packages:
> [1] quantmod_0.3-11 TTR_0.20-1      Defaults_1.1-1  xts_0.6-7
> [5] zoo_1.5-8
>
> loaded via a namespace (and not attached):
> [1] grid_2.9.2      lattice_0.17-25
> >
>

        [[alternative HTML version deleted]]

_______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance
-- Subscriber-posting only.
-- If you want to post, subscribe first.
Jeff Ryan

Re: how to use xts in setClass()

Reply Threaded More More options
Print post
Permalink
In reply to this post by Wind2
In fact zoo doesn't work for me by default.  I think the issue is that
quantmod calls setOldClass for you (to use S3 as S4 slots).

library(zoo)
setClass("trader",representation(prices="zoo",indicator="zoo"))

[1] "trader"
Warning message:
In .completeClassSlots(ClassDef, where) :
  undefined slot classes in definition of "trader": prices(class
"zoo"), indicator(class "zoo")


Keeping the environment as clean as possibly (don't attach other
packages that can change the game) is the best way to find the issue.

library(xts)
setClass("trader",representation(prices="xts",indicator="xts"))

[1] "trader"
Warning message:
In .completeClassSlots(ClassDef, where) :
  undefined slot classes in definition of "trader": prices(class
"xts"), indicator(class "xts")


# have to call setOldClass ... this really should be setS3Class IMO,
as "Old" implies bad...

setOldClass("xts")
setClass("trader",representation(prices="xts",indicator="xts"))
[1] "trader"

getClass("trader")
Class "trader" [in ".GlobalEnv"]

Slots:

Name:     prices indicator
Class:       xts       xts

As may be evident from my previous work, I'd petition you not to use
S4 classes until S5 comes out ;)  quantmod is in the process of
removing all S4 objects, instead migrating to more powerful (though
slightly less OO style in some sense) functional closures.  Yes
_functional closures_...

One other point, the newest xts_0.6-8 from CRAN should be used now, as
there were some major improvements and bug fixes implemented in the
release.

Best,
Jeff

On Tue, Oct 27, 2009 at 5:22 AM, Wind <[hidden email]> wrote:

> I wonder how to  use xts in setClass().   It seems that zoo is OK.
> Thanks.
>
> Wind
>
>
>> library(quantmod)
> Loading required package: xts
> Loading required package: zoo
>
> Attaching package: 'zoo'
>
>
> The following object(s) are masked from package:base :
>
>  as.Date.numeric
>
> xts now requires a valid TZ environment variable to be set
>  your current TZ:CST-8
> Loading required package: Defaults
> Loading required package: TTR
>> setClass("trader",representation(prices="zoo",indicator="zoo"))
> [1] "trader"
>> setClass("trader",representation(prices="xts",indicator="xts"))
> [1] "trader"
> Warning message:
> In .completeClassSlots(ClassDef, where) :
>  undefined slot classes in definition of "trader": prices(class "xts"),
> indicator(class "xts")
>
>> sessionInfo()
> R version 2.9.2 (2009-08-24)
> i386-pc-mingw32
>
> locale:
> LC_COLLATE=Chinese (Simplified)_People's Republic of
> China.936;LC_CTYPE=Chinese (Simplified)_People's Republic of
> China.936;LC_MONETARY=Chinese (Simplified)_People's Republic of
> China.936;LC_NUMERIC=C;LC_TIME=English_United States.1252
>
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods   base
>
> other attached packages:
> [1] quantmod_0.3-11 TTR_0.20-1      Defaults_1.1-1  xts_0.6-7
> [5] zoo_1.5-8
>
> loaded via a namespace (and not attached):
> [1] grid_2.9.2      lattice_0.17-25
>>
>
>        [[alternative HTML version deleted]]
>
> _______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only.
> -- If you want to post, subscribe first.
>



--
Jeffrey Ryan
[hidden email]

ia: insight algorithmics
www.insightalgo.com

_______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance
-- Subscriber-posting only.
-- If you want to post, subscribe first.
Wind2

Re: how to use xts in setClass()

Reply Threaded More More options
Print post
Permalink
Thanks Jeff for the detailed explanations as always.
setOldClass("xts") helps me get rid of the warnings.

I am a little curious on your functional closures design plan. I know
functional language such as OCaml or kdb+ are good for time series
calcualtions. R seems also kind of functional language. But what will be the
role of closures in quantmod or xts? Would you please reveal some of the
functional closures design in plain English for mortals like me? :)

And what's your suggestion if I want to define a new class? Before S5? The
slots of the class would be mainly xts.

Regards,
Wind




On Tue, Oct 27, 2009 at 11:29 PM, Jeff Ryan <[hidden email]> wrote:

> In fact zoo doesn't work for me by default.  I think the issue is that
> quantmod calls setOldClass for you (to use S3 as S4 slots).
>
> library(zoo)
> setClass("trader",representation(prices="zoo",indicator="zoo"))
>
> [1] "trader"
> Warning message:
> In .completeClassSlots(ClassDef, where) :
>  undefined slot classes in definition of "trader": prices(class
> "zoo"), indicator(class "zoo")
>
>
> Keeping the environment as clean as possibly (don't attach other
> packages that can change the game) is the best way to find the issue.
>
> library(xts)
> setClass("trader",representation(prices="xts",indicator="xts"))
>
> [1] "trader"
> Warning message:
> In .completeClassSlots(ClassDef, where) :
>  undefined slot classes in definition of "trader": prices(class
> "xts"), indicator(class "xts")
>
>
> # have to call setOldClass ... this really should be setS3Class IMO,
> as "Old" implies bad...
>
> setOldClass("xts")
> setClass("trader",representation(prices="xts",indicator="xts"))
> [1] "trader"
>
> getClass("trader")
> Class "trader" [in ".GlobalEnv"]
>
> Slots:
>
> Name:     prices indicator
> Class:       xts       xts
>
> As may be evident from my previous work, I'd petition you not to use
> S4 classes until S5 comes out ;)  quantmod is in the process of
> removing all S4 objects, instead migrating to more powerful (though
> slightly less OO style in some sense) functional closures.  Yes
> _functional closures_...
>
> One other point, the newest xts_0.6-8 from CRAN should be used now, as
> there were some major improvements and bug fixes implemented in the
> release.
>
> Best,
> Jeff
>
> On Tue, Oct 27, 2009 at 5:22 AM, Wind <[hidden email]> wrote:
> > I wonder how to  use xts in setClass().   It seems that zoo is OK.
> > Thanks.
> >
> > Wind
> >
> >
> >> library(quantmod)
> > Loading required package: xts
> > Loading required package: zoo
> >
> > Attaching package: 'zoo'
> >
> >
> > The following object(s) are masked from package:base :
> >
> >  as.Date.numeric
> >
> > xts now requires a valid TZ environment variable to be set
> >  your current TZ:CST-8
> > Loading required package: Defaults
> > Loading required package: TTR
> >> setClass("trader",representation(prices="zoo",indicator="zoo"))
> > [1] "trader"
> >> setClass("trader",representation(prices="xts",indicator="xts"))
> > [1] "trader"
> > Warning message:
> > In .completeClassSlots(ClassDef, where) :
> >  undefined slot classes in definition of "trader": prices(class "xts"),
> > indicator(class "xts")
> >
> >> sessionInfo()
> > R version 2.9.2 (2009-08-24)
> > i386-pc-mingw32
> >
> > locale:
> > LC_COLLATE=Chinese (Simplified)_People's Republic of
> > China.936;LC_CTYPE=Chinese (Simplified)_People's Republic of
> > China.936;LC_MONETARY=Chinese (Simplified)_People's Republic of
> > China.936;LC_NUMERIC=C;LC_TIME=English_United States.1252
> >
> > attached base packages:
> > [1] stats     graphics  grDevices utils     datasets  methods   base
> >
> > other attached packages:
> > [1] quantmod_0.3-11 TTR_0.20-1      Defaults_1.1-1  xts_0.6-7
> > [5] zoo_1.5-8
> >
> > loaded via a namespace (and not attached):
> > [1] grid_2.9.2      lattice_0.17-25
> >>
> >
> >        [[alternative HTML version deleted]]
> >
> > _______________________________________________
> > [hidden email] mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> > -- Subscriber-posting only.
> > -- If you want to post, subscribe first.
> >
>
>
>
> --
> Jeffrey Ryan
> [hidden email]
>
> ia: insight algorithmics
> www.insightalgo.com
>

        [[alternative HTML version deleted]]

_______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance
-- Subscriber-posting only.
-- If you want to post, subscribe first.
Guillaume Yziquel-4

Re: how to use xts in setClass()

Reply Threaded More More options
Print post
Permalink
Wind a écrit :
>
> I am a little curious on your functional closures design plan. I know
> functional language such as OCaml or kdb+ are good for time series
> calcualtions.
>
> On Tue, Oct 27, 2009 at 11:29 PM, Jeff Ryan <[hidden email]> wrote:
>
>> slightly less OO style in some sense) functional closures.  Yes
>> _functional closures_...

Grin...

Slightly off-topic: There's a binding allowing to embed R in OCaml.

        http://home.gna.org/ocaml-r/gettingstarted.en.html

And a debian package:

        http://yziquel.homelinux.org/topos/debian-ocamlr.html

A 0.2 version should be available in the coming month or so, with tricks
inspired from littler to avoid calling R CMD all the time. Hopefully the
whole stuff will be in Debian soon enough.

All the best,

--
      Guillaume Yziquel
http://yziquel.homelinux.org/

_______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance
-- Subscriber-posting only.
-- If you want to post, subscribe first.
Wind2

Re: how to use xts in setClass()

Reply Threaded More More options
Print post
Permalink
Does the OCaml-R support windows edition of OCaml?
Thanks for your works making both R and OCaml more powerful.

Wind

On Wed, Oct 28, 2009 at 12:55 AM, Guillaume Yziquel <
[hidden email]> wrote:

> Wind a écrit :
>
>>
>> I am a little curious on your functional closures design plan. I know
>> functional language such as OCaml or kdb+ are good for time series
>> calcualtions.
>>
>> On Tue, Oct 27, 2009 at 11:29 PM, Jeff Ryan <[hidden email]>
>> wrote:
>>
>>  slightly less OO style in some sense) functional closures.  Yes
>>> _functional closures_...
>>>
>>
> Grin...
>
> Slightly off-topic: There's a binding allowing to embed R in OCaml.
>
>        http://home.gna.org/ocaml-r/gettingstarted.en.html
>
> And a debian package:
>
>        http://yziquel.homelinux.org/topos/debian-ocamlr.html
>
> A 0.2 version should be available in the coming month or so, with tricks
> inspired from littler to avoid calling R CMD all the time. Hopefully the
> whole stuff will be in Debian soon enough.
>
> All the best,
>
> --
>     Guillaume Yziquel
> http://yziquel.homelinux.org/
>
        [[alternative HTML version deleted]]


_______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance
-- Subscriber-posting only.
-- If you want to post, subscribe first.
Guillaume Yziquel-4

Re: how to use xts in setClass()

Reply Threaded More More options
Print post
Permalink
Wind a écrit :
> Does the OCaml-R support windows edition of OCaml?

Haven't tried yet (I do not have Windows). As it stands, no.
Nevertheless, here's the current state of the whole stuff:

-1- You would need to have dynamic libraries for R. On Debian, it's
there by default, but on Windows, I do not know.

-2- You would have to adjust the build system of OCaml-R on Windows.
There's probably no real issue there, except taking time for it.

-3- Should stick with 0.1 of OCaml-R. 0.2 uses some trickery and Unix
system calls to set environment variables to avoid launching everything
with R CMD. Help on making it work on Windows would be appreciated.

Aside from these issues, I do not believe there is any real problem with
using it on Windows. I'd nevertheless recommend using GODI & Cygwin & MinGW.

But all this talk would perhaps be better off on the ocaml-r-devel
mailing list.

        https://gna.org/mail/?group=ocaml-r

> Thanks for your works making both R and OCaml more powerful.

Thanks for your interest.

> Wind
>
> On Wed, Oct 28, 2009 at 12:55 AM, Guillaume Yziquel <
> [hidden email]> wrote:
>
>> Wind a écrit :
>>
>>> I am a little curious on your functional closures design plan. I know
>>> functional language such as OCaml or kdb+ are good for time series
>>> calcualtions.
>>>
>>> On Tue, Oct 27, 2009 at 11:29 PM, Jeff Ryan <[hidden email]>
>>> wrote:
>>>
>>>  slightly less OO style in some sense) functional closures.  Yes
>>>> _functional closures_...
>>>>
>> Grin...
>>
>> Slightly off-topic: There's a binding allowing to embed R in OCaml.
>>
>>        http://home.gna.org/ocaml-r/gettingstarted.en.html
>>
>> And a debian package:
>>
>>        http://yziquel.homelinux.org/topos/debian-ocamlr.html
>>
>> A 0.2 version should be available in the coming month or so, with tricks
>> inspired from littler to avoid calling R CMD all the time. Hopefully the
>> whole stuff will be in Debian soon enough.
>>
>> All the best,
>>
>> --
>>     Guillaume Yziquel
>> http://yziquel.homelinux.org/
>>
>


--
      Guillaume Yziquel
http://yziquel.homelinux.org/

_______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance
-- Subscriber-posting only.
-- If you want to post, subscribe first.
Clhis Alberty

Manipulate database

Reply Threaded More More options
Print post
Permalink
In reply to this post by Wind2
Guys
I have a problem.
I have a  Big database (in the table below) that i need to manupulate the data across. But I´m not getting.
I tried to use function aggragate,table and tapply, to a cross date whit the clossing price equit. But i din´t succeed.
 exemplo
My database

Simbulo Período      Data   hora Abertura Máximo Mínimo Fechamento Quantidade Financeiro
1  ABCB11       D 24/9/2007 185000    93.89   93.9   93.7       93.8      16300    1529782
2  PETR4       D 21/9/2007 185000       92  94.06     92      92.95      91800    8448657
3  PETR3       D 20/9/2007 185000     93.4   93.5   92.5       92.5      11100    1031339
4  VALE5        D 19/9/2007 185000       94     94   93.5      93.99       3300     309885
5  VALE3       D 18/9/2007 185000    92.99     94   91.5         94      10500     976880
6  BBAS3       D 17/9/2007 185000       93     93     92       92.7      49700    4604635
 
I will need to do (date / Closing Equite)

         Date ABCB11 PETR4 PETR3 VALE5 VALE3 BBAS3
24/9/2007    93.7 93.7 93.7 93.7 93.7 93.7
21/9/2007    92 92 92 92 92 92
20/9/2007      92.5 92.5 92.5 92.5 92.5 92.5
19/9/2007    93.5 93.5 93.5 93.5 93.5 93.5
18/9/2007    91.5 91.5 91.5 91.5 91.5 91.5
17/9/2007    92 92 92 92 92 92

what is the function to accomplishment this intersection?
someone help me?
Thank.
Clhis Alberty


      ____________________________________________________________________________________
[[elided Yahoo spam]]

        [[alternative HTML version deleted]]


_______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance
-- Subscriber-posting only.
-- If you want to post, subscribe first.
Brian G. Peterson

Re: Manipulate database

Reply Threaded More More options
Print post
Permalink
While all this can be accomplished in R, this question would be best
asked on R-help, as it has nothing to do with finance specifically.  If
you want an answer here or on r-help, I would suggest providing a
reproducible example and the code you've tried.

That said, if you have a "database", then write your database query to
give you the data in the format you need it in.  A couple of "join" and
"coalesce" statements in a "where" look like they would do the trick.

Regards,

    - Brian

Clhis Alberty wrote:

> Guys
> I have a problem.
> I have a  Big database (in the table below) that i need to manupulate the data across. But I´m not getting.
> I tried to use function aggragate,table and tapply, to a cross date whit the clossing price equit. But i din´t succeed.
>  exemplo
> My database
>
> Simbulo Período      Data   hora Abertura Máximo Mínimo Fechamento Quantidade Financeiro
> 1  ABCB11       D 24/9/2007 185000    93.89   93.9   93.7       93.8      16300    1529782
> 2  PETR4       D 21/9/2007 185000       92  94.06     92      92.95      91800    8448657
> 3  PETR3       D 20/9/2007 185000     93.4   93.5   92.5       92.5      11100    1031339
> 4  VALE5        D 19/9/2007 185000       94     94   93.5      93.99       3300     309885
> 5  VALE3       D 18/9/2007 185000    92.99     94   91.5         94      10500     976880
> 6  BBAS3       D 17/9/2007 185000       93     93     92       92.7      49700    4604635
>  
> I will need to do (date / Closing Equite)
>
>          Date ABCB11 PETR4 PETR3 VALE5 VALE3 BBAS3
> 24/9/2007    93.7 93.7 93.7 93.7 93.7 93.7
> 21/9/2007    92 92 92 92 92 92
> 20/9/2007      92.5 92.5 92.5 92.5 92.5 92.5
> 19/9/2007    93.5 93.5 93.5 93.5 93.5 93.5
> 18/9/2007    91.5 91.5 91.5 91.5 91.5 91.5
> 17/9/2007    92 92 92 92 92 92
>
> what is the function to accomplishment this intersection?
> someone help me?
> Thank.
> Clhis Alberty
>
>
>       ____________________________________________________________________________________
> [[elided Yahoo spam]]
>
> [[alternative HTML version deleted]]
>
>  
> ------------------------------------------------------------------------
>
> _______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only.
> -- If you want to post, subscribe first.

_______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance
-- Subscriber-posting only.
-- If you want to post, subscribe first.