• 欢迎访问小杰博客网站
  • 欢迎访问小杰博客网站哦

【小杰说股】指数基金利润研究-php代码分析

未分类 小杰 6年前 (2015-04-19) 635次浏览 已收录 0个评论

<?php

// 指数基金分析
// 假设指数基金 和大盘保持 一致

$dapan_index_start = 4300;
$money = 10000;
$up_index = 0.01;
$down_index = 0.01;

get_jijin($dapan_index_start,$money);
//get_jijin_low_in($dapan_index_start,$money);

function qlog($msg) {
var_dump($msg);
}

function get_game_result($win,$lose) {
$game_result = array();
$game_count = 120;
$up = $down = 0;

for($i=0;$i<$game_count;$i++) {
if($win == $lose) {
if(rand(1,120)%2 == 1) {
$game_result[] = 1;
$up ++;
} else {
$game_result[] = -1;
$down++;
}
} else if($win == 2*$lose) {
if(rand(1,120)%3 == 0 || rand(1,120)%3 == 1) {
$game_result[] = 1;
$up ++;
} else {
$game_result[] = -1;
$down++;
}

}

qlog($up);
qlog($down);
    qlog($game_result);
    
    return $game_result;
}

// 放着不管
function get_jijin($dapan_index,$money) {
$up_index = 0.01;
$down_index = 0.01;
$base_index = 0.01;
$games = get_game_result(2,1);
foreach($games as $game) {
$dapan_index = $dapan_index*(1+$game*$base_index);
$money = $money*(1+$game*$base_index);
qlog(‘$dapan_index:’.$dapan_index.’ money:’.$money.’ $game:’.$game.’ $base_index:’.$base_index);

}
}

// 低点买入
function get_jijin_low_in($dapan_index,$origin_money) {
$up_index = 0.01;
$down_index = 0.01;
$base_index = 0.01;
$the_origin_money = $origin_money;
$low_in_all_money = 0;
$low_in_base_money = 200;
$low_in_current_money = 0;
$low_in = array();
$games = get_game_result(2,1);
foreach($games as $game) {

$dapan_index = $dapan_index*(1+$game*$base_index);
$origin_money = $origin_money*(1+$game*$base_index);
$low_in_current_money = $low_in_current_money*(1+$game*$base_index);

// 低点
if($game == -1) {
$low_in_all_money += $low_in_base_money;
$low_in_current_money += $low_in_base_money;
}

$chenben = $the_origin_money+$low_in_all_money;
$current_money = $origin_money+$low_in_current_money;
$lirun = $current_money – $chenben;
$average_rirun = $lirun/120;
qlog(‘$lirun:’.$lirun.’ $average_rirun:’.$average_rirun.’ $chenben:’.$chenben.’ $current_money:’.$current_money.’ $dapan_index:’.$dapan_index.’ $origin_money:’.$origin_money.’ $low_in_current_money:’.$low_in_current_money.’ $low_in_all_money:’.$low_in_all_money.’ $game:’.$game.’ $base_index:’.$base_index);

}
}
?>


小杰博客 , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:【小杰说股】指数基金利润研究-php代码分析
喜欢 (0)
发表我的评论
取消评论
表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址