TeeChartPHP
[ class tree: TeeChartPHP ] [ index: TeeChartPHP ] [ all elements ]

Source for file OHLC.php

Documentation is available at OHLC.php

  1. <?php
  2.  
  3. /**
  4.  * OHLC class
  5.  *
  6.  * Description: OHLC is an base Series class that maintains lists for Open,
  7.  * Close, High and Low values
  8.  *
  9.  * @author
  10.  * @copyright (c) 1995-2008 by Steema Software SL. All Rights Reserved. <info@steema.com>
  11.  * @version 1.0
  12.  * @package TeeChartPHP
  13.  * @subpackage styles
  14.  * @link http://www.steema.com
  15.  */
  16.  
  17.  class OHLC extends Custom {
  18.  
  19.     protected $vHighValues;
  20.     protected $vLowValues;
  21.     protected $vOpenValues;
  22.  
  23.     // Interceptors
  24.     function __get$property {
  25.       $method ="get{$property}";
  26.       if method_exists$this$method ) ) {
  27.         return $this->$method();
  28.       }
  29.     }
  30.  
  31.     function __set $property,$value {
  32.       $method ="set{$property}";
  33.       if method_exists$this$method ) ) {
  34.         return $this->$method($value);
  35.       }
  36.     }
  37.  
  38.     public function OHLC($c=null{
  39.         parent::Custom($c);
  40.  
  41.         $this->getXValues()->setDateTime(true);
  42.         $this->getXValues()->setName("ValuesDate")// TODO $this->Language->getString("ValuesDate");
  43.         $this->getYValues()->setName("ValuesClose")// TODO $this->Language->getString("ValuesClose");
  44.  
  45.         $this->vHighValues = new ValueList($this"ValuesHigh")// TODO $this->Language->getString("ValuesHigh"));
  46.         $this->vLowValues = new ValueList($this"ValuesLow")// TODO $this->Language->getString("ValuesLow"));
  47.         $this->vOpenValues = new ValueList($this"ValuesOpen")//$this->Language->getString("ValuesOpen"));
  48.     }
  49.  
  50.     /**
  51.     * All the Stock market Date values.
  52.     * You can access Date values in the same way you can access X or Y values.
  53.     *
  54.     * @return ValueList 
  55.     */
  56.     public function getDateValues({
  57.         return $this->getXValues();
  58.     }
  59.  
  60.     /**
  61.     * Sets all Stock market Date values.
  62.     * You can access Date values in the same way you can access X or Y values.
  63.     *
  64.     * @param ValueList $value 
  65.     */
  66.     public function setDateValues($value{
  67.         $this->setValueList($this->getXValues()$value);
  68.     }
  69.  
  70.     /**
  71.     * All the Stock market Close values.
  72.     * You can access Close values in the same way you can access X or Y values.
  73.     *
  74.     * @return ValueList 
  75.     */
  76.     public function getCloseValues({
  77.         return $this->getYValues();
  78.     }
  79.  
  80.     /**
  81.     * Sets all Stock market Close values.
  82.     * You can access Close values in the same way you can access X or Y values.
  83.     *
  84.     * @param ValueList $value 
  85.     */
  86.     public function setCloseValues($value{
  87.         $this->setValueList($this->getYValues()$value);
  88.     }
  89.  
  90.     /**
  91.     * All the Stock market Open values.
  92.     * You can access Open values in the same way you can access X or Y values.
  93.     *
  94.     * @return ValueList 
  95.     */
  96.     public function getOpenValues({
  97.         return $this->vOpenValues;
  98.     }
  99.  
  100.     /**
  101.     * Sets all Stock market Open values.
  102.     * You can access Open values in the same way you can access X or Y values.
  103.     *
  104.     * @param ValueList $value 
  105.     */
  106.     public function setOpenValues($value{
  107.         $this->setValueList($this->vOpenValues$value);
  108.     }
  109.  
  110.     /**
  111.     * All the Stock market High values.
  112.     * You can access High values in the same way you can access X or Y values.
  113.     *
  114.     * @return ValueList 
  115.     */
  116.     public function getHighValues({
  117.         return $this->vHighValues;
  118.     }
  119.  
  120.         /**
  121.           * Sets all Stock market High values.<br>
  122.           * You can access High values in the same way you can access X or Y values.
  123.           *
  124.           * @param value ValueList
  125.           */
  126.     public function setHighValues($value{
  127.         $this->setValueList($this->vHighValues$value);
  128.     }
  129.  
  130.         /**
  131.           * All the Stock market Low values.<br>
  132.           * You can access High values in the same way you can access X or Y values.
  133.           *
  134.           * @return ValueList 
  135.           */
  136.     public function getLowValues({
  137.         return $this->vLowValues;
  138.     }
  139.  
  140.         /**
  141.           * Sets all Stock market Low values.<br>
  142.           * You can access High values in the same way you can access X or Y values.
  143.           *
  144.           * @param value ValueList
  145.           */
  146.     public function setLowValues($value{
  147.         $this->setValueList($this->vLowValues$value);
  148.     }
  149.  
  150.         /**
  151.           * Adds new point with specified integer index and double open, high,
  152.           * low and close.
  153.           *
  154.           * @param index int
  155.           * @param open double
  156.           * @param high double
  157.           * @param low double
  158.           * @param close double
  159.           * @return int index of added point
  160.           */
  161. /* TODO remove    public function add($index, $open, $high, $low,$close) {
  162.         $tmp = $index;
  163.         return $this->add($tmp, $open, $high, $low, $close);
  164.     }*/
  165.  
  166.         /**
  167.           * Adds new point with specified double index and double open, high, low
  168.           * and close.
  169.           *
  170.           * @param index double
  171.           * @param open double
  172.           * @param high double
  173.           * @param low double
  174.           * @param close double
  175.           * @return int index of added point
  176.           */
  177.     public function addCandle($index$open$high$low$close,$text=""{
  178.         $this->vHighValues->tempValue $high;
  179.         $this->vLowValues->tempValue $low;
  180.         $this->vOpenValues->tempValue $open;
  181.  
  182.         if ($text == "")
  183.           return $this->addXY($index$close);
  184.         else
  185.           return $this->addXYText($index$close,$text);
  186.     }
  187.  
  188.         /**
  189.           * Adds new point with specified double open, high, low and close.
  190.           *
  191.           * @param open double
  192.           * @param high double
  193.           * @param low double
  194.           * @param close double
  195.           * @return int index of added point
  196.           */
  197. /* TODO    public function add($open, $high, $low, $close) {
  198.         return $this->add($this->getCount(), $open, $high, $low, $close);
  199.     }  */
  200.  
  201.         /**
  202.           * Adds new point with specified DateTime x and double open, high, low
  203.           * and close.
  204.           * @param aDate DateTime
  205.           * @param open double
  206.           * @param high double
  207.           * @param low double
  208.           * @param close double
  209.           * @return int index of added point
  210.           */
  211.     public function addCandleDate($aDate$open$high$low$close{
  212.         return $this->add($aDate->toDouble()$open$high$low$close);
  213.     }
  214.  
  215.         /**
  216.           * Adds the DataView to the OHLC series.
  217.           *
  218.           * @param view DataView
  219.           */
  220.         /**
  221.           * Validates Series datasource.
  222.           *
  223.           * @param value ISeries the series to validate.
  224.           * @return boolean true if value can be a Series data source.
  225.           */
  226.     public function isValidSourceOf($value{
  227.         return $value instanceof OHLC;
  228.     }
  229.  
  230.         /**
  231.           * The Maximum Value of the Series Y Values List.
  232.           *
  233.           * @return double 
  234.           */
  235.     public function getMaxYValue({
  236.         $result max($this->getCloseValues()->getMaximum(),
  237.                                  $this->vHighValues->getMaximum());
  238.         $result max($result$this->vLowValues->getMaximum());
  239.         return max($result$this->vOpenValues->getMaximum());
  240.     }
  241.  
  242.         /**
  243.           * The Minimum Value of the Series Y Values List.<br>
  244.           * As some Series have more than one Y Values List, this Minimum Value is
  245.           * the "Minimum of Minimums" of all Series Y Values lists.
  246.           *
  247.           * @return double 
  248.           */
  249.     public function getMinYValue({
  250.         $result min($this->getCloseValues()->getMinimum(),
  251.                                  $this->vHighValues->getMinimum());
  252.         $result min($result$this->vLowValues->getMinimum());
  253.         return min($result$this->vOpenValues->getMinimum());
  254.     }
  255.  
  256.     protected function numSampleValues({
  257.         return 40;
  258.     }
  259.  
  260.     protected function addSampleValues($numValues{
  261.         $r $this->randomBounds($numValues);
  262.  
  263.         $aOpen $r->MinY MathUtils::round($r->DifY $r->Random())//  open price
  264.  
  265.         for $t 1$t <= $numValues$t++{
  266.             // Generate random figures
  267.             $ohlc $this->getRandomOHLC($r$aOpen$r->DifY);
  268.  
  269.             // Call the standard add method
  270.             $this->addCandle($r->tmpX$aOpen$ohlc->aHigh$ohlc->aLow$ohlc->aClose);
  271.  
  272.             $r->tmpX += $r->StepX// <--   X value
  273.  
  274.             // Tomorrow, the market will open at today's close plus/minus something
  275.             $aOpen $ohlc->aClose (10 $r->Random()) 5;
  276.         }
  277.     }
  278.  
  279.         /**
  280.           * Point characteristics
  281.           *
  282.           * @param index int
  283.           * @return SeriesOHLCPoint 
  284.           */
  285.     public function getOHLCPoint($index{
  286.         return new SeriesOHLCPoint($this$index);
  287.     }
  288.  
  289.     private function getRandomOHLC($rr$aOpen,$yRange{
  290.  
  291.         $r new RandomOHLC();
  292.         $tmpY abs(MathUtils::round($yRange 400.0));
  293.  
  294.         $r->aClose $aOpen MathUtils::round($yRange 25.0$rr->Random(-
  295.                    ($this->yRange 50.0)/*   close price->->-> */
  296.  
  297.         /* and imagine the high and low session price */
  298.  
  299.         $tmpFixed MathUtils::round(abs($r->aClose $aOpen10.0);
  300.  
  301.         if ($r->aClose $aOpen{
  302.             $r->aHigh $r->aClose $tmpFixed $tmpY $rr->Random();
  303.             $r->aLow $aOpen $tmpFixed $tmpY $rr->Random();
  304.         else {
  305.             $r->aHigh $aOpen $tmpFixed $tmpY $rr->Random();
  306.             $r->aLow $r->aClose $tmpFixed $tmpY $rr->Random();
  307.         }
  308.         return $r;
  309.     }
  310. }
  311.  
  312. ?>

Documentation generated on Wed, 16 Jun 2010 12:07:07 +0200 by phpDocumentor 1.4.1