比特币定投时机分析
前几天我写了比特币定投的文章,我当时选的是每个月第一天买入1000块钱比特币,然后我就想如果是在其它日期买入收益是怎样呢。然后代码如下:
echo 'simple policy: buy 140 usd on the first day of everymonth:'.PHP_EOL;
$btc = [];
$money = [];
$max = [];
for ($i=0;$i<32;$i++) {
$btc[$i] = $money[$i] = 0;
}
foreach ($result as $row) {
$i = ltrim(explode("-", $row[$keys[0]])[2], "0");
$price = $row[$keys[1]];
$spend = 140;
$btc[$i] += $spend/$price;
$money[$i] += $spend;
}
for ($i = 1; $i < sizeof($btc); $i++) {
echo 'on '.$i.'st day of month buy '.$btc[$i].' BTC for '.$money[$i].' USD';
echo '. ROI is '.($last_price*$btc[$i]/$money[$i]).PHP_EOL;
}
echo PHP_EOL;
结果如下:
simple policy: buy 140 usd on different days of everymonth:
on 1st day of month buy 22.171847894906 BTC for 11060 USD. ROI is 18.745575707508
on 2st day of month buy 22.483835796744 BTC for 11060 USD. ROI is 19.009351323391
on 3st day of month buy 22.683132436126 BTC for 11060 USD. ROI is 19.177850144936
on 4st day of month buy 22.873776562158 BTC for 11060 USD. ROI is 19.339033548082
on 5st day of month buy 22.663165006578 BTC for 11060 USD. ROI is 19.160968333188
on 6st day of month buy 22.829619605275 BTC for 11060 USD. ROI is 19.301700278335
on 7st day of month buy 22.895282529045 BTC for 10920 USD. ROI is 19.605385580803
on 8st day of month buy 22.758523723982 BTC for 10920 USD. ROI is 19.488278089274
on 9st day of month buy 22.772445297502 BTC for 10920 USD. ROI is 19.500199227019
on 10st day of month buy 22.693920417488 BTC for 10920 USD. ROI is 19.432957840135
on 11st day of month buy 22.499652101912 BTC for 10920 USD. ROI is 19.266604565037
on 12st day of month buy 22.281754478063 BTC for 10920 USD. ROI is 19.08001735314
on 13st day of month buy 22.068019586461 BTC for 10920 USD. ROI is 18.896994717075
on 14st day of month buy 22.068686013953 BTC for 10920 USD. ROI is 18.897565383452
on 15st day of month buy 22.379413146748 BTC for 10920 USD. ROI is 19.163643132924
on 16st day of month buy 22.212017346347 BTC for 10920 USD. ROI is 19.020300974674
on 17st day of month buy 22.181794017372 BTC for 10920 USD. ROI is 18.994420533262
on 18st day of month buy 21.982156192808 BTC for 10920 USD. ROI is 18.823469311231
on 19st day of month buy 22.179971247115 BTC for 10920 USD. ROI is 18.992859682739
on 20st day of month buy 21.974796783756 BTC for 10920 USD. ROI is 18.817167399388
on 21st day of month buy 21.872727840678 BTC for 10920 USD. ROI is 18.729765071755
on 22st day of month buy 21.729407841843 BTC for 10920 USD. ROI is 18.607039185536
on 23st day of month buy 21.647836522888 BTC for 10920 USD. ROI is 18.537189112343
on 24st day of month buy 21.504258966867 BTC for 10920 USD. ROI is 18.41424267816
on 25st day of month buy 21.636898731196 BTC for 10920 USD. ROI is 18.527823007195
on 26st day of month buy 21.575032925006 BTC for 10920 USD. ROI is 18.474846898118
on 27st day of month buy 21.486862408557 BTC for 10920 USD. ROI is 18.399345887391
on 28st day of month buy 22.420571564532 BTC for 11060 USD. ROI is 18.955863474289
on 29st day of month buy 21.492371373023 BTC for 10360 USD. ROI is 19.398877480778
on 30st day of month buy 20.996120074596 BTC for 10220 USD. ROI is 19.210566469857
on 31st day of month buy 12.562011754005 BTC for 6440 USD. ROI is 18.240021560587
结论是除了31号以外没有太大差别,因为不是每个月都有31号。
我又想到另外一个问题,就是这个简单策略从不同的时候开始对应的收益是多少呢?
for($year = 2013; $year < 2020; $year++){
$btc = 0;
$money = 0;
foreach ($result as $row) {
if (strtotime($row[$keys[0]]) < strtotime($year.'-01-01')) {
continue;
}
if (explode("-", $row[$keys[0]])[2]=='01') {
$price = $row[$keys[1]];
$btc += 140/$price;
$money += 140;
}
}
echo 'start from '.$year;
echo ' buy '.$btc.' BTC for '.$money.' USD';
echo '. ROI is '.($last_price*$btc/$money).PHP_EOL;
}
结果如下:
start from 2013 buy 22.171847894906 BTC for 11060 USD. ROI is 18.745575707508
start from 2014 buy 14.422215949735 BTC for 9940 USD. ROI is 13.567431233189
start from 2015 buy 11.074658072271 BTC for 8260 USD. ROI is 12.537250354511
start from 2016 buy 4.6269273232684 BTC for 6580 USD. ROI is 6.5753489208709
start from 2017 buy 1.399094962316 BTC for 4900 USD. ROI is 2.6699500225044
start from 2018 buy 0.49292426430722 BTC for 3220 USD. ROI is 1.4314505327275
start from 2019 buy 0.26423599874152 BTC for 1540 USD. ROI is 1.6044392685404
结论当然是开始定投的时间越晚,收益越低。
同样如果动态调整买入数量,得到结果是:
on 1st day of month buy 54.68896148375 BTC for 24198.152323714 USD. ROI is 21.133405659588
on 2st day of month buy 48.267456335385 BTC for 21573.03055174 USD. ROI is 20.921618237196
on 3st day of month buy 51.927616303556 BTC for 23261.473649997 USD. ROI is 20.874360617497
on 4st day of month buy 54.068655783724 BTC for 23821.542164162 USD. ROI is 21.224023525604
on 5st day of month buy 56.741726914806 BTC for 24986.400799988 USD. ROI is 21.234931601517
on 6st day of month buy 53.217372045735 BTC for 24506.095243249 USD. ROI is 20.306324724596
on 7st day of month buy 49.480430048546 BTC for 23050.151453025 USD. ROI is 20.072973050566
on 8st day of month buy 43.009364229676 BTC for 21216.65825486 USD. ROI is 18.955622929084
on 9st day of month buy 44.911577713843 BTC for 21182.432421281 USD. ROI is 19.825972595816
on 10st day of month buy 46.503338955097 BTC for 21126.39968875 USD. ROI is 20.583094305775
on 11st day of month buy 49.933543814475 BTC for 22750.574451838 USD. ROI is 20.523529101953
on 12st day of month buy 46.670234156205 BTC for 22531.934998415 USD. ROI is 19.36838946566
on 13st day of month buy 44.246103969017 BTC for 22059.150509462 USD. ROI is 18.755915647944
on 14st day of month buy 45.929917738979 BTC for 22048.423270757 USD. ROI is 19.479156609693
on 15st day of month buy 46.619072138652 BTC for 22018.097956519 USD. ROI is 19.798662171002
on 16st day of month buy 45.994781276714 BTC for 22525.160165509 USD. ROI is 19.093814083309
on 17st day of month buy 44.01241958069 BTC for 22716.862562778 USD. ROI is 18.11669251188
on 18st day of month buy 42.904043520119 BTC for 22212.986120989 USD. ROI is 18.061062625519
on 19st day of month buy 45.26385493709 BTC for 22631.051873757 USD. ROI is 18.702463569818
on 20st day of month buy 45.857495755562 BTC for 22263.487782646 USD. ROI is 19.260570739059
on 21st day of month buy 45.105945523037 BTC for 21563.342732128 USD. ROI is 19.560039371102
on 22st day of month buy 44.572688867049 BTC for 21267.952653427 USD. ROI is 19.597251599066
on 23st day of month buy 43.274217689149 BTC for 20151.421970835 USD. ROI is 20.080547395047
on 24st day of month buy 42.184610969101 BTC for 20127.810971946 USD. ROI is 19.597899330555
on 25st day of month buy 41.603369954415 BTC for 19646.816392842 USD. ROI is 19.801055612622
on 26st day of month buy 43.569844882186 BTC for 20399.918765522 USD. ROI is 19.971449891362
on 27st day of month buy 46.073866974541 BTC for 22240.262415163 USD. ROI is 19.37165724189
on 28st day of month buy 49.860591240701 BTC for 23312.017117417 USD. ROI is 19.999981317215
on 29st day of month buy 48.409926306664 BTC for 21470.517141603 USD. ROI is 21.083559590936
on 30st day of month buy 51.125198054587 BTC for 22318.755862658 USD. ROI is 21.419880376601
on 31st day of month buy 23.662189356623 BTC for 11086.585427419 USD. ROI is 19.957637817137
和
start from 2013 buy 54.68896148375 BTC for 24198.15 USD. ROI is 21.133405659588
start from 2014 buy 34.138451267446 BTC for 18978.9 USD. ROI is 16.819955805149
start from 2015 buy 13.124232059274 BTC for 11972.62 USD. ROI is 10.250300012662
start from 2016 buy 5.0865272908385 BTC for 9908.83 USD. ROI is 4.800108353695
start from 2017 buy 1.9449513947794 BTC for 8228.12 USD. ROI is 2.2103466625796
start from 2018 buy 1.2345328381095 BTC for 6817.58 USD. ROI is 1.6932623616336
start from 2019 buy 0.22404450624699 BTC for 1383.58 USD. ROI is 1.5141907571945
跟简单策略类似,哪一天买入对结果影响不大,同样买入越晚收益越低。
我就换了一个思路,不是每个月固定时间投,而是每次价格下跌5%,我就买入1000块钱:
echo 'buy when price down policy:'.PHP_EOL;
$btc = 0;
$money = 0;
foreach($result as $i => $row){
if($i == 0){continue;}
$yesterday_price = ($result[$i-1][$keys[1]] + $result[$i-1][$keys[4]]) / 2;
$price = $row[$keys[1]];
if($price < $yesterday_price*0.95){
$buy = 140;
$btc += $buy/$price;
$money += $buy;
echo $row[$keys[0]].' '.$row[$keys[1]].' '.$row[$keys[4]].' ';
echo 'buy '.$buy/$price.' BTC for '.$buy.' USD'.PHP_EOL;
}
}
echo 'BTC: '.$btc.PHP_EOL;
echo 'Spend money: '.$money.PHP_EOL;
echo 'Final value: '.($btc*$last_price).PHP_EOL;
echo 'Final ROI: '.(($btc*$last_price)/$money).PHP_EOL;
echo PHP_EOL;
结果如下:
BTC: 16.835854779097
Spend money: 7840
Final value: 157429.88937822
Final ROI: 20.080343032936
就是花了7840usd(56000人民币)买了16.835854779097个比特币,价值157429.89usd(1124499.21人民币),收益率20.08倍收益。
可以看到这种方案跟简单定投方案的收益率差不多。
不过这种方案收益率跟起投时间的关系更密切:
echo 'buy when price down policy:'.PHP_EOL;
for($year = 2013; $year < 2020; $year++){
$btc = 0;
$money = 0;
foreach($result as $i => $row){
if (strtotime($row[$keys[0]]) < strtotime($year.'-01-01')) {
continue;
}
if($i == 0){continue;}
$yesterday_price = ($result[$i-1][$keys[1]] + $result[$i-1][$keys[4]]) / 2;
$price = $row[$keys[1]];
if($price < $yesterday_price*0.95){
$buy = 140;
$btc += $buy/$price;
$money += $buy;
}
}
echo 'start from '.$year;
echo ' buy '.$btc.' BTC for '.$money.' USD';
echo '. ROI is '.($last_price*$btc/$money).PHP_EOL;
}
结果是:
start from 2013 buy 16.835854779097 BTC for 7840 USD. ROI is 20.080343032936
start from 2014 buy 7.2568342363667 BTC for 5880 USD. ROI is 11.540427475479
start from 2015 buy 5.5110740890794 BTC for 4900 USD. ROI is 10.51700762599
start from 2016 buy 2.0373331871337 BTC for 4060 USD. ROI is 4.6923245762494
start from 2017 buy 1.2092733133323 BTC for 3640 USD. ROI is 3.106526798747
start from 2018 buy 0.30747030774609 BTC for 2380 USD. ROI is 1.2080314607537
start from 2019 buy 0.070211328288695 BTC for 700 USD. ROI is 0.93791000479273
如果是从2019开始用这种策略投资,收益是负的。因为2019没有几次买入的机会。
前面的几种策略里面我都是只有买入,如果加入买出能否获得更多收益呢?
代码:
echo 'buy when price down policy and sell when price up:'.PHP_EOL;
$max_roi = 0;
for ($buy_ratio = 0.1; $buy_ratio <= 1; $buy_ratio += 0.01) {
for ($sell_ratio = 0; $sell_ratio <= 0.1; $sell_ratio += 0.01) {
$btc = 0;
$init_money = 11060;
$money = $init_money;
foreach ($result as $i => $row) {
if (0 == $i) {
continue;
}
$yesterday_price = ($result[$i - 1][$keys[1]] + $result[$i - 1][$keys[4]]) / 2;
if (strtotime($row[$keys[0]]) < strtotime('2013-01-01')) {
continue;
}
$price = $row[$keys[1]];
if ($price < $yesterday_price * 0.95) {
//best buy ratio is 0.5 for 2013-2019
$buy = $money * $buy_ratio;
if ($buy < 10) {
continue;
}
$money -= $buy;
$btc += $buy / $price;
}
if ($price > $yesterday_price * 1.05) {
// best sell ratio is 0 for 2013-2019
$sell = $btc * $sell_ratio;
if ($sell < 0.01) {
continue;
}
$btc -= $sell;
$money += $price * $sell;
}
}
//echo 'BTC: '.$btc.PHP_EOL;
//echo 'money: '.$money.PHP_EOL;
//echo 'Final value: '.($btc*$last_price+$money).PHP_EOL;
echo 'Buy Ratio: '.$buy_ratio.' , sell ratio '.$sell_ratio.' get '.$btc.' BTC with '.$money.' ';
$roi = ($btc * $last_price + $money) / $init_money;
$max_roi = $roi > $max_roi ? $roi : $max_roi;
echo 'Final ROI: '.$roi.PHP_EOL;
//echo PHP_EOL;
}
}
echo 'max roi :'.$max_roi.PHP_EOL;
我的策略很简单,就是价格下跌了5%就买入全部金额的一定比例比特币,价格上涨了5%就卖出一定比例比特币。
结果发现买入比例49%,卖出比例0的时候能得到最高的ROI, 93.036942129554。这个比例高于直接起始的时候直接买入比特币的策略,因为有一部分的比特币是降价之后才买的。同时卖出比例为0,说明这个策略里面不能卖出比特币。其实也很好理解,因为比特币总体是上涨的,一旦你卖出,因为价格升高,你后面买回来的比特币就越少。总体收益也就减少了。
同时这种策略跟市场紧密相关,
如果从2013开始买入,最佳买入比例是0.49, 最佳卖出比例是0.
如果从2014开始买入,最佳买入比例是0.13, 最佳卖出比例是0.
如果从2015开始买入,最佳买入比例是0.46, 最佳卖出比例是0.
如果从2016开始买入,最佳买入比例是0.99, 最佳卖出比例是0.
如果从2017开始买入,最佳买入比例是0.56, 最佳卖出比例是0.
如果从2018开始买入,最佳买入比例是0.09, 最佳卖出比例是0.01.
如果从2019开始买入,最佳买入比例是0, 最佳卖出比例是0.
所以这种策略没有太多的价值,因为我们无从判断未来行情走向。同时如果从2019年开始用这种策略,最优选择是不要买。:)
类似,如果记录上一次的卖出价格做为参考点:
如果从2013开始买入,
Buy Ratio: 0.45 , sell ratio 0 get 102.70933163813 BTC with 306.1478853125 Final ROI: 86.865077379783
如果从2014开始买入,
Buy Ratio: 0.16 , sell ratio 0 get 21.895526577296 BTC with 1146.5311163133 Final ROI: 18.615619685547
如果从2015开始买入,
Buy Ratio: 0.61 , sell ratio 0 get 40.768021693446 BTC with 255.8665746 Final ROI: 34.491169763761
如果从2016开始买入,
Buy Ratio: 0.99 , sell ratio 0 get 29.992604158107 BTC with 110.59999999999 Final ROI: 25.367770564549
如果从2017开始买入,
Buy Ratio: 0.92 , sell ratio 0 get 12.312205165812 BTC with 70.783999999999 Final ROI: 10.415968708755
如果从2018开始买入,
Buy Ratio: 0.1 , sell ratio 0 get 1.2671786688341 BTC with 2811.3036061319 Final ROI: 1.3255449010102
如果从2019开始买入,
Buy Ratio: 0.96 , sell ratio 0 get 3.0243124957152 BTC with 17.695999999999 Final ROI: 2.5585577745758
跟上一种策略的结果类似,没有太大价值。
我还不死心,又想到一个策略,就是下跌5%就买1000块,上涨5%就卖掉5%。
echo 'buy when price down policy and sell when price up:'.PHP_EOL;
$btc = 0;
$invest = 0;
$return = 0;
foreach($result as $i => $row){
if($i == 0){continue;}
$yesterday_price = ($result[$i-1][$keys[1]] + $result[$i-1][$keys[4]]) / 2;
$price = $row[$keys[1]];
if($price < $yesterday_price*0.95){
$buy = 140;
$btc += $buy/$price;
$invest += $buy;
echo $row[$keys[0]].' '.$row[$keys[1]].' '.$row[$keys[4]].' ';
echo 'buy '.$buy/$price.' BTC for '.$buy.' USD'.PHP_EOL;
}
if($price > $yesterday_price*1.05){
$sell = $btc * 0.05;
if($sell == 0){continue;}
$btc -= $sell;
$return += $price*$sell;
echo $row[$keys[0]].' '.$row[$keys[1]].' '.$row[$keys[4]].' ';
echo 'sell '.$sell.' BTC for '.($price*$sell).' USD'.PHP_EOL;
}
}
echo 'BTC: '.$btc.PHP_EOL;
echo 'Invest money: '.$invest.PHP_EOL;
echo 'Final value: '.($btc*$last_price+$return).PHP_EOL;
echo 'Final ROI: '.(($btc*$last_price+$return)/$invest).PHP_EOL;
echo PHP_EOL;
结果是
BTC: 3.2084003878113
Invest money: 7840
Final value: 76196.536163102
Final ROI: 9.7189459391712
就是花了7840usd(56000人民币)买了3.2084003878113个比特币,价值76196.53usd(544260.93人民币)加上中间卖出比特币获得了46195.20usd(329965.71人民币),9.72倍收益。
可以看出这种策略的收益率不到每逢价格下跌5%就买入1000块钱的策略的一半,不过这种策略的优势在于,投入的资金小于卖出比特币获得的资金,也就是很多时候你是用你的盈利来投资,所以比较能够承受住价格波动带来的损失。这种策略里面卖出比例为0的时候收益率最高,也就变成了每逢价格下跌5%就买入1000块钱的策略。
综合所有的结果,我的结论是老老实实也定投,各种策略能跑赢定投的不多。定投的日期也无所谓,只要不是每个月31号就行。
发表回复
要发表评论,您必须先登录。