dollar_volume_weights.iloc[i] = dollar_volume_weights.iloc[i] / tickers_sum[i] return dollar_volume_weights project_tests.test_generate_dollar_volume_weights(generate_dollar_volume_weights) # ### View Data # Let's generate the index weights using `generate_dollar_volume_weights` and view them using a heatmap. # In[ ]: index_weights = generate_dollar_volume_weights(close, volume) project_helper.plot_weights(index_weights, "Index Weights") # ## Portfolio Weights # Now that we have the index weights, let's choose the portfolio weights based on dividend. You would normally calculate the weights based on trailing dividend yield, but we'll simplify this by just calculating the total dividend yield over time. # # Implement `calculate_dividend_weights` to return the weights for each stock based on its total dividend yield over time. This is similar to generating the weight for the index, but it's using dividend data instead. # For example, assume the following is `dividends` data: # ``` # Prices # A B # 2013-07-08 0 0 # 2013-07-09 0 1 # 2013-07-10 0.5 0 # 2013-07-11 0 0 # 2013-07-12 2 0
dollar_volume_weights.iloc[i, :] = (product / product.sum()).astype(float) return dollar_volume_weights project_tests.test_generate_dollar_volume_weights( generate_dollar_volume_weights) # ### View Data # Let's generate the index weights using `generate_dollar_volume_weights` and view them using a heatmap. # In[31]: index_weights = generate_dollar_volume_weights(close, volume) project_helper.plot_weights(index_weights, 'Index Weights') # ## Portfolio Weights # Now that we have the index weights, let's choose the portfolio weights based on dividend. You would normally calculate the weights based on trailing dividend yield, but we'll simplify this by just calculating the total dividend yield over time. # # Implement `calculate_dividend_weights` to return the weights for each stock based on its total dividend yield over time. This is similar to generating the weight for the index, but it's using dividend data instead. # For example, assume the following is `dividends` data: # ``` # Prices # A B # 2013-07-08 0 0 # 2013-07-09 0 1 # 2013-07-10 0.5 0 # 2013-07-11 0 0 # 2013-07-12 2 0 # ... ... ...