Yahoo data download problem

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Yahoo data download problem

SUMANTA BASAK-4
Hi all R-Experts,

I'm facing one problem in yahoo data downloading. I'm suing Windows XP, R 2.2.0, and i'm using yahoo.get.hist.quote function to download data. I need 500 companies of S&P index daily 'closing price' data for last ten years. My questions are:

1) I have all the ticker names of S&P 500 companies in a .csv format. I'm reading those names in R and they are coming as data.frame object. How can i change this to a vector?

2) How can i get all companies data downloaded using a simple "for" loop?

I'm using the following function for a single stock data.


library(gdata)
s<-yahoo.get.hist.quote(instrument = "mo", destfile = paste("mo", ".csv", sep = ""), start="1996-01-01",
                     end="2006-06-16", quote = c("Close"), adjusted = TRUE, download = TRUE, origin = "1970-01-01",
                     compression = "d")


Thanks,
Sumanta Basak.

 
---------------------------------


        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: Yahoo data download problem

PIKAL Petr
Hi


On 16 Jun 2006 at 8:52, SUMANTA BASAK wrote:

Date sent:       Fri, 16 Jun 2006 08:52:22 +0100 (BST)
From:           SUMANTA BASAK <[hidden email]>
To:             R HELP <[hidden email]>,
        [hidden email]
Subject:         [R] Yahoo data download problem

> Hi all R-Experts,
>
> I'm facing one problem in yahoo data downloading. I'm suing Windows
> XP, R 2.2.0, and i'm using yahoo.get.hist.quote function to download
> data. I need 500 companies of S&P index daily 'closing price' data for
> last ten years. My questions are:
>
> 1) I have all the ticker names of S&P 500 companies in a .csv format.
> I'm reading those names in R and they are coming as data.frame object.
> How can i change this to a vector?

df<-data.frame(x=sample(letters,10))

 as.vector(df$x)
 [1] "g" "b" "p" "u" "r" "q" "j" "h" "o" "k"
>

HTH
Petr


>
> 2) How can i get all companies data downloaded using a simple "for"
> loop?
>
> I'm using the following function for a single stock data.
>
>
> library(gdata)
> s<-yahoo.get.hist.quote(instrument = "mo", destfile = paste("mo",
> ".csv", sep = ""), start="1996-01-01",
>                      end="2006-06-16", quote = c("Close"), adjusted =
>                      TRUE, download = TRUE, origin = "1970-01-01",
>                      compression = "d")
>
>
> Thanks,
> Sumanta Basak.
>
>
> ---------------------------------
>
>
>  [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html

Petr Pikal
[hidden email]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: Yahoo data download problem

SUMANTA BASAK-4
Hi Petr,

Thanks for the solution. But my problem is still there. I have 500 company names in a single column in an excel sheet of S&P 500 index. I need to call all those compnies in a 'for' loop and write that whole dataset into a text file. I've developed the following one, but the problem is getting all those company names in a vector.

h<-c("GE","MMM")
s<-matrix(0,3818,2)
for  (i in 1:2)
{
s[,i]<-yahoo.get.hist.quote(instrument = h[i], destfile = paste(h[i], ".csv", sep = ""), start="1996-01-01",
                     end="2006-06-16", quote = c("Close"), adjusted = TRUE, download = TRUE, origin = "1970-01-01",
                     compression = "d")
write.csv(s,file="Z:/yahoo.out.csv")
}

Here i have taken only two compnies. But i want to fetch all the company names and put them in a vector so that i can call them in a 'for' loop. Please guide.

Thanks,
Sumanta Basak.

Petr Pikal <[hidden email]> wrote: Hi


On 16 Jun 2006 at 8:52, SUMANTA BASAK wrote:

Date sent:       Fri, 16 Jun 2006 08:52:22 +0100 (BST)
From:            SUMANTA BASAK
To:              R HELP ,
 [hidden email]
Subject:         [R] Yahoo data download problem

> Hi all R-Experts,
>
> I'm facing one problem in yahoo data downloading. I'm suing Windows
> XP, R 2.2.0, and i'm using yahoo.get.hist.quote function to download
> data. I need 500 companies of S&P index daily 'closing price' data for
> last ten years. My questions are:
>
> 1) I have all the ticker names of S&P 500 companies in a .csv format.
> I'm reading those names in R and they are coming as data.frame object.
> How can i change this to a vector?

