I'm trying to calculate Money Flow Index for bitcoin price.
我正在尝试计算比特币价格的资金流量指数。
To do this I'm using gdax, pandas and pyti.
要做到这一点,我使用gdax,pandas和pyti。
Here's my code:
这是我的代码:
import gdax
import pandas as pd
from pyti.money_flow_index import money_flow_index as mfi
public_client = gdax.PublicClient()
historic = public_client.get_product_historic_rates('BTC-USD', granularity=60)
pd.set_option('display.max_rows', 30)
df = pd.DataFrame(historic)
df.columns = ['Time', 'Low', 'High', 'Open', 'Close', 'Volume']
df = df.head(n=30)
print(df, '\n')
close_data = df['Close'][0]
high_data = df['High'][0]
low_data = df['Low'][0]
volume_data = df['Volume'][0]
period = 14
print(mfi(close_data, high_data, low_data, volume_data, period))
Here's the error I'm getting:
这是我得到的错误:
Traceback (most recent call last):
File "tiiii.py", line 18, in <module>
print(mfi(close_data, high_data, low_data, volume_data, period))
File "C:\Users\user\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pyti\money_
flow_index.py", line 19, in money_flow_index
close_data, high_data, low_data, volume
File "C:\Users\user\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pyti\catch_
errors.py", line 26, in check_for_input_len_diff
arrays_len = [len(arr) for arr in args]
File "C:\Users\user\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pyti\catch_
errors.py", line 26, in <listcomp>
arrays_len = [len(arr) for arr in args]
TypeError: object of type 'numpy.float64' has no len()
Edit: OK so now I'm using:
编辑:好的,现在我正在使用:
close_data = df['Close']
high_data = df['High']
low_data = df['Low']
volume_data = df['Volume']
And here's what I'm getting:
这就是我得到的:
0
0 NaN
1 NaN
2 NaN
3 NaN
4 NaN
5 NaN
6 NaN
.. ...
23 97.914228
24 97.816960
25 96.440309
26 94.668462
27 94.340548
28 91.255057
29 87.706573
[30 rows x 1 columns]
I don't understand the order of the values. Also why am I not getting the full list?
我不明白价值观的顺序。另外,为什么我没有得到完整的清单?
P.S. Thanks for the help Rahul and timgeb!
附:感谢Rahul和timgeb的帮助!
2 个解决方案
#1
0
The function money_flow_index
calls check_for_input_len_diff and throws an error on line 26 when it tries to accumulate the length of the arguments close_data, high_data, low_data, volume
you provided to money_flow_index
(imported as mfi
).
函数money_flow_index调用check_for_input_len_diff并在它尝试累积您提供给money_flow_index(导入为mfi)的参数close_data,high_data,low_data,volume的长度时在第26行引发错误。
The comments indicate that these arguments are supposed to be data sets (or at least data structures with a length), but you provided a float number, which has no length.
注释表明这些参数应该是数据集(或者至少是具有长度的数据结构),但是您提供了一个没有长度的浮点数。
#2
0
I have extracted functions from pyti
module. This is how your code actually execute inside modules.
我从pyti模块中提取了函数。这就是您的代码在模块中实际执行的方式。
def money_flow_index (close_data, high_data, low_data, volume, period):
check_for_input_len_diff(
close_data, high_data, low_data, volume
)
def check_for_input_len_diff(*args):
arrays_len = [len(arr) for arr in args]
print(
money_flow_index(
close_data, high_data,
low_data, volume_data, period
)
)
So money_flow_index
need every argument as array
. you are providing numpy.float64
所以money_flow_index需要每个参数作为数组。你提供numpy.float64
#1
0
The function money_flow_index
calls check_for_input_len_diff and throws an error on line 26 when it tries to accumulate the length of the arguments close_data, high_data, low_data, volume
you provided to money_flow_index
(imported as mfi
).
函数money_flow_index调用check_for_input_len_diff并在它尝试累积您提供给money_flow_index(导入为mfi)的参数close_data,high_data,low_data,volume的长度时在第26行引发错误。
The comments indicate that these arguments are supposed to be data sets (or at least data structures with a length), but you provided a float number, which has no length.
注释表明这些参数应该是数据集(或者至少是具有长度的数据结构),但是您提供了一个没有长度的浮点数。
#2
0
I have extracted functions from pyti
module. This is how your code actually execute inside modules.
我从pyti模块中提取了函数。这就是您的代码在模块中实际执行的方式。
def money_flow_index (close_data, high_data, low_data, volume, period):
check_for_input_len_diff(
close_data, high_data, low_data, volume
)
def check_for_input_len_diff(*args):
arrays_len = [len(arr) for arr in args]
print(
money_flow_index(
close_data, high_data,
low_data, volume_data, period
)
)
So money_flow_index
need every argument as array
. you are providing numpy.float64
所以money_flow_index需要每个参数作为数组。你提供numpy.float64