[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 ... >>> ...
随机推荐
- POJ 1064 Cable master 【二分答案】
和杭电那一题一样,只不过G++交不能通过,C++能过 wa了好多好多好多次----------------------------------------- #include<iostream& ...
- Quartz任务调度 服务日志+log4net打印日志+制作windows服务
引言 现在许多的项目都需要定时的服务进行支撑,而我们经常用到的定时服务就是Quartz任务调度了.不过我们在使用定时Job进行获取的时候,有时候我们就需要记录一下自定义的日志,甚至我们还会对执行定时J ...
- MySQL 高可用:mysql+mycat实现数据库分片(分库分表)
本文引用于http://blog.csdn.net/kk185800961/article/details/51147029 MySQL 高可用:mysql+mycat实现数据库分片(分库分表) 什么 ...
- 动态Axios配置
推荐使用Vue-cli工具来创建和管理项目,就算刚开始不熟悉,用着用着便可知晓其中的奥妙.前一段时间官方所推荐的数据请求插件还是Vue-resource,但现在已经变了,变成了Axios,不用知道为什 ...
- 紫书 习题 11-4 UVa 1660 (网络流拆点法)
这道题改了两天-- 因为这道题和节点有关, 所以就用拆点法解决节点的容量问题. 节点拆成两个点, 连一条弧容量为1, 表示只能经过一次. 然后图中的弧容量无限. 然后求最小割, 即最大流, 即为答案. ...
- gps 地图
http://www.cnblogs.com/sylvanas2012/p/5342530.html http://blog.csdn.net/ma969070578/article/details/ ...
- Hive-jdbc获取sessionId
在HiveStatement中有一个sessHandle: public class HiveStatement implements java.sql.Statement { ... private ...
- git的学习笔记整理
Git学习较好的网址:http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/001373 ...
- BZOJ4479 [JSOI2013] 吃货jyy 解题报告(三进制状态压缩+欧拉回路)
题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=4479 Description [故事背景]作为JSOI的著名吃货,JYY的理想之一就是吃 ...
- TYVJ 1340 折半暴搜+二分
思路: 1. 这 题 不卡常过不去啊-- (先加一个random_shuffle) 首先 我们可以折半 搜这一半可以到达的重量 sort一遍 然后搜另一半 对于路程中每一个解 我们可以二分前一半中加这 ...