Location: PHPKode > projects > Finasystem > fs_ta/roc.php
<?php
/**
* Finasystem version 0.4 Lin Hai - Technical Analysis Library in PHP
 *Release: 14/10/2006
 *Copyright (C) 2006 Rudy Zuck
 *mailto:rudy[-at-]zuck.fr
 *web:http://sourceforge.net/projects/finasystem
 *
 *This program is free software; you can redistribute it and/or
 *modify it under the terms of the GNU General Public License
 *as published by the Free Software Foundation; either version 2
 *of the License, or any later version.
 *
 *This program is distributed in the hope that it will be useful,
 *but WITHOUT ANY WARRANTY; without even the implied warranty of
 *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *GNU General Public License for more details.
 *
 *You should have received a copy of the GNU General Public License
 *along with this program; if not, write to the Free Software
 *Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA  
 */

/**
 * Rate Of Change (roc)
 *
 *<p>The Rate of Change function measures rate of change relative to previous 
 *periods. The function is used to determine how rapidly the data is changing. The 
 *factor is usually 100, and is used merely to make the numbers easier to interpret or 
 *graph. The function can be used to measure the Rate of Change of any data series, such 
 *as price or another indicator. When used with the price, it is referred to as the Price 
 *Rate Of Change, or PROC.</p>
 *
 *<p>Formula:</p>
 *
 * - ROC = 100 * ( input(t) / input(t-n) ) 
 *
 * @author Rudy Zuck <rudy[-at-]zuck.fr>
 * @copyright Copyright, 2006, Rudy Zuck
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
 * @version 0.4
 * @package fs_ta
 */

class roc{

	/**
	 * @var double[]
	 */
	private $roc;
	
	/**
     * @param double[] $data
	 * @param int $range
	 * @return double[]
     */
	function get($data,$range){
		
		$size_data = count($data);
		for ($i=$range-1; $i<$size_data;$i++){
				$this->roc[$i]= 100 * ($data[$i] / $data[$i-$range+1]);
		}
		return $this->roc;
	}
}
?>
Return current item: Finasystem