Last active
June 13, 2016 13:56
-
-
Save thewinterwind/793eeb2ecff957dd0298 to your computer and use it in GitHub Desktop.
Revisions
-
thewinterwind revised this gist
Jun 20, 2014 . 1 changed file with 3 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,9 +4,6 @@ class StoringController extends BaseController { public function store_streaks() { $date = date('Y-m-d'); $stocks = DB::table('stocks')->select('symbol')->orderBy('symbol', 'asc')->get(); @@ -54,15 +51,15 @@ public function store_streaks() // check if the winning streak is over or not if ($streak > 0) { // if current day's close is less than the day before it, the winning streak is over if ($days[$i]->close < $days[$i + 1]->close) break; // the winning streak continues $streak++; } elseif ($streak < 0) { // if the current day's close is more than the day before it, the losing streak is over if ($days[$i]->close > $days[$i + 1]->close) break; // the losing streak continues @@ -80,5 +77,4 @@ public function store_streaks() print "Stored a streak of " . $streak . " for: " . $stock->symbol . "\n"; } } } -
thewinterwind revised this gist
Jun 18, 2014 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -54,15 +54,15 @@ public function store_streaks() // check if the winning streak is over or not if ($streak > 0) { // if current day's close is less than day before it, streak is over if ($days[$i]->close < $days[$i + 1]->close) break; // the winning streak continues $streak++; } elseif ($streak < 0) { // if current day's close is more than day before it, streak is over if ($days[$i]->close > $days[$i + 1]->close) break; // the losing streak continues -
thewinterwind revised this gist
Jun 18, 2014 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -54,15 +54,15 @@ public function store_streaks() // check if the winning streak is over or not if ($streak > 0) { // if current day's close is less than the day before it, streak is over if ($days[$i]->close < $days[$i + 1]->close) break; // the winning streak continues $streak++; } elseif ($streak < 0) { // if the current day's close is more than the day before it, streak is over if ($days[$i]->close > $days[$i + 1]->close) break; // the losing streak continues -
thewinterwind created this gist
Jun 18, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,84 @@ <?php class StoringController extends BaseController { public function store_streaks() { ini_set("memory_limit", "-1"); set_time_limit(0); $date = date('Y-m-d'); $stocks = DB::table('stocks')->select('symbol')->orderBy('symbol', 'asc')->get(); foreach ($stocks as $stock) { $stored = DB::table('stocks') ->where('symbol', $stock->symbol) ->where('streak_stored', $date) ->first(); if ($stored) continue; $days = DB::table('summaries') ->select('close') ->where('symbol', $stock->symbol) ->orderBy('date', 'desc') ->limit(20) ->get(); $streak = 0; for ($i = 0; $i < count($days); $i++) { // if we're at the earliest day recorded for a stock, the streak is over if ( ! isset($days[$i + 1])) break; // if the next days price is the same as the current, the streak is over if ($days[$i]->close === $days[$i + 1]->close) break; // one time check for the first iteration if ($i === 0) { if ($days[$i] > $days[$i + 1]) { $streak++; continue; } if ($days[$i] < $days[$i + 1]) { $streak--; continue; } } // check if the winning streak is over or not if ($streak > 0) { // if current day's close is less than the day before it, the winning streak is over if ($days[$i]->close < $days[$i + 1]->close) break; // the winning streak continues $streak++; } elseif ($streak < 0) { // if the current day's close is more than the day before it, the losing streak is over if ($days[$i]->close > $days[$i + 1]->close) break; // the losing streak continues $streak--; } } DB::table('stocks') ->where('symbol', $stock->symbol) ->update([ 'streak' => $streak, 'streak_stored' => $date, ]); print "Stored a streak of " . $streak . " for: " . $stock->symbol . "\n"; } } }