Issue
Anybody wish to help me understand why below code doesn't work?
start_date = '1990-01-01'
ticker_list = ['SPY', 'QQQ', 'IWM','GLD']
tickers = yf.download(ticker_list, start=start_date)['Close'].dropna()
ticker_vol_share = (tickers.pct_change().rolling(20).std()) \
/ ((tickers.pct_change().rolling(20).std()).sum(axis=1))
Both (tickers.pct_change().rolling(20).std())
and ((tickers.pct_change().rolling(20).std()).sum(axis=1))
runs fine by themselves, but when ran together they form a dataframe with thousands of columns all filled with nan
Solution
Try this.
rolling_std = tickers.pct_change().rolling(20).std()
ticker_vol_share = rolling_std.apply(lambda row:row/sum(row),axis = 1)
Answered By - sayan dasgupta
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.