用在PHP中的股票分析寫的一個類

日期:2006-08-09  作者:喜騰小二  來源:PHPChina


原文:http://www6.blog.163.com/article/-6O04-xo4My2.html

/*******************************************************

  做股票就是跟莊.跟莊就賺錢.哈哈.
  writer:xiaojianhe,time:2006-6-20
  e-mail:do-found@163.com
  功能:用於分析股票數據的記錄值

********************************************************/

class get_stock_data

{
 //PHP裡的這些意思不大,先寫上吧,用不用再說

 var $b_price;
 var $b_total;
 var $p_price;
 var $p_total;
 var $z_price;
 var $z_total;

 var $b_a_price;
 var $p_a_price;
 var $z_a_price;

 var $hd;
 var $filename;
 
 function get_stock_data()
 {
  global $filename;
  $this -> hd = file("$filename");
 }
 function open_all_data()
 {
  
  foreach($this -> hd as $values)
  {

   $fc = explode("",$values);
   $l_a = ereg_replace("[[:space:]]","",$fc[0]);
   $l_b = ereg_replace("[[:space:]]","",$fc[1]);
   $l_c = ereg_replace("[[:space:]]","",$fc[2]);
   $l_d = ereg_replace("[[:space:]]","",$fc[3]);
   
   if($l_d == "買盤")
   {
    
    $b_total .= $i."----)))".$l_a."___".$l_b."___".$l_c."___".$l_d."___總價格:".$l_b*$l_c."人民幣
";  ////買盤所有值

    $b_time .= $l_a.",";       ////買盤各條時間
    $b_price_only_total[] = $l_c;     ////買盤的價格
    $b_price_only_nums[] = $l_b;     ////買盤的數量
    $b_price_nums += $l_b;       ////買盤總數量
    $b_price_all_total += $l_c*$l_b;    ////買盤總值
    
    $i++;

   }elseif($l_d == "賣盤"){
    
    $p_total .= $l_a."___".$l_b."___".$l_c."___".$l_d."___總價格:".$l_b*$l_c."人民幣
";  ////賣盤所有值

    $p_time .= $l_a.",";       ////賣盤各條時間
    $p_price_only_total[] = $l_c;     ////賣盤的價格
    $p_price_only_nums[] = $l_b;     ////賣盤的數量
    $p_price_nums += $l_b;
    $p_price_all_total += $l_c*$l_b;    ////賣盤總值

   }else{

    //"中性盤";
    $t++;
    $z_total .= $l_a."___".$l_b."___".$l_c."___".$l_d."
";

    $z_time .= $l_a.",";        ////中性盤各條時間
    $z_price_only_total .= $l_c.",";     ////中性盤所有的價格
    $z_price_nums .= $l_b.",";       ////中性盤各條數量
    $z_price_all_total += $l_c*$l_b;     ////中性盤總值

   }

   $all_pp[] = $l_c;

  }
  
  
  $all_mydata = array
     (
      'b_price' => $b_price_only_total,
      'p_price' => $p_price_only_total,
      'a_price' => $all_pp,
      'b_a' => $b_price_all_total,
      'p_a' => $p_price_all_total,
      'b_num' => $b_price_nums,
      'p_num' => $p_price_nums,
     );
  return $all_mydata;
 }

 //測試用了
 function get_arr_value($s)
 {
  $i = 0;
  foreach ($s as $key => $values)
  {
   echo $i++."___".$key ."=>".$values."
";
   
  }
  //return substr($val,0,-1);
 }

 //這部份暫時沒用
 function re_max($s,$model=1)
 {
  $s = explode(",",$s);
  for ( $i = 0 ; $i < count($s) ; $i ++ )
  {
   if ( $i == 0 )
   {
      $max = $s[$i];
      $min = $s[++$i];
      $i--;

   }else{

      $min = $s[$i];
   }

   if($model)
   {
    if ( $max <= $min )     $max = $s[$i];

   }else{

    if ( $max > $min )     $max = $s[$i];
   }
  }
  return $max;
 }

 //取唯一

 function get_lines($a)
 {
  return array_unique($a);
 }

 function get_once_detail($cu,$param,$model=1)
 {
  foreach($this -> hd as $values)
  {
   $fc = explode("",$values);
   $l_a = ereg_replace("[[:space:]]","",$fc[0]);
   $l_b = ereg_replace("[[:space:]]","",$fc[1]);
   $l_c = ereg_replace("[[:space:]]","",$fc[2]);
   $l_d = ereg_replace("[[:space:]]","",$fc[3]);
   
   if($l_d == "$param")
   {
    //echo $l_d;
    if($l_c == $cu)
    {
     $cu_nums += $l_b;
     $cu_values += $l_b*$l_c;
    }
    $all_nums += $l_b;
    $all_values += $l_b*$l_c;
   }
  }

  switch($model)
  {
   case 0: return $cu_nums; break;
   case 1: return $cu_values; break;
   case 2: return "買入總股數:".$all_nums."   買入總值".$all_values; break;
  }
 }
}
?>

<<<返回技術中心

技術文章

站內新聞

我要啦免费统计