[ad_1]
Facebook –
GitHub –
Google+ –
LinkedIn –
reddit –
Support –
thenewboston –
Twitter –
PHP Stock Market Analyzer – 20 – The Final Product!
by
Tags:
Comments
43 responses to “PHP Stock Market Analyzer – 20 – The Final Product!”
-
Hi, This is great thanks for showing all this. A question I have is, can you show or direct us on how to use Yahoo API to pull these data which will enable stock updates faster than using a cron jobs? Thanks.
-
The 2nd part of the code (for the actual analysis part, The 1st part is a comment on the 12th tutorial) (there's a few tweaks from bucky's code, for example – I create the table from code and not manually, and also I used different variables names)
<?php
include ('connect.php'); //my connect is on the same work-folder
function masterLoop(){
$mainTickerFile = fopen("tickerMaster.txt","r");
while(! feof($mainTickerFile)){
$companyTicker = fgets($mainTickerFile);
$companyTicker = trim($companyTicker);$nextDayInc = 0;
$nextDayDec = 0;
$nextDayNoC = 0;
$total = 0;$sumOfInc = 0;
$sumOfDec = 0;$sqlSel = "SELECT Date, percentage_change FROM $companyTicker WHERE percentage_change < '0' ORDER BY Date ASC"; //
$resultSel = mysql_query($sqlSel);if($resultSel){
while($row = mysql_fetch_array($resultSel)){
$date1 = $row['Date'];
$per_change = $row['percentage_change'];$sql2 = "SELECT Date, percentage_change FROM $companyTicker WHERE Date > '$date1' ORDER BY Date ASC LIMIT 1";
$resultSel2 = mysql_query($sql2);
$numOfRows = mysql_num_rows($resultSel2);
$row2 = mysql_fetch_array($resultSel2);
$date2 = $row2['Date'];
$per_change2 = $row2['percentage_change'];if($numOfRows==1){
if($per_change2 > 0){
$nextDayInc++;
$sumOfInc += $per_change2;
$total++;
}else if($per_change2 < 0){
$nextDayDec++;
$sumOfDec += $per_change2;
$total++;
}else{
$nextDayNoC++;
$total++;
}
}else if ($numOfRows==0){
//no data after today
}else{
echo "You have an error";
}
}
}else{
echo "unable to select $companyTicker <br />";
}$nextDayIncPer = ($nextDayInc/$total)*100;
$nextDayDecPer = ($nextDayDec/$total)*100;
$avgIncPer = $sumOfInc/$nextDayInc;
$avgDecPer = $sumOfDec/$nextDayDec;insIntoTable($companyTicker, $nextDayInc, $nextDayIncPer, $avgIncPer, $nextDayDec, $nextDayDecPer, $avgDecPer);
}
}function insIntoTable($companyTicker, $nextDayInc, $nextDayIncPer, $avgIncPer, $nextDayDec, $nextDayDecPer, $avgDecPer){
$buckyBuy = $nextDayIncPer * $avgIncPer;
$buckySell = $nextDayDecPer * $avgDecPer;$queryS = "SELECT * FROM analysisA WHERE ticker = '$companyTicker' ";
$result3 = mysql_query($queryS);
$numOfRows2 = mysql_num_rows($result3);if($numOfRows2==1){
$queryUpd = "UPDATE analysisA SET ticker='$companyTicker',daysInc='$nextDayInc',pctOfDaysInc='$nextDayIncPer',avgIncPer='$avgIncPer',daysDec='$nextDayDec',pctOfDaysDec='$nextDayDecPer',avgDecPer='$avgDecPer', buy='$buckyBuy', sell='$buckySell' ";
mysql_query($queryUpd);
}else{
$queryIns = "INSERT INTO analysisA (ticker, daysInc, pctOfDaysInc, avgIncPer, daysDec, pctOfDaysDec, avgDecPer, buy, sell) VALUES('$companyTicker','$nextDayInc','$nextDayIncPer','$avgIncPer','$nextDayDec','$nextDayDecPer','$avgDecPer','$buckyBuy','$buckySell')";
mysql_query($queryIns);
}
}$queryC = "CREATE TABLE analysisA (ticker VARCHAR(8), PRIMARY KEY(ticker), daysInc INT, pctOfDaysInc FLOAT, avgIncPer FLOAT, daysDec INT, pctOfDaysDec FLOAT, avgDecPer FLOAT, buy FLOAT, sell FLOAT)";
mysql_query($queryC);
masterLoop();?>
-
I need the code bucky please help me out
-
After spending 45 minutes debugging, the culprit was a missing " ' " symbol in one of the queries. Annoying but glad to find it – great tutorials!
-
where can i get the code please help me guys
-
awesome tutorial
-
I hope you cashed in on NFLX!
-
yeahhhhh did it !!!
thanks bucky 🙂 you're awesome -
Thank you soooooooooooooooooooooo much!!!!!!!!!!!!!!
-
Thank you!!
-
hey bucky thank so much
-
why don't you use all this data and become a millionaire through the stock market?!? Seriously! 🙂
-
Funny part…. this video has more views than the majority of the ones in this series XD.
Thanks Bucky for everything. You provide and incredible amount of help to me and thousands of others.
-
I don't get it where's the code it's deleted
-
this is nice but it doesn't do what you actual said it is going to do, and that is tell you how many times it went up the following day after being down…
this script you wrote basically tells you nothing, however I did learn some PHP so thanks 🙂
-
I disagree, programming in Java is just as fast if you're familiar with it.
-
I've always thought that programming in Java takes much longer than in PHP. That's probably the reason why.
-
share with us!
-
yes, it is at the bottom inside the masterloop function and it takes many arguments:
insertIntoResultTable($companyTicker,$nextDayIncrease,$nextDayIncreasePercent,$averageIncreasePercent,$nextDayDecrease,$nextDayDecreasePercent,$averageDecreasePercent); -
google "high charts".
I've used them. -
Thanks Bucky. Terrific effort for the community!
-
google with "jqplot" or "flot"
-
damn, i went to thenewboston forum and went under PHP and saw PHP source codes. This tutorial is not there. There's only 2 pages of stuff there of very short codes from what looks like the PHP beginner/basics tutorial playlist.
Did you end up putting the function "insertIntoResultTable ()" back up under the while loop or did you keep it in the bottom??
-
how can i use/put a chart for this kind of program?(through php?)
-
great series. Thanks!
-
This series would be much, much more complete if you spent the time to actually make an interface page for the public. It seems kind of redundant to make an online application that can only be accessed by the admin, eh?
-
This was good. Bucky loves stock market analyzers, he had started one for java but never completed.
Please give us some advanced java tutorials like making a chatting tool in java using sockets or RPC. Please don't completely forget the java tutorials, they were very good.
-
Bucky can you write a script to get the world out of economic recession? Thanks.
-
Amazing bucky. Also, i was wondering if you're gonna do advanced C++ ?
-
how can this have just 316 view?
-
A challenge for Bucky would be to make a script that will login to your scottrade or other stock account and automatically buy or sell stocks depending on the signal your analysis says.
-
I tried this and the only table I had to create was the analysisA table which he shows in the video. It took about 30 minutes to test it all and it worked flawlessly!! Its very fast too. Looks like netflicks is still going up more than down. Maybe the download script could delete the old data if it exists first and then also have a dynamic variable for number of weeks of data to download and it will figure out what day that is and enter it in the url. That would make it greater. Wonderful job.
-
Does anyone have a good script idea for making a guess of whether to buy or sell a stock. You would need to change the algorythum if you make it work for longer term than a couple weeks.
-
php makes some kick ass phishing sites lol
-
Please c++ opengl PLEASE.
-
advanced udk tutorials
-
I just watched this, but good thing I didnt watch it before NFLX tanked.
-
I literally screamed when I saw this. Screamed in joy, that is.
-
Hey man thanks for what you do. Please keep it up bro. You are better than my current teacher in college. I have learned alot from you.
-
Bucky!! my boy!!! 😀
-
i just went to eat something and you are done god damn
-
PERFECT please we like to see more projects. very good work
-
Nice, went by quick
Leave a Reply