/** * Default Page. * * @Route("/{codigo}/show", name="cotacao_show") * @Method("GET") * @Template("RoyopaSicinBundle:Cotacao:show.html.twig") */ public function showAction($codigo) { $client = new \Scheb\YahooFinanceApi\ApiClient(); $ativo = $client->search($codigo); if (count($ativo['ResultSet']['Result']) == 0) { return new Response('Ativo não encontrado.'); } $ativo = $ativo['ResultSet']['Result'][0]; $dataInicial = new \DateTime('now'); $interval = new \DateInterval('P3M'); $interval->invert = 1; $dataInicial = $dataInicial->add($interval); $chart = new Highchart(Highchart::HIGHSTOCK); $chart->chart->renderTo = "container"; $chart->rangeSelector->selected = 1; $chart->title->text = "AAPL Stock Price"; $chart->series[] = array('name' => "AAPL", 'data' => new HighchartJsExpr("data"), 'tooltip' => array('valueDecimals' => 2)); //Get historical data $data = $client->getHistoricalData($ativo['symbol'], $dataInicial, new \DateTime('now')); return array('ativo' => $ativo, 'entities' => $data['query']['results'], 'chart' => $chart); }
public function getHistoricalData() { $quotes = array(); $client = new \Scheb\YahooFinanceApi\ApiClient(); try { sleep(0.8); $hist_data1 = $client->getHistoricalData($this->ticker, new \DateTime("-1 year"), new \DateTime("-1 day")); sleep(0.8); $hist_data2 = $client->getHistoricalData($this->ticker, new \DateTime("-2 years"), new \DateTime("-1 year")); $data1 = $hist_data1['query']['results']['quote']; $data2 = $hist_data2['query']['results']['quote']; $data = array_merge($data1, $data2); foreach ($data as $datum) { $quotes[strtotime($datum['Date']) * 1000] = round($datum['Close'], 2); } } catch (Exception $e) { echo $e->getMessage(); } return $quotes; }
$date->modify('next day'); } // saturday or sunday if (is_weekend($date)) { $date->modify('next monday'); } return $date->format('Y-m-d'); } $client = new \Scheb\YahooFinanceApi\ApiClient(); $mutual_funds = ['FPHAX', 'FRXIX']; $funds = []; foreach ($mutual_funds as $mutual_fund) { $symbol = $mutual_fund; $start_date = new DateTime('2015-09-01'); $end_date = new DateTime('NOW'); $history_nav = $client->getHistoricalData($symbol, $start_date, $end_date); $current_nav = $client->getQuotes($symbol); $current_nav = $current_nav['query']['results']['quote']['LastTradePriceOnly']; //print '<pre>'; //print_r($history_nav); //print '</pre>'; //exit; $interval = DateInterval::createFromDateString('first day of next month'); $period = new DatePeriod($start_date, $interval, $end_date, DatePeriod::EXCLUDE_START_DATE); $trans_date[] = is_market_closed($start_date); $start_date_day = $start_date->format('d'); if ($start_date_day < 15) { $days_till_fifteenth = 15 - $start_date_day; $fifteenth_day = $start_date->add(new DateInterval('P' . $days_till_fifteenth . 'D')); $trans_date[] = is_market_closed($fifteenth_day); }