bastien2019 2022-02-04 21:52 采纳率: 0%
浏览 200

Python 'NoneType' object has no attribute 'apply'

#设定回撤值
withdraw = 0.03
#设定突破值
breakthrough =0.03
#设定账户资金
account = 10000
#持有仓位手数
position = 0

def buy(bar):
    global account,position
    print("{}: buy{}".format(bar.date,bar.close))
    #一手价格
    one = bar.close*100
    position = account//one
    account = account - (position*one)
    
def sell(bar):
    global account,position
    #一手价格
    print("{}:sell{}".format(bar.date,bar.close))
    one =bar.close*100
    account+=position*one
    position = 0
    
print("开始时间投资时间:",df.iloc[0]).apply(lambda x : x.days)
for date in df.index:
    bar = df.loc[date]
    if bar.pchange and bar.pchange > breakthrough and position ==0:
        buy(bar)
    elif bar.pchange and bar.pchange <withdraw and position > 0:
        sell(bar)
print("最终可有现金:",account)
print("最终持有市值:",position*df.iloc[-1].close*100)

  • 写回答

1条回答 默认 最新

  • 关注

    print("开始时间投资时间:",df.iloc[0]).apply(lambda x : x.days)
    改成
    print("开始时间投资时间:",df.iloc[0].apply(lambda x : x.days))
    .iloc[0] 之后的)移到后面

    评论 编辑记录

报告相同问题?

问题事件

  • 创建了问题 2月4日

悬赏问题

  • ¥170 如图所示配置eNSP
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥15 键盘指令混乱情况下的启动盘系统重装