df<-data.frame(x=sample(letters,10))

 as.vector(df$x)
 [1] "g" "b" "p" "u" "r" "q" "j" "h" "o" "k"
>

HTH
Petr


>
> 2) How can i get all companies data downloaded using a simple "for"
> loop?
>
> I'm using the following function for a single stock data.
>
>
> library(gdata)
> s<-yahoo.get.hist.quote(instrument = "mo", destfile = paste("mo",
> ".csv", sep = ""), start="1996-01-01",
>                      end="2006-06-16", quote = c("Close"), adjusted =
>                      TRUE, download = TRUE, origin = "1970-01-01",
>                      compression = "d")
>
>
> Thanks,
> Sumanta Basak.
>
>
> ---------------------------------
>
>
>  [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html

Petr Pikal
[hidden email]



 
---------------------------------


        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: Yahoo data download problem

Charles Annis, P.E.
Why create an enormous matrix?  Why not read each company's info and
immediately write it to the file using write.csv( ... append = TRUE ...)?
                                                      ^^^^^^^^^^^^^

Charles Annis, P.E.

[hidden email]
phone: 561-352-9699
eFax:  614-455-3265
http://www.StatisticalEngineering.com
 

-----Original Message-----
From: [hidden email]
[mailto:[hidden email]] On Behalf Of SUMANTA BASAK
Sent: Friday, June 16, 2006 7:11 AM
To: Petr Pikal; R HELP
Subject: Re: [R] Yahoo data download problem

Hi Petr,

Thanks for the solution. But my problem is still there. I have 500 company
names in a single column in an excel sheet of S&P 500 index. I need to call
all those compnies in a 'for' loop and write that whole dataset into a text
file. I've developed the following one, but the problem is getting all those
company names in a vector.

h<-c("GE","MMM")
s<-matrix(0,3818,2)
for  (i in 1:2)
{
s[,i]<-yahoo.get.hist.quote(instrument = h[i], destfile = paste(h[i],
".csv", sep = ""), start="1996-01-01",
                     end="2006-06-16", quote = c("Close"), adjusted = TRUE,
download = TRUE, origin = "1970-01-01",
                     compression = "d")
write.csv(s,file="Z:/yahoo.out.csv")
}

Here i have taken only two compnies. But i want to fetch all the company
names and put them in a vector so that i can call them in a 'for' loop.
Please guide.

Thanks,
Sumanta Basak.

Petr Pikal <[hidden email]> wrote: Hi


On 16 Jun 2006 at 8:52, SUMANTA BASAK wrote:

Date sent:       Fri, 16 Jun 2006 08:52:22 +0100 (BST)
From:            SUMANTA BASAK
To:              R HELP ,
 [hidden email]
Subject:         [R] Yahoo data download problem

> Hi all R-Experts,
>
> I'm facing one problem in yahoo data downloading. I'm suing Windows
> XP, R 2.2.0, and i'm using yahoo.get.hist.quote function to download
> data. I need 500 companies of S&P index daily 'closing price' data for
> last ten years. My questions are:
>
> 1) I have all the ticker names of S&P 500 companies in a .csv format.
> I'm reading those names in R and they are coming as data.frame object.
> How can i change this to a vector?

df<-data.frame(x=sample(letters,10))

 as.vector(df$x)
 [1] "g" "b" "p" "u" "r" "q" "j" "h" "o" "k"
>

HTH
Petr


