This is a 100% cool code. Came up with it on my own with what little spare time I have. I hope it's appreciated as much as I think it will be.
There are a couple of things to keep in mind when you're dealing with what I call the Arkansas 10 Index.
In the below part of the code, each number is respectively matched with the symbols that you'll want to keep track of. In other words, if you have 20 symbols you're tracking, the number would have to be divisible by 100, thus making it change to 0.05 instead of 0.10.
$portfolioperc=array("0.10","0.10","0.10","0.10","0.10","0.10","0.10","0.10","0.10","0.10");Here's the code:
<html>
<head>
<title>The Arkansas 10</title>
</head>
<body>
<?php
# Stock symbols (should match the below respectively)
$stocks=array("abfs","at","acxm","dds","del","jbht","mur","ozrk","tsn","wmt");
# The decimal percentage the stock makes up of the total
# portfolio (should match to the above respectively)
$portfolioperc=array("0.10","0.10","0.10","0.10","0.10","0.10","0.10","0.10","0.10","0.10");
$i=0;
foreach ($stocks as $stock) {
# Yahoo! Finance URL to fetch the CSV data
$fp = fopen ("http://finance.yahoo.com/d/quotes.csv?s=$stock&f=sl1d1t1c1ohgvnpc1p2&e=.csv","r");
$data = fgetcsv ($fp, 1000, ",");
$price=$data[1];
$volume=$data[8];
$name=$data[9];
$previous=$data[10];
$change=$data[11];
$pchange=$data[12];
$indexcurrent=$indexcurrent+$price;
$indexvolume=$indexvolume+$volume;
$previousclose=$previousclose+$previous;
$totalchange=$totalchange+($price-$previous);
$totalperc=$totalperc+($portfolioperc[$i]*$pchange);
fclose ($fp);
$i++;
}
echo "<p><b>The Arkansas 10</b><dt>$".$indexcurrent." <span style=\"";
# Same concept with the colors of text used above
if ($totalperc>0) {
echo "color: #009900;";
} elseif ($totalperc<0) {
echo "color: #990000;";
} else {
echo "font-weight: normal;";
}
echo "\">$".round($totalchange,2)." - (".round($totalperc,2)."%)</span><dt>";
echo "<b>Previous Close:</b> ".round($previousclose,2)."<dt><b>Volume:</b> ".$indexvolume."<dt>\n";
?>
</div>
</body>
</html>
Hope you enjoy!