Skip to content

Error in Blotter's Longtrend Demo

7 messages · Wolfgang Wu, Brian G. Peterson

#
I am trying to reproduce the longtrend example in the current blotter package.
Loading required package: blotter
Loading required package: FinancialInstrument
The demo breaks after the for loop with the error: object 'ConMult' not found. 
Is this a known issue or am I doing something wrong?

I have compared my R settings with Brian's examples in http://ethos.braverock.com/brian/longtrend/sessioninfo.txt
My xts and zoo package seem to be newer than the ones in the example settings. Is this causing the problem? 

Maybe someone can point me to the right direction.

My current setup is the following:
_                            
platform       i386-pc-mingw32              
arch           i386                         
os             mingw32                      
system         i386, mingw32                
status                                      
major          2                            
minor          10.1                         
year           2009                         
month          12                           
day            14                           
svn rev        50720                        
language       R                            
version.string R version 2.10.1 (2009-12-14)
R version 2.10.1 (2009-12-14) 
i386-pc-mingw32 

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

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

other attached packages:
[1] PerformanceAnalytics_1.0.2 blotter_0.4                FinancialInstrument_0.0.2  quantmod_0.3-14            TTR_0.20-1                
[6] Defaults_1.1-1             xts_0.7-1                  zoo_1.6-3                 

loaded via a namespace (and not attached):
[1] grid_2.10.1    lattice_0.18-3 tools_2.10.1  



And here is the code snippet of the demo('longtrend') that is breaking:
+     # browser()
+     CurrentDate=time(GSPC)[i]
+     cat(".")
+     equity = getEndEq(ltaccount, CurrentDate)
+ 
+     ClosePrice = as.numeric(Ad(GSPC[i,]))
+     Posn = getPosQty(ltportfolio, Symbol='GSPC', Date=CurrentDate)
+     UnitSize = as.numeric(trunc(equity/ClosePrice))
+ 
+     # Position Entry (assume fill at close)
+     if( Posn == 0 ) { 
+     # No position, so test to initiate Long position
+         if( as.numeric(Ad(GSPC[i,])) > as.numeric(GSPC[i,'SMA10m']) ) { 
+             cat('\n')
+             # Store trade with blotter
+             addTxn(ltportfolio, Symbol='GSPC', TxnDate=CurrentDate, TxnPrice=ClosePrice, TxnQty = UnitSize , TxnFees=0, verbose=verbose)
+         } 
+     } else {
+     # Have a position, so check exit
+         if( as.numeric(Ad(GSPC[i,]))  <  as.numeric(GSPC[i,'SMA10m'])) { 
+             cat('\n')
+             # Store trade with blotter
+             addTxn(ltportfolio, Symbol='GSPC', TxnDate=CurrentDate, TxnPrice=ClosePrice, TxnQty = -Posn , TxnFees=0, verbose=verbose)
+         } 
+     }
+ 
+     # Calculate P&L and resulting equity with blotter
+     updatePortf(ltportfolio, Dates = CurrentDate)
+     updateAcct(ltaccount, Dates = CurrentDate)
+     updateEndEq(ltaccount, Dates = CurrentDate)
+ } # End dates loop
.
[1] "1998-10-30 GSPC 91 @ 1098.67"
Error: object 'ConMult' not found
In addition: There were 15 warnings (use warnings() to see them)

Thanks for your help!

Regards,

 Wolfgang Wu


_______________________________
?gt ?ber einen herausragenden Schutz gegen Massenmails. 
http://mail.yahoo.com
#
It seems like the error happens in the first iteration of the loop with i=10 on the following statement:
Error: object 'ConMult' not found
[1] "1998-10-30 GMT"
$GSPC
$GSPC$txn
           Txn.Qty Txn.Price Txn.Fees Txn.Value Txn.Avg.Cost Pos.Qty Pos.Avg.Cost Realized.PL Con.Mult
