我用PHP编写了布林带乐队,但与Binance交易所有一些重要区别。 在python中,我进行了测试,并且获得了与Binance类似的值,尽管它们并不相同。 我需要的是能够检测PHP算法中的错误,有人可以帮我吗?
PYTHON:
upper, middle, lower = ta.BBANDS(x,20,2,2,MA_Type.TEMA)
结果:
[ nan nan nan nan nan nan
nan nan nan nan nan nan
nan nan nan nan nan nan
nan nan nan nan nan nan
nan nan nan nan nan nan
nan nan nan nan nan nan
nan nan nan nan nan nan
nan nan nan nan nan nan
nan nan nan nan nan nan
nan nan nan 0.00008001 0.00008 0.00007998
0.00007999 0.00007998 0.00007997 0.00007996 0.00007993 0.00007992
0.00007991 0.00007996 0.00007996 0.00007998 0.00008 0.00008005
0.00008004 0.00008005 0.00008003 0.00008002 0.00008002 0.00007999
0.00007995 0.0000799 0.00007989 0.00007987 0.00007987 0.00007988
0.00007986 0.00007986 0.00007986 0.00007984 0.00007985 0.00007984
0.00007996 0.0000804 0.00008063 0.00008071 0.0000807 0.00008068]
[ nan nan nan nan nan nan
nan nan nan nan nan nan
nan nan nan nan nan nan
nan nan nan nan nan nan
nan nan nan nan nan nan
nan nan nan nan nan nan
nan nan nan nan nan nan
nan nan nan nan nan nan
nan nan nan nan nan nan
nan nan nan 0.00007961 0.00007958 0.00007954
0.00007956 0.0000796 0.00007964 0.00007968 0.00007967 0.00007966
0.00007967 0.00007972 0.00007973 0.00007975 0.00007977 0.00007981
0.0000798 0.00007981 0.00007979 0.00007979 0.00007979 0.0000798
0.00007979 0.00007977 0.00007976 0.00007973 0.00007973 0.00007974
0.00007973 0.00007974 0.00007974 0.00007972 0.00007973 0.00007973
0.0000798 0.00008001 0.00008014 0.0000802 0.00008019 0.00008016]
[ nan nan nan nan nan nan
nan nan nan nan nan nan
nan nan nan nan nan nan
nan nan nan nan nan nan
nan nan nan nan nan nan
nan nan nan nan nan nan
nan nan nan nan nan nan
nan nan nan nan nan nan
nan nan nan nan nan nan
nan nan nan 0.00007921 0.00007915 0.0000791
0.00007914 0.00007923 0.00007932 0.00007941 0.0000794 0.0000794
0.00007943 0.00007948 0.0000795 0.00007953 0.00007954 0.00007957
0.00007956 0.00007957 0.00007955 0.00007955 0.00007955 0.00007962
0.00007962 0.00007964 0.00007962 0.00007958 0.00007959 0.0000796
0.0000796 0.00007961 0.00007961 0.00007961 0.00007961 0.00007961
0.00007964 0.00007962 0.00007966 0.00007969 0.00007967 0.00007965]
PHP
class BollingerBands {
static function lag($period = 5) {
return $period - 1;
}
static function run($data, $period = 5) {
$data = Sma::run($data, $period);
foreach($data as $key => $row) {
if ($key >= $period){
$sum_tmp = 0;
for ($i = $key - ($period); $i < $key; $i ++) {
$tmp = $data[$i]['close'] - $data[$key]['val'];
$tmp = pow($tmp, 2);
$sum_tmp += $tmp;
}
$sum_tmp = $sum_tmp / $period;
$sum_tmp = sqrt($sum_tmp);
$data[$key]['bollingerBands']['upper'] = FormatHelper::satoshi($data[$key]['val'] + (2 * $sum_tmp));
$data[$key]['bollingerBands']['middle'] = FormatHelper::satoshi($data[$key]['val']);
$data[$key]['bollingerBands']['lower'] = FormatHelper::satoshi($data[$key]['val'] - (2 * $sum_tmp));
}
}
return $data;
}
}
class Sma {
static function lag($period = 5) {
return $period - 1;
}
static function run($data, $period = 5) {
foreach($data as $key => $row){
if ($key >= $period){
$sum = 0;
for ($i = $key - ($period); $i <= $key; $i ++) {
$sum += $data[$i]['close'];
}
$sma = $sum / $period;
$data[$key]['val'] = $sma;
}
}
return $data;
}
}
PHP结果:
string(6) "XRPBTC"
Array
(
...
[473] => Array
(
[open] => 0.00007977
[high] => 0.00007987
[low] => 0.00007971
[close] => 0.00007983
[volume] => 25.95434042
[openTime] => 2019-03-11 05:45:00
[closeTime] => 2019-03-11 05:59:59
[assetVolume] => 325303.00000000
[baseVolume] => 25.95434042
[trades] => 449
[assetBuyVolume] => 207496.00000000
[takerBuyVolume] => 16.55606665
[ignored] => 0
[val] => 8.3725E-5
[bollingerBands] => Array
(
[upper] => 0.00009171
[middle] => 0.00008373
[lower] => 0.00007574
)
)
[474] => Array
(
[open] => 0.00007983
[high] => 0.00007993
[low] => 0.00007977
[close] => 0.00007981
[volume] => 29.72240274
[openTime] => 2019-03-11 06:00:00
[closeTime] => 2019-03-11 06:14:59
[assetVolume] => 372172.00000000
[baseVolume] => 29.72240274
[trades] => 614
[assetBuyVolume] => 173119.00000000
[takerBuyVolume] => 13.82655679
[ignored] => 0
[val] => 8.37235E-5
[bollingerBands] => Array
(
[upper] => 0.00009171
[middle] => 0.00008372
[lower] => 0.00007574
)
)
[475] => Array
(
[open] => 0.00007981
[high] => 0.00007994
[low] => 0.00007977
[close] => 0.00007991
[volume] => 25.50036018
[openTime] => 2019-03-11 06:15:00
[closeTime] => 2019-03-11 06:29:59
[assetVolume] => 319374.00000000
[baseVolume] => 25.50036018
[trades] => 473
[assetBuyVolume] => 176827.00000000
[takerBuyVolume] => 14.12048711
[ignored] => 0
[val] => 8.37285E-5
[bollingerBands] => Array
(
[upper] => 0.00009172
[middle] => 0.00008373
[lower] => 0.00007573
)
)
[476] => Array
(
[open] => 0.00007992
[high] => 0.00007994
[low] => 0.00007977
[close] => 0.00007977
[volume] => 21.25886350
[openTime] => 2019-03-11 06:30:00
[closeTime] => 2019-03-11 06:44:59
[assetVolume] => 266183.00000000
[baseVolume] => 21.25886350
[trades] => 444
[assetBuyVolume] => 161738.00000000
[takerBuyVolume] => 12.91799478
[ignored] => 0
[val] => 8.37275E-5
[bollingerBands] => Array
(
[upper] => 0.00009171
[middle] => 0.00008373
[lower] => 0.00007575
)
)
[477] => Array
(
[open] => 0.00007978
[high] => 0.00008000
[low] => 0.00007975
[close] => 0.00007982
[volume] => 49.39448164
[openTime] => 2019-03-11 06:45:00
[closeTime] => 2019-03-11 06:59:59
[assetVolume] => 618672.00000000
[baseVolume] => 49.39448164
[trades] => 919
[assetBuyVolume] => 360535.00000000
[takerBuyVolume] => 28.78915565
[ignored] => 0
[val] => 8.3728E-5
[bollingerBands] => Array
(
[upper] => 0.00009171
[middle] => 0.00008373
[lower] => 0.00007574
)
)
[478] => Array
(
[open] => 0.00007984
[high] => 0.00007985
[low] => 0.00007961
[close] => 0.00007972
[volume] => 41.87002732
[openTime] => 2019-03-11 07:00:00
[closeTime] => 2019-03-11 07:14:59
[assetVolume] => 525273.00000000
[baseVolume] => 41.87002732
[trades] => 751
[assetBuyVolume] => 234434.00000000
[takerBuyVolume] => 18.68869598
[ignored] => 0
[val] => 8.3723E-5
[bollingerBands] => Array
(
[upper] => 0.0000917
[middle] => 0.00008372
[lower] => 0.00007575
)
)
[479] => Array
(
[open] => 0.00007972
[high] => 0.00007983
[low] => 0.00007969
[close] => 0.00007976
[volume] => 36.06297716
[openTime] => 2019-03-11 07:15:00
[closeTime] => 2019-03-11 07:29:59
[assetVolume] => 452269.00000000
[baseVolume] => 36.06297716
[trades] => 632
[assetBuyVolume] => 196876.00000000
[takerBuyVolume] => 15.70228958
[ignored] => 0
[val] => 8.3721E-5
[bollingerBands] => Array
(
[upper] => 0.0000917
[middle] => 0.00008372
[lower] => 0.00007574
)
)
[480] => Array
(
[open] => 0.00007976
[high] => 0.00007982
[low] => 0.00007972
[close] => 0.00007977
[volume] => 20.30593916
[openTime] => 2019-03-11 07:30:00
[closeTime] => 2019-03-11 07:44:59
[assetVolume] => 254577.00000000
[baseVolume] => 20.30593916
[trades] => 491
[assetBuyVolume] => 126142.00000000
[takerBuyVolume] => 10.06268333
[ignored] => 0
[val] => 8.37265E-5
[bollingerBands] => Array
(
[upper] => 0.00009171
[middle] => 0.00008373
[lower] => 0.00007575
)
)
[481] => Array
(
[open] => 0.00007977
[high] => 0.00007987
[low] => 0.00007976
[close] => 0.00007984
[volume] => 15.68951279
[openTime] => 2019-03-11 07:45:00
[closeTime] => 2019-03-11 07:59:59
[assetVolume] => 196556.00000000
[baseVolume] => 15.68951279
[trades] => 395
[assetBuyVolume] => 114078.00000000
[takerBuyVolume] => 9.10625891
[ignored] => 0
[val] => 8.3737E-5
[bollingerBands] => Array
(
[upper] => 0.00009172
[middle] => 0.00008374
[lower] => 0.00007575
)
)
[482] => Array
(
[open] => 0.00007983
[high] => 0.00007984
[low] => 0.00007965
[close] => 0.00007973
[volume] => 19.45142661
[openTime] => 2019-03-11 08:00:00
[closeTime] => 2019-03-11 08:14:59
[assetVolume] => 244007.00000000
[baseVolume] => 19.45142661
[trades] => 379
[assetBuyVolume] => 84822.00000000
[takerBuyVolume] => 6.76341528
[ignored] => 0
[val] => 8.37515E-5
[bollingerBands] => Array
(
[upper] => 0.00009173
[middle] => 0.00008375
[lower] => 0.00007578
)
)
[483] => Array
(
[open] => 0.00007973
[high] => 0.00007982
[low] => 0.00007967
[close] => 0.00007972
[volume] => 18.80712164
[openTime] => 2019-03-11 08:15:00
[closeTime] => 2019-03-11 08:29:59
[assetVolume] => 235873.00000000
[baseVolume] => 18.80712164
[trades] => 412
[assetBuyVolume] => 123262.00000000
[takerBuyVolume] => 9.83036795
[ignored] => 0
[val] => 8.3759E-5
[bollingerBands] => Array
(
[upper] => 0.00009173
[middle] => 0.00008376
[lower] => 0.00007579
)
)
[484] => Array
(
[open] => 0.00007972
[high] => 0.00007977
[low] => 0.00007970
[close] => 0.00007970
[volume] => 14.55686636
[openTime] => 2019-03-11 08:30:00
[closeTime] => 2019-03-11 08:44:59
[assetVolume] => 182594.00000000
[baseVolume] => 14.55686636
[trades] => 366
[assetBuyVolume] => 71567.00000000
[takerBuyVolume] => 5.70645955
[ignored] => 0
[val] => 8.3767E-5
[bollingerBands] => Array
(
[upper] => 0.00009174
[middle] => 0.00008377
[lower] => 0.0000758
)
)
[485] => Array
(
[open] => 0.00007971
[high] => 0.00007971
[low] => 0.00007958
[close] => 0.00007965
[volume] => 15.86494558
[openTime] => 2019-03-11 08:45:00
[closeTime] => 2019-03-11 08:59:59
[assetVolume] => 199163.00000000
[baseVolume] => 15.86494558
[trades] => 468
[assetBuyVolume] => 95842.00000000
[takerBuyVolume] => 7.63620911
[ignored] => 0
[val] => 8.37625E-5
[bollingerBands] => Array
(
[upper] => 0.00009173
[middle] => 0.00008376
[lower] => 0.0000758
)
)
[486] => Array
(
[open] => 0.00007961
[high] => 0.00007980
[low] => 0.00007961
[close] => 0.00007975
[volume] => 18.37654358
[openTime] => 2019-03-11 09:00:00
[closeTime] => 2019-03-11 09:14:59
[assetVolume] => 230432.00000000
[baseVolume] => 18.37654358
[trades] => 422
[assetBuyVolume] => 164739.00000000
[takerBuyVolume] => 13.13834379
[ignored] => 0
[val] => 8.376E-5
[bollingerBands] => Array
(
[upper] => 0.00009174
[middle] => 0.00008376
[lower] => 0.00007578
)
)
[487] => Array
(
[open] => 0.00007973
[high] => 0.00007981
[low] => 0.00007966
[close] => 0.00007976
[volume] => 28.43980759
[openTime] => 2019-03-11 09:15:00
[closeTime] => 2019-03-11 09:29:59
[assetVolume] => 356624.00000000
[baseVolume] => 28.43980759
[trades] => 513
[assetBuyVolume] => 120745.00000000
[takerBuyVolume] => 9.62951548
[ignored] => 0
[val] => 8.37565E-5
[bollingerBands] => Array
(
[upper] => 0.00009173
[middle] => 0.00008376
[lower] => 0.00007578
)
)
[488] => Array
(
[open] => 0.00007975
[high] => 0.00007979
[low] => 0.00007963
[close] => 0.00007971
[volume] => 23.46516528
[openTime] => 2019-03-11 09:30:00
[closeTime] => 2019-03-11 09:44:59
[assetVolume] => 294434.00000000
[baseVolume] => 23.46516528
[trades] => 462
[assetBuyVolume] => 140429.00000000
[takerBuyVolume] => 11.19196464
[ignored] => 0
[val] => 8.37495E-5
[bollingerBands] => Array
(
[upper] => 0.00009172
[middle] => 0.00008375
[lower] => 0.00007578
)
)
[489] => Array
(
[open] => 0.00007969
[high] => 0.00008009
[low] => 0.00007961
[close] => 0.00007976
[volume] => 36.70458053
[openTime] => 2019-03-11 09:45:00
[closeTime] => 2019-03-11 09:59:59
[assetVolume] => 460148.00000000
[baseVolume] => 36.70458053
[trades] => 627
[assetBuyVolume] => 312494.00000000
[takerBuyVolume] => 24.93586649
[ignored] => 0
[val] => 8.37545E-5
[bollingerBands] => Array
(
[upper] => 0.00009173
[middle] => 0.00008375
[lower] => 0.00007578
)
)
[490] => Array
(
[open] => 0.00007974
[high] => 0.00007980
[low] => 0.00007969
[close] => 0.00007973
[volume] => 28.98881036
[openTime] => 2019-03-11 10:00:00
[closeTime] => 2019-03-11 10:14:59
[assetVolume] => 363527.00000000
[baseVolume] => 28.98881036
[trades] => 521
[assetBuyVolume] => 145166.00000000
[takerBuyVolume] => 11.57629094
[ignored] => 0
[val] => 8.3757E-5
[bollingerBands] => Array
(
[upper] => 0.00009173
[middle] => 0.00008376
[lower] => 0.00007578
)
)
[491] => Array
(
[open] => 0.00007976
[high] => 0.00007976
[low] => 0.00007968
[close] => 0.00007969
[volume] => 23.69615611
[openTime] => 2019-03-11 10:15:00
[closeTime] => 2019-03-11 10:29:59
[assetVolume] => 297266.00000000
[baseVolume] => 23.69615611
[trades] => 394
[assetBuyVolume] => 185619.00000000
[takerBuyVolume] => 14.79745895
[ignored] => 0
[val] => 8.37545E-5
[bollingerBands] => Array
(
[upper] => 0.00009172
[middle] => 0.00008375
[lower] => 0.00007578
)
)
[492] => Array
(
[open] => 0.00007969
[high] => 0.00007976
[low] => 0.00007968
[close] => 0.00007975
[volume] => 48.72391533
[openTime] => 2019-03-11 10:30:00
[closeTime] => 2019-03-11 10:44:59
[assetVolume] => 611169.00000000
[baseVolume] => 48.72391533
[trades] => 582
[assetBuyVolume] => 432676.00000000
[takerBuyVolume] => 34.49727219
[ignored] => 0
[val] => 8.37475E-5
[bollingerBands] => Array
(
[upper] => 0.00009172
[middle] => 0.00008375
[lower] => 0.00007577
)
)
[493] => Array
(
[open] => 0.00007974
[high] => 0.00007976
[low] => 0.00007967
[close] => 0.00007972
[volume] => 66.07960619
[openTime] => 2019-03-11 10:45:00
[closeTime] => 2019-03-11 10:59:59
[assetVolume] => 828765.00000000
[baseVolume] => 66.07960619
[trades] => 907
[assetBuyVolume] => 573576.00000000
[takerBuyVolume] => 45.73687689
[ignored] => 0
[val] => 8.3745E-5
[bollingerBands] => Array
(
[upper] => 0.00009172
[middle] => 0.00008374
[lower] => 0.00007577
)
)
[494] => Array
(
[open] => 0.00007973
[high] => 0.00008003
[low] => 0.00007970
[close] => 0.00008002
[volume] => 52.95426210
[openTime] => 2019-03-11 11:00:00
[closeTime] => 2019-03-11 11:14:59
[assetVolume] => 663154.00000000
[baseVolume] => 52.95426210
[trades] => 664
[assetBuyVolume] => 395356.00000000
[takerBuyVolume] => 31.56660667
[ignored] => 0
[val] => 8.37545E-5
[bollingerBands] => Array
(
[upper] => 0.00009176
[middle] => 0.00008375
[lower] => 0.00007575
)
)
[495] => Array
(
[open] => 0.00008005
[high] => 0.00008064
[low] => 0.00008002
[close] => 0.00008058
[volume] => 106.52013854
[openTime] => 2019-03-11 11:15:00
[closeTime] => 2019-03-11 11:29:59
[assetVolume] => 1327039.00000000
[baseVolume] => 106.52013854
[trades] => 1438
[assetBuyVolume] => 598355.00000000
[takerBuyVolume] => 48.04201257
[ignored] => 0
[val] => 8.3793E-5
[bollingerBands] => Array
(
[upper] => 0.00009185
[middle] => 0.00008379
[lower] => 0.00007573
)
)
[496] => Array
(
[open] => 0.00008057
[high] => 0.00008089
[low] => 0.00008042
[close] => 0.00008045
[volume] => 102.10166676
[openTime] => 2019-03-11 11:30:00
[closeTime] => 2019-03-11 11:44:59
[assetVolume] => 1265524.00000000
[baseVolume] => 102.10166676
[trades] => 1614
[assetBuyVolume] => 517164.00000000
[takerBuyVolume] => 41.72926216
[ignored] => 0
[val] => 8.382E-5
[bollingerBands] => Array
(
[upper] => 0.00009187
[middle] => 0.00008382
[lower] => 0.00007577
)
)
[497] => Array
(
[open] => 0.00008045
[high] => 0.00008045
[low] => 0.00008003
[close] => 0.00008023
[volume] => 46.38883444
[openTime] => 2019-03-11 11:45:00
[closeTime] => 2019-03-11 11:59:59
[assetVolume] => 578525.00000000
[baseVolume] => 46.38883444
[trades] => 881
[assetBuyVolume] => 263520.00000000
[takerBuyVolume] => 21.12153222
[ignored] => 0
[val] => 8.3843E-5
[bollingerBands] => Array
(
[upper] => 0.00009188
[middle] => 0.00008384
[lower] => 0.00007581
)
)
[498] => Array
(
[open] => 0.00008016
[high] => 0.00008021
[low] => 0.00007989
[close] => 0.00008004
[volume] => 43.03050892
[openTime] => 2019-03-11 12:00:00
[closeTime] => 2019-03-11 12:14:59
[assetVolume] => 537848.00000000
[baseVolume] => 43.03050892
[trades] => 717
[assetBuyVolume] => 264685.00000000
[takerBuyVolume] => 21.17610389
[ignored] => 0
[val] => 8.3854E-5
[bollingerBands] => Array
(
[upper] => 0.00009187
[middle] => 0.00008385
[lower] => 0.00007583
)
)
[499] => Array
(
[open] => 0.00008003
[high] => 0.00008013
[low] => 0.00007992
[close] => 0.00008002
[volume] => 36.70682082
[openTime] => 2019-03-11 12:15:00
[closeTime] => 2019-03-11 12:29:59
[assetVolume] => 458655.00000000
[baseVolume] => 36.70682082
[trades] => 435
[assetBuyVolume] => 295461.00000000
[takerBuyVolume] => 23.64634840
[ignored] => 0
[val] => 8.3869E-5
[bollingerBands] => Array
(
[upper] => 0.00009189
[middle] => 0.00008387
[lower] => 0.00007585
)
)
)
谢谢