>
> 2) How can i get all companies data downloaded using a simple "for"
> loop?
>
> I'm using the following function for a single stock data.
>
>
> library(gdata)
> s<-yahoo.get.hist.quote(instrument = "mo", destfile = paste("mo",
> ".csv", sep = ""), start="1996-01-01",
>                      end="2006-06-16", quote = c("Close"), adjusted =
>                      TRUE, download = TRUE, origin = "1970-01-01",
>                      compression = "d")
>
>
> Thanks,
> Sumanta Basak.
>
>
> ---------------------------------
>
>
>  [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html

Petr Pikal
[hidden email]



 
---------------------------------


        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: Yahoo data download problem

Neuro LeSuperHéros
In reply to this post by SUMANTA BASAK-4
Hi, this is what you asked for.  You should consider transforming your ts
data into something else as you get no column name or date in the basic
form.

#Initialize empty table
closing <-NULL

#Downalod consituents since I don't have it on my comp
download.file("http://www2.standardandpoors.com/spf/csv/index/sp500.csv",
"c:/constituents.csv", "internal", quiet = FALSE, mode = "wb",cacheOK =
TRUE)
constituents <-read.csv("c:/constituents.csv",header=TRUE,skip=2,as.is=TRUE)


for (i in constituents$Ticker) {
s<-yahoo.get.hist.quote(instrument = sub("\\.","\\-",i),
destfile = paste(i, ".csv", sep = ""), start="1996-01-01",
end="2006-06-16", quote = c("Close"), adjusted =
TRUE, download = TRUE, origin = "1970-01-01", compression = "d")
closing  <-cbind.ts(closing ,s)
}

write.csv(closing,"c:/yahoooutput.csv")

Neuro

>From: SUMANTA BASAK <[hidden email]>
>To: Petr Pikal <[hidden email]>, R HELP <[hidden email]>
>Subject: Re: [R] Yahoo data download problem
>Date: Fri, 16 Jun 2006 12:10:31 +0100 (BST)
>
>Hi Petr,
>
>Thanks for the solution. But my problem is still there. I have 500 company
>names in a single column in an excel sheet of S&P 500 index. I need to call
>all those compnies in a 'for' loop and write that whole dataset into a text
>file. I've developed the following one, but the problem is getting all
>those company names in a vector.
>
>h<-c("GE","MMM")
>s<-matrix(0,3818,2)
>for  (i in 1:2)
>{
>s[,i]<-yahoo.get.hist.quote(instrument = h[i], destfile = paste(h[i],
>".csv", sep = ""), start="1996-01-01",
>                      end="2006-06-16", quote = c("Close"), adjusted =
>TRUE, download = TRUE, origin = "1970-01-01",
>                      compression = "d")
>write.csv(s,file="Z:/yahoo.out.csv")
>}
>
>Here i have taken only two compnies. But i want to fetch all the company
>names and put them in a vector so that i can call them in a 'for' loop.
>Please guide.
>
>Thanks,
>Sumanta Basak.
>
>Petr Pikal <[hidden email]> wrote: Hi
>
>
>On 16 Jun 2006 at 8:52, SUMANTA BASAK wrote:
>
>Date sent:       Fri, 16 Jun 2006 08:52:22 +0100 (BST)
>From:            SUMANTA BASAK
>To:              R HELP ,
>  [hidden email]
>Subject:         [R] Yahoo data download problem
>
> > Hi all R-Experts,
> >
> > I'm facing one problem in yahoo data downloading. I'm suing Windows
> > XP, R 2.2.0, and i'm using yahoo.get.hist.quote function to download
> > data. I need 500 companies of S&P index daily 'closing price' data for
> > last ten years. My questions are:
> >
> > 1) I have all the ticker names of S&P 500 companies in a .csv format.
> > I'm reading those names in R and they are coming as data.frame object.
> > How can i change this to a vector?
>
>df<-data.frame(x=sample(letters,10))
>
>  as.vector(df$x)
>  [1] "g" "b" "p" "u" "r" "q" "j" "h" "o" "k"
> >
>
>HTH
>Petr
>
>
> >
> > 2) How can i get all companies data downloaded using a simple "for"
> > loop?
> >
> > I'm using the following function for a single stock data.
> >
> >
> > library(gdata)
> > s<-yahoo.get.hist.quote(instrument = "mo", destfile = paste("mo",
> > ".csv", sep = ""), start="1996-01-01",
> >                      end="2006-06-16", quote = c("Close"), adjusted =
> >                      TRUE, download = TRUE, origin = "1970-01-01",
> >                      compression = "d")
> >
> >
> > Thanks,
> > Sumanta Basak.
> >
> >
> > ---------------------------------
> >
> >
> >  [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > [hidden email] mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide!
> > http://www.R-project.org/posting-guide.html
>
>Petr Pikal
>[hidden email]
>
>
>
>
>---------------------------------
>
>
> [[alternative HTML version deleted]]
>
>______________________________________________
>[hidden email] mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide!
>http://www.R-project.org/posting-guide.html

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: Yahoo data download problem

esmetaman
In reply to this post by SUMANTA BASAK-4
I have some function to solve your problem.


#Plot stock quote
PSQ <- function(INSTRUMENT,FROM,TO,START){
   #Procedure to download Stock Quote Information
   DATA <-yahoo.get.hist.quote(
       instrument = INSTRUMENT,
       destfile = paste(INSTRUMENT, ".csv", sep = ""),
       start=FROM,
       end=TO,
       quote = c("Close"),
       adjusted = TRUE,
       download = TRUE,
       origin = "1970-01-01",
       compression = "d");

   #Conversion procedure to Time Series R Objetct;
   DATA.TS = ts(DATA,frequency = 365, start = c(START, 1))
   plot(DATA.TS);
   return(DATA.TS);
}

#To compare
COMPARE_QUOTES <- function(QUOTES,FROM,TO,START){
   L = length(COMPANIES);
   par(mfrow=c(L,1));
   for  (i in 1:L){
       PSQ(QUOTES[i],FROM,TO,START);
   }
   par(mfrow=c(1,1));
}

COMPANIES <-c("GE","MMM","IBM");

COMPARE_QUOTES(COMPANIES,"1990-01-01","2006-06-16",1990);
IBM <- PSQ("IBM","1990-01-01","2006-06-16",1990);

>
> Message: 1
> Date: Fri, 16 Jun 2006 12:10:53 +0200
> From: "Petr Pikal" <[hidden email]>
> Subject: Re: [R] Yahoo data download problem
> To: SUMANTA BASAK <[hidden email]>, R HELP
> <[hidden email]>
> Message-ID: <44929FCD.26976.F5A06E@localhost>
> Content-Type: text/plain; charset=US-ASCII
>
> Hi
>
>
> On 16 Jun 2006 at 8:52, SUMANTA BASAK wrote:
>
> Date sent:       Fri, 16 Jun 2006 08:52:22 +0100 (BST)
> From:           SUMANTA BASAK <[hidden email]>
> To:             R HELP <[hidden email]>,
> [hidden email]
> Subject:         [R] Yahoo data download problem
>
>> Hi all R-Experts,
>>
>> I'm facing one problem in yahoo data downloading. I'm suing Windows
>> XP, R 2.2.0, and i'm using yahoo.get.hist.quote function to download
>> data. I need 500 companies of S&P index daily 'closing price' data for
>> last ten years. My questions are:
>>
>> 1) I have all the ticker names of S&P 500 companies in a .csv format.
>> I'm reading those names in R and they are coming as data.frame object.
>> How can i change this to a vector?
>
> df<-data.frame(x=sample(letters,10))  
>
>  as.vector(df$x)
>  [1] "g" "b" "p" "u" "r" "q" "j" "h" "o" "k"
>>
>
> HTH
> Petr
>
>
>>
>> 2) How can i get all companies data downloaded using a simple "for"
>> loop?
>>
>> I'm using the following function for a single stock data.
>>
>>
>> library(gdata)
>> s<-yahoo.get.hist.quote(instrument = "mo", destfile = paste("mo",
>> ".csv", sep = ""), start="1996-01-01",
>>                      end="2006-06-16", quote = c("Close"), adjusted =
>>                      TRUE, download = TRUE, origin = "1970-01-01",
>>                      compression = "d")
>>
>>
>> Thanks,
>> Sumanta Basak.
>>
>>
>> ---------------------------------
>>
>>
>>  [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> [hidden email] mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide!
>> http://www.R-project.org/posting-guide.html
>
> Petr Pikal
> [hidden email]
>
 

Juan Antonio Breña Moral.
Advanced Marketing Ph.D. , URJC, Spain (Now)
Industrial Organisation Engineering, ICAI, Spain.
Technical Computer Programming Engineering, ICAI, Spain
Web: http://www.juanantonio.info
Mobile: +34 655970320

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html