python 计算股市技术分析PSY指标

PSY,心理线,百度百科链接:

https://baike.baidu.com/item/PSY%E6%8C%87%E6%A0%87/3083493?fr=aladdin


价格上涨可以通过两种方式判定:第一种是当日收盘价格高于前日收盘价格;

第二种是当日收盘价格高于当日开盘价格。这里用的是第一种方法。


import numpy as np
def getPSY(priceData, period):
    #rolling calculation of the PSY, psychological line
    #priceData should be the close price data, in np format
    #period is the length of days in which we look at how many days witness price increase
    difference = priceData[1:] - priceData[:-1]
    #price change
#    difference = np.append(np.nan, difference)
    #to make the length of the difference same as the priceData, lag of one day
    #to avoid the warning, use 0 instead of np.nan, the result should be the same
    difference = np.append(0, difference)    
    difference_dir = np.where(difference > 0, 1, 0)
    #get the direction of the price change, if increase, 1, el
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值