PHP Stock Market Analyzer – 20 – The Final Product!

[ad_1]
Facebook –
GitHub –
Google+ –
LinkedIn –
reddit –
Support –
thenewboston –
Twitter –


Posted

in

by

Tags:

Comments

43 responses to “PHP Stock Market Analyzer – 20 – The Final Product!”

  1. Crypto JohnSimpson Avatar

    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.

  2. D. Refaeli Avatar

    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();

    ?>

  3. pranav surampudi Avatar

    I need the code bucky please help me out

  4. Adam Jesse Avatar

    After spending 45 minutes debugging, the culprit was a missing " ' " symbol in one of the queries. Annoying but glad to find it – great tutorials!

  5. Vamshi Chigullapally Avatar

    where can i get the code please help me guys

  6. viralpennies83 Avatar

    I hope you cashed in on NFLX!

  7. freak frets Avatar

    yeahhhhh did it !!!
    thanks bucky 🙂 you're awesome

  8. thebestbestman123 Avatar

    Thank you soooooooooooooooooooooo much!!!!!!!!!!!!!!

  9. Mandlaenkosi Moyo Avatar

    hey bucky thank so much

  10. Mohnish Avatar

    why don't you use all this data and become a millionaire through the stock market?!? Seriously! 🙂

  11. Snow Avatar

    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.

  12. drako Caballero Avatar

    I don't get it where's the code it's deleted

  13. Andrey Avatar

    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 🙂

  14. 6NoHope9 Avatar

    I disagree, programming in Java is just as fast if you're familiar with it.

  15. latlov Avatar

    I've always thought that programming in Java takes much longer than in PHP. That's probably the reason why.

  16. latlov Avatar

    share with us!

  17. latlov Avatar

    yes, it is at the bottom inside the masterloop function and it takes many arguments:
    insertIntoResultTable($companyTicker,$nextDayIncrease,$nextDayIncreasePercent,$averageIncreasePercent,$nextDayDecrease,$nextDayDecreasePercent,$averageDecreasePercent);

  18. latlov Avatar

    google "high charts".
    I've used them.

  19. D Avatar

    Thanks Bucky. Terrific effort for the community!

  20. D Avatar

    google with "jqplot" or "flot"

  21. PancakePlease Avatar

    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??

  22. weward Avatar

    how can i use/put a chart for this kind of program?(through php?)

  23. Synth_Boi_Gaming Avatar

    great series. Thanks!

  24. Potado Tomado Avatar

    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?

  25. fckingkim Avatar

    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.

  26. josephknightcom Avatar

    Bucky can you write a script to get the world out of economic recession? Thanks.

  27. Skuzzi Avatar

    Amazing bucky. Also, i was wondering if you're gonna do advanced C++ ?

  28. meverycalm Avatar

    how can this have just 316 view?

  29. Michael Stokes Avatar

    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.

  30. Michael Stokes Avatar

    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.

  31. Michael Stokes Avatar

    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.

  32. MuhammadDerkaDerka Avatar

    php makes some kick ass phishing sites lol

  33. LuxrayIsEpic Avatar

    Please c++ opengl PLEASE.

  34. Hasnain Bilgrami Avatar

    advanced udk tutorials

  35. Andrew L Avatar

    I just watched this, but good thing I didnt watch it before NFLX tanked.

  36. Potado Tomado Avatar

    I literally screamed when I saw this. Screamed in joy, that is.

  37. William Freeman Avatar

    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.

  38. MegaBhatti1987 Avatar

    Bucky!! my boy!!! 😀

  39. BigSzuST Avatar

    i just went to eat something and you are done god damn

  40. ManuFrias Avatar

    PERFECT please we like to see more projects. very good work

  41. MooCow Gaming Avatar

    Nice, went by quick

Leave a Reply

Your email address will not be published. Required fields are marked *