[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] Histograms for analysis Daily return
A histogram is an accurate representation of the distribution of numerical data. Y axis is the occur ...
- [D3] Build a Scatter Plot with D3 v4
Scatter plots, sometimes also known as bubble charts, are another common type of visualization. They ...
- python matplotlib plot 数据中的中文无法正常显示的解决办法
转发自:http://blog.csdn.net/laoyaotask/article/details/22117745?utm_source=tuicool python matplotlib pl ...
- python中生成器对象和return 还有循环的区别
python中生成器对象和return 还有循环的区别 在python中存在这么一个关键字yield,这个关键字在项目中经常被用到,比如我写一个函数不想它只返回一次就结束那我们就不能用return,因 ...
- Python Matplotlib.plot Update image Questions
1. 最近在测试一款设备,采集了一些设备后需要一帧一帧显示图像,经常使用Python,所以选用了Matplotlib进行图像操作 数据结构: timesatamp polar_distance hor ...
- [D3] 9. Scatter Plot
Up until now we've just looked at bar charts. A handy chart, no doubt, but D3 offers a variety of ch ...
- python matplotlib.plot画图显示中文乱码的问题
在matplotlib.plot生成的统计图表中,中文总是无法正常显示.在网上也找了些资料,说是在程序中指定字体文件,不过那样的话需要对plot进行很多设置,而且都是说的设置坐标轴标题为中文,有时候图 ...
- Python函数基础--def及return语句地操作
1·def是可执行的代码 Python的函数是有一个新的语句编写的,即def.不像C这样的编译语言,def 实际上是一个可执行的语句--函数并不存在,直到Python运行了def后才存在.在典型的操作 ...
- [python]函数返回多个return值
python支持函数直接返回多个变量,具体用法如下: >>> def test(): ... a=2 ... b=3 ... return a,b ... >>> ...
随机推荐
- shell-3.bash的基本功能:输入输出重定向
1. 2. 3. 4.
- SpringCloud学习笔记(8)----Spring Cloud Netflix之负载均衡-Ribbon的负载均衡的策略
一. 内置 负载均衡策略的介绍的 IRule的实现类 2. 通过代码实现负载均衡 在第六节Riddom的使用的工程中,随机策略配置类 package com.wangx.cloud.springclo ...
- HTML提交表单
一.使用form提交表单 <form action="#" method="post"> {% csrf_token %} 班级<input ...
- Pimple相关的源码
已经有了非常好的Pimple的相关解析,建议先看下:Pimple - 一个简单的 PHP 依赖注入容器读 PHP - Pimple 源码笔记(上)读 PHP - Pimple 源码笔记(下) 这里通过 ...
- Maven copy方式列举
maven copy有很多种方法: 1.maven-antrun-plugin (使用ant复制) <build> <finalName>flex</finalName& ...
- CSDN博客给我带来的一些诱惑和选择机会
武汉九天鸟-p2p网贷系统开发-互联网应用软件开发 公司官网:http://jiutianniao.com 社交问答:http://ask.jiutianniao.com 最近1年多,尤其是今年5月 ...
- 【codeforces 196B】Infinite Maze
[题目链接]:http://codeforces.com/problemset/problem/196/B [题意] 给你一个n*m的棋盘; 然后你能够无限复制这个棋盘; 在这个棋盘上你有一个起点s; ...
- IOS中UIImagePickerController中文界面问题
今天沈阳斌子,写IOS项目遇到一个调用照相机的问题,找到解决方法,高速攻克了拿给PM看,结果PM说程序调用的照相机不是中文的是英文的.必须改成中文.上网找到了方法.试用后好用拿出来和大家分享.方法例如 ...
- invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause
Column 'dbo.tbm_vie_View.ViewID' is invalid in the select list because it is not contained in either ...
- 34.angularJS的{{}}和ng-bind
转自:https://www.cnblogs.com/best/tag/Angular/ 1. <html> <head> <meta charset="utf ...