资源简介

代码片段和文件信息
#!/usr/bin/python
# -*- coding: utf-8 -*-
# cadf.py
import datetime
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import pandas as pd
import pandas.io.data as web
import pprint
import statsmodels.tsa.stattools as ts
from pandas.stats.api import ols
def plot_price_series(df ts1 ts2):
months = mdates.MonthLocator() # every month
fig ax = plt.subplots()
ax.plot(df.index df[ts1] label=ts1)
ax.plot(df.index df[ts2] label=ts2)
ax.xaxis.set_major_locator(months)
ax.xaxis.set_major_formatter(mdates.DateFormatter(‘%b %Y‘))
ax.set_xlim(datetime.datetime(2012 1 1) datetime.datetime(2013 1 1))
ax.grid(True)
fig.autofmt_xdate()
plt.xlabel(‘Month/Year‘)
plt.ylabel(‘Price ($)‘)
plt.title(‘%s and %s Daily Prices‘ % (ts1 ts2))
plt.legend()
plt.show()
def plot_scatter_series(df ts1 ts2):
plt.xlabel(‘%s Price ($)‘ % ts1)
plt.ylabel(‘%s Price ($)‘ % ts2)
plt.title(‘%s and %s Price Scatterplot‘ % (ts1 ts2))
plt.scatter(df[ts1] df[ts2])
plt.show()
def plot_residuals(df):
months = mdates.MonthLocator() # every month
fig ax = plt.subplots()
ax.plot(df.index df[“res“] label=“Residuals“)
ax.xaxis.set_major_locator(months)
ax.xaxis.set_major_formatter(mdates.DateFormatter(‘%b %Y‘))
ax.set_xlim(datetime.datetime(2012 1 1) datetime.datetime(2013 1 1))
ax.grid(True)
fig.autofmt_xdate()
plt.xlabel(‘Month/Year‘)
plt.ylabel(‘Price ($)‘)
plt.title(‘Residual Plot‘)
plt.legend()
plt.plot(df[“res“])
plt.show()
if __name__ == “__main__“:
start = datetime.datetime(2012 1 1)
end = datetime.datetime(2013 1 1)
arex = web.DataReader(“AREX“ “yahoo“ start end)
wll = web.DataReader(“WLL“ “yahoo“ start end)
df = pd.Dataframe(index=arex.index)
df[“AREX“] = arex[“Adj Close“]
df[“WLL“] = wll[“Adj Close“]
# Plot the two time series
plot_price_series(df “AREX“ “WLL“)
# Display a scatter plot of the two time series
plot_scatter_series(df “AREX“ “WLL“)
# Calculate optimal hedge ratio “beta“
res = ols(y=df[‘WLL‘] x=df[“AREX“])
beta_hr = res.beta.x
# Calculate the residuals of the linear combination
df[“res“] = df[“WLL“] - beta_hr*df[“AREX“]
# Plot the residuals
plot_residuals(df)
# Calculate and output the CADF test on the residuals
cadf = ts.adfuller(df[“res“])
pprint.pprint(cadf)
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2015-06-18 08:55 algo-ebook-full-source-code-20150618\
目录 0 2015-06-18 08:55 algo-ebook-full-source-code-20150618\chapter10\
文件 2481 2015-06-18 08:55 algo-ebook-full-source-code-20150618\chapter10\cadf.py
目录 0 2015-06-18 08:55 algo-ebook-full-source-code-20150618\chapter11\
文件 4129 2015-06-18 08:55 algo-ebook-full-source-code-20150618\chapter11\forecast.py
目录 0 2015-06-18 08:55 algo-ebook-full-source-code-20150618\chapter12\
文件 2780 2015-06-18 08:55 algo-ebook-full-source-code-20150618\chapter12\sharpe.py
目录 0 2015-06-18 08:55 algo-ebook-full-source-code-20150618\chapter13\
文件 922 2015-06-18 08:55 algo-ebook-full-source-code-20150618\chapter13\var.py
目录 0 2015-06-18 08:55 algo-ebook-full-source-code-20150618\chapter14\
文件 4445 2015-06-18 08:55 algo-ebook-full-source-code-20150618\chapter14\backtest.py
文件 7340 2015-06-18 08:55 algo-ebook-full-source-code-20150618\chapter14\data.py
文件 4954 2015-06-18 08:55 algo-ebook-full-source-code-20150618\chapter14\event.py
文件 2263 2015-06-18 08:55 algo-ebook-full-source-code-20150618\chapter14\execution.py
文件 6968 2015-06-18 08:55 algo-ebook-full-source-code-20150618\chapter14\ib_execution.py
文件 3515 2015-06-18 08:55 algo-ebook-full-source-code-20150618\chapter14\mac.py
文件 1431 2015-06-18 08:55 algo-ebook-full-source-code-20150618\chapter14\performance.py
文件 8898 2015-06-18 08:55 algo-ebook-full-source-code-20150618\chapter14\portfolio.py
文件 1071 2015-06-18 08:55 algo-ebook-full-source-code-20150618\chapter14\strategy.py
目录 0 2015-06-18 08:55 algo-ebook-full-source-code-20150618\chapter15\
文件 4445 2015-06-18 08:55 algo-ebook-full-source-code-20150618\chapter15\backtest.py
文件 1860 2015-06-18 08:55 algo-ebook-full-source-code-20150618\chapter15\create_lagged_series.py
文件 7464 2015-06-18 08:55 algo-ebook-full-source-code-20150618\chapter15\data.py
文件 4954 2015-06-18 08:55 algo-ebook-full-source-code-20150618\chapter15\event.py
文件 2263 2015-06-18 08:55 algo-ebook-full-source-code-20150618\chapter15\execution.py
文件 5509 2015-06-18 08:55 algo-ebook-full-source-code-20150618\chapter15\hft_data.py
文件 9070 2015-06-18 08:55 algo-ebook-full-source-code-20150618\chapter15\hft_portfolio.py
文件 6968 2015-06-18 08:55 algo-ebook-full-source-code-20150618\chapter15\ib_execution.py
文件 5391 2015-06-18 08:55 algo-ebook-full-source-code-20150618\chapter15\intraday_mr.py
文件 3603 2015-06-18 08:55 algo-ebook-full-source-code-20150618\chapter15\mac.py
文件 1431 2015-06-18 08:55 algo-ebook-full-source-code-20150618\chapter15\performance.py
............此处省略22个文件信息
- 上一篇:蚂蚁金服UI规范
- 下一篇:Dspace使用入门
相关资源
- Pythonamp;课堂amp;笔记(高淇amp;400;集第
- Python中Numpy库最新教程
- 用python编写的移动彩信的发送程序
- Python全栈学习笔记面向对象大作业:
- python实现的ftp自动上传、下载脚本
- Python版的A*寻路算法
- IronPython IDE
- pip-10.0.1.tar.gz
- Data Science from Scratch 2nd Edition
- shape_predictor_68_face_landmarks.dat.bz2 68个标
- 爬取豆瓣电影TOP250程序,包含非常详
- 中文维基百科语料库百度网盘网址.
- MSCNN_dehaze.rar
- 爬取豆瓣排行榜电影数据(含GUI界面
- 字典文本资源
- Brainfuck / OoK 解码脚本
- 案例实战信用卡欺诈检测数据集
- 招商策略_抱团启示录那些年我们一起
- sip-4.19.zip
- 树莓派3b+学习使用教程
- numpy 中文学习手册
- 打开量化投资的黑箱(原书第2版)
- pytorch-1.4.0-py3.7_cpu_0.tar.bz2
- 机器学习实战 高清完整版PDF
- 泰坦尼克号0.81准确率实验报告.docx
-
abaqus sc
ripting reference manual.pdf - 网页版聊天程序--网络程序设计课程大
- Give Me Some Credit
-
ba
semap安装出错时,正确得pyproj文件 - 微信头像拼接工具
评论
共有 条评论