I have a small PHP code that fetches data from yahoos csv stock feed. It works great for a static stock symbol. (e.g. GOOG, YHOO)
But what I am wanting to do, is update the stock symbol based on what date it is. Specifically oil and gas futures. Since the "active" futures symbol changes based on what date it is.
The symbol looks like this: CLZ10.NYM
CL is for crude oil, Z is the month code, 10 is the year. Here are the other month codes.
F=January
G=February
H=March
J=April
K=May
M=June
N=July
Q=August
U=September
V=October
X=November
Z=December
The tricky thing is, the symbol doesn't change at the end of the month, it changes sometimes during the month, like the 3rd friday or something.
Any ideas or suggestions on how to accomplish what I'm talking about?
Here is the current code:
$stock = 'CLZ10.NYM';
if ($stock != "") {
$yahoo_file = fopen ("http://finance.yahoo.com/d/quotes.csv?s=$stock&f=sl1d1t1c1ohgv&e=.csv","r");
$stock_info = fgetcsv ($yahoo_file, 1000, ",");
echo "<b>NYMEX</b> Crude Oil (bbl) $<b>$stock_info[1]</b>";
}
else {
echo"Not Working!";
}
//close the filehandle $fp
fclose ($yahoo_file);