1

I wrote this line of code in order to get an indication if the IBM stock closed up or down per last day before the current day. I'm new to quantmod so i wrote this line of code based on my R knowledge but i got some strange results.What is wrong? I got a strange summary results and an indication fo duplicates. Here are my lines of code:

> IBM_TRAIN$LastDay_green<- ifelse((lag(IBM_TRAIN$IBM.Open,k=1) < lag(IBM_TRAIN$IBM.Close,k=1)),1,0)
> summary(IBM_TRAIN$LastDay_green)
     Index            LastDay_green   
 Min.   :2007-01-03   Min.   :0.0000  
 1st Qu.:2008-10-15   1st Qu.:0.0000  
 Median :2010-07-21   Median :1.0000  
 Mean   :2010-07-21   Mean   :0.5418  
 3rd Qu.:2012-04-24   3rd Qu.:1.0000  
 Max.   :2014-01-30   Max.   :1.0000  
                      NA's   :1769    
Warning message:
In data.row.names(row.names, rowsi, i) :
  some row.names duplicated: 15,17,19,23,25,27,29,33,35,37,39,43,45,47,49,53,55,57,61,63,65,67,71,73,75,77,81,83,85,87,91,93,95,97,101,103,105,107,111,113,115,119,121,123,125,129,131,133,135,139,141,143,145,149,151,153,155,159,161,163,165,169,171,173,175,179,181,183,185,189,191,193,197,199,201,203,207,209,211,213,217,219,221,223,227,229,231,233,237,241,245,247,249,251,255,257,259,261,265,267,269,271,275,277,279,281,285,287,289,291,295,297,299,301,305,307,309,311,315,317,319,321,325,327,329,333,335,337,339,343,345,347,349,353,355,357,359,363,365,367,369,373,375,377,379,383,385,387,389,393,395,397,399,403,405,407,409,413,415,417,419,423,425,427,429,433,435,441,443,445,447,451,453,455,457,461,463,465,467,471,473,475,477,483,485,491,493,497,499,501,503,507,509,511,513,517,519,521,525,527,529,531,535,537,539,541,545,547,549,551,555,557,559,563,565,567,569,573,575,577,579,583,585,587,589,593,595,597,601,603,605,607,611,613,615,617,621,623,625,627,631,633,635,637,641,643,645,647,651,653,655,657 [... truncated]
mql4beginner
  • 2,193
  • 5
  • 34
  • 73
  • 1
    Please provide a [reproducible example](http://stackoverflow.com/q/5963269/271616) and include the output from `sessionInfo`. – Joshua Ulrich Jul 21 '15 at 16:50
  • 1
    I tried running a version of your code on data obtained with `getSymbols("IBM")` and it worked fine. I wonder if this is somehow an artifact of your training/test splitting process? – ulfelder Jul 21 '15 at 17:11
  • Thank you ulfelder.That was the problem.But I still don't understand the resone for having two summaries for this field (Index & regular summary) and why can't I get the regular output of an str() function? – mql4beginner Jul 21 '15 at 20:15

2 Answers2

1
library(quantmod)
#get stock data
getSymbols("IBM")


#Show last two days of the series
  tail(IBM, n=2)

#series will show you the change day to day. 
dailyReturn(IBM))



           daily.returns
2015-07-13  0.0145553042
2015-07-14 -0.0045460147
2015-07-15 -0.0004744796
2015-07-16  0.0146561503
2015-07-17  **0.0088303801**
2015-07-20  **0.0041157383**
vinchinzu
  • 604
  • 1
  • 7
  • 16
  • That's nice but I'm looking into building my own signals So I would like to understand what is wrong with my line of code. – mql4beginner Jul 21 '15 at 16:59
1

I can't comment so adding this as an answer. The index summary is because the result of first operation is an XTS.

I reckon this should give summary for the colums values only -

summary(coredata(IBM_TRAIN$LastDay_green) )
R.S.
  • 2,093
  • 14
  • 29