def plot_return_vs_beta():
    Coef = ReadData.GetCoef(START_TRAIN, END_TRAIN, StockReturns, CarhartDaily,
                            SP500Returns, DataFolder)
    avaTickers = pd.merge(
        Coef[['ticker']],
        StockBeta[np.isnan(StockBeta.cqaBeta) == False][['ticker']])
    avaTickers = pd.merge(
        avaTickers,
        StockPrices[StockPrices.date == START_TRAIN][['ticker']],
        on='ticker')
    avaTickers = pd.merge(
        avaTickers,
        StockPrices[StockPrices.date == END_TRAIN][['ticker']],
        on='ticker')
    avaTickers = pd.merge(avaTickers,
                          StockPrices[StockPrices.date == START][['ticker']],
                          on='ticker')
    avaTickers = pd.merge(avaTickers,
                          StockPrices[StockPrices.date == END][['ticker']],
                          on='ticker')
    Coef = Coef.merge(avaTickers, on='ticker')

    stock_returns_sample = StockReturns[(StockReturns['endDate'] >= START)
                                        & (StockReturns['endDate'] <= END)]
    stock_annual_returns = stock_returns_sample.groupby(
        'ticker').sum().reset_index()
    stock_annual_returns['return'] = stock_annual_returns['return'].map(
        math.exp) - 1

    beta_return_comp = Coef[['ticker', 'Mkt-RF']].merge(stock_annual_returns)
    # plt.figure()
    fig = plt.figure()
    ax = fig.add_subplot(1, 1, 1)
    fmt = '%.0f%%'  # Format you want the ticks, e.g. '40%'
    yticks = mtick.FormatStrFormatter(fmt)
    ax.yaxis.set_major_formatter(yticks)
    # plt.scatter(beta_return_comp['Mkt-RF'], beta_return_comp[ 'return'], marker='x')
    ax.scatter(beta_return_comp['Mkt-RF'],
               beta_return_comp['return'] * 100,
               marker='o',
               s=40,
               color='#FF6E1E')
    matplotlib.rc('xtick', labelsize=36)
    matplotlib.rc('ytick', labelsize=36)
    plt.xlabel('Stock Beta', fontsize=36)
    plt.ylabel('Annual Return (in percentage)', fontsize=36)
    plt.grid()
    plt.title('Return vs Beta (Nov 2013-Oct 2014)', fontsize=36)
    plt.gcf().subplots_adjust(left=0.15, bottom=0.14)
    plt.show()
##beta_corr2 = np.corrcoef(aapl3y['return-RF'], aapl3y['SP500-RF'])[1,0]
##y = aapl3y['return-RF']
##X = aapl3y['SP500-RF']
##
##def fun1(y, X):
##    model = sm.OLS(y, X).fit()
##    print aaplModel.summary()
##fun1(y, X) # this returns 0.84, which is very close to beta_CQA = 0.83
##fun1(y, sm.add_constant(X))

##############################################################################
# Calculate or Read regression coefficients, depending on your own needs
# Coef = ReadData.ReadCoef(START_TRAIN, END_TRAIN, DataFolder)
# Coef2 = ReadData.ReadCoef(datetime.datetime(2011,11,1),
#                          datetime.datetime(2014,10,31), DataFolder)
Coef = ReadData.GetCoef(START_TRAIN, END_TRAIN, StockReturns, CarhartDaily,
                        SP500Returns, DataFolder)
# Coef2 = ReadData.GetCoef(datetime.datetime(2011,11,1),
#                          datetime.datetime(2014,10,31),
#                          StockReturns, CarhartDaily, SP500Returns, DataFolder)

avaTickers = pd.merge(
    Coef[['ticker']],
    StockBeta[np.isnan(StockBeta.cqaBeta) == False][['ticker']])
avaTickers = pd.merge(avaTickers,
                      StockPrices[StockPrices.date == START_TRAIN][['ticker']],
                      on='ticker')
avaTickers = pd.merge(avaTickers,
                      StockPrices[StockPrices.date == END_TRAIN][['ticker']],
                      on='ticker')
avaTickers = pd.merge(avaTickers,
                      StockPrices[StockPrices.date == START][['ticker']],