Re: [R-SIG-Finance] 'Defaults' removed from CRAN? (2014-10-03)

2014-10-08 Thread Mark Knecht
On Tue, Oct 7, 2014 at 7:14 PM, Joshua Ulrich josh.m.ulr...@gmail.com wrote:
 I just pushed an updated quantmod_0.4-2 to R-Forge.  Most of the
 Defaults-related issues have been addressed, except for
 getSymbols.MySQL and setTA/unsetTA.  Feedback would be much
 appreciated.
 --
 Joshua Ulrich  |  about.me/joshuaulrich
 FOSS Trading  |  www.fosstrading.com


 On Tue, Oct 7, 2014 at 3:40 PM, Brian G. Peterson br...@braverock.com wrote:
 On 10/07/2014 03:26 PM, Daniel Cegiełka wrote:

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

 That's a pretty important package that is required by quantmod.


 Yes.

 Defaults makes use of unlockBindings to change loaded package namespaces.
 That's no longer allowed by CRAN.

 So, we'll need to modify getSymbols to not require it.

 The old chartSeries uses it too, but we'll be replacing that soon, so I'm
 not worried about that dependency.

 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.


OK, it seems to work but requires me to modify long working code to remove
setDefaults and then put the database stuff in the actual call. Is
this the way this
is intended to work in the future and I should modify my files?

I'm pretty sure the data is coming from MySQL as AAPL is not in the ETF
database and it fails if I add it to the symbol list:

 source('~/.active-rstudio-document')
[1] From MySQL --  SPY
[1] From MySQL --  IWM
[1] From MySQL --  QQQ
[1] From MySQL --  AAPL
Error in Symbols[[i]] : subscript out of bounds
In addition: Warning message:
In getSymbols.MySQL(Symbols = AAPL, env = environment, verbose = FALSE,  :
  could not load symbol(s):  AAPL



The code I ran is at the bottom.

Thanks,
Mark


 source('~/R/Test Cases/RMySQL-Test.R')
Loading required package: xts
Loading required package: zoo

Attaching package: ‘zoo’

The following objects are masked from ‘package:base’:

as.Date, as.Date.numeric

Loading required package: TTR
Version 0.4-0 included new data defaults. See ?getSymbols.
Loading required package: DBI
[1] From MySQL --  SPY
As of 0.4-0, ‘getSymbols’ uses env=parent.frame() and
 auto.assign=TRUE by default.

 This  behavior  will be  phased out in 0.5-0  when the call  will
 default to use auto.assign=FALSE. getOption(getSymbols.env) and
 getOptions(getSymbols.auto.assign) are now checked for alternate defaults

 This message is shown once per session and may be disabled by setting
 options(getSymbols.warning4.0=FALSE). See ?getSymbol for more details
[1] From MySQL --  IWM
[1] From MySQL --  QQQ




llibrary(quantmod)
library(RMySQL)

Sys.setenv(TZ = UTC)
DataStart = 1990-01-01
DataEnd = format(Sys.time(), %Y-%m-%d)
SymbolSrc = yahoo
dbName = R_ETF
MyAdjust = TRUE
UseMySQL = TRUE

SymbolList = c(SPY,IWM,QQQ)

if (UseMySQL){
  if (MyAdjust) { dbName = paste0(dbName, Adjust)}
  dbc = dbConnect(MySQL(), dbname=dbName)
#   setDefaults(getSymbols.MySQL, user=mark,
password=MyTempPassword, dbname=dbName)
}

if (!UseMySQL){
  for (i in 1:length(SymbolList)){
print(paste(From ,SymbolSrc, -- ,SymbolList[i]))
getSymbolsCont(SymbolList[i], from = DataStart, to = DataEnd,
adjust = MyAdjust, src=SymbolSrc)
  }
} else {
  for (i in 1:length(SymbolList)){
print(paste(From MySQL -- ,SymbolList[i]))
 #   getSymbols(SymbolList[i], src=MySQL)
getSymbols(SymbolList[i], src=MySQL, user=mark,
password=MyTempPassword, dbname=dbName)
assign(SymbolList[i], get(SymbolList[i])[paste0(DataStart,/,DataEnd)])
  }
  dbDisconnect(dbc)
}

___
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] 'Defaults' removed from CRAN? (2014-10-03)

2014-10-08 Thread Daniel Cegiełka
Thank you for this information. This solves annoying problems that
have recently emerged in this topic, but as Mark pointed out, the
complete removal of Defaults may take much more time.

Best regards,
Daniel

___
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] 'Defaults' removed from CRAN? (2014-10-03)

2014-10-08 Thread Mark Knecht
On Wed, Oct 8, 2014 at 9:27 AM, Daniel Cegiełka
daniel.cegie...@gmail.com wrote:
 Thank you for this information. This solves annoying problems that
 have recently emerged in this topic, but as Mark pointed out, the
 complete removal of Defaults may take much more time.

 Best regards,
 Daniel