1997-12-31       0      0.00        0      0.00         0.00       0         0.00           0        0
1998-10-30      91   1098.67        0  99978.97      1098.67      91      1098.67           0        1

$GSPC$posPL
           Pos.Qty Con.Mult Ccy.Mult Pos.Value Txn.Value Txn.Fees Realized.PL Unrealized.PL Trading.PL
1997-12-31       0        1        1         0         0        0           0             0          0


attr(,"class")
[1] "blotter_portfolio" "portfolio"        


Thanks.

Regards,

 Wolfgang Wu





----- Urspr?ngliche Mail ----
Von: Wob Wu <wobwu22 at yahoo.de>
An: r-sig-finance at stat.math.ethz.ch
Gesendet: Donnerstag, den 25. M?rz 2010, 8:37:31 Uhr
Betreff: [R-SIG-Finance] Error in Blotter's Longtrend Demo

I am trying to reproduce the longtrend example in the current blotter package.
Loading required package: blotter
Loading required package: FinancialInstrument
The demo breaks after the for loop with the error: object 'ConMult' not found. 
Is this a known issue or am I doing something wrong?

I have compared my R settings with Brian's examples in http://ethos.braverock.com/brian/longtrend/sessioninfo.txt
My xts and zoo package seem to be newer than the ones in the example settings. Is this causing the problem? 

Maybe someone can point me to the right direction.

My current setup is the following:
_                            
platform       i386-pc-mingw32              
arch           i386                        
os             mingw32                      
system         i386, mingw32                
status                                      
major          2                            
minor          10.1                        
year           2009                        
month          12                          
day            14                          
svn rev        50720                        
language       R                            
version.string R version 2.10.1 (2009-12-14)
R version 2.10.1 (2009-12-14) 
i386-pc-mingw32 

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

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

other attached packages:
[1] PerformanceAnalytics_1.0.2 blotter_0.4                FinancialInstrument_0.0.2  quantmod_0.3-14            TTR_0.20-1                
[6] Defaults_1.1-1             xts_0.7-1                  zoo_1.6-3                

loaded via a namespace (and not attached):
[1] grid_2.10.1    lattice_0.18-3 tools_2.10.1  



And here is the code snippet of the demo('longtrend') that is breaking:
+     # browser()
+     CurrentDate=time(GSPC)[i]
+     cat(".")
+     equity = getEndEq(ltaccount, CurrentDate)
+ 
+     ClosePrice = as.numeric(Ad(GSPC[i,]))
+     Posn = getPosQty(ltportfolio, Symbol='GSPC', Date=CurrentDate)
+     UnitSize = as.numeric(trunc(equity/ClosePrice))
+ 
+     # Position Entry (assume fill at close)
+     if( Posn == 0 ) { 
+     # No position, so test to initiate Long position
+         if( as.numeric(Ad(GSPC[i,])) > as.numeric(GSPC[i,'SMA10m']) ) { 
+             cat('\n')
+             # Store trade with blotter
+             addTxn(ltportfolio, Symbol='GSPC', TxnDate=CurrentDate, TxnPrice=ClosePrice, TxnQty = UnitSize , TxnFees=0, verbose=verbose)
+         } 
+     } else {
+     # Have a position, so check exit
+         if( as.numeric(Ad(GSPC[i,]))  <  as.numeric(GSPC[i,'SMA10m'])) { 
+             cat('\n')
+             # Store trade with blotter
+             addTxn(ltportfolio, Symbol='GSPC', TxnDate=CurrentDate, TxnPrice=ClosePrice, TxnQty = -Posn , TxnFees=0, verbose=verbose)
+         } 
+     }
+ 
+     # Calculate P&L and resulting equity with blotter
+     updatePortf(ltportfolio, Dates = CurrentDate)
+     updateAcct(ltaccount, Dates = CurrentDate)
+     updateEndEq(ltaccount, Dates = CurrentDate)
+ } # End dates loop
.
[1] "1998-10-30 GSPC 91 @ 1098.67"
Error: object 'ConMult' not found
In addition: There were 15 warnings (use warnings() to see them)

