sthoooon
2/15/2016 - 9:49 PM

Analyzing Stock Returns

Analyzing Stock Returns

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