For getSymbols.MySQL only:

WRT to coding I'm certainly not the best person to do it but if
getSymbols.MySQL ,
or even just some other support function, read the .my.cnf file then
we'd probably
have a more standard long term solution with (slightly) better
security. I'm coding
up a simple function to do that for my simple needs. It doesn't seem
like it should
be an overly difficult task. The basic file format is:

mark@c2RAID6 ~ $ cat .my.cnf
[client]
user = mark
password = MyTempPassword
host = localhost

mark@c2RAID6 ~ $

so finding the [client] group and then gathering user  password would be
enough to handle the security part of the MySQL access.

 args(getSymbols.MySQL)
function (Symbols, env, return.class = xts, db.fields = c(date,
o, h, l, c, v, a), field.names = NULL, user = NULL,
password = NULL, dbname = NULL, host = localhost, port = 3306,
...)
NULL



If the function was called from within getSymbols.MySQL then the
user  password would remain private and be destroyed when exiting
getSymbols.MySQL which would yield better security. (I think...) The user
could still pass in the values if he didn't want to do this on every call.

I need to learn to handle strings better... :-)

- Mark

___
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] 'Defaults' removed from CRAN? (2014-10-03)

2014-10-08 Thread G See
Out of curiosity, did you try _not_ changing your current code, but
instead adding library(Defaults) to the top of the script?  It's not
ideal, but Defaults _is_ still available
(http://cran.r-project.org/src/contrib/Archive/Defaults/).  That could
buy you some time until you come up with something better.

Just a (possibly bad) thought.
Garrett

On Wed, Oct 8, 2014 at 9:43 AM, Mark Knecht markkne...@gmail.com wrote:
 On Tue, Oct 7, 2014 at 7:14 PM, Joshua Ulrich josh.m.ulr...@gmail.com wrote:
 I just pushed an updated quantmod_0.4-2 to R-Forge.  Most of the
 Defaults-related issues have been addressed, except for
 getSymbols.MySQL and setTA/unsetTA.  Feedback would be much
 appreciated.
 --
 Joshua Ulrich  |  about.me/joshuaulrich
 FOSS Trading  |  www.fosstrading.com


 On Tue, Oct 7, 2014 at 3:40 PM, Brian G. Peterson br...@braverock.com 
 wrote:
 On 10/07/2014 03:26 PM, Daniel Cegiełka wrote:

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

 That's a pretty important package that is required by quantmod.


 Yes.

 Defaults makes use of unlockBindings to change loaded package namespaces.
 That's no longer allowed by CRAN.

 So, we'll need to modify getSymbols to not require it.

 The old chartSeries uses it too, but we'll be replacing that soon, so I'm
 not worried about that dependency.

 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.


 OK, it seems to work but requires me to modify long working code to remove
 setDefaults and then put the database stuff in the actual call. Is
 this the way this
 is intended to work in the future and I should modify my files?

 I'm pretty sure the data is coming from MySQL as AAPL is not in the ETF
 database and it fails if I add it to the symbol list:

 source('~/.active-rstudio-document')
 [1] From MySQL --  SPY
 [1] From MySQL --  IWM
 [1] From MySQL --  QQQ
 [1] From MySQL --  AAPL
 Error in Symbols[[i]] : subscript out of bounds
 In addition: Warning message:
 In getSymbols.MySQL(Symbols = AAPL, env = environment, verbose = FALSE,  :
   could not load symbol(s):  AAPL



 The code I ran is at the bottom.

 Thanks,
 Mark


 source('~/R/Test Cases/RMySQL-Test.R')
 Loading required package: xts
 Loading required package: zoo

 Attaching package: ‘zoo’

 The following objects are masked from ‘package:base’:

 as.Date, as.Date.numeric

 Loading required package: TTR
 Version 0.4-0 included new data defaults. See ?getSymbols.
 Loading required package: DBI
 [1] From MySQL --  SPY
 As of 0.4-0, ‘getSymbols’ uses env=parent.frame() and
  auto.assign=TRUE by default.

  This  behavior  will be  phased out in 0.5-0  when the call  will
  default to use auto.assign=FALSE. getOption(getSymbols.env) and
  getOptions(getSymbols.auto.assign) are now checked for alternate defaults

  This message is shown once per session and may be disabled by setting
  options(getSymbols.warning4.0=FALSE). See ?getSymbol for more details
 [1] From MySQL --  IWM
 [1] From MySQL --  QQQ




 llibrary(quantmod)
 library(RMySQL)

 Sys.setenv(TZ = UTC)
 DataStart = 1990-01-01
 DataEnd = format(Sys.time(), %Y-%m-%d)
 SymbolSrc = yahoo
 dbName = R_ETF
 MyAdjust = TRUE
 UseMySQL = TRUE

 SymbolList = c(SPY,IWM,QQQ)

 if (UseMySQL){
   if (MyAdjust) { dbName = paste0(dbName, Adjust)}
   dbc = dbConnect(MySQL(), dbname=dbName)
 #   setDefaults(getSymbols.MySQL, user=mark,
 password=MyTempPassword, dbname=dbName)
 }

 if (!UseMySQL){
   for (i in 1:length(SymbolList)){
 print(paste(From ,SymbolSrc, -- ,SymbolList[i]))
 getSymbolsCont(SymbolList[i], from = DataStart, to = DataEnd,
 adjust = MyAdjust, src=SymbolSrc)
   }
 } else {
   for (i in 1:length(SymbolList)){
 print(paste(From MySQL -- ,SymbolList[i]))
  #   getSymbols(SymbolList[i], src=MySQL)
 getSymbols(SymbolList[i], src=MySQL, user=mark,
 password=MyTempPassword, dbname=dbName)
 assign(SymbolList[i], get(SymbolList[i])[paste0(DataStart,/,DataEnd)])
   }
   dbDisconnect(dbc)
 }

 ___
 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

Re: [R-SIG-Finance] 'Defaults' removed from CRAN? (2014-10-03)

2014-10-08 Thread Mark Knecht
On Wed, Oct 8, 2014 at 9:56 AM, G See gsee...@gmail.com wrote:
 Out of curiosity, did you try _not_ changing your current code, but
 instead adding library(Defaults) to the top of the script?  It's not
 ideal, but Defaults _is_ still available
 (http://cran.r-project.org/src/contrib/Archive/Defaults/).  That could
 buy you some time until you come up with something better.

 Just a (possibly bad) thought.
 Garrett


I did not but for whatever reason it didn't seem to work for me. SetDefaults is
apparently found and the defaults are in therebut getSymbols.MySQL didn't
apparently pick up. SPY is not returned, QQQ is when I pass the info
in explicitly.
I'm probably doing something stupid...

- Mark

 library(quantmod)
 library(RMySQL)
 library(Defaults)


 dbName = R_ETF

 getDefaults()
[1] getSymbols.MySQL

 dbc = dbConnect(MySQL(), dbname=dbName)
 setDefaults(getSymbols.MySQL, user=mark, password=MyTempPassword, 
 dbname=dbName)

 getDefaults()
[1] getSymbols.MySQL

 getDefaults(getSymbols.MySQL)
$user
[1] 'mark'

$password
[1] 'MyTempPassword'

$dbname
[1] dbName


 getSymbols(SPY, src=MySQL)
Error in getSymbols.MySQL(Symbols = SPY, env = environment,
verbose = FALSE,  :
  At least one connection argument ( ‘user’ ‘password’ ‘dbname’ ) is not set

 getSymbols(QQQ, src=MySQL, user=mark, password=MyTempPassword, 
 dbname=dbName)
[1] QQQ





library(quantmod)
library(RMySQL)
library(Defaults)


dbName = R_ETF

getDefaults()

dbc = dbConnect(MySQL(), dbname=dbName)
setDefaults(getSymbols.MySQL, user=mark, password=MyTempPassword,
dbname=dbName)

getDefaults()

getDefaults(getSymbols.MySQL)

getSymbols(SPY, src=MySQL)

getSymbols(QQQ, src=MySQL, user=mark, password=MyTempPassword,
dbname=dbName)

___
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] Return.rebalancing contemporaneous calculation

2014-10-08 Thread Charles Duranceau
Hi,
I'm working with Performance Analytics for calculating portfolio returns 
using the function Return.rebalancing. I don't understand why the results - 
portfolio returns - are lagged by 1 period when compared to Return.portfolio 
(assuming weight are time invariant).

I read the definition that explain the rebalancing is taken place in the next 
period but since the input are returns (like in  Return.portfolio) they should 
be consolidated on same period.
Is there a way not losing the first input?

Here few lines to illustrate my question

pfmf2003-Return.rebalancing(mfr2003,wghts1)
pfstat-Return.portfolio(mfr2003,c(1,0))
** wghts1 = 1 for the period

Results
portfolio.Rebal   portfolio.returns.
2003-05-31  0.0087336245 0.203679369
2003-06-30  0.1093073593 0.008733624
2003-07-31 -0.0351219512 0.109307359
2003-08-31 -0.0404448938-0.035121951
2003-09-30 -0.0063224447-0.040444894



many thanks

Charles


**
The contents of this email and any attachments are confidential to the intended 
recipient.  They may not be disclosed to or used by or copied in any way by 
anyone other than the intended recipient.  If this email is received in error, 
please contact Northview Investment Advisors Ltd. on + 1 345 943 2828 quoting 
the name of the sender and the email address to which it has been sent and then 
delete it.

Please further note that neither Northview Investment Advisors Ltd. nor the 
sender accepts any responsibility for viruses and it is your responsibility to 
scan or otherwise check this email and any attachments.

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