Esempio n. 1
0
?>
<style>
    tr,td,th{height: 20px!important;margin: 0px!important;padding: 0px!important;}
</style>
<div class="row">
    <div class="col-md-12">
        <table class="table table-striped table-hover">
            <thead>
            <tr>
                <td colspan="3" style="text-align: center;font-weight: 700;">
                    月涨幅记录--编号:<?php 
echo $num;
?>
;
                    类型:<?php 
echo \common\models\FundNum::getTypeName($num);
?>
;
                    均值:<?php 
echo number_format($average, 2);
?>
;
                    标准差:<?php 
echo number_format($sd, 2);
?>
;
                    比例:<?php 
echo number_format($sd / $average, 2);
?>
;
                    总计:<?php 
Esempio n. 2
0
 /**
  * 获取若干指定基金的指定类型详情
  * @param $date_type
  * @return array|string
  */
 public function actionFundDetailFilter($date_type)
 {
     if (!$date_type || !in_array($date_type, ['month', 'week', 'day'])) {
         return '';
     }
     if (Yii::$app->request->isPost) {
         Yii::$app->response->format = Response::FORMAT_JSON;
         $nums = Yii::$app->request->post('nums');
         if (!$nums) {
             return '';
         }
         $data = [];
         foreach ($nums as $num) {
             $fund = FundNum::find()->where(['fund_num' => $num])->one();
             if (!$fund) {
                 continue;
             }
             $connection = Yii::$app->db;
             if ($date_type == 'month') {
                 $sql = "SELECT YEAR(`date`) as `year`,MONTH(`date`) as `month`,SUM((rate+0)) AS sum_rate FROM fund_history WHERE fund_num = '" . $num . "' GROUP BY YEAR(`date`),MONTH(`date`) ORDER BY YEAR(`date`) DESC,MONTH(`date`) DESC";
             } elseif ($date_type == 'week') {
                 $sql = "SELECT YEAR(`date`) as `year`,MONTH(`date`) as `month`,WEEK(`date`) as `week`,SUM((rate+0)) AS sum_rate FROM fund_history WHERE fund_num = '" . $num . "' GROUP BY YEAR(`date`),MONTH(`date`),WEEK(`date`) ORDER BY YEAR(`date`) DESC,MONTH(`date`) DESC,WEEK(`date`) DESC ";
             } elseif ($date_type == 'day') {
                 $sql = "SELECT `date`,(rate+0) as sum_rate FROM fund_history WHERE fund_num = '" . $num . "' ORDER BY `date` DESC";
             } else {
                 return '';
             }
             $command = $connection->createCommand($sql);
             $posts = $command->queryAll();
             $rate_data = ArrayHelper::getColumn($posts, 'sum_rate');
             $sd = 0;
             if ($rate_data) {
                 $average = array_sum($rate_data) / count($rate_data);
                 $n = 0;
                 foreach ($rate_data as $v) {
                     $n += ($v - $average) * ($v - $average);
                 }
                 $sd = sqrt($n / count($rate_data));
             } else {
                 $average = 0;
             }
             $data[] = ['fund_num' => $num, 'type' => FundNum::getTypeName($num), 'average' => number_format($average, 2), 'sd' => number_format($sd, 2)];
         }
         return $data;
     } else {
         return '';
     }
 }