python 分析股票收益
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 分析股票收益相关的知识,希望对你有一定的参考价值。
c = np.loadtxt('data.csv', delimiter=',', usecols=(6,),unpack=True)
returns = np.diff(c)/c[:-1] #diff returns difference between two consecutive array elements
print "Standard Deviation =", np.std(returns)
print np.diff(np.log(c)) #log returns
positive_return_indices = np.where(returns > 0) #Return positives
print "Indices with positive return is", positive_return_indices
annual_volatility = np.std(np.log(c))/np.mean(np.log(c))
annual_volatility + annual_volatility / np.sqrt(1./252.)
print annual_volatility #Returns annualized volatility; Make sure to use float
以上是关于python 分析股票收益的主要内容,如果未能解决你的问题,请参考以下文章