给你一个例程,用于抓取新浪股票2017年1月份的股票数据。程序如下:
clc;
clear;
year=2017;
season = 1 ;
fprintf('抓取%d年%d季度的数据中\n', year, season)
[sourcefile, status] = urlread(sprintf('>
class RSI{
static function lag($period = 14){
return $period;
}
static function run($data, $period = 14){
$change_array = array();
//loop data
foreach($data as $key => $row){
//need 2 points to get change
if($key >= 1){
$change = $data[$key]['close'] - $data[$key - 1]['close'];
//add to front
array_unshift($change_array, $change);
//pop back if too long
if(count($change_array) > $period)
array_pop($change_array);
}
//have enough data to calc rsi
if($key > $period){
//reduce change array getting sum loss and sum gains
$res = array_reduce($change_array, function($result, $item) {
if($item >= 0)
$result['sum_gain'] += $item;
if($item < 0)
$result['sum_loss'] += abs($item);
return $result;
}, array('sum_gain' => 0, 'sum_loss' => 0));
$avg_gain = $res['sum_gain'] / $period;
$avg_loss = $res['sum_loss'] / $period;
//check divide by zero
if($avg_loss == 0){
$rsi = 100;
} else {
//calc and normalize
$rs = $avg_gain / $avg_loss;
$rsi = 100 - (100 / ( 1 + $rs));
}
//save
$data[$key]['val'] = $rsi;
}
}
return $data;
}
}
以上就是关于matlab怎样抓取Yahoo/Sina的股票数据全部的内容,包括:matlab怎样抓取Yahoo/Sina的股票数据、急求!哪位懂股票的IT大神能用php代码写出RSI的算法,最好带有注解 谢谢、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)