[Python] Scatter Plot for daily return

Sploe = 2: means that SPY move up 1, ABC move up 2

Correlation: how close those dots close to the line.

 

def scatter(df):

    plot_data(df, title="Data frame", yLabel="Time")
    plt.show()

    dr = compute_daily_return(df)
    plot_data(dr, title="Daily returns", yLabel="Daily returns")

    dr['GOOG'].hist(bins=20, label="GOOG") 
    dr['SPY'].hist(bins=20, label="SPY") 
    plt.legend(loc='upper right')

    # Scatterplot SPY vs GOOG
    dr.plot(kind='scatter', x = 'SPY', y = 'GOOG')
    spy = dr['SPY'][:-1] # remove nan value
    goog = dr['GOOG'][:-1] # remove nan value
    beta_goog, alpha_goog = np.polyfit(spy, goog, 1)
    # beta_goog= 1.23719057977
    # alpha_goog= -0.000283995818653
    plt.plot(dr['SPY'], beta_goog*dr['SPY']+alpha_goog, '-', color='r')
    plt.show()

    print("Correlation", dr.corr(method='pearson'))

    # Get kurtosis
    print("kurtosis=", dr.kurtosis())


if __name__ == '__main__':
    df=test_run()
    scatter(df[['SPY', 'GOOG']])

[Python] Scatter Plot for daily return

[Python] Scatter Plot for daily return

 

相关文章:

  • 2021-08-19
  • 2021-11-20
  • 2021-09-16
  • 2021-05-30
  • 2022-12-23
  • 2021-03-31
  • 2021-12-16
猜你喜欢
  • 2022-12-23
  • 2021-08-01
  • 2021-05-02
  • 2022-01-09
  • 2022-01-18
  • 2021-04-23
相关资源
相似解决方案