Thanks for your help!

Regards,

Wolfgang Wu


_______________________________
?gt ?ber einen herausragenden Schutz gegen Massenmails. 
http://mail.yahoo.com

_______________________________________________
R-SIG-Finance at stat.math.ethz.ch 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.


___________________________________
t ?ber einen herausragenden Schutz gegen Massenmails. 
http://mail.yahoo.com
#
I am unable to reproduce your error.  Current SVN works fine for me on 
two different machines, one of them only updated after your email.

If it is failing, I'm guessing it is happening earlier in the script.  
Are there any warnings?  The one I would expect is related to the 
instrument definition.

If there is no instrument defined, blotter attempts to proceed forward 
with a contract multiplier of 1.

It is possible that we have not made this assumption everywhere, 
expectially in updatePosn or updateAcct.  If there is a warning earlier 
in the demo, that would confirm that this is where I need to look.

Regards,

     - Brian
On 03/25/2010 03:37 AM, Wob Wu wrote:

  
    
#
Thanks Brian,

I do get the following warnings but my knowledge of R is unfortunately reaching its limit to evaluate if they are relevant or not.

[1] "1998-10-30 GSPC 91 @ 1098.67"
Error: object 'ConMult' not found
In addition: There were 15 warnings (use warnings() to see them)
Warning messages:
1: In rm("account.longtrend", "portfolio.longtrend", pos = .blotter) :
  object 'account.longtrend' not found
2: In rm("account.longtrend", "portfolio.longtrend", pos = .blotter) :
  object 'portfolio.longtrend' not found
3: In rm("ltaccount", "ltportfolio", "ClosePrice", "CurrentDate",  ... :
  object 'ltaccount' not found
4: In rm("ltaccount", "ltportfolio", "ClosePrice", "CurrentDate",  ... :
  object 'ltportfolio' not found
5: In rm("ltaccount", "ltportfolio", "ClosePrice", "CurrentDate",  ... :
  object 'ClosePrice' not found
6: In rm("ltaccount", "ltportfolio", "ClosePrice", "CurrentDate",  ... :
  object 'CurrentDate' not found
7: In rm("ltaccount", "ltportfolio", "ClosePrice", "CurrentDate",  ... :
  object 'equity' not found
8: In rm("ltaccount", "ltportfolio", "ClosePrice", "CurrentDate",  ... :
  object 'GSPC' not found
9: In rm("ltaccount", "ltportfolio", "ClosePrice", "CurrentDate",  ... :
  object 'i' not found
10: In rm("ltaccount", "ltportfolio", "ClosePrice", "CurrentDate",  ... :
  object 'initDate' not found
11: In rm("ltaccount", "ltportfolio", "ClosePrice", "CurrentDate",  ... :
  object 'initEq' not found
12: In rm("ltaccount", "ltportfolio", "ClosePrice", "CurrentDate",  ... :
  object 'Posn' not found
13: In rm("ltaccount", "ltportfolio", "ClosePrice", "CurrentDate",  ... :
  object 'UnitSize' not found
14: In rm("ltaccount", "ltportfolio", "ClosePrice", "CurrentDate",  ... :
  object 'verbose' not found
15: In download.file(paste(yahoo.URL, "s=", Symbols.name,  ... :
  downloaded length 187356 != reported length 200



It seems like the error happens in the first iteration of the loop with 
i=10. 
When I run the following statement I get the same error:
Dates = CurrentDate)
Error: object 'ConMult' not found
[1] 10
CurrentDate
[1] "1998-10-30 GMT"
getPortfolio(ltportfolio)
$GSPC
$GSPC$txn
          Txn.Qty Txn.Price Txn.Fees Txn.Value Txn.Avg.Cost Pos.Qty Pos.Avg.Cost Realized.PL Con.Mult
1997-12-31       0      0.00        0      
0.00         0.00       0         0.00           0        0
1998-10-30      91   1098.67        0  99978.97      1098.67      91      1098.67           0        1

$GSPC$posPL
           Pos.Qty Con.Mult 
Ccy.Mult Pos.Value Txn.Value Txn.Fees Realized.PL Unrealized.PL 
Trading.PL
1997-12-31       0        1        1         0         0        0           0             0          0


attr(,"class")
[1] "blotter_portfolio" "portfolio"        


Thanks.

Regards,


 Wolfgang Wu





----- Urspr?ngliche Mail ----
Von: Brian G. Peterson <brian at braverock.com>
An: r-sig-finance at stat.math.ethz.ch
Gesendet: Donnerstag, den 25. M?rz 2010, 11:11:46 Uhr
Betreff: Re: [R-SIG-Finance] Error in Blotter's Longtrend Demo

I am unable to reproduce your error.  Current SVN works fine for me on 
two different machines, one of them only updated after your email.

If it is failing, I'm guessing it is happening earlier in the script.  
Are there any warnings?  The one I would expect is related to the 
instrument definition.

If there is no instrument defined, blotter attempts to proceed forward 
with a contract multiplier of 1.

It is possible that we have not made this assumption everywhere, 
expectially in updatePosn or updateAcct.  If there is a warning earlier 
in the demo, that would confirm that this is where I need to look.

Regards,

     - Brian
On 03/25/2010 03:37 AM, Wob Wu wrote:

  
    
#
On 03/25/2010 06:25 AM, Wolfgang Wu wrote:
Try rerunning the demo in the same R session as your first, failed/error 
attempt.  The 'rm' errors are there to clean out the side effects from 
previous demo runs.  Rerunning will get rid of those, and may give us 
the warning I expect that would point towards where your problem is.

Regards,

     - Brian
#
Ok. Here is another log of me trying to get through the demo. It seems like the first warnings are just there because the rm function can't find the objects. I then get another warning when trying to do a getsymbol. Does this help at all?
Warning messages:
1: In rm("account.longtrend", "portfolio.longtrend", pos = .blotter) :
  object 'account.longtrend' not found
2: In rm("account.longtrend", "portfolio.longtrend", pos = .blotter) :
  object 'portfolio.longtrend' not found
There were 12 warnings (use warnings() to see them)
Warning messages:
1: In rm("ltaccount", "ltportfolio", "ClosePrice", "CurrentDate",  ... :
  object 'ltaccount' not found
2: In rm("ltaccount", "ltportfolio", "ClosePrice", "CurrentDate",  ... :
  object 'ltportfolio' not found
3: In rm("ltaccount", "ltportfolio", "ClosePrice", "CurrentDate",  ... :
  object 'ClosePrice' not found
4: In rm("ltaccount", "ltportfolio", "ClosePrice", "CurrentDate",  ... :
  object 'CurrentDate' not found
5: In rm("ltaccount", "ltportfolio", "ClosePrice", "CurrentDate",  ... :
  object 'equity' not found
6: In rm("ltaccount", "ltportfolio", "ClosePrice", "CurrentDate",  ... :
  object 'GSPC' not found
7: In rm("ltaccount", "ltportfolio", "ClosePrice", "CurrentDate",  ... :
  object 'i' not found
8: In rm("ltaccount", "ltportfolio", "ClosePrice", "CurrentDate",  ... :
  object 'initDate' not found
9: In rm("ltaccount", "ltportfolio", "ClosePrice", "CurrentDate",  ... :
  object 'initEq' not found
10: In rm("ltaccount", "ltportfolio", "ClosePrice", "CurrentDate",  ... :
  object 'Posn' not found
11: In rm("ltaccount", "ltportfolio", "ClosePrice", "CurrentDate",  ... :
  object 'UnitSize' not found
12: In rm("ltaccount", "ltportfolio", "ClosePrice", "CurrentDate",  ... :
  object 'verbose' not found
[1] "Loading data"
[1] "GSPC"
Warning message:
In download.file(paste(yahoo.URL, "s=", Symbols.name, "&a=", from.m,  :
  downloaded length 187356 != reported length 200
[1] "Setting up indicators"
[1] "Initializing portfolio and account structure"
[1] "longtrend"
[1] "longtrend"
.> equity = getEndEq(ltaccount, CurrentDate)
[1] 0
[1] TRUE
[1] "1998-10-30 GSPC 0 @ 1098.67"
Error: object 'ConMult' not found

 

Regards,


Wolfgang Wu



----- Urspr?ngliche Mail ----
Von: Brian G. Peterson <brian at braverock.com>
An: r-sig-finance at stat.math.ethz.ch
Gesendet: Donnerstag, den 25. M?rz 2010, 11:11:46 Uhr
Betreff: Re: [R-SIG-Finance] Error in Blotter's Longtrend Demo

I am unable to reproduce your error.  Current SVN works fine for me on 
two different machines, one of them only updated after your email.

If it is failing, I'm guessing it is happening earlier in the script.  
Are there any warnings?  The one I would expect is related to the 
instrument definition.

If there is no instrument defined, blotter attempts to proceed forward 
with a contract multiplier of 1.

It is possible that we have not made this assumption everywhere, 
expectially in updatePosn or updateAcct.  If there is a warning earlier 
in the demo, that would confirm that this is where I need to look.

Regards,

     - Brian
On 03/25/2010 03:37 AM, Wob Wu wrote:

  
    
#
Ok. I understand. So when I run it the second time the warnings regarding the rm functions are gone. I still get a warning for getSymbols.
[1] "GSPC"
Warning message:
In download.file(paste(yahoo.URL, "s=", Symbols.name, "&a=", from.m,  :
  downloaded length 187356 != reported length 200

My GSPC time series looks like this:

          GSPC.Open GSPC.High GSPC.Low GSPC.Close  GSPC.Volume GSPC.Adjusted   SMA10m
1998-01-30    970.43    992.65   912.83     980.28  12733830000        980.28       NA
1998-02-27    980.28   1051.66   980.28    1049.34  11656550000       1049.34       NA
1998-03-31   1049.34   1113.07  1030.87    1101.75  13719590000       1101.75       NA
1998-04-30   1101.75   1132.98  1076.70    1111.75  13656060000       1111.75       NA
1998-05-29   1111.75   1130.52  1074.39    1090.82  11477140000       1090.82       NA
1998-06-30   1090.82   1145.15  1074.67    1133.84  13551970000       1133.84       NA
1998-07-31   1133.84   1190.58  1114.30    1120.67  14194800000       1120.67       NA
1998-08-31   1120.67   1121.79   957.28     957.28  15071550000        957.28       NA
1998-09-30    957.28   1066.11   939.98    1017.01  16714080000       1017.01       NA
1998-10-30   1017.01   1103.78   923.32    1098.67  18001650000       1098.67 1066.141
1998-11-30   1098.67   1192.97  1098.67    1163.63  13451280000       1163.63 1084.476

There are no other warnings. And I still get
Error: object 'ConMult' not found

Any other ideas? 


Regards,

Wolfgang Wu



----- Urspr?ngliche Mail ----
Von: Brian G. Peterson <brian at braverock.com>
An: Wolfgang Wu <wobwu22 at yahoo.de>
CC: r-sig-finance at stat.math.ethz.ch
Gesendet: Donnerstag, den 25. M?rz 2010, 12:09:05 Uhr
Betreff: Re: AW: [R-SIG-Finance] Error in Blotter's Longtrend Demo
On 03/25/2010 06:25 AM, Wolfgang Wu wrote:
Try rerunning the demo in the same R session as your first, failed/error attempt.  The 'rm' errors are there to clean out the side effects from previous demo runs.  Rerunning will get rid of those, and may give us the warning I expect that would point towards where your problem is.

Regards,

    - Brian

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

__________________________________________________
Do You Yahoo!?
hutz gegen Massenmails. 
http://mail.yahoo.com