有一个朋友,我们认识很多年了。2013年的时候,记得某一天我跟他说比特币你可以了解一下,现在好像涨到一千块一个了,你可以花一万块钱买上十个,然后放起来,过几年再看,肯定不是现在的价格。他一脸蒙逼,然后事情就过去了。
到了今年的某一天,那个朋友跟我说,现在比特币好几万一个了,当初应该买一点的,我说你现在买也不迟呀。然后他就决定以后每个月给我一千块钱让我帮他买比特币。
今天我心血来潮就想算一下,如果从2013年起每个月买一千块钱比特币,现在有多少收益。(你看,为了朋友感觉扎心,我也很拼的。)
首先要拿到比特币价格的历史数据,google一下之后,我在coinmarketcap找到从2013年04月28日到今天的数据。
直接chrome里面右键copy element,把数据复制到一个history.html文件里面。
数据大概长这样:
<table class="table">
<thead>
<tr>
<th class="text-left">Date</th>
<th class="text-right">Open*</th>
<th class="text-right">High</th>
<th class="text-right">Low</th>
<th class="text-right">Close**</th>
<th class="text-right">Volume</th>
<th class="text-right">Market Cap</th>
</tr>
</thead>
<tbody>
<tr class="text-right">
<td class="text-left">Nov 06, 2019</td>
<td data-format-fiat="" data-format-value="9340.86427973">9,340.86</td>
<td data-format-fiat="" data-format-value="9423.23703723">9,423.24</td>
<td data-format-fiat="" data-format-value="9305.90931362">9,305.91</td>
<td data-format-fiat="" data-format-value="9360.87991187">9,360.88</td>
<td data-format-market-cap="" data-format-value="23133895764.6">23,133,895,765</td>
.
..
...
<tr class="text-right">
<td class="text-left">Apr 28, 2013</td>
<td data-format-fiat="" data-format-value="135.300003052">135.30</td>
<td data-format-fiat="" data-format-value="135.979995728">135.98</td>
<td data-format-fiat="" data-format-value="132.100006104">132.10</td>
<td data-format-fiat="" data-format-value="134.210006714">134.21</td>
<td data-format-market-cap="" data-format-value="-">-</td>
<td data-format-market-cap="" data-format-value="1488566728.25">1,488,566,728</td>
</tr>
</tbody>
</table>
一看这个数据很归整,每一行7个数据,分别是日期,开盘价格,最高价格,最低价格,收盘价格,交易量和总市值。我就写了个php脚本来分析:
<?php
$html = file_get_contents("history.html");
$doc = new DOMDocument();
$doc->loadHTML('<?xml encoding="utf-8" ?>'.$html);
$trs = $doc->getElementsByTagName('tr');
$ths = $trs[0]->getElementsByTagName('th');
$keys = [];
foreach ($ths as $th) {
$keys[] = trim($th->nodeValue, "*").PHP_EOL;
}
$result = [];
foreach ($trs as $tr) {
$tds = $tr->getElementsByTagName('td');
$row = [];
if ($tds->length > 0) {
for ($i = 0; $i<sizeof($keys); $i++) {
if ($i == 0) {
$tds[$i]->nodeValue = date('Y-m-d', strtotime($tds[$i]->nodeValue));
}
$row[$keys[$i]] = str_replace(',', '', $tds[$i]->nodeValue);
}
}
if ($row) {
$result[]=$row;
}
}
// reverse order
$result = array_reverse($result);
然后我就计算如果每个月一号买1000块钱的比特币,最后能买到多少币:
(因为拿到的价格是用美元计算的,为了方便计算,我就把1000块写成140usd)
$btc = 0;
$money = 0;
echo 'simple policy: buy 100 usd on the first day of everymonth:'.PHP_EOL;
foreach ($result as $row) {
if (explode("-", $row[$keys[0]])[2]=='01') {
$price = ($row[$keys[1]]+$row[$keys[4]])/2;
$btc += 140/$price;
$money += 140;
echo $row[$keys[0]].' '.$row[$keys[1]].' '.$row[$keys[4]].' ';
echo 'buy '.(100/$price).' BTC for 100 USD'.PHP_EOL;
}
}
echo 'total:'.PHP_EOL;
echo 'buy '.$btc.' BTC for '.$money.' USD'.PHP_EOL;
输出结果是这样的:
buy 140 usd on the first day of everymonth:
2013-05-01 139.00 116.99 buy 1.0937927262784 BTC for 140 USD
2013-06-01 128.82 129.30 buy 1.0847667751433 BTC for 140 USD
2013-07-01 97.51 88.05 buy 1.5089458935115 BTC for 140 USD
2013-08-01 106.21 104.00 buy 1.3320013320013 BTC for 140 USD
2013-09-01 135.14 138.34 buy 1.0238408658768 BTC for 140 USD
2013-10-01 132.68 132.18 buy 1.0571622744091 BTC for 140 USD
2013-11-01 203.90 206.18 buy 0.68279360124854 BTC for 140 USD
2013-12-01 1128.92 955.85 buy 0.13430738162963 BTC for 140 USD
2014-01-01 754.97 771.40 buy 0.18344176051678 BTC for 140 USD
2014-02-01 828.61 832.58 buy 0.16855386801028 BTC for 140 USD
2014-03-01 549.92 565.61 buy 0.25100176597671 BTC for 140 USD
2014-04-01 457.00 478.38 buy 0.29934358228741 BTC for 140 USD
2014-05-01 447.63 457.76 buy 0.30925899336198 BTC for 140 USD
2014-06-01 623.69 630.23 buy 0.22329973204032 BTC for 140 USD
2014-07-01 641.39 640.81 buy 0.21837466853845 BTC for 140 USD
2014-08-01 586.20 594.92 buy 0.23706312652398 BTC for 140 USD
2014-09-01 477.79 474.88 buy 0.29391079807278 BTC for 140 USD
2014-10-01 387.43 383.61 buy 0.36314588088815 BTC for 140 USD
2014-11-01 338.65 325.75 buy 0.421432871764 BTC for 140 USD
2014-12-01 378.25 379.24 buy 0.36964184345668 BTC for 140 USD
2015-01-01 320.43 314.25 buy 0.4411672023697 BTC for 140 USD
2015-02-01 216.87 226.97 buy 0.6308579668349 BTC for 140 USD
2015-03-01 254.28 260.20 buy 0.54423884310372 BTC for 140 USD
2015-04-01 244.22 247.27 buy 0.56969622983174 BTC for 140 USD
2015-05-01 235.94 232.08 buy 0.59826503140891 BTC for 140 USD
2015-06-01 230.23 222.93 buy 0.61788330832377 BTC for 140 USD
2015-07-01 263.35 258.62 buy 0.53642929670288 BTC for 140 USD
2015-08-01 284.69 281.60 buy 0.49444630842854 BTC for 140 USD
2015-09-01 230.26 228.12 buy 0.61084689558881 BTC for 140 USD
2015-10-01 236.00 237.55 buy 0.59127864005913 BTC for 140 USD
2015-11-01 315.01 325.43 buy 0.43719942539504 BTC for 140 USD
2015-12-01 377.41 362.49 buy 0.37842951750237 BTC for 140 USD
2016-01-01 430.72 434.33 buy 0.32368071209757 BTC for 140 USD
2016-02-01 369.35 373.06 buy 0.37715009226708 BTC for 140 USD
2016-03-01 437.92 435.12 buy 0.32071840923669 BTC for 140 USD
2016-04-01 416.76 417.96 buy 0.33544182480353 BTC for 140 USD
2016-05-01 448.48 451.88 buy 0.31098671642454 BTC for 140 USD
2016-06-01 531.11 536.92 buy 0.26216492046104 BTC for 140 USD
2016-07-01 672.52 676.30 buy 0.20758885544402 BTC for 140 USD
2016-08-01 624.60 606.27 buy 0.22748137496242 BTC for 140 USD
2016-09-01 575.55 572.30 buy 0.24393431197456 BTC for 140 USD
2016-10-01 609.93 613.98 buy 0.2287749916252 BTC for 140 USD
2016-11-01 701.34 729.79 buy 0.19564959158148 BTC for 140 USD
2016-12-01 746.05 756.77 buy 0.18631639184999 BTC for 140 USD
2017-01-01 963.66 998.33 buy 0.14271224623979 BTC for 140 USD
2017-02-01 970.94 989.02 buy 0.14286005836854 BTC for 140 USD
2017-03-01 1180.04 1222.50 buy 0.11654332498106 BTC for 140 USD
2017-04-01 1071.71 1080.50 buy 0.1300988286459 BTC for 140 USD
2017-05-01 1348.30 1421.60 buy 0.10108668182967 BTC for 140 USD
2017-06-01 2288.33 2407.88 buy 0.059622546691907 BTC for 140 USD
2017-07-01 2492.60 2434.55 buy 0.056827983722842 BTC for 140 USD
2017-08-01 2871.30 2718.26 buy 0.050093388388353 BTC for 140 USD
2017-09-01 4701.76 4892.01 buy 0.029185606909484 BTC for 140 USD
2017-10-01 4341.05 4403.74 buy 0.032019065066171 BTC for 140 USD
2017-11-01 6440.97 6767.31 buy 0.021198823768121 BTC for 140 USD
2017-12-01 10198.60 10975.60 buy 0.013223640090299 BTC for 140 USD
2018-01-01 14112.20 13657.20 buy 0.010083041045179 BTC for 140 USD
2018-02-01 10237.30 9170.54 buy 0.014427159333548 BTC for 140 USD
2018-03-01 10385.00 10951.00 buy 0.013123359580052 BTC for 140 USD
2018-04-01 7003.06 6844.23 buy 0.020220563012691 BTC for 140 USD
2018-05-01 9251.47 9119.01 buy 0.015241844524476 BTC for 140 USD
2018-06-01 7500.70 7541.45 buy 0.018614360314184 BTC for 140 USD
2018-07-01 6411.68 6385.82 buy 0.021879273295566 BTC for 140 USD
2018-08-01 7769.04 7624.91 buy 0.018188963846186 BTC for 140 USD
2018-09-01 7044.81 7193.25 buy 0.019665600510182 BTC for 140 USD
2018-10-01 6619.85 6589.62 buy 0.02119691403213 BTC for 140 USD
2018-11-01 6318.14 6377.78 buy 0.022054329264835 BTC for 140 USD
2018-12-01 4024.46 4214.67 buy 0.033984170658795 BTC for 140 USD
2019-01-01 3746.71 3843.52 buy 0.036889527721821 BTC for 140 USD
2019-02-01 3460.55 3487.95 buy 0.040296466863352 BTC for 140 USD
2019-03-01 3853.76 3859.58 buy 0.036300746498923 BTC for 140 USD
2019-04-01 4105.36 4158.18 buy 0.033883783463262 BTC for 140 USD
2019-05-01 5350.91 5402.70 buy 0.026037767782168 BTC for 140 USD
2019-06-01 8573.84 8564.02 buy 0.016338095888285 BTC for 140 USD
2019-07-01 10796.93 10583.13 buy 0.013096314977601 BTC for 140 USD
2019-08-01 10077.44 10399.67 buy 0.013673804555428 BTC for 140 USD
2019-09-01 9630.59 9757.97 buy 0.014441505712647 BTC for 140 USD
2019-10-01 8299.72 8343.28 buy 0.016823889923692 BTC for 140 USD
2019-11-01 9193.99 9261.10 buy 0.015171966107995 BTC for 140 USD
total:
buy 22.313812243429 BTC for 11060 USD
就是从2013年5月1号起每个月的1号买1000块钱比特币,到2019年11月1号,总共79个月,共花了79000块钱,买到了22.313812243429个比特币,这些比特币今天(2019-11-07)的价格是1,429,726.68人民币。18.1倍的收益。
我想起之前读过的一本书叫做价值平均策略,大概的意思是动态的调整每个月投资的额度,具体算法我不太记得了,我就自己想了一个简单粗暴的动态策略,用已知的最高价格作为参考值,把最高价格除以当前价格做为系数,这样价格越低买入的越多。代码如下:
$btc = 0;
$money = 0;
$init_price = ($result[0][$keys[1]]+$result[0][$keys[4]])/2;
echo 'initial price on '.$result[0][$keys[0]].': '.$init_price.PHP_EOL;
foreach ($result as $row) {
if (explode("-", $row[$keys[0]])[2]=='01') {
$price = ($row[$keys[1]]+$row[$keys[4]])/2;
$spend = 140*($init_price/$price);
$btc += $spend/$price;
$money += $spend;
echo $row[$keys[0]].' '.$row[$keys[1]].' '.$row[$keys[4]].' ';
echo 'buy '.$spend/$price.' BTC for '.$spend.' USD'.PHP_EOL;
$init_price = $price > $init_price ? $price: $init_price;
}
}
echo 'total:'.PHP_EOL;
echo 'buy '.$btc.' BTC for '.$money.' USD'.PHP_EOL;
输出结果是这样的:
buy 140*(local high price/current price):
initial price on 2013-04-28: 134.755
2013-05-01 139.00 116.99 buy 1.1515609112047 BTC for 147.39403882964 USD
2013-06-01 128.82 129.30 buy 1.1326340212648 BTC for 146.17774678444 USD
2013-07-01 97.51 88.05 buy 2.191614613927 BTC for 203.33800388015 USD
2013-08-01 106.21 104.00 buy 1.7077573806559 BTC for 179.49383949384 USD
2013-09-01 135.14 138.34 buy 1.0089781766947 BTC for 137.96767588123 USD
2013-10-01 132.68 132.18 buy 1.0915681447006 BTC for 144.5563694027 USD
2013-11-01 203.90 206.18 buy 0.45535113653299 BTC for 93.365197034725 USD
2013-12-01 1128.92 955.85 buy 0.026418631819663 BTC for 27.538385529339 USD
2014-01-01 754.97 771.40 buy 0.25055122877977 BTC for 191.21693953629 USD
2014-02-01 828.61 832.58 buy 0.21153272498137 BTC for 175.6980237059 USD
2014-03-01 549.92 565.61 buy 0.46908729631231 BTC for 261.64047582763 USD
2014-04-01 457.00 478.38 buy 0.667175394006 BTC for 312.03126002266 USD
2014-05-01 447.63 457.76 buy 0.71210624326671 BTC for 322.36693579562 USD
2014-06-01 623.69 630.23 buy 0.37125859892633 BTC for 232.76429118285 USD
2014-07-01 641.39 640.81 buy 0.35506235979481 BTC for 227.63047886445 USD
2014-08-01 586.20 594.92 buy 0.41843512452875 BTC for 247.1110471417 USD
2014-09-01 477.79 474.88 buy 0.6431780306908 BTC for 306.3682072491 USD
2014-10-01 387.43 383.61 buy 0.98188892677318 BTC for 378.5378190496 USD
2014-11-01 338.65 325.75 buy 1.3223820109383 BTC for 439.29530403371 USD
2014-12-01 378.25 379.24 buy 1.0173312201919 BTC for 385.30911299159 USD
2015-01-01 320.43 314.25 buy 1.4491273531296 BTC for 459.86607424214 USD
2015-02-01 216.87 226.97 buy 2.9632159415969 BTC for 657.59688175919 USD
2015-03-01 254.28 260.20 buy 2.2053584452988 BTC for 567.30640646867 USD
2015-04-01 244.22 247.27 buy 2.416500048966 BTC for 593.84280453315 USD
2015-05-01 235.94 232.08 buy 2.6649395101285 BTC for 623.62249476518 USD
2015-06-01 230.23 222.93 buy 2.8425822771077 BTC for 644.07229234707 USD
2015-07-01 263.35 258.62 buy 2.1425210354757 BTC for 559.16585244363 USD
2015-08-01 284.69 281.60 buy 1.8202808285906 BTC for 515.40341521129 USD
2015-09-01 230.26 228.12 buy 2.7782086533372 BTC for 636.73764125834 USD
2015-10-01 236.00 237.55 buy 2.6030619162413 BTC for 616.33998521803 USD
2015-11-01 315.01 325.43 buy 1.4231781994891 BTC for 455.73012304041 USD
2015-12-01 377.41 362.49 buy 1.0662772066542 BTC for 394.4692526017 USD
2016-01-01 430.72 434.33 buy 0.78007032906727 BTC for 337.39991907982 USD
2016-02-01 369.35 373.06 buy 1.0590794814936 BTC for 393.13559892782 USD
2016-03-01 437.92 435.12 buy 0.76585736967879 BTC for 334.31205901219 USD
2016-04-01 416.76 417.96 buy 0.83778878317957 BTC for 349.65952654782 USD
2016-05-01 448.48 451.88 buy 0.72008505131324 BTC for 324.1678884002 USD
2016-06-01 531.11 536.92 buy 0.51173989609801 BTC for 273.27678061478 USD
2016-07-01 672.52 676.30 buy 0.32085453816226 BTC for 216.38750908201 USD
2016-08-01 624.60 606.27 buy 0.385293610276 BTC for 237.12317304021 USD
2016-09-01 575.55 572.30 buy 0.44304302441539 BTC for 254.2734677876 USD
2016-10-01 609.93 613.98 buy 0.38968816276562 BTC for 238.47161964524 USD
2016-11-01 701.34 729.79 buy 0.28500862887461 BTC for 203.94219952066 USD
2016-12-01 746.05 756.77 buy 0.25846530139145 BTC for 194.21341211855 USD
2017-01-01 963.66 998.33 buy 0.15164308156174 BTC for 148.76110479666 USD
2017-02-01 970.94 989.02 buy 0.15195736845904 BTC for 148.91518194249 USD
2017-03-01 1180.04 1222.50 buy 0.10112881684416 BTC for 121.48301381038 USD
2017-04-01 1071.71 1080.50 buy 0.14523101359762 BTC for 156.28381988746 USD
2017-05-01 1348.30 1421.60 buy 0.087679987206416 BTC for 121.43239828153 USD
2017-06-01 2288.33 2407.88 buy 0.035166334572328 BTC for 82.574246040956 USD
2017-07-01 2492.60 2434.55 buy 0.054164404460803 BTC for 133.43807271952 USD
2017-08-01 2871.30 2718.26 buy 0.044156899397747 BTC for 123.40881929884 USD
2017-09-01 4701.76 4892.01 buy 0.017004233055095 BTC for 81.567350478488 USD
2017-10-01 4341.05 4403.74 buy 0.03512760693623 BTC for 153.59177292994 USD
2017-11-01 6440.97 6767.31 buy 0.015397662640547 BTC for 101.68831975094 USD
2017-12-01 10198.60 10975.60 buy 0.0082487905532152 BTC for 87.330770465944 USD
2018-01-01 14112.20 13657.20 buy 0.0076883305976663 BTC for 106.75016384942 USD
2018-02-01 10237.30 9170.54 buy 0.020642872076286 BTC for 200.31677919851 USD
2018-03-01 10385.00 10951.00 buy 0.017080419081473 BTC for 182.21391076115 USD
2018-04-01 7003.06 6844.23 buy 0.040550382242634 BTC for 280.7564512623 USD
2018-05-01 9251.47 9119.01 buy 0.023040055422503 BTC for 211.628438669 USD
2018-06-01 7500.70 7541.45 buy 0.034364078094468 BTC for 258.45480865435 USD
2018-07-01 6411.68 6385.82 buy 0.04747601421011 BTC for 303.78714592694 USD
2018-08-01 7769.04 7624.91 buy 0.032811371521298 BTC for 252.54830631514 USD
2018-09-01 7044.81 7193.25 buy 0.038355079751556 BTC for 273.05096340372 USD
2018-10-01 6619.85 6589.62 buy 0.044560878258085 BTC for 294.31279226192 USD
2018-11-01 6318.14 6377.78 buy 0.048238764192504 BTC for 306.21774554345 USD
2018-12-01 4024.46 4214.67 buy 0.11454122324716 BTC for 471.86001434617 USD
2019-01-01 3746.71 3843.52 buy 0.13496297887131 BTC for 512.20002555917 USD
2019-02-01 3460.55 3487.95 buy 0.16104320456432 BTC for 559.50435345758 USD
2019-03-01 3853.76 3859.58 buy 0.1306891631676 BTC for 504.02497491359 USD
2019-04-01 4105.36 4158.18 buy 0.11386552694181 BTC for 470.46616825235 USD
2019-05-01 5350.91 5402.70 buy 0.067238182215101 BTC for 361.52659432507 USD
2019-06-01 8573.84 8564.02 buy 0.02647349902264 BTC for 226.84955998007 USD
2019-07-01 10796.93 10583.13 buy 0.017010093009046 BTC for 181.83840456949 USD
2019-08-01 10077.44 10399.67 buy 0.0185433075381 BTC for 189.85667411075 USD
2019-09-01 9630.59 9757.97 buy 0.020683947066558 BTC for 200.51597436839 USD
2019-10-01 8299.72 8343.28 buy 0.028071220864445 BTC for 233.59466442348 USD
2019-11-01 9193.99 9261.10 buy 0.022829278840654 BTC for 210.65819781968 USD
total:
buy 51.375763838804 BTC for 22893.725512278 USD
最后结果是花了22893.72USD(就是163526.57人民币)买到了51.375763838804个比特币,这些比特币今天(2019-11-07)的价格是3,290,352.13元人民币。20.1倍的收益。
两者对比,后一个方案虽然收益多了两倍,但是投入的资金也翻倍了,而且每个月还要计算投多少钱进去,感觉不太值得,当然如果看最后结果的话,
79000变成1,429,726.68 (八万变成一百四十万)
163526.57变成3,290,352.13 (十六万变成三百二十万)
可能很多人还是愿意选择第二个方案,因为16万虽然不是小数目,但是努力一下还是可以拿出来的,最后的收益也更有吸引力的。
友情提示,本文章只是历史数据分析,并不构成任何投资建议,比特币风险很大,你需要强大的心脏来承受价格的巨大波动。
发表回复
要发表评论,您必须先登录。