Questions

Stock Calculation

Hi i saw this code from one web site i forgot the site name

so please make use it








My Portfolio





My Portfolio

<?php
$fp = fopen ("http://finance.yahoo.com/d/quotes.csv?s=$stock&f=sl1d1t1c1ohgv&e=.csv","r");
$yahoo_file = fopen ("http://finance.yahoo.com/d/quotes.csv?s=$stock&f=sl1d1t1c1ohgv&e=.csv","r");
$data = fgetcsv ($fp, 1000, ",");


# Name of our stocks (Yahoo! does not provide this in the CSV file)
$stockname=array("Google");

# Stock symbols (should match to the above respectively)
$stocks=array("GOOG");

# What we bought at (should match to the above respectively)
$stockbuy=array("58.76");

# How many shares we own of each stock
$sharesowned=array("400");

# The decimal percentage the stock makes up of the total
# portfolio (should match to the above respectively)
$portfolioperc=array(".20");
$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=sl1d1t1c1ohgv&e=.csv","r");
$yahoo_file = fopen ("http://finance.yahoo.com/d/quotes.csv?s=$stock&f=sl1d1t1c1ohgv&e=.csv","r");
$data = fgetcsv ($fp, 1000, ",");
$price=$data[1];
echo "".$stockname[$i]." (".$stock.") - ".$stock."n";
echo "n";


echo "Current Price: $".$price."n";

// The Amount of shares we hold for each individual stock
echo "Shares Owned: ".$sharesowned[$i]."n";

// Here is the value of the shares we own for each individual stock
$stocktotal=($price*$sharesowned[$i]);
echo "Value Of Stock: $".$stocktotal."n";

echo "Purchase Price: $".round($stockbuy[$i],2)."n";

$perc=round(((($price-$stockbuy[$i])/$price)*100),2);
echo "Percent Change: ".$perc."%n";
echo "n";
$totalperc=$totalperc+($portfolioperc[$i]*$perc);
echo "n";
echo "n";
fclose ($fp);
$i++;
}
echo "n";
echo "2005 Percentage Change: ".round($totalperc,2)."%";

echo "Shares: ".$sharesowned."n";

?>






tha out put will come like the bellow



My Portfolio

* Google (GOOG) - GOOGn
o nCurrent Price: $449.578
o nShares Owned: 400
o nValue Of Stock: $179831.2
o nPurchase Price: $58.76
o nPercent Change: 86.93%
nnn
n

n

2005 Percentage Change: 17.39%Shares

Your Answers

Your Name:
Your Answers :
<> is a code tag
Preview
Enter the verification code:

Answers

No Answers..