Northwest Arkansas Community
Welcome, Guest. Please login or register.
July 30, 2010, 05:17:58 AM

Login with username, password and session length
Search:     Advanced search
Welcome to NWA's community on the web!
698 Posts in 331 Topics by 512 Members
Latest Member: angiela2j
* Home Help Search Login Register
Northwest Arkansas Community  |  Computer Talk  |  Scripting Languages  |  PHP Stock Quotes Code  |  Topic: Create Your Own Index of Stocks 0 Members and 1 Guest are viewing this topic. « previous next »
Pages: [1] Go Down Print
Author Topic: Create Your Own Index of Stocks  (Read 3476 times)
Jim
Administrator
Hero Member
*****

Karma: +109/-2
Offline Offline

Gender: Male
Posts: 544


View Profile WWW
« on: September 08, 2007, 11:08:19 AM »

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:

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 ($fp1000",");

   
$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."&nbsp;&nbsp;<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!
Logged
neigschbeid
Newbie
*

Karma: +0/-0
Offline Offline

Posts: 3


View Profile
« Reply #1 on: September 28, 2007, 02:07:47 PM »

hello of people,

how can I insert the stock quote scripts into a table?
(HTML file.)
I do not have no notion and did not understand that. Huh Huh Huh Huh
please help me

greeting neigschbeid
Logged
Jim
Administrator
Hero Member
*****

Karma: +109/-2
Offline Offline

Gender: Male
Posts: 544


View Profile WWW
« Reply #2 on: September 29, 2007, 07:08:55 AM »

Copy and paste the code where you want it to appear.
Logged
Pages: [1] Go Up Print 
Northwest Arkansas Community  |  Computer Talk  |  Scripting Languages  |  PHP Stock Quotes Code  |  Topic: Create Your Own Index of Stocks « previous next »
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.4 | SMF © 2006-2007, Simple Machines LLC Valid XHTML 1.0! Valid CSS!