def hist_vol(sym, days=10): try: quotes = DataReader(sym, 'yahoo')['Close'][-days:] except Exception: print "Problem getting historical volatility!" raise SystemExit(code) return None, None logreturns = np.log(quotes / quotes.shift(1)) vol = np.sqrt(252*logreturns.var()) #252 trading days in year (annualized volatility) return float(vol)
def getParams(ticker): data = DataReader(ticker, "yahoo", datetime(1890, 1, 1), datetime.now()) changes = log(data['Adj Close'][1:]) - log(data.shift()['Adj Close'][1:]) params = laplace.fit(changes) return params, std(changes[-365:]) * (365**(.5))
plt.fill_between(INF.index,INF['sig'],0) plt.subplot(414) plt.plot(INF.index,INF['PNL']) # plt.show() pic.new() plt.savefig("C:/Users/oskar/Documents/doc_no_backup/python_crap/temp/%s.png" %(str(pic.num))) rep.addimage("C:/Users/oskar/Documents/doc_no_backup/python_crap/temp/%s.png"%(str(pic.num)),7,4,'LEFT') plt.close() # #corporate profits------------ C_POFIT = DataReader("CP", "fred", start, end) #corporate profit after tax C_POFIT['lag6m']=C_POFIT['CP'].shift(2) C_POFIT['SIG']=C_POFIT['CP']>C_POFIT['lag6m'] C_POFIT=C_POFIT.shift(5, freq='D') # print C_POFIT.to_string() print C_POFIT.tail(5) plt.subplot(211) plt.plot(C_POFIT.index,C_POFIT[['CP','lag6m']]) plt.subplot(212) plt.fill_between(C_POFIT.index,C_POFIT['SIG'],0) # plt.show() pic.new() plt.savefig("C:/Users/oskar/Documents/doc_no_backup/python_crap/temp/%s.png" %(str(pic.num))) rep.addimage("C:/Users/oskar/Documents/doc_no_backup/python_crap/temp/%s.png"%(str(pic.num)),7,4,'LEFT') plt.close() ##