鱼C论坛

 找回密码
 立即注册
查看: 3752|回复: 2

[已解决]报错求助:TypeError: 'numpy.float64' object cannot be interpreted as an integer

[复制链接]
发表于 2018-10-24 10:42:01 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
定义了一个以pandas  dataframe作为变量的函数, 但是调用函数的时候报错了。求大神帮助
import talib as ta
import numpy as np
import math
import matplotlib
from gm.api import*

def my_strategy(his_data):
    his_data['ret'] = float(0)
    his_data.loc[1:,'ret'] = np.diff(np.log(his_data.close))
    his_data['d_ret'] = 1 + np.cumsum(his_data['ret'])
    his_data['highwaterlevel'] = float(0)
    for i in his_data.index:
        if i == his_data.index[0]:
            his_data.loc[i,'highwaterlevel'] = 1
        else:
            his_data.loc[i,'highwaterlevel'] = np.max(his_data['d_ret'][i],his_data['highwaterlevel'][i-1])
    his_data['drawdown'] = his_data.d_ret - his_data.highwaterlevel
    return his_data   

set_token('b41acf599734d5411ee31dcd94c0484aa962fee3')
symbol      = 'SHFE.AU'
starttime   = '2017-10-23 09:00:00'
endtime     = '2018-10-23 15:00:00'
his_data = history(symbol ,frequency='1d',start_time=starttime, end_time=endtime, skip_suspended=True, adjust=1, df=True)
His_data = my_strategy(his_data)


报错信息如下:

TypeError                                 Traceback (most recent call last)
<ipython-input-33-0617598d8d73> in <module>()
      4 endtime     = '2018-10-23 15:00:00'
      5 his_data = history(symbol ,frequency='1d',start_time=starttime, end_time=endtime, skip_suspended=True, adjust=1, df=True)
----> 6 His_data = my_strategy(his_data)

<ipython-input-30-276ba0880765> in my_strategy(his_data)
      8             his_data.loc[i,'highwaterlevel'] = 1
      9         else:
---> 10             his_data.loc[i,'highwaterlevel'] = np.max(his_data['d_ret'],his_data['highwaterlevel'][i-1])
     11     his_data['drawdown'] = his_data.d_ret - his_data.highwaterlevel
     12     return his_data

~\Anaconda3\lib\site-packages\numpy\core\fromnumeric.py in amax(a, axis, out, keepdims)
   2315             pass
   2316         else:
-> 2317             return amax(axis=axis, out=out, **kwargs)
   2318
   2319     return _methods._amax(a, axis=axis,

~\Anaconda3\lib\site-packages\numpy\core\_methods.py in _amax(a, axis, out, keepdims)
     24 # small reductions
     25 def _amax(a, axis=None, out=None, keepdims=False):
---> 26     return umr_maximum(a, axis, None, out, keepdims)
     27
     28 def _amin(a, axis=None, out=None, keepdims=False):

TypeError: 'numpy.float64' object cannot be interpreted as an integer
[/i]
最佳答案
2018-10-24 10:49:46
你的索引有小数吧,把他转换成整数
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2018-10-24 10:49:46 | 显示全部楼层    本楼为最佳答案   
你的索引有小数吧,把他转换成整数
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2018-10-24 20:19:53 | 显示全部楼层
塔利班 发表于 2018-10-24 10:49
你的索引有小数吧,把他转换成整数

谢谢大神!
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2026-7-13 11:50

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表