PyAlgoTrade Documentation

Size: px
Start display at page:

Download "PyAlgoTrade Documentation"

Transcription

1 PyAlgoTrade Documentation 发 布 017 Gabriel Martín Becedillas Ruiz 2016 年 02 月 26 日

2

3 Contents 1 简 介 3 2 简 明 教 程 5 21 交 易 9 22 优 化 绘 图 15 3 代 码 的 文 档 说 明 bar 品 种 的 价 格 dataseries 数 据 序 列 基 类 feed 数 据 源 基 类 CSV 支 持 CSV 支 持 的 例 子 barfeed Bar 数 据 来 源 CSV Yahoo! Finance Google Finance Quandl Ninja Trader technical 技 术 指 标 例 子 移 动 平 均 线 动 量 指 标 其 他 指 标 broker 订 单 管 理 类 基 类 和 模 块 回 测 模 块 和 类 strategy 策 略 基 类 Strategy Position stratanalyzer Strategy analyzers Returns Sharpe Ratio DrawDown Trades Example plotter Strategy plotter optimizer Parallel optimizers 26 i

4 311 marketsession Market sessions 26 4 工 具 Yahoo! Finance Quandl BarFeed resampling 29 5 Event profiler Example 31 6 Xignite support xignite Xignite reference Feeds Xignite Example 35 7 Bitcoin Bitstamp support bitstamp Bitstamp reference Bitstamp Example Bitcoin Charts support bitcoincharts Bitcoin Charts reference Bitcoin Charts example 41 8 Twitter support twitter Twitter feed reference Feed Twitter Example 45 9 TA-Lib integration Computational Investing Part I Homework Homework 3 and 策 略 例 子 动 量 交 易 VWAP 动 量 交 易 SMA 交 叉 均 线 交 叉 择 时 均 值 回 归 Ernie Chan s 黄 金 vs 黄 金 矿 工 布 林 带 RSI 其 他 Quandl 合 集 Indices and tables 79 Python 模 块 索 引 81 ii

5 目 录 : Contents 1

6 2 Contents

7 CHAPTER 1 简 介 PyAlgoTrade 作 为 事 件 驱 动 型 的 算 法 交 易 工 具, 其 支 持 : 从 CSV 文 件 中 获 取 历 史 数 据 并 进 行 回 测 通 过 使 用 Xignite 和 Bitstamp 的 实 时 数 据 进 行 模 拟 交 易 在 Bitstamp 上 进 行 实 战 交 易 它 可 以 很 方 便 的 在 多 台 计 算 机 之 间 优 化 策 略 PyAlgoTrade 基 于 Python27 开 发 并 依 托 于 以 下 python 库 : NumPy and SciPy ( 科 学 计 算 库 pytz ( matplotlib ( : 绘 图 库 ws4py ( : 用 于 得 到 Bitstamp 支 持 tornado ( 用 于 得 到 Bitstamp 支 持 tweepy ( 用 于 得 到 推 特 支 持 因 此, 你 需 要 安 装 上 述 扩 展 库 才 能 使 用 本 扩 展 库 你 可 以 通 过 pip 来 安 装 PyAlgoTrade: pip install pyalgotrade 译 者 注 : 017 版 本 已 经 迁 移 到 Python3x 上, 原 版 只 能 在 py27 环 境 下 运 行, 请 谨 慎 升 级 down:pyalgotrade016_for_py : 目 前, 已 有 国 内 版 本 地 址 : 基 于 py27, 支 持 A 股 交 易 以 及 封 装 了 tushare 的 A 股 即 时 行 情 项 目 QQ 群 : 水 平 有 限, 如 有 疏 漏, 敬 请 谅 解! 欢 迎 一 起 翻 译 &debug! 3

8 4 Chapter 1 简 介

9 CHAPTER 2 简 明 教 程 本 教 程 的 目 的 是 让 你 能 够 快 速 入 门 PyAlgoTrade 如 之 前 简 介 中 所 述,PyAlgoTrade 的 目 标 是 帮 助 你 测 试 股 票 交 易 策 略 一 般 而 言, 如 果 你 有 一 个 交 易 策 略 的 构 思, 并 且 想 在 历 史 数 据 中 看 看 它 的 表 现 的 话, PyAlgoTrade 应 该 能 够 给 你 一 些 帮 助 感 谢 要 放 在 最 开 始 感 谢 豪 尔 赫 帮 助 审 查 初 步 设 计 和 文 档 本 教 程 是 在 UNIX 下 开 发 的, 但 是 把 它 调 整 为 windows 环 境 应 该 是 比 较 简 单 的 因 为 我 就 是 在 windows 下 翻 译 的 PyAlgoTrade 有 6 大 主 要 组 件 : Strategies 策 略 Feeds 数 据 源 Brokers 经 纪 商 DataSeries 数 据 序 列 Technicals 指 标 计 算 Optimizer 优 化 Strategies 这 是 你 定 义 的 实 现 交 易 逻 辑 的 类 : 何 时 买 何 时 卖, 等 等 Feeds These are data providing abstractions 例 如, 你 可 以 使 用 CSV 数 据 源 从 一 个 格 式 化 后 的 csv( 以 逗 号 分 割 ) 文 件 中 加 载 数 据 推 送 给 策 略 数 据 源 不 仅 限 于 bars 例 如, 可 以 利 用 Twitter 数 据 源 将 Twitter 的 事 件 信 息 转 化 为 交 易 决 策 ( 译 者 注 : 事 件 驱 动 ) Brokers 经 纪 商 模 块 负 责 执 行 订 单 DataSeries DataSeries 是 用 于 管 理 时 间 序 列 的 抽 象 类 Technicals 这 是 你 用 来 对 DataSeries 进 行 计 算 的 一 组 过 滤 ( 指 标 ) 器 例 如 简 单 移 动 平 均 线 (SMA), 相 对 强 弱 指 标 (RSI) 等 这 些 过 滤 ( 指 标 ) 器 被 建 模 为 DataSeries 的 装 饰 器 Optimizer 这 是 能 让 你 在 不 同 电 脑 之 间 或 多 进 程 或 二 者 结 合 以 加 快 回 测 效 率 的 一 组 类 说 到 这 里, 我 们 测 试 策 略 时 需 要 一 些 数 据, 让 我 们 使 用 以 下 命 令 获 取 甲 骨 文 (Oracle)2000 年 的 数 据 : python -c "from pyalgotradetools import yahoofinance; yahoofinancedownload_daily_bars('orcl', 2000, pyalgotradetoolsyahoofinance 从 雅 虎 金 融 (Yahoo! 2000csv 的 格 式 和 内 容 如 下 : Finance) 上 打 包 下 载 格 式 化 后 的 CSV 数 据 文 件 orcl- 5

10 Date,Open,High,Low,Close,Volume,Adj Close ,3087,3131,2869,2906, , ,3056,3112,3037,3106, , ,3037,3106,2937,3069, , ,11550,11862,10500,10769, , ,12462,12519,11162,11812, ,2881 让 我 们 从 一 个 简 单 的 策 略 开 始, 即 在 运 行 过 程 中 只 打 印 收 盘 价 : from pyalgotrade import strategy from pyalgotradebarfeed import yahoofeed class MyStrategy(strategyBacktestingStrategy): def init (self, feed, instrument): strategybacktestingstrategy init (self, feed) self instrument = instrument def onbars(self, bars): bar = bars[self instrument] selfinfo(bargetclose()) # Load the yahoo feed from the CSV file feed = yahoofeedfeed() feedaddbarsfromcsv("orcl", "orcl-2000csv") # Evaluate the strategy with the feed's bars mystrategy = MyStrategy(feed, "orcl") mystrategyrun() 这 段 代 码 主 要 做 了 3 件 事 情 :(???) 1 声 明 了 一 个 新 的 策 略, 这 个 策 略 中 只 定 义 了 一 个 方 法 onbars, 这 个 方 法 会 在 推 送 的 每 一 个 bar 执 行 (???) 2 从 一 个 CSV 文 件 载 入 数 据 源 3 在 数 据 源 推 送 的 每 根 bar 上 执 行 策 略 如 果 你 运 行 了 这 个 脚 本, 你 应 该 在 命 令 中 看 到 收 盘 价 : :00:00 strategy [INFO] :00:00 strategy [INFO] :00:00 strategy [INFO] :00:00 strategy [INFO] :00:00 strategy [INFO] :00:00 strategy [INFO] 2906 下 一 步 我 们 实 现 一 个 打 印 SMA 价 格 的 策 略, 用 来 演 示 technicals 是 如 何 被 使 用 的 : from pyalgotrade import strategy from pyalgotradebarfeed import yahoofeed from pyalgotradetechnical import ma 6 Chapter 2 简 明 教 程

11 class MyStrategy(strategyBacktestingStrategy): def init (self, feed, instrument): strategybacktestingstrategy init (self, feed) # We want a 15 period SMA over the closing prices self sma = masma(feed[instrument]getclosedataseries(), 15) self instrument = instrument def onbars(self, bars): bar = bars[self instrument] selfinfo("%s %s" % (bargetclose(), self sma[-1])) # Load the yahoo feed from the CSV file feed = yahoofeedfeed() feedaddbarsfromcsv("orcl", "orcl-2000csv") # Evaluate the strategy with the feed's bars mystrategy = MyStrategy(feed, "orcl") mystrategyrun() 这 跟 之 前 的 例 子 很 相 似, 除 了 : 1 我 们 在 收 盘 价 基 础 上 初 始 化 了 一 个 SMA 过 滤 器 ( 指 标 ) 2 我 们 将 SMA 的 值 随 着 收 盘 价 一 起 打 印 出 来 运 行 该 脚 本 后 将 会 看 到 逐 行 对 应 的 收 盘 价 和 SMA 值, 但 是 实 际 情 况 是 前 14 行 的 SMA 值 是 None 这 是 因 为 我 们 至 少 需 要 15 个 值 才 能 把 SMA 计 算 出 来 : :00:00 strategy [INFO] None :00:00 strategy [INFO] None :00:00 strategy [INFO] 1020 None :00:00 strategy [INFO] 960 None :00:00 strategy [INFO] None :00:00 strategy [INFO] None :00:00 strategy [INFO] None :00:00 strategy [INFO] None :00:00 strategy [INFO] None :00:00 strategy [INFO] None :00:00 strategy [INFO] None :00:00 strategy [INFO] 5713 None :00:00 strategy [INFO] 5925 None :00:00 strategy [INFO] 5969 None :00:00 strategy [INFO] :00:00 strategy [INFO] :00:00 strategy [INFO] :00:00 strategy [INFO] :00:00 strategy [INFO] 若 给 定 的 时 间 不 足 以 计 算, 则 所 有 的 technicals 将 返 回 None 一 件 重 要 的 事 情 是 technicals 可 以 进 行 组 合, 因 为 他 们 作 为 DataSeries 是 模 块 化 的 比 如, 计 算 收 盘 价 的 RSI 再 计 算 RSI 的 SMA 就 很 简 单 : from pyalgotrade import strategy from pyalgotradebarfeed import yahoofeed from pyalgotradetechnical import ma 7

12 from pyalgotradetechnical import rsi class MyStrategy(strategyBacktestingStrategy): def init (self, feed, instrument): strategybacktestingstrategy init (self, feed) self rsi = rsirsi(feed[instrument]getclosedataseries(), 14) self sma = masma(self rsi, 15) self instrument = instrument def onbars(self, bars): bar = bars[self instrument] selfinfo("%s %s %s" % (bargetclose(), self rsi[-1], self sma[-1])) # Load the yahoo feed from the CSV file feed = yahoofeedfeed() feedaddbarsfromcsv("orcl", "orcl-2000csv") # Evaluate the strategy with the feed's bars mystrategy = MyStrategy(feed, "orcl") mystrategyrun() 运 行 该 脚 本, 你 应 该 看 到 在 屏 幕 上 有 一 堆 值 : 前 14 个 RSI 值 是 None 因 为 我 们 至 少 需 要 15 个 值 来 计 算 RSI 前 28 个 SMA 值 是 None 前 14 个 RSI 值 是 None,SMA 过 滤 器 ( 指 标 ) 接 收 的 数 据 从 第 15 个 开 始 才 不 是 None 我 们 计 算 SMA(15) 至 少 需 要 15 个 非 None 值 :00:00 strategy [INFO] None None :00:00 strategy [INFO] None None :00:00 strategy [INFO] 1020 None None :00:00 strategy [INFO] 960 None None :00:00 strategy [INFO] None None :00:00 strategy [INFO] None None :00:00 strategy [INFO] None None :00:00 strategy [INFO] None None :00:00 strategy [INFO] None None :00:00 strategy [INFO] None None :00:00 strategy [INFO] None None :00:00 strategy [INFO] 5713 None None :00:00 strategy [INFO] 5925 None None :00:00 strategy [INFO] 5969 None None :00:00 strategy [INFO] None :00:00 strategy [INFO] None :00:00 strategy [INFO] None :00:00 strategy [INFO] None :00:00 strategy [INFO] None :00:00 strategy [INFO] None :00:00 strategy [INFO] None :00:00 strategy [INFO] None :00:00 strategy [INFO] None :00:00 strategy [INFO] None :00:00 strategy [INFO] None :00:00 strategy [INFO] None :00:00 strategy [INFO] None :00:00 strategy [INFO] None :00:00 strategy [INFO] :00:00 strategy [INFO] Chapter 2 简 明 教 程

13 :00:00 strategy [INFO] :00:00 strategy [INFO] :00:00 strategy [INFO] 交 易 现 在 让 我 们 用 一 个 简 单 的 策 略 模 拟 实 际 的 交 易, 思 路 很 简 单 : 如 果 复 权 价 格 在 SMA(15) 之 上 时, 我 们 买 入 一 个 多 单 ( 我 们 发 出 一 张 买 订 单 ) 如 果 我 们 持 有 一 张 多 单, 当 复 权 价 跌 破 SMA(15) 时, 我 们 平 多 单 ( 我 们 发 出 一 张 卖 单 ) from pyalgotrade import strategy from pyalgotradebarfeed import yahoofeed from pyalgotradetechnical import ma class MyStrategy(strategyBacktestingStrategy): def init (self, feed, instrument, smaperiod): strategybacktestingstrategy init (self, feed, 1000) self position = None self instrument = instrument # We'll use adjusted close values instead of regular close values selfsetuseadjustedvalues(true) self sma = masma(feed[instrument]getpricedataseries(), smaperiod) def onenterok(self, position): execinfo = positiongetentryorder()getexecutioninfo() selfinfo("buy at $%2f" % (execinfogetprice())) def onentercanceled(self, position): self position = None def onexitok(self, position): execinfo = positiongetexitorder()getexecutioninfo() selfinfo("sell at $%2f" % (execinfogetprice())) self position = None def onexitcanceled(self, position): # If the exit was canceled, re-submit it self positionexitmarket() def onbars(self, bars): # Wait for enough bars to be available to calculate a SMA if self sma[-1] is None: return bar = bars[self instrument] # If a position was not opened, check if we should enter a long position if self position is None: if bargetprice() > self sma[-1]: # Enter a buy market order for 10 shares The order is good till canceled self position = selfenterlong(self instrument, 10, True) # Check if we have to exit the position 21 交 易 9

14 elif bargetprice() < self sma[-1] and not self positionexitactive(): self positionexitmarket() def run_strategy(smaperiod): # Load the yahoo feed from the CSV file feed = yahoofeedfeed() feedaddbarsfromcsv("orcl", "orcl-2000csv") # Evaluate the strategy with the feed mystrategy = MyStrategy(feed, "orcl", smaperiod) mystrategyrun() print(("final portfolio value: $%2f" % mystrategygetbroker()getequity())) run_strategy(15) 运 行 该 脚 本, 你 将 看 到 跟 下 面 类 似 的 东 西 : :00:00 strategy [INFO] BUY at $ :00:00 strategy [INFO] SELL at $ :00:00 strategy [INFO] BUY at $ :00:00 strategy [INFO] SELL at $ :00:00 strategy [INFO] BUY at $ :00:00 strategy [INFO] SELL at $ :00:00 strategy [INFO] BUY at $ :00:00 strategy [INFO] SELL at $ :00:00 strategy [INFO] BUY at $ :00:00 strategy [INFO] SELL at $ :00:00 strategy [INFO] BUY at $ :00:00 strategy [INFO] SELL at $ :00:00 strategy [INFO] BUY at $ :00:00 strategy [INFO] SELL at $ :00:00 strategy [INFO] BUY at $ :00:00 strategy [INFO] SELL at $ :00:00 strategy [INFO] BUY at $ :00:00 strategy [INFO] SELL at $ :00:00 strategy [INFO] BUY at $ :00:00 strategy [INFO] SELL at $ :00:00 strategy [INFO] BUY at $ :00:00 strategy [INFO] SELL at $ :00:00 strategy [INFO] BUY at $ :00:00 strategy [INFO] SELL at $ :00:00 strategy [INFO] BUY at $ :00:00 strategy [INFO] SELL at $ :00:00 strategy [INFO] BUY at $ :00:00 strategy [INFO] SELL at $ :00:00 strategy [INFO] BUY at $ :00:00 strategy [INFO] SELL at $ :00:00 strategy [INFO] BUY at $ :00:00 strategy [INFO] SELL at $ :00:00 strategy [INFO] BUY at $ :00:00 strategy [INFO] SELL at $ :00:00 strategy [INFO] BUY at $ :00:00 strategy [INFO] SELL at $ :00:00 strategy [INFO] BUY at $ :00:00 strategy [INFO] SELL at $ :00:00 strategy [INFO] BUY at $ :00:00 strategy [INFO] SELL at $ Chapter 2 简 明 教 程

15 :00:00 strategy [INFO] BUY at $2917 Final portfolio value: $97944 如 果 我 们 用 30 替 代 15 来 作 为 SMA 的 参 数 会 怎 样? 绩 效 会 变 好 还 是 变 坏? 我 们 很 确 定 可 以 通 过 以 下 方 法 来 验 证 : for i in range(10, 30): run_strategy(i) 我 们 会 发 现, 使 用 SMA(20) 后 能 得 到 更 好 的 回 报 : Final portfolio value: $ 我 们 只 是 尝 试 了 一 组 有 限 的 参 数 组, 看 起 来 没 有 什 么 问 题 如 果 我 们 需 要 测 试 一 个 有 多 个 参 数 的 策 略 怎 么 办? 使 用 串 行 计 算 就 不 会 让 策 略 变 得 更 复 杂 22 优 化 了 解 优 化 组 件 后, 优 化 会 变 得 非 常 简 单 : 有 一 个 服 务 负 责 : 提 供 策 略 运 行 所 需 的 bars 提 供 策 略 运 行 所 需 的 参 数 记 录 来 自 每 个 工 作 过 程 的 交 易 记 录 结 果 并 且 有 多 个 工 作 过 程 负 责 : 在 由 服 务 提 供 的 参 数 K 线 基 础 上 运 行 策 略 我 们 使 用 一 个 名 为 RSI2 的 策 略 来 说 明 上 述 架 构 ( 它 需 要 以 下 参 数 : entrysma: 一 个 SMA 趋 势 识 别 的 长 度 参 数 范 围 [150 ~ 250] exitsma: 一 个 较 短 的 SMA 出 场 点 长 度 参 数 范 围 [5~10] rsiperiod: 多 空 入 场 点 参 数 范 围 [2 ~ 10] oversoldthreshold:rsi 多 单 平 仓 点 参 数 范 围 [5 ~ 25] overboughtthreshold:rsi 空 单 平 仓 点 参 数 范 围 [75 ~ 95] 如 果 我 没 算 错 的 话 你 的 意 思 是 数 学 是 体 育 老 师 教 的?? 这 将 有 个 参 数 组 合 我 这 里 测 试 其 中 一 个 参 数 组 的 时 间 大 约 016 秒, 估 计 需 要 85 天 才 能 要 运 行 完 整 个 参 数 组 合 然 后 找 到 最 优 参 数 时 间 太 长 了 如 果 我 能 有 10 台 8 核 的 机 器 同 时 进 行 优 化, 那 么 时 间 将 缩 短 到 25 小 时 长 话 短 说, 我 们 需 要 并 行 计 算 我 们 先 下 载 道 琼 斯 工 业 指 数 3 年 的 日 线 数 据 : python -c "from pyalgotradetools import yahoofinance; yahoofinancedownload_daily_bars('dia', 2009, python -c "from pyalgotradetools import yahoofinance; yahoofinancedownload_daily_bars('dia', 2010, python -c "from pyalgotradetools import yahoofinance; yahoofinancedownload_daily_bars('dia', 2011, 保 存 以 下 代 码 到 rsi2py: 22 优 化 11

16 from pyalgotrade import strategy from pyalgotradetechnical import ma from pyalgotradetechnical import rsi from pyalgotradetechnical import cross class RSI2(strategyBacktestingStrategy): def init (self, feed, instrument, entrysma, exitsma, rsiperiod, overboughtthreshold, oversoldt strategybacktestingstrategy init (self, feed) self instrument = instrument # We'll use adjusted close values, if available, instead of regular close values if feedbarshaveadjclose(): selfsetuseadjustedvalues(true) self priceds = feed[instrument]getpricedataseries() self entrysma = masma(self priceds, entrysma) self exitsma = masma(self priceds, exitsma) self rsi = rsirsi(self priceds, rsiperiod) self overboughtthreshold = overboughtthreshold self oversoldthreshold = oversoldthreshold self longpos = None self shortpos = None def getentrysma(self): return self entrysma def getexitsma(self): return self exitsma def getrsi(self): return self rsi def onentercanceled(self, position): if self longpos == position: self longpos = None elif self shortpos == position: self shortpos = None else: assert(false) def onexitok(self, position): if self longpos == position: self longpos = None elif self shortpos == position: self shortpos = None else: assert(false) def onexitcanceled(self, position): # If the exit was canceled, re-submit it positionexitmarket() def onbars(self, bars): # Wait for enough bars to be available to calculate SMA and RSI if self exitsma[-1] is None or self entrysma[-1] is None or self rsi[-1] is None: return bar = bars[self instrument] if self longpos is not None: 12 Chapter 2 简 明 教 程

17 if selfexitlongsignal(): self longposexitmarket() elif self shortpos is not None: if selfexitshortsignal(): self shortposexitmarket() else: if selfenterlongsignal(bar): shares = int(selfgetbroker()getcash() * 09 / bars[self instrument]getprice()) self longpos = selfenterlong(self instrument, shares, True) elif selfentershortsignal(bar): shares = int(selfgetbroker()getcash() * 09 / bars[self instrument]getprice()) self shortpos = selfentershort(self instrument, shares, True) def enterlongsignal(self, bar): return bargetprice() > self entrysma[-1] and self rsi[-1] <= self oversoldthreshold def exitlongsignal(self): return crosscross_above(self priceds, self exitsma) and not self longposexitactive() def entershortsignal(self, bar): return bargetprice() < self entrysma[-1] and self rsi[-1] >= self overboughtthreshold def exitshortsignal(self): return crosscross_below(self priceds, self exitsma) and not self shortposexitactive() 这 是 服 务 器 脚 本 : import itertools from pyalgotradebarfeed import yahoofeed from pyalgotradeoptimizer import server def parameters_generator(): instrument = ["dia"] entrysma = list(range(150, 251)) exitsma = list(range(5, 16)) rsiperiod = list(range(2, 11)) overboughtthreshold = list(range(75, 96)) oversoldthreshold = list(range(5, 26)) return itertoolsproduct(instrument, entrysma, exitsma, rsiperiod, overboughtthreshold, oversoldt # The if name == ' main ' part is necessary if running on Windows if name == ' main ': # Load the feed from the CSV files feed = yahoofeedfeed() feedaddbarsfromcsv("dia", "dia-2009csv") feedaddbarsfromcsv("dia", "dia-2010csv") feedaddbarsfromcsv("dia", "dia-2011csv") # Run the server serverserve(feed, parameters_generator(), "localhost", 5000) 服 务 器 脚 本 做 了 3 件 事 : 1 声 明 一 个 生 成 器 函 数, 这 个 函 数 可 以 根 据 参 数 范 围 为 策 略 生 成 参 数 组 合 2 从 我 们 下 载 的 CSV 文 件 载 入 数 据 源 3 运 行 服 务 端 并 在 端 口 5000 上 等 待 连 接 22 优 化 13

18 This is the worker script that uses the pyalgotradeoptimizerworker module to run the strategy in parallel with the data supplied by the server: from pyalgotradeoptimizer import worker import rsi2 # The if name == ' main ' part is necessary if running on Windows if name == ' main ': workerrun(rsi2rsi2, "localhost", 5000, workername="localworker") 当 您 运 行 服 务 器 和 客 户 端 时, 您 会 看 到 在 服 务 器 控 制 台 上 看 到 的 类 似 下 面 的 内 容 : :04:01,083 server [INFO] Loading bars :04:01,348 server [INFO] Waiting for workers :04:58,277 server [INFO] Partial result with parameters: ('dia', 150, 5, :04:58,566 server [INFO] Partial result with parameters: ('dia', 150, 5, :05:50,965 server [INFO] Partial result with parameters: ('dia', 150, 5, 3, :05:51,325 server [INFO] Partial result with parameters: ('dia', 150, 5, 3 在 客 户 机 控 制 台 可 以 看 到 下 面 的 内 容 : :02:25,360 localworker [INFO] Running strategy with parameters ('dia', 150, 5, 2, 84, :02:25,377 localworker [INFO] Running strategy with parameters ('dia', 150, 5, 2, 94, 5) :02:25,661 localworker [INFO] Result :02:25,661 localworker [INFO] Result :02:25,662 localworker [INFO] Running strategy with parameters ('dia', 150, 5, 2, 93, :02:25,665 localworker [INFO] Running strategy with parameters ('dia', 150, 5, 2, 84, :02:25,995 localworker [INFO] Result :02:25,996 localworker [INFO] Running strategy with parameters ('dia', 150, 5, 2, 93, :02:26,006 localworker [INFO] Result :02:26,007 localworker [INFO] Running strategy with parameters ('dia', 150, 5, 2, 84, :02:26,256 localworker [INFO] Result :02:26,257 localworker [INFO] Running strategy with parameters ('dia', 150, 5, 2, 84, :02:26,280 localworker [INFO] Result 注 意!! 你 只 能 运 行 一 个 服 务 器 和 一 个 或 者 多 个 客 户 机 译 者 补 充 : 这 里 说 的 是 同 一 个 优 化 项 目 下 只 能 运 行 一 个 服 务 器 如 果 你 只 想 在 自 己 的 电 脑 上 对 策 略 并 行 计 算, 你 可 以 利 用 pyalgotradeoptimizerlocal 模 块 来 实 现 : import itertools from pyalgotradeoptimizer import local from pyalgotradebarfeed import yahoofeed import rsi2 def parameters_generator(): instrument = ["dia"] entrysma = list(range(150, 251)) exitsma = list(range(5, 16)) rsiperiod = list(range(2, 11)) overboughtthreshold = list(range(75, 96)) oversoldthreshold = list(range(5, 26)) return itertoolsproduct(instrument, entrysma, exitsma, rsiperiod, overboughtthreshold, oversoldt 14 Chapter 2 简 明 教 程

19 # The if name == ' main ' part is necessary if running on Windows if name == ' main ': # Load the feed from the CSV files feed = yahoofeedfeed() feedaddbarsfromcsv("dia", "dia-2009csv") feedaddbarsfromcsv("dia", "dia-2010csv") feedaddbarsfromcsv("dia", "dia-2011csv") localrun(rsi2rsi2, feed, parameters_generator()) 上 述 代 码 做 了 3 件 事 : 1 声 明 一 个 生 成 器 函 数, 这 个 函 数 可 以 根 据 参 数 范 围 为 策 略 生 成 参 数 组 合 2 从 我 们 下 载 的 CSV 文 件 载 入 数 据 源 3 通 过 pyalgotradeoptimizerlocal 模 块 运 行 策 略 并 寻 优 当 你 执 行 这 段 代 码 后, 你 可 以 看 到 类 似 下 面 的 结 果 : :08:06,587 server [INFO] Loading bars :08:06,910 server [INFO] Waiting for workers :08:58,347 server [INFO] Partial result with parameters: ('dia', 150, 5, :08:58,967 server [INFO] Partial result with parameters: ('dia', 150, 5, :09:52,097 server [INFO] Partial result with parameters: ('dia', 150, 5, 3, :09:52,921 server [INFO] Partial result with parameters: ('dia', 150, 5, :10:40,826 server [INFO] Partial result with parameters: ('dia', 150, 5, :10:41,318 server [INFO] Partial result with parameters: ('dia', 150, 5, 4 在 记 录 中, 最 优 结 果 为 $231440, 它 的 参 数 组 是 : 1 entrysma: exitsma: 5 3 rsiperiod: 2 4 overboughtthreshold: 91 5 oversoldthreshold: 绘 图 PyAlgoTrade 可 以 很 容 易 的 对 策 略 运 行 进 行 绘 图 保 存 为 sma_crossoverpy: from pyalgotrade import strategy from pyalgotradetechnical import ma from pyalgotradetechnical import cross class SMACrossOver(strategyBacktestingStrategy): def init (self, feed, instrument, smaperiod): strategybacktestingstrategy init (self, feed) self instrument = instrument self position = None # We'll use adjusted close values instead of regular close values 23 绘 图 15

20 selfsetuseadjustedvalues(true) self prices = feed[instrument]getpricedataseries() self sma = masma(self prices, smaperiod) def getsma(self): return self sma def onentercanceled(self, position): self position = None def onexitok(self, position): self position = None def onexitcanceled(self, position): # If the exit was canceled, re-submit it self positionexitmarket() def onbars(self, bars): # If a position was not opened, check if we should enter a long position if self position is None: if crosscross_above(self prices, self sma) > 0: shares = int(selfgetbroker()getcash() * 09 / bars[self instrument]getprice()) # Enter a buy market order The order is good till canceled self position = selfenterlong(self instrument, shares, True) # Check if we have to exit the position elif not self positionexitactive() and crosscross_below(self prices, self sma) > 0: self positionexitmarket() 保 存 这 段 代 码 到 另 外 一 个 文 件 : from pyalgotrade import plotter from pyalgotradebarfeed import yahoofeed from pyalgotradestratanalyzer import returns import sma_crossover # Load the yahoo feed from the CSV file feed = yahoofeedfeed() feedaddbarsfromcsv("orcl", "orcl-2000csv") # Evaluate the strategy with the feed's bars mystrategy = sma_crossoversmacrossover(feed, "orcl", 20) # Attach a returns analyzers to the strategy returnsanalyzer = returnsreturns() mystrategyattachanalyzer(returnsanalyzer) # Attach the plotter to the strategy plt = plotterstrategyplotter(mystrategy) # Include the SMA in the instrument's subplot to get it displayed along with the closing prices pltgetinstrumentsubplot("orcl")adddataseries("sma", mystrategygetsma()) # Plot the simple returns on each bar pltgetorcreatesubplot("returns")adddataseries("simple returns", returnsanalyzergetreturns()) # Run the strategy mystrategyrun() mystrategyinfo("final portfolio value: $%2f" % mystrategygetresult()) # Plot the strategy 16 Chapter 2 简 明 教 程

21 pltplot() 上 述 代 码 做 了 3 件 事 : 1 从 一 个 CSV 文 件 中 加 载 数 据 源 2 通 过 数 据 源 提 供 的 bar 逐 根 运 行 策 略 ; 提 供 一 个 策 略 绘 图 程 序 3 绘 制 策 略 图 形 图 形 如 下 : 我 希 望 你 能 喜 欢 这 份 简 明 教 程 同 时 提 醒 你 下 载 地 址 在 这 里 : 开 始 编 写 你 自 己 的 策 略 吧! 你 可 以 在 策 略 例 子 找 到 更 多 的 例 子 23 绘 图 17

22 18 Chapter 2 简 明 教 程

23 CHAPTER 3 代 码 的 文 档 说 明 目 录 : 31 bar 品 种 的 价 格 32 dataseries 数 据 序 列 基 类 数 据 序 列 是 管 理 time-series 数 据 的 抽 象 类 33 feed 数 据 源 基 类 Feeds 是 将 时 间 序 列 抽 象 化 当 这 些 在 事 件 调 度 循 环 时, 会 推 送 一 个 新 的 可 用 数 据 When these are included in the event dispatch loop, they emit an event as new data is available Feeds are also responsible for updating the pyalgotradedataseriesdataseries associated with each piece of data that the feed provides 当 前 位 置 是 关 于 数 据 源 基 类 的, 要 了 解 bar 的 数 据 源 请 查 阅 : barfeed Bar 数 据 来 源 板 块 331 CSV 支 持 332 CSV 支 持 的 例 子 一 个 带 有 以 下 格 式 的 文 件 Date,USD,GBP,EUR ,13330,831203, ,134925,842755, ,13185,831546, ,13870,886885, 像 这 样 引 入 并 使 用 : 19

24 from pyalgotradefeed import csvfeed feed = csvfeedfeed("date", "%Y-%m-%d") feedaddvaluesfromcsv("quandl_gold_2csv") for datetime, value in feed: print(datetime, value) 输 出 结 果 如 下 : :00:00 {'USD': 370, 'GBP': , 'EUR': ''} :00:00 {'USD': 380, 'GBP': , 'EUR': ''} :00:00 {'USD': 3765, 'GBP': , 'EUR': ''} :00:00 {'USD': 3865, 'GBP': , 'EUR': ''} :00:00 {'USD': 391, 'GBP': , 'EUR': ''} :00:00 {'USD': 396, 'GBP': , 'EUR': ''} :00:00 {'USD': 415, 'GBP': , 'EUR': ''} :00:00 {'USD': 4175, 'GBP': , 'EUR': ''} :00:00 {'USD': 4195, 'GBP': 176, 'EUR': ''} :00:00 {'USD': 4125, 'GBP': , 'EUR': ''} :00:00 {'USD': 13310, 'GBP': 86423, 'EUR': } :00:00 {'USD': , 'GBP': , 'EUR': } :00:00 {'USD': 13090, 'GBP': , 'EUR': 97979} :00:00 {'USD': , 'GBP': , 'EUR': } :00:00 {'USD': 13775, 'GBP': , 'EUR': 10306} :00:00 {'USD': , 'GBP': , 'EUR': } :00:00 {'USD': 13870, 'GBP': , 'EUR': } :00:00 {'USD': 13185, 'GBP': , 'EUR': } :00:00 {'USD': , 'GBP': , 'EUR': } :00:00 {'USD': 13330, 'GBP': , 'EUR': 98675} 34 barfeed Bar 数 据 来 源 341 CSV 342 Yahoo! Finance 343 Google Finance 344 Quandl 345 Ninja Trader 35 technical 技 术 指 标 351 例 子 下 面 的 这 个 例 子 演 示 了 如 何 结 合 EventWindow 和 EventBasedFilter 来 计 算 一 个 指 标 : 20 Chapter 3 代 码 的 文 档 说 明

25 from pyalgotrade import dataseries from pyalgotrade import technical # An EventWindow is responsible for making calculations using a window of values class Accumulator(technicalEventWindow): def getvalue(self): ret = None if selfwindowfull(): ret = selfgetvalues()sum() return ret # Build a sequence based DataSeries seqds = dataseriessequencedataseries() # Wrap it with a filter that will get fed as new values get added to the underlying DataSeries accum = technicaleventbasedfilter(seqds, Accumulator(3)) # Put in some values for i in range(0, 50): seqdsappend(i) # Get some values print(accum[0]) # Not enough values yet print(accum[1]) # Not enough values yet print(accum[2]) # Ok, now we should have at least 3 values print(accum[3]) # Get the last value, which should be equal to print(accum[-1]) 输 出 内 容 如 下 : None None 移 动 平 均 线 353 动 量 指 标 354 其 他 指 标 36 broker 订 单 管 理 类 361 基 类 和 模 块 362 回 测 模 块 和 类 37 strategy 策 略 基 类 Strategies 类 是 你 定 义 的 何 时 买 何 时 卖 等 等 交 易 逻 辑 的 类 36 broker 订 单 管 理 类 21

26 做 多 和 做 空 可 以 通 过 以 下 两 种 方 式 : 使 用 下 面 任 意 一 个 方 法 下 单 : pyalgotradestrategybasestrategymarketorder() pyalgotradestrategybasestrategylimitorder() pyalgotradestrategybasestrategystoporder() pyalgotradestrategybasestrategystoplimitorder() 使 用 封 装 了 买 / 卖 的 高 级 接 口 下 单 : pyalgotradestrategybasestrategyenterlong() pyalgotradestrategybasestrategyentershort() pyalgotradestrategybasestrategyenterlonglimit() pyalgotradestrategybasestrategyentershortlimit() Positions are higher level abstractions for placing orders They are escentially a pair of entry-exit orders and provide easier tracking for returns and PnL than using individual orders 371 Strategy 372 Position 38 stratanalyzer Strategy analyzers Strategy analyzers provide an extensible way to attach different calculations to strategy executions class pyalgotradestratanalyzerstrategyanalyzer 基 类 :object Base class for strategy analyzers 注 解 : This is a base class and should not be used directly 381 Returns 382 Sharpe Ratio 383 DrawDown class pyalgotradestratanalyzerdrawdowndrawdown 基 类 :pyalgotradestratanalyzerstrategyanalyzer A pyalgotradestratanalyzerstrategyanalyzer that calculates max drawdown and longest drawdown duration for the portfolio getlongestdrawdownduration() Returns the duration of the longest drawdown 返 回 类 型 datetimetimedelta 22 Chapter 3 代 码 的 文 档 说 明

27 注 解 : Note that this is the duration of the longest drawdown, not necessarily the deepest one getmaxdrawdown() Returns the max (deepest) drawdown 384 Trades 385 Example Save this code as sma_crossoverpy: from pyalgotrade import strategy from pyalgotradetechnical import ma from pyalgotradetechnical import cross class SMACrossOver(strategyBacktestingStrategy): def init (self, feed, instrument, smaperiod): strategybacktestingstrategy init (self, feed) self instrument = instrument self position = None # We'll use adjusted close values instead of regular close values selfsetuseadjustedvalues(true) self prices = feed[instrument]getpricedataseries() self sma = masma(self prices, smaperiod) def getsma(self): return self sma def onentercanceled(self, position): self position = None def onexitok(self, position): self position = None def onexitcanceled(self, position): # If the exit was canceled, re-submit it self positionexitmarket() def onbars(self, bars): # If a position was not opened, check if we should enter a long position if self position is None: if crosscross_above(self prices, self sma) > 0: shares = int(selfgetbroker()getcash() * 09 / bars[self instrument]getprice()) # Enter a buy market order The order is good till canceled self position = selfenterlong(self instrument, shares, True) # Check if we have to exit the position elif not self positionexitactive() and crosscross_below(self prices, self sma) > 0: self positionexitmarket() and save this code in a different file: from pyalgotradebarfeed import yahoofeed from pyalgotradestratanalyzer import returns from pyalgotradestratanalyzer import sharpe 38 stratanalyzer Strategy analyzers 23

28 from pyalgotradestratanalyzer import drawdown from pyalgotradestratanalyzer import trades import sma_crossover # Load the yahoo feed from the CSV file feed = yahoofeedfeed() feedaddbarsfromcsv("orcl", "orcl-2000csv") # Evaluate the strategy with the feed's bars mystrategy = sma_crossoversmacrossover(feed, "orcl", 20) # Attach different analyzers to a strategy before executing it retanalyzer = returnsreturns() mystrategyattachanalyzer(retanalyzer) sharperatioanalyzer = sharpesharperatio() mystrategyattachanalyzer(sharperatioanalyzer) drawdownanalyzer = drawdowndrawdown() mystrategyattachanalyzer(drawdownanalyzer) tradesanalyzer = tradestrades() mystrategyattachanalyzer(tradesanalyzer) # Run the strategy mystrategyrun() print("final portfolio value: $%2f" % mystrategygetresult()) print("cumulative returns: %2f %%" % (retanalyzergetcumulativereturns()[-1] * 100)) print("sharpe ratio: %2f" % (sharperatioanalyzergetsharperatio(005))) print("max drawdown: %2f %%" % (drawdownanalyzergetmaxdrawdown() * 100)) print("longest drawdown duration: %s" % (drawdownanalyzergetlongestdrawdownduration())) print() print("total trades: %d" % (tradesanalyzergetcount())) if tradesanalyzergetcount() > 0: profits = tradesanalyzergetall() print("avg profit: $%2f" % (profitsmean())) print("profits std dev: $%2f" % (profitsstd())) print("max profit: $%2f" % (profitsmax())) print("min profit: $%2f" % (profitsmin())) returns = tradesanalyzergetallreturns() print("avg return: %2f %%" % (returnsmean() * 100)) print("returns std dev: %2f %%" % (returnsstd() * 100)) print("max return: %2f %%" % (returnsmax() * 100)) print("min return: %2f %%" % (returnsmin() * 100)) print() print("profitable trades: %d" % (tradesanalyzergetprofitablecount())) if tradesanalyzergetprofitablecount() > 0: profits = tradesanalyzergetprofits() print("avg profit: $%2f" % (profitsmean())) print("profits std dev: $%2f" % (profitsstd())) print("max profit: $%2f" % (profitsmax())) print("min profit: $%2f" % (profitsmin())) returns = tradesanalyzergetpositivereturns() print("avg return: %2f %%" % (returnsmean() * 100)) print("returns std dev: %2f %%" % (returnsstd() * 100)) print("max return: %2f %%" % (returnsmax() * 100)) print("min return: %2f %%" % (returnsmin() * 100)) 24 Chapter 3 代 码 的 文 档 说 明

29 print() print("unprofitable trades: %d" % (tradesanalyzergetunprofitablecount())) if tradesanalyzergetunprofitablecount() > 0: losses = tradesanalyzergetlosses() print("avg loss: $%2f" % (lossesmean())) print("losses std dev: $%2f" % (lossesstd())) print("max loss: $%2f" % (lossesmin())) print("min loss: $%2f" % (lossesmax())) returns = tradesanalyzergetnegativereturns() print("avg return: %2f %%" % (returnsmean() * 100)) print("returns std dev: %2f %%" % (returnsstd() * 100)) print("max return: %2f %%" % (returnsmax() * 100)) print("min return: %2f %%" % (returnsmin() * 100)) The output should look like this: Final portfolio value: $ Cumulative returns: 2959 % Sharpe ratio: 070 Max drawdown: 2453 % Longest drawdown duration: 277 days, 0:00:00 Total trades: 13 Avg profit: $14437 Profits std dev: $ Max profit: $ Min profit: $ Avg return: 2 % Returns std dev: 13 % Max return: 46 % Min return: -7 % Profitable trades: 3 Avg profit: $ Profits std dev: $ Max profit: $ Min profit: $66537 Avg return: 21 % Returns std dev: 18 % Max return: 46 % Min return: 6 % Unprofitable trades: 10 Avg loss: $ Losses std dev: $23601 Max loss: $ Min loss: $-4516 Avg return: -3 % Returns std dev: 2 % Max return: -0 % Min return: -7 % 38 stratanalyzer Strategy analyzers 25

30 39 plotter Strategy plotter 310 optimizer Parallel optimizers 注 解 : The server component will split strategy executions in chunks which are distributed among the different workers pyalgotradeoptimizerserverserverdefaultbatchsize controls the chunk size The pyalgotradestrategybasestrategygetresult() method is used to select the best strategy execution You can override that method to rank executions using a different criteria 311 marketsession Market sessions class pyalgotrademarketsessionmarketsession 基 类 :object Base class for market sessions 注 解 : This is a base class and should not be used directly classmethod gettimezone() Returns the pytz timezone for the market session class pyalgotrademarketsessionnasdaq 基 类 :pyalgotrademarketsessionmarketsession NASDAQ market session class pyalgotrademarketsessionnyse 基 类 :pyalgotrademarketsessionmarketsession New York Stock Exchange market session class pyalgotrademarketsessionusequities 基 类 :pyalgotrademarketsessionmarketsession US Equities market session class pyalgotrademarketsessionmerval 基 类 :pyalgotrademarketsessionmarketsession Buenos Aires (Argentina) market session class pyalgotrademarketsessionbovespa 基 类 :pyalgotrademarketsessionmarketsession BOVESPA (Brazil) market session class pyalgotrademarketsessionftse 基 类 :pyalgotrademarketsessionmarketsession London Stock Exchange market session 26 Chapter 3 代 码 的 文 档 说 明

31 class pyalgotrademarketsessiontse 基 类 :pyalgotrademarketsessionmarketsession Tokyo Stock Exchange market session 311 marketsession Market sessions 27

32 28 Chapter 3 代 码 的 文 档 说 明

33 CHAPTER 4 工 具 41 Yahoo! Finance 42 Quandl 43 BarFeed resampling 29

34 30 Chapter 4 工 具

35 CHAPTER 5 Event profiler Inspired in QSTK ( the eventprofiler module is a tool to analyze, statistically, how events affect future equity prices The event profiler scans over historical data for a specified event and then calculates the impact of that event on the equity prices in the past and the future over a certain lookback period The goal of this tool is to help you quickly validate an idea, before moving forward with the backtesting process 51 Example The following example is inspired on the Buy-on-Gap Model from Ernie Chan s book: Algorithmic Trading: Winning Strategies and Their Rationale : The idea is to select a stock near the market open whose returns from their previous day s lows to today s open are lower that one standard deviation The standard deviation is computed using the daily close-to-close returns of the last 90 days These are the stocks that gapped down This is narrowed down by requiring the open price to be higher than the 20-day moving average of the closing price from pyalgotrade import eventprofiler from pyalgotradetechnical import stats from pyalgotradetechnical import roc from pyalgotradetechnical import ma from pyalgotradetools import yahoofinance # Event inspired on an example from Ernie Chan's book: # 'Algorithmic Trading: Winning Strategies and Their Rationale' class BuyOnGap(eventprofilerPredicate): def init (self, feed): stddevperiod = 90 smaperiod = 20 self returns = {} self stddev = {} self ma = {} for instrument in feedgetregisteredinstruments(): priceds = feed[instrument]getadjclosedataseries() # Returns over the adjusted close values self returns[instrument] = rocrateofchange(priceds, 1) # StdDev over those returns 31

36 self stddev[instrument] = statsstddev(self returns[instrument], stddevperiod) # MA over the adjusted close values self ma[instrument] = masma(priceds, smaperiod) def gappeddown(self, instrument, bards): ret = False if self stddev[instrument][-1] is not None: prevbar = bards[-2] currbar = bards[-1] low2openret = (currbargetopen(true) - prevbargetlow(true)) / float(prevbargetlow(true) if low2openret < (self returns[instrument][-1] - self stddev[instrument][-1]): ret = True return ret def abovesma(self, instrument, bards): ret = False if self ma[instrument][-1] is not None and bards[-1]getopen(true) > self ma[instrument][ ret = True return ret def eventoccurred(self, instrument, bards): ret = False if self gappeddown(instrument, bards) and self abovesma(instrument, bards): ret = True return ret def main(plot): instruments = ["AA", "AES", "AIG"] feed = yahoofinancebuild_feed(instruments, 2008, 2009, "") predicate = BuyOnGap(feed) eventprofiler = eventprofilerprofiler(predicate, 5, 5) eventprofilerrun(feed, True) results = eventprofilergetresults() print("%d events found" % (resultsgeteventcount())) if plot: eventprofilerplot(results) if name == " main ": main(true) The code is doing 4 things: 1 Declaring a Predicate that implements the Buy-on-Gap Model event identification 2 Loading bars for some stocks 3 Running the analysis 4 Plotting the results This is what the output should look like: 32 Chapter 5 Event profiler

37 :30:45,340 yahoofinance [INFO] Creating data directory :30:45,341 yahoofinance [INFO] Downloading AA 2008 to data/aa-2008-yahoofinancecsv :30:46,092 yahoofinance [INFO] Downloading AES 2008 to data/aes-2008-yahoofinancecsv :30:46,683 yahoofinance [INFO] Downloading AIG 2008 to data/aig-2008-yahoofinancecsv :30:47,260 yahoofinance [INFO] Downloading AA 2009 to data/aa-2009-yahoofinancecsv :30:48,019 yahoofinance [INFO] Downloading AES 2009 to data/aes-2009-yahoofinancecsv :30:48,761 yahoofinance [INFO] Downloading AIG 2009 to data/aig-2009-yahoofinancecsv 14 events found Note that Cummulative returns are normalized to the time of the event 51 Example 33

38 34 Chapter 5 Event profiler

39 CHAPTER 6 Xignite support The xignite package adds support for paper trading strategies using Xignite s live feeds via the XigniteGlobalRealTime API ( in conjunction with PyAlgoTrade backtesting capabilities Contents: 61 xignite Xignite reference 611 Feeds 62 Xignite Example This goal of this example is to show how to put all the pieces together to paper trade a strategy using realtime feeds supplied by Xignite ( This example assumes that you re already familiar with the basic concepts presented in the 简 明 教 程 section The key things to highlight are: 1 We re using pyalgotradestrategybasestrategy instead of pyalgotradestrategybacktestingstrategy as the base class This is not a backtest 2 pyalgotradexignitebarfeedlivefeed is used to pull 5 minute bars directly from Xignite In order to use this service you need to sign up for the XigniteGlobalRealTime API ( to get an API token 3 As described in indentifiers are fully qualified identifiers for the security as determined by the IdentifierType parameter You must include the exchange suffix 4 You can only paper trade while the market is open 5 The 5 minute bars are requested 60 seconds after the 5 minute window closes because data may not be immediately available from pyalgotrade import strategy from pyalgotradebar import Frequency from pyalgotradexignite import barfeed from pyalgotradebroker import backtesting from pyalgotradetechnical import ma 35

40 class Strategy(strategyBaseStrategy): def init (self, feed, brk): strategybasestrategy init (self, feed, brk) self sma = {} for instrument in feedgetregisteredinstruments(): self sma[instrument] = masma(feed[instrument]getclosedataseries(), 5) def onbars(self, bars): for instrument in barsgetinstruments(): bar = bars[instrument] selfinfo("%s: Open: %s High: %s Low: %s Close: %s Volume: %s SMA: %s" % (instrument, bar def main(): # Replace apitoken with your own API token apitoken = "<YOUR API TOKEN HERE>" # indentifiers are fully qualified identifiers for the security and must include the exchange suf indentifiers = ["RIOlCHIX", "HSBAlCHIX"] # apicalldelay is necessary because the bar may not be immediately available apicalldelay = 60 feed = barfeedlivefeed(apitoken, indentifiers, FrequencyMINUTE*5, apicalldelay) brk = backtestingbroker(1000, feed) mystrategy = Strategy(feed, brk) mystrategyrun() if name == " main ": main() The output should look like this: :31:01,389 strategy [INFO] HSBAlCHIX: Open: 6093 High: 6102 Low: 6093 Close: 6101 V :31:01,390 strategy [INFO] RIOlCHIX: Open: 3308 High: 3308 Low: Close: 3307 V :36:01,494 strategy [INFO] HSBAlCHIX: Open: 6102 High: 6102 Low: 6099 Close: 6099 V :36:01,495 strategy [INFO] RIOlCHIX: Open: High: 3309 Low: Close: :41:01,885 strategy [INFO] HSBAlCHIX: Open: 6101 High: 6101 Low: 6097 Close: 6097 V :41:01,886 strategy [INFO] RIOlCHIX: Open: 3304 High: 3304 Low: Close: :46:00,943 strategy [INFO] HSBAlCHIX: Open: 6098 High: 6098 Low: 6093 Close: 6094 V :46:00,943 strategy [INFO] RIOlCHIX: Open: High: Low: Close: :51:01,604 strategy [INFO] HSBAlCHIX: Open: 6093 High: 6099 Low: 6092 Close: 6097 V :51:01,604 strategy [INFO] RIOlCHIX: Open: 3299 High: Low: Close: :56:01,511 strategy [INFO] HSBAlCHIX: Open: 6099 High: 61 Low: 6096 Close: 6098 Vol :56:01,511 strategy [INFO] RIOlCHIX: Open: 3298 High: 3301 Low: 3296 Close: 3301 Vo When apicalldelay is not long enough, or when there is no data at all, you may receive the following error message: xignite [ERROR] No ticks available for Symbol:RIOlCHIX from 3/28/2014 1:10:00 PM to 3/28/2014 1:11:0 36 Chapter 6 Xignite support

41 CHAPTER 7 Bitcoin Contents: 71 Bitstamp support The bitstamp package adds support for paper trading strategies using Bitstamp s live trade and orderbook feeds ( in conjunction with PyAlgoTrade backtesting capabilities Future versions will support real trading Bitstamp support depends on ws4py ( and tornado ( so be sure to have those installed before moving forward Contents: 711 bitstamp Bitstamp reference WebSocket This package has classes for the events emitted by Bitstamp s streaming service Check for more information Feeds Brokers 712 Bitstamp Example This goal of this simple SMA crossover example is to show how to put all the pieces together to paper trade a strategy using realtime feeds supplied by Bitstamp ( This example assumes that you re already familiar with the basic concepts presented in the 简 明 教 程 section The key things to highlight are: 1 We re using pyalgotradestrategybasestrategy instead of pyalgotradestrategybacktestingstrategy as the base class This is not a backtest 2 Trade events get notified via the call to onbars No need to manually subscribe 37

42 3 Order book update events are handled by manually subscribing to pyalgotradebitstampbarfeedlivetradefeedgetorderbookupdateevent This is needed to be up to date with latest bid and ask prices from pyalgotradebitstamp import barfeed from pyalgotradebitstamp import broker from pyalgotrade import strategy from pyalgotradetechnical import ma from pyalgotradetechnical import cross class Strategy(strategyBaseStrategy): def init (self, feed, brk): strategybasestrategy init (self, feed, brk) smaperiod = 20 self instrument = "BTC" self prices = feed[self instrument]getclosedataseries() self sma = masma(self prices, smaperiod) self bid = None self ask = None self position = None self possize = 005 # Subscribe to order book update events to get bid/ask prices to trade feedgetorderbookupdateevent()subscribe(self onorderbookupdate) def onorderbookupdate(self, orderbookupdate): bid = orderbookupdategetbidprices()[0] ask = orderbookupdategetaskprices()[0] if bid!= self bid or ask!= self ask: self bid = bid self ask = ask selfinfo("order book updated Best bid: %s Best ask: %s" % (self bid, self ask)) def onenterok(self, position): selfinfo("position opened at %s" % (positiongetentryorder()getexecutioninfo()getprice())) def onentercanceled(self, position): selfinfo("position entry canceled") self position = None def onexitok(self, position): self position = None selfinfo("position closed at %s" % (positiongetexitorder()getexecutioninfo()getprice())) def onexitcanceled(self, position): # If the exit was canceled, re-submit it self positionexitlimit(self bid) def onbars(self, bars): bar = bars[self instrument] selfinfo("price: %s Volume: %s" % (bargetclose(), bargetvolume())) # Wait until we get the current bid/ask prices if self ask is None: return # If a position was not opened, check if we should enter a long position 38 Chapter 7 Bitcoin

43 if self position is None: if crosscross_above(self prices, self sma) > 0: selfinfo("entry signal Buy at %s" % (self ask)) self position = selfenterlonglimit(self instrument, self ask, self possize, # Check if we have to close the position elif not self positionexitactive() and crosscross_below(self prices, self sma) > 0: selfinfo("exit signal Sell at %s" % (self bid)) self positionexitlimit(self bid) def main(): barfeed = barfeedlivetradefeed() brk = brokerpapertradingbroker(1000, barfeed) strat = Strategy(barFeed, brk) stratrun() if name == " main ": main() The output should look like this: :35:59,085 bitstamp [INFO] Initializing websocket client :35:59,452 bitstamp [INFO] Connection established :35:59,453 bitstamp [INFO] Initialization ok :36:30,726 strategy [INFO] Order book updated Best bid: 6296 Best ask: :39:04,829 strategy [INFO] Order book updated Best bid: Best ask: :44:18,845 strategy [INFO] Price: 6300 Volume: :44:18,894 strategy [INFO] Order book updated Best bid: 6300 Best ask: :44:29,719 strategy [INFO] Price: 6300 Volume: :44:59,861 strategy [INFO] Price: Volume: :45:37,425 strategy [INFO] Order book updated Best bid: 6300 Best ask: :45:39,848 strategy [INFO] Price: 6316 Volume: :45:39,918 strategy [INFO] Price: Volume: :45:39,971 strategy [INFO] Price: Volume: :45:40,057 strategy [INFO] Price: Volume: :45:40,104 strategy [INFO] Price: Volume: :45:40,205 strategy [INFO] Order book updated Best bid: 6300 Best ask: :48:30,005 strategy [INFO] Price: 6300 Volume: :48:30,039 strategy [INFO] Price: 6296 Volume: :48:30,121 strategy [INFO] Price: Volume: :48:33,053 strategy [INFO] Price: Volume: :48:33,164 strategy [INFO] Price: Volume: :48:33,588 strategy [INFO] Price: Volume: :48:33,635 strategy [INFO] Order book updated Best bid: Best ask: :48:33,727 strategy [INFO] Price: Volume: :48:34,261 strategy [INFO] Price: Volume: :48:34,908 strategy [INFO] Order book updated Best bid: Best ask: :48:36,203 strategy [INFO] Order book updated Best bid: Best ask: :49:01,945 strategy [INFO] Order book updated Best bid: Best ask: :49:34,743 strategy [INFO] Order book updated Best bid: Best ask: :49:57,651 strategy [INFO] Price: Volume: Bitstamp support 39

44 :49:57,651 strategy [INFO] Entry signal Buy at :50:09,934 strategy [INFO] Order book updated Best bid: Best ask: :50:20,786 strategy [INFO] Order book updated Best bid: Best ask: :50:25,658 strategy [INFO] Price: Volume: :50:25,732 strategy [INFO] Price: Volume: :50:25,791 strategy [INFO] Price: Volume: :50:25,847 strategy [INFO] Price: Volume: :50:25,900 strategy [INFO] Price: Volume: :50:25,952 strategy [INFO] Price: Volume: :50:26,000 strategy [INFO] Price: Volume: :50:26,065 strategy [INFO] Price: Volume: :50:26,139 strategy [INFO] Price: Volume: :50:26,300 strategy [INFO] Order book updated Best bid: Best ask: :50:26,398 strategy [INFO] Price: 6331 Volume: :50:29,850 strategy [INFO] Position opened at :50:29,850 strategy [INFO] Price: 6290 Volume: :50:29,850 strategy [INFO] Exit signal Sell at :50:37,294 strategy [INFO] Order book updated Best bid: Best ask: :50:43,526 strategy [INFO] Order book updated Best bid: Best ask: :51:07,604 strategy [INFO] Order book updated Best bid: Best ask: :51:46,194 strategy [INFO] Order book updated Best bid: Best ask: :52:08,223 strategy [INFO] Position closed at :52:08,223 strategy [INFO] Price: Volume: :52:08,290 strategy [INFO] Price: Volume: :52:08,530 strategy [INFO] Order book updated Best bid: Best ask: :52:35,347 strategy [INFO] Price: Volume: :52:35,347 strategy [INFO] Entry signal Buy at :52:35,348 strategy [INFO] Price: Volume: :52:35,428 strategy [INFO] Price: 6310 Volume: :54:14,077 strategy [INFO] Order book updated Best bid: Best ask: :54:21,084 strategy [INFO] Order book updated Best bid: 6310 Best ask: :54:34,484 strategy [INFO] Price: 6324 Volume: :54:34,484 strategy [INFO] Exit signal Sell at :54:34,484 strategy [INFO] Position entry canceled :54:34,578 strategy [INFO] Price: Volume: :54:34,642 strategy [INFO] Price: Volume: :54:34,708 strategy [INFO] Price: Volume: :54:34,789 strategy [INFO] Price: Volume: :54:34,885 strategy [INFO] Price: Volume: :54:34,949 strategy [INFO] Price: Volume: :54:35,029 strategy [INFO] Price: Volume: :54:35,165 strategy [INFO] Price: Volume: :54:35,165 strategy [INFO] Entry signal Buy at :54:35,286 strategy [INFO] Price: 6330 Volume: :54:35,357 strategy [INFO] Price: 6331 Volume: :56:48,885 strategy [INFO] Order book updated Best bid: 6321 Best ask: :56:57,234 strategy [INFO] Position opened at :56:57,235 strategy [INFO] Price: 6321 Volume: :56:57,235 strategy [INFO] Exit signal Sell at :56:57,268 strategy [INFO] Price: Volume: :56:57,356 strategy [INFO] Order book updated Best bid: Best ask: :57:03,528 strategy [INFO] Price: Volume: Chapter 7 Bitcoin

45 :57:03,604 strategy [INFO] Order book updated Best bid: 6310 Best ask: :57:04,824 strategy [INFO] Order book updated Best bid: 6310 Best ask: :57:09,775 strategy [INFO] Order book updated Best bid: 6310 Best ask: :57:11,112 strategy [INFO] Order book updated Best bid: 6321 Best ask: :57:15,822 strategy [INFO] Position closed at :57:15,822 strategy [INFO] Price: 6321 Volume: :57:20,839 strategy [INFO] Price: 6321 Volume: :57:22,065 strategy [INFO] Price: 6312 Volume: :57:22,122 strategy [INFO] Price: Volume: :57:22,122 strategy [INFO] Entry signal Buy at :57:22,184 strategy [INFO] Price: Volume: In order to live trade this strategy you should use pyalgotradebitstampbrokerlivebroker instead of pyalgotradebitstampbrokerpapertradingbroker Note that if you try to live trade this strategy you will probably loose money Before jumping to live trading, be sure to write your own strategy, backtest and paper trade it thoroughly before risking real money 72 Bitcoin Charts support The bitcoincharts package adds support for integrating with historical trade data supplied by for backtesting Bitcoin strategies Historical trade data in CSV format is described in and files can be downloaded from Contents: 721 bitcoincharts Bitcoin Charts reference Feeds 722 Bitcoin Charts example Although it is absolutely possible to backtest a strategy with tick data as supplied by using pyalgotradebitcoinchartsbarfeedcsvtradefeed, you may want to to backtest using summarized bars at a different frequency to make backtesting faster As of 12-Aug-2014, has events so we ll transform a portion of it into 30 minute bars for backtesting purposes with the following script: from pyalgotradebitcoincharts import barfeed from pyalgotradetools import resample from pyalgotrade import bar import datetime def main(): barfeed = barfeedcsvtradefeed() barfeedaddbarsfromcsv("bitstampusdcsv", fromdatetime=datetimedatetime(2014, 1, 1)) resampleresample_to_csv(barfeed, barfrequencyminute*30, "30min-bitstampUSDcsv") 72 Bitcoin Charts support 41

46 if name == " main ": main() It will take some time to execute, so be patient The resampled file should look like this: Date Time,Open,High,Low,Close,Volume,Adj Close :00:00,7320,73825,72901,73481, , :30:00,73481,7399,73447,73902, , :00:00,73902,73997,73765,73811, , :30:00,7380,7420,73765,74189, , :00:00,74189,75799,74189,75223, , :30:00,75223,7550,7470,7472, , :00:00,74498,74802,74498,74719, , We can now take advantage of pyalgotradebarfeedcsvfeedgenericbarfeed to load the resampled file and backtest a Bitcoin strategy We ll be using a VWAP momentum strategy for illustration purposes: from pyalgotrade import bar from pyalgotrade import strategy from pyalgotrade import plotter from pyalgotradetechnical import vwap from pyalgotradebarfeed import csvfeed from pyalgotradebitstamp import broker from pyalgotrade import broker as basebroker class VWAPMomentum(strategyBacktestingStrategy): MIN_TRADE = 5 def init (self, feed, brk, instrument, vwapwindowsize, buythreshold, sellthreshold): strategybacktestingstrategy init (self, feed, brk) self instrument = instrument self vwap = vwapvwap(feed[instrument], vwapwindowsize) self buythreshold = buythreshold self sellthreshold = sellthreshold def _getactiveorders(self): orders = selfgetbroker()getactiveorders() buy = [o for o in orders if oisbuy()] sell = [o for o in orders if oissell()] return buy, sell def _cancelorders(self, orders): brk = selfgetbroker() for o in orders: selfinfo("canceling order %s" % (ogetid())) brkcancelorder(o) def _buysignal(self, price): buyorders, sellorders = self_getactiveorders() self_cancelorders(sellorders) brk = selfgetbroker() cashavail = brkgetcash() * 098 size = round(cashavail / price, 3) 42 Chapter 7 Bitcoin

47 if len(buyorders) == 0 and price*size > VWAPMomentumMIN_TRADE: selfinfo("buy %s at %s" % (size, price)) try: selflimitorder(self instrument, price, size) except Exception as e: selferror("failed to buy: %s" % (e)) def _sellsignal(self, price): buyorders, sellorders = self_getactiveorders() self_cancelorders(buyorders) brk = selfgetbroker() shares = brkgetshares(self instrument) if len(sellorders) == 0 and shares > 0: selfinfo("sell %s at %s" % (shares, price)) selflimitorder(self instrument, price, shares*-1) def getvwap(self): return self vwap def onbars(self, bars): vwap = self vwap[-1] if vwap is None: return price = bars[self instrument]getclose() if price > vwap * (1 + self buythreshold): self_buysignal(price) elif price < vwap * (1 - self sellthreshold): self_sellsignal(price) def onorderupdated(self, order): if orderisbuy(): ordertype = "Buy" else: ordertype = "Sell" selfinfo("%s order %d updated - Status: %s - %s" % ( ordertype, ordergetid(), basebrokerorderstatetostring(ordergetstate()), ordergetexecutioninfo(), )) def main(plot): instrument = "BTC" initialcash = 1000 vwapwindowsize = 100 buythreshold = 002 sellthreshold = 001 barfeed = csvfeedgenericbarfeed(barfrequencyminute*30) barfeedaddbarsfromcsv(instrument, "30min-bitstampUSDcsv") brk = brokerbacktestingbroker(initialcash, barfeed) strat = VWAPMomentum(barFeed, brk, instrument, vwapwindowsize, buythreshold, sellthreshold) if plot: plt = plotterstrategyplotter(strat) 72 Bitcoin Charts support 43

48 pltgetinstrumentsubplot(instrument)adddataseries("vwap", stratgetvwap()) stratrun() if plot: pltplot() if name == " main ": main(true) This is what the plot looks like: 44 Chapter 7 Bitcoin

49 CHAPTER 8 Twitter support The twitter package adds support for receiving Twitter events in your strategy and incorporate those in your trading decisions Note that since this is a realtime feed, it only makes sense in paper trading or real trading scenarios, but not in backtesting Twitter support depends on tweepy ( so be sure to have it installed before moving forward Contents: 81 twitter Twitter feed reference 811 Feed 82 Twitter Example This goal of this simple example is to show you how to put all the pieces together to incorporate Twitter events in a strategy We will be using Bitstamp s live feed since backtesting with Twitter is not supported so please take a look at the Bitstamp Example section before moving forward In order to connect to Twitter s API you ll need: Consumer key Consumer secret Access token Access token secret Go to and create an app The consumer key and secret will be generated for you after that Then you ll need to create an access token under the Your access token section The key things to highlight are: 1 We re using pyalgotradestrategybasestrategy instead of pyalgotradestrategybacktestingstrategy as the base class This is not a backtest 2 The pyalgotradetwitterfeedtwitterfeed instance has to be included in the strategy event dispatch loop before running the strategy 45

50 from pyalgotrade import strategy from pyalgotradebitstamp import barfeed from pyalgotradebitstamp import broker from pyalgotradetwitter import feed as twitterfeed class Strategy(strategyBaseStrategy): def init (self, feed, brk, twitterfeed): strategybasestrategy init (self, feed, brk) self instrument = "BTC" # Subscribe to Twitter events twitterfeedsubscribe(self ontweet) def ontweet(self, data): # Refer to for # the information available in data try: selfinfo("twitter: %s" % (data["text"])) except KeyError: pass def onbars(self, bars): bar = bars[self instrument] selfinfo("price: %s Volume: %s" % (bargetclose(), bargetvolume())) def main(): # Go to and create an app # The consumer key and secret will be generated for you after that consumer_key = "<YOUR-CONSUMER-KEY-HERE>" consumer_secret = "<YOUR-CONSUMER-SECRET-HERE>" # After the step above, you will be redirected to your app's page # Create an access token under the the "Your access token" section access_token = "<YOUR-ACCESS-TOKEN-HERE>" access_token_secret = "<YOUR-ACCESS-TOKEN-SECRET-HERE>" # Create a twitter feed to track BitCoin related events track = ["bitcoin", "btc", "mtgox", "bitstamp", "xapo"] follow = [] languages = ["en"] twitterfeed = twitterfeedtwitterfeed(consumer_key, consumer_secret, access_token, access_token_s barfeed = barfeedlivetradefeed() brk = brokerpapertradingbroker(1000, barfeed) strat = Strategy(barFeed, brk, twitterfeed) # It is VERY important to add twitterfeed to the event dispatch loop before running the strategy stratgetdispatcher()addsubject(twitterfeed) stratrun() if name == " main ": main() The output should look like this: 46 Chapter 8 Twitter support

51 :42:07,696 bitstamp [INFO] Initializing client :42:08,174 bitstamp [INFO] Connection established :42:08,175 bitstamp [INFO] Initialization ok :42:08,175 twitter [INFO] Initializing client :42:09,238 twitter [INFO] Connected :42:15,107 strategy [INFO] Twitter: Warren Buffett Urges Investors to Stay Away from B :42:22,926 strategy [INFO] Twitter: FundingUnion Inc Bitcoin MLM Social Build - The Cu :42:23,577 strategy [INFO] Twitter: #News Alleged Bitcoin creator denies he's the one ht :42:29,378 strategy [INFO] Twitter: #News Alleged Bitcoin creator denies :42:38,012 strategy [INFO] Twitter: Need for speed dulu at BTC XXI :42:40,162 strategy [INFO] Price: Volume: :42:45,867 strategy [INFO] Twitter: Analysis of the leaked MTGOX database :42:46,761 strategy [INFO] Twitter: [ANN] After MtGox implosion, this is the first excha :42:46,825 strategy @cdixon you guys remember CentMail :42:47,285 strategy [INFO] Twitter: Help me convince my Dad to mine Bitcoins! :42:47,492 strategy [INFO] Twitter: Warren Buffett: Bitcoin is a 'mirag :42:47,625 strategy [INFO] Twitter: I believe in bitcoin as not only a easy exchange of :42:47,979 strategy [INFO] Twitter: Bitcoin protocol/algorithm is being managed by a bun :42:48,388 strategy [INFO] Twitter: Does anyone still think Dorian Nakomoto is Satoshi N :42:53,313 strategy [INFO] Twitter: Last sale price at #Bitstamp was $63299 per #Bitcoi :42:54,058 strategy [INFO] Twitter: Last sale price at #BTCe was $62300 per #Bitcoin :42:54,059 strategy [INFO] Twitter: Last sale price at #Coinbase was $63299 per #Bitcoi :42:57,148 strategy [INFO] Twitter: GET PAID WITH USD OR BITCOIN TO PROMOTE LINKS!!! :43:00,845 strategy [INFO] Twitter: We're back! Bitcoin expert Pete Watson explaining ju :43:28,001 strategy [INFO] Twitter: Bitcoin's COO Explains What #Bitcoin Is :43:31,888 strategy [INFO] Twitter: #BINARY-OPTIONS! and BITCOIN! Trade Area! With fanta :43:42,148 strategy [INFO] Twitter: GET PAID WITH USD OR BITCOIN TO PROMOTE LINKS!!! 82 Twitter Example 47

52 48 Chapter 8 Twitter support

53 CHAPTER 9 TA-Lib integration The pyalgotradetalibextindicator module provides integration with Python wrapper for TA-Lib ( to enable calling TA-Lib functions directly with pyalgotradedataseriesdataseries or pyalgotradedataseriesbardsbardataseries instances instead of numpy arrays If you re familiar with the talib module, then using the pyalgotradetalibextindicator module should be straightforward When using talib standalone you do something like this: import numpy import talib data = numpyrandomrandom(100) upper, middle, lower = talibbbands(data, matype=talibma_t3) To use the pyalgotradetalibextindicator module in your strategies you should do something like this: def onbars(self, bars): closeds = selfgetfeed()getdataseries("orcl")getclosedataseries() upper, middle, lower = pyalgotradetalibextindicatorbbands(closeds, 100, matype=talibma_t3) if upper!= None: print "%s" % upper[-1] Every function in the pyalgotradetalibextindicator module receives one or more dataseries (most receive just one) and the number of values to use from the dataseries In the example above, we re calculating Bollinger Bands over the last 100 closing prices If the parameter name is ds, then you should pass a regular pyalgotradedataseriesdataseries instance, like the one shown in the example above If the parameter name is bards, then you should pass a pyalgotradedataseriesbardsbardataseries instance, like in the next example: def onbars(self, bars): bards = selfgetfeed()getdataseries("orcl") sar = indicatorsar(bards, 100) if sar!= None: print "%s" % sar[-1] The following TA-Lib functions are available through the pyalgotradetalibextindicator module: 49

54 50 Chapter 9 TA-Lib integration

55 CHAPTER 10 Computational Investing Part I As I was taking the Computational Investing Part I course in 2012 I had to work on a set of assignments and for some of them I used PyAlgoTrade 101 Homework 1 For this assignment I had to pick 4 stocks, invest a total of $ during 2011, and calculate: Final portfolio value Anual return Average daily return Std dev of daily returns Sharpe ratio Download the data with the following commands: python -c "from pyalgotradetools import yahoofinance; yahoofinancedownload_daily_bars('aeti', 2011, python -c "from pyalgotradetools import yahoofinance; yahoofinancedownload_daily_bars('egan', 2011, python -c "from pyalgotradetools import yahoofinance; yahoofinancedownload_daily_bars('glng', 2011, python -c "from pyalgotradetools import yahoofinance; yahoofinancedownload_daily_bars('simo', 2011, Although the deliverable was an Excel spreadsheet, I validated the results using this piece of code: from pyalgotrade import strategy from pyalgotradebarfeed import yahoofeed from pyalgotradestratanalyzer import returns from pyalgotradestratanalyzer import sharpe from pyalgotradeutils import stats class MyStrategy(strategyBacktestingStrategy): def init (self, feed): strategybacktestingstrategy init (self, feed, ) # We wan't to use adjusted close prices instead of close selfsetuseadjustedvalues(true) # Place the orders to get them processed on the first bar orders = { "aeti": , 51

56 "egan": 81266, "glng": 11095, "simo": 17293, } for instrument, quantity in list(ordersitems()): selfmarketorder(instrument, quantity, onclose=true, allornone=true) def onbars(self, bars): pass # Load the yahoo feed from CSV files feed = yahoofeedfeed() feedaddbarsfromcsv("aeti", "aeti-2011-yahoofinancecsv") feedaddbarsfromcsv("egan", "egan-2011-yahoofinancecsv") feedaddbarsfromcsv("glng", "glng-2011-yahoofinancecsv") feedaddbarsfromcsv("simo", "simo-2011-yahoofinancecsv") # Evaluate the strategy with the feed's bars mystrategy = MyStrategy(feed) # Attach returns and sharpe ratio analyzers retanalyzer = returnsreturns() mystrategyattachanalyzer(retanalyzer) sharperatioanalyzer = sharpesharperatio() mystrategyattachanalyzer(sharperatioanalyzer) # Run the strategy mystrategyrun() # Print the results print("final portfolio value: $%2f" % mystrategygetresult()) print("anual return: %2f %%" % (retanalyzergetcumulativereturns()[-1] * 100)) print("average daily return: %2f %%" % (statsmean(retanalyzergetreturns()) * 100)) print("std dev daily return: %4f" % (statsstddev(retanalyzergetreturns()))) print("sharpe ratio: %2f" % (sharperatioanalyzergetsharperatio(0))) The results were: Final portfolio value: $ Anual return: 6050 % Average daily return: 020 % Std dev daily return: Sharpe ratio: Homework 3 and 4 For these assignments I had to build a market simulation tool that loads orders from a file, executes those, and prints the results for each day The orders file for homework 3 look like this: 2011,1,10,AAPL,Buy,1500, 2011,1,13,AAPL,Sell,1500, 2011,1,13,IBM,Buy,4000, 2011,1,26,GOOG,Buy,1000, 2011,2,2,XOM,Sell,4000, 52 Chapter 10 Computational Investing Part I

57 2011,2,10,XOM,Buy,4000, 2011,3,3,GOOG,Sell,1000, 2011,3,3,IBM,Sell,2200, 2011,6,3,IBM,Sell,3300, 2011,5,3,IBM,Buy,1500, 2011,6,10,AAPL,Buy,1200, 2011,8,1,GOOG,Buy,55, 2011,8,1,GOOG,Sell,55, 2011,12,20,AAPL,Sell,1200, This is the market simulation tool that I built: import csv import datetime import os from pyalgotradebarfeed import yahoofeed from pyalgotradebarfeed import csvfeed from pyalgotrade import strategy from pyalgotradeutils import stats from pyalgotradestratanalyzer import returns from pyalgotradestratanalyzer import sharpe class OrdersFile: def init (self, ordersfile): self orders = {} self firstdate = None self lastdate = None self instruments = [] # Load orders from the file reader = csvdictreader(open(ordersfile, "r"), fieldnames=["year", "month", "day", "symbol", for row in reader: datetime = datetimedatetime(int(row["year"]), int(row["month"]), int(row["day"])) self orderssetdefault(datetime, []) order = (row["symbol"], row["action"], int(row["qty"])) self orders[datetime]append(order) # As we process the file, store instruments, first date, and last date if row["symbol"] not in self instruments: self instrumentsappend(row["symbol"]) if self firstdate is None: self firstdate = datetime else: self firstdate = min(self firstdate, datetime) if self lastdate is None: self lastdate = datetime else: self lastdate = max(self lastdate, datetime) def getfirstdate(self): return self firstdate def getlastdate(self): return self lastdate 102 Homework 3 and 4 53

58 def getinstruments(self): return self instruments def getorders(self, datetime): return self ordersget(datetime, []) class MyStrategy(strategyBacktestingStrategy): def init (self, feed, cash, ordersfile, useadjustedclose): # Suscribe to the feed bars event before the broker just to place the orders properly feedgetnewvaluesevent()subscribe(self onbarsbeforebroker) strategybacktestingstrategy init (self, feed, cash) self ordersfile = ordersfile selfsetuseadjustedvalues(useadjustedclose) # We will allow buying more shares than cash allows selfgetbroker()setallownegativecash(true) def onbarsbeforebroker(self, datetime, bars): for instrument, action, quantity in self ordersfilegetorders(datetime): if actionlower() == "buy": selfmarketorder(instrument, quantity, onclose=true) else: selfmarketorder(instrument, quantity*-1, onclose=true) def onorderupdated(self, order): if orderiscanceled(): raise Exception("Order canceled Ran out of cash?") def onbars(self, bars): portfoliovalue = selfgetbroker()getequity() selfinfo("portfolio value: $%2f" % (portfoliovalue)) def main(): # Load the orders file ordersfile = OrdersFile("orderscsv") print("first date", ordersfilegetfirstdate()) print("last date", ordersfilegetlastdate()) print("symbols", ordersfilegetinstruments()) # Load the data from QSTK storage QS environment variable has to be defined if osgetenv("qs") is None: raise Exception("QS environment variable not defined") feed = yahoofeedfeed() feedsetbarfilter(csvfeeddaterangefilter(ordersfilegetfirstdate(), ordersfilegetlastdate())) feedsetdailybartime(datetimetime(0, 0, 0)) # This is to match the dates loaded with the ones i for symbol in ordersfilegetinstruments(): feedaddbarsfromcsv(symbol, ospathjoin(osgetenv("qs"), "QSData", "Yahoo", symbol + "csv") # Run the strategy cash = useadjustedclose = True mystrategy = MyStrategy(feed, cash, ordersfile, useadjustedclose) # Attach returns and sharpe ratio analyzers retanalyzer = returnsreturns() mystrategyattachanalyzer(retanalyzer) sharperatioanalyzer = sharpesharperatio() 54 Chapter 10 Computational Investing Part I

59 main() mystrategyattachanalyzer(sharperatioanalyzer) mystrategyrun() # Print the results print("final portfolio value: $%2f" % mystrategygetresult()) print("anual return: %2f %%" % (retanalyzergetcumulativereturns()[-1] * 100)) print("average daily return: %2f %%" % (statsmean(retanalyzergetreturns()) * 100)) print("std dev daily return: %4f" % (statsstddev(retanalyzergetreturns()))) print("sharpe ratio: %2f" % (sharperatioanalyzergetsharperatio(0))) The output for homework 3 looks like this: First date :00:00 Last date :00:00 Symbols ['AAPL', 'IBM', 'GOOG', 'XOM'] :00:00: Portfolio value: $ :00:00: Portfolio value: $ :00:00: Portfolio value: $ :00:00: Portfolio value: $ :00:00: Portfolio value: $ :00:00: Portfolio value: $ :00:00: Portfolio value: $ :00:00: Portfolio value: $ Final portfolio value: $ Anual return: 1339 % Average daily return: 005 % Std dev daily return: Sharpe ratio: Homework 3 and 4 55

60 56 Chapter 10 Computational Investing Part I

61 CHAPTER 11 策 略 例 子 111 动 量 交 易 1111 VWAP 动 量 交 易 本 例 基 于 : from pyalgotrade import strategy from pyalgotrade import plotter from pyalgotradetools import yahoofinance from pyalgotradetechnical import vwap from pyalgotradestratanalyzer import sharpe class VWAPMomentum(strategyBacktestingStrategy): def init (self, feed, instrument, vwapwindowsize, threshold): strategybacktestingstrategy init (self, feed) self instrument = instrument self vwap = vwapvwap(feed[instrument], vwapwindowsize) self threshold = threshold def getvwap(self): return self vwap def onbars(self, bars): vwap = self vwap[-1] if vwap is None: return shares = selfgetbroker()getshares(self instrument) price = bars[self instrument]getclose() notional = shares * price if price > vwap * (1 + self threshold) and notional < : selfmarketorder(self instrument, 100) elif price < vwap * (1 - self threshold) and notional > 0: selfmarketorder(self instrument, -100) def main(plot): 57

62 instrument = "aapl" vwapwindowsize = 5 threshold = 001 # Download the bars feed = yahoofinancebuild_feed([instrument], 2011, 2012, "") strat = VWAPMomentum(feed, instrument, vwapwindowsize, threshold) sharperatioanalyzer = sharpesharperatio() stratattachanalyzer(sharperatioanalyzer) if plot: plt = plotterstrategyplotter(strat, True, False, True) pltgetinstrumentsubplot(instrument)adddataseries("vwap", stratgetvwap()) stratrun() print("sharpe ratio: %2f" % sharperatioanalyzergetsharperatio(005)) if plot: pltplot() if name == " main ": main(true) 本 例 输 出 结 果 如 下 : :01:23,813 yahoofinance [INFO] Creating data directory :01:23,814 yahoofinance [INFO] Downloading aapl 2011 to data/aapl-2011-yahoofinancecsv :01:25,275 yahoofinance [INFO] Downloading aapl 2012 to data/aapl-2012-yahoofinancecsv Sharpe ratio: 089 最 终 结 果 绘 制 如 下 图 所 示 : 58 Chapter 11 策 略 例 子

63 你 可 以 通 过 调 整 VWAP 和 参 数 阈 值 得 到 更 高 的 回 报 1112 SMA 交 叉 保 存 代 码 到 sma_crossoverpy: from pyalgotrade import strategy from pyalgotradetechnical import ma from pyalgotradetechnical import cross class SMACrossOver(strategyBacktestingStrategy): def init (self, feed, instrument, smaperiod): strategybacktestingstrategy init (self, feed) self instrument = instrument self position = None # We'll use adjusted close values instead of regular close values selfsetuseadjustedvalues(true) self prices = feed[instrument]getpricedataseries() self sma = masma(self prices, smaperiod) def getsma(self): 111 动 量 交 易 59

64 return self sma def onentercanceled(self, position): self position = None def onexitok(self, position): self position = None def onexitcanceled(self, position): # If the exit was canceled, re-submit it self positionexitmarket() def onbars(self, bars): # If a position was not opened, check if we should enter a long position if self position is None: if crosscross_above(self prices, self sma) > 0: shares = int(selfgetbroker()getcash() * 09 / bars[self instrument]getprice()) # Enter a buy market order The order is good till canceled self position = selfenterlong(self instrument, shares, True) # Check if we have to exit the position elif not self positionexitactive() and crosscross_below(self prices, self sma) > 0: self positionexitmarket() 通 过 以 下 代 码 运 行 策 略 : import sma_crossover from pyalgotrade import plotter from pyalgotradetools import yahoofinance from pyalgotradestratanalyzer import sharpe def main(plot): instrument = "aapl" smaperiod = 163 # Download the bars feed = yahoofinancebuild_feed([instrument], 2011, 2012, "") strat = sma_crossoversmacrossover(feed, instrument, smaperiod) sharperatioanalyzer = sharpesharperatio() stratattachanalyzer(sharperatioanalyzer) if plot: plt = plotterstrategyplotter(strat, True, False, True) pltgetinstrumentsubplot(instrument)adddataseries("sma", stratgetsma()) stratrun() print("sharpe ratio: %2f" % sharperatioanalyzergetsharperatio(005)) if plot: pltplot() if name == " main ": main(true) 本 例 输 出 结 果 如 下 : 60 Chapter 11 策 略 例 子

65 :01:23,813 yahoofinance [INFO] Creating data directory :01:23,814 yahoofinance [INFO] Downloading aapl 2011 to data/aapl-2011-yahoofinancecsv :01:25,275 yahoofinance [INFO] Downloading aapl 2012 to data/aapl-2012-yahoofinancecsv Sharpe ratio: 112 最 终 结 果 绘 制 如 下 图 所 示 : 你 可 以 通 过 调 整 sma 的 周 期 得 到 更 好 的 回 报 1113 均 线 交 叉 择 时 This example is inspired on the Market Timing / GTAA model described in: The stragegy supports analyzing more than one instrument per asset class, and selects the one that has highest returns in the last month from pyalgotrade import strategy from pyalgotrade import plotter from pyalgotradetools import yahoofinance from pyalgotradetechnical import ma 111 动 量 交 易 61

66 from pyalgotradetechnical import cumret from pyalgotradestratanalyzer import sharpe from pyalgotradestratanalyzer import returns class MarketTiming(strategyBacktestingStrategy): def init (self, feed, instrumentsbyclass, initialcash): strategybacktestingstrategy init (self, feed, initialcash) selfsetuseadjustedvalues(true) self instrumentsbyclass = instrumentsbyclass self rebalancemonth = None self sharestobuy = {} # Initialize indicators for each instrument self sma = {} for assetclass in instrumentsbyclass: for instrument in instrumentsbyclass[assetclass]: priceds = feed[instrument]getpricedataseries() self sma[instrument] = masma(priceds, 200) def _shouldrebalance(self, datetime): return datetimemonth!= self rebalancemonth def _getrank(self, instrument): # If the price is below the SMA, then this instrument doesn't rank at # all smas = self sma[instrument] price = selfgetlastprice(instrument) if len(smas) == 0 or smas[-1] is None or price < smas[-1]: return None # Rank based on 20 day returns ret = None lookback = 20 priceds = selfgetfeed()[instrument]getpricedataseries() if len(priceds) >= lookback and smas[-1] is not None and smas[-1*lookback] is not None: ret = (priceds[-1] - priceds[-1*lookback]) / float(priceds[-1*lookback]) return ret def _gettopbyclass(self, assetclass): # Find the instrument with the highest rank ret = None highestrank = None for instrument in self instrumentsbyclass[assetclass]: rank = self_getrank(instrument) if rank is not None and (highestrank is None or rank > highestrank): highestrank = rank ret = instrument return ret def _gettop(self): ret = {} for assetclass in self instrumentsbyclass: ret[assetclass] = self_gettopbyclass(assetclass) return ret def _placependingorders(self): remainingcash = selfgetbroker()getcash() * 09 # Use less chash just in case price changes 62 Chapter 11 策 略 例 子

67 for instrument in self sharestobuy: ordersize = self sharestobuy[instrument] if ordersize > 0: # Adjust the order size based on available cash lastprice = selfgetlastprice(instrument) cost = ordersize * lastprice while cost > remainingcash and ordersize > 0: ordersize -= 1 cost = ordersize * lastprice if ordersize > 0: remainingcash -= cost assert(remainingcash >= 0) if ordersize!= 0: selfinfo("placing market order for %d %s shares" % (ordersize, instrument)) selfmarketorder(instrument, ordersize, goodtillcanceled=true) self sharestobuy[instrument] -= ordersize def _logpossize(self): totalequity = selfgetbroker()getequity() positions = selfgetbroker()getpositions() for instrument in selfgetbroker()getpositions(): possize = positions[instrument] * selfgetlastprice(instrument) / totalequity * 100 selfinfo("%s - %02f %%" % (instrument, possize)) def _rebalance(self): selfinfo("rebalancing") # Cancel all active/pending orders for order in selfgetbroker()getactiveorders(): selfgetbroker()cancelorder(order) cashperassetclass = selfgetbroker()getequity() / float(len(self instrumentsbyclass)) self sharestobuy = {} # Calculate which positions should be open during the next period topbyclass = self_gettop() for assetclass in topbyclass: instrument = topbyclass[assetclass] selfinfo("best for class %s: %s" % (assetclass, instrument)) if instrument is not None: lastprice = selfgetlastprice(instrument) cashforinstrument = cashperassetclass - selfgetbroker()getshares(instrument) * last # This may yield a negative value and we have to reduce this # position self sharestobuy[instrument] = int(cashforinstrument / lastprice) # Calculate which positions should be closed for instrument in selfgetbroker()getpositions(): if instrument not in list(topbyclassvalues()): currentshares = selfgetbroker()getshares(instrument) assert(instrument not in self sharestobuy) self sharestobuy[instrument] = currentshares * -1 def getsma(self, instrument): return self sma[instrument] def onbars(self, bars): 111 动 量 交 易 63

68 currentdatetime = barsgetdatetime() if self_shouldrebalance(currentdatetime): self rebalancemonth = currentdatetimemonth self_rebalance() self_placependingorders() def main(plot): initialcash = instrumentsbyclass = { "US Stocks": ["VTI"], "Foreign Stocks": ["VEU"], "US 10 Year Government Bonds": ["IEF"], "Real Estate": ["VNQ"], "Commodities": ["DBC"], } # Download the bars instruments = ["SPY"] for assetclass in instrumentsbyclass: instrumentsextend(instrumentsbyclass[assetclass]) feed = yahoofinancebuild_feed(instruments, 2007, 2013, "data", skiperrors=true) strat = MarketTiming(feed, instrumentsbyclass, initialcash) sharperatioanalyzer = sharpesharperatio() stratattachanalyzer(sharperatioanalyzer) returnsanalyzer = returnsreturns() stratattachanalyzer(returnsanalyzer) if plot: plt = plotterstrategyplotter(strat, False, False, True) pltgetorcreatesubplot("cash")addcallback("cash", lambda x: stratgetbroker()getcash()) # Plot strategy vs SPY cumulative returns pltgetorcreatesubplot("returns")adddataseries("spy", cumretcumulativereturn(feed["spy"]ge pltgetorcreatesubplot("returns")adddataseries("strategy", returnsanalyzergetcumulativeretu stratrun() print("sharpe ratio: %2f" % sharperatioanalyzergetsharperatio(005)) print("returns: %2f %%" % (returnsanalyzergetcumulativereturns()[-1] * 100)) if plot: pltplot() if name == " main ": main(true) 本 例 输 出 结 果 如 下 : :36:59,740 yahoofinance [INFO] Creating data directory :36:59,740 yahoofinance [INFO] Downloading SPY 2007 to data/spy-2007-yahoofinancecsv :37:06,332 yahoofinance [INFO] Downloading VTI 2007 to data/vti-2007-yahoofinancecsv :37:10,666 yahoofinance [INFO] Downloading DBC 2007 to data/dbc-2007-yahoofinancecsv :37:13,102 yahoofinance [INFO] Downloading IEF 2007 to data/ief-2007-yahoofinancecsv :37:19,394 yahoofinance [INFO] Downloading VEU 2007 to data/veu-2007-yahoofinancecsv :37:27,378 yahoofinance [INFO] Downloading VNQ 2007 to data/vnq-2007-yahoofinancecsv :37:32,771 yahoofinance [INFO] Downloading SPY 2008 to data/spy-2008-yahoofinancecsv 64 Chapter 11 策 略 例 子

69 :37:38,326 yahoofinance [INFO] Downloading VTI 2008 to data/vti-2008-yahoofinancecsv :37:42,262 yahoofinance [INFO] Downloading DBC 2008 to data/dbc-2008-yahoofinancecsv :00:00 strategy [INFO] Rebalancing :00:00 strategy [INFO] Best for class US Stocks: VTI :00:00 strategy [INFO] Best for class Commodities: None :00:00 strategy [INFO] Best for class US 10 Year Government Bonds: None :00:00 strategy [INFO] Best for class Foreign Stocks: VEU :00:00 strategy [INFO] Best for class Real Estate: None :00:00 strategy [INFO] Placing market order for -1 VTI shares :00:00 strategy [INFO] Placing market order for -39 VNQ shares Sharpe ratio: -006 Returns: 3297 % 最 终 结 果 绘 制 如 下 图 所 示 : 111 动 量 交 易 65

70 112 均 值 回 归 1121 Ernie Chan s 黄 金 vs 黄 金 矿 工 本 例 基 于 : from pyalgotrade import strategy from pyalgotrade import dataseries from pyalgotradedataseries import aligned from pyalgotrade import plotter from pyalgotradetools import yahoofinance from pyalgotradestratanalyzer import sharpe import numpy as np import statsmodelsapi as sm def get_beta(values1, values2): # model = smols(values1, values2) results = modelfit() return resultsparams[0] class StatArbHelper: def init (self, ds1, ds2, windowsize): # We're going to use datetime aligned versions of the dataseries self ds1, self ds2 = aligneddatetime_aligned(ds1, ds2) self windowsize = windowsize self hedgeratio = None self spread = None self spreadmean = None self spreadstd = None self zscore = None def getspread(self): return self spread def getspreadmean(self): return self spreadmean def getspreadstd(self): return self spreadstd def getzscore(self): return self zscore def gethedgeratio(self): return self hedgeratio def updatehedgeratio(self, values1, values2): self hedgeratio = get_beta(values1, values2) def updatespreadmeanandstd(self, values1, values2): 66 Chapter 11 策 略 例 子

71 if self hedgeratio is not None: spread = values1 - values2 * self hedgeratio self spreadmean = spreadmean() self spreadstd = spreadstd(ddof=1) def updatespread(self): if self hedgeratio is not None: self spread = self ds1[-1] - self hedgeratio * self ds2[-1] def updatezscore(self): if self spread is not None and self spreadmean is not None and self spreadstd is not No self zscore = (self spread - self spreadmean) / float(self spreadstd) def update(self): if len(self ds1) >= self windowsize: values1 = npasarray(self ds1[-1*self windowsize:]) values2 = npasarray(self ds2[-1*self windowsize:]) self updatehedgeratio(values1, values2) self updatespread() self updatespreadmeanandstd(values1, values2) self updatezscore() class StatArb(strategyBacktestingStrategy): def init (self, feed, instrument1, instrument2, windowsize): strategybacktestingstrategy init (self, feed) selfsetuseadjustedvalues(true) self statarbhelper = StatArbHelper(feed[instrument1]getAdjCloseDataSeries(), feed[instrume self i1 = instrument1 self i2 = instrument2 # These are used only for plotting purposes self spread = dataseriessequencedataseries() self hedgeratio = dataseriessequencedataseries() def getspreadds(self): return self spread def gethedgeratiods(self): return self hedgeratio def getordersize(self, bars, hedgeratio): cash = selfgetbroker()getcash(false) price1 = bars[self i1]getadjclose() price2 = bars[self i2]getadjclose() size1 = int(cash / (price1 + hedgeratio * price2)) size2 = int(size1 * hedgeratio) return (size1, size2) def buyspread(self, bars, hedgeratio): amount1, amount2 = self getordersize(bars, hedgeratio) selfmarketorder(self i1, amount1) selfmarketorder(self i2, amount2 * -1) def sellspread(self, bars, hedgeratio): amount1, amount2 = self getordersize(bars, hedgeratio) selfmarketorder(self i1, amount1 * -1) selfmarketorder(self i2, amount2) 112 均 值 回 归 67

72 def reduceposition(self, instrument): currentpos = selfgetbroker()getshares(instrument) if currentpos > 0: selfmarketorder(instrument, currentpos * -1) elif currentpos < 0: selfmarketorder(instrument, currentpos * -1) def onbars(self, bars): self statarbhelperupdate() # These is used only for plotting purposes self spreadappendwithdatetime(barsgetdatetime(), self statarbhelpergetspread()) self hedgeratioappendwithdatetime(barsgetdatetime(), self statarbhelpergethedgeratio() if barsgetbar(self i1) and barsgetbar(self i2): hedgeratio = self statarbhelpergethedgeratio() zscore = self statarbhelpergetzscore() if zscore is not None: currentpos = abs(selfgetbroker()getshares(self i1)) + abs(selfgetbroker()getsha if abs(zscore) <= 1 and currentpos!= 0: selfreduceposition(self i1) selfreduceposition(self i2) elif zscore <= -2 and currentpos == 0: # Buy spread when its value drops below 2 sta selfbuyspread(bars, hedgeratio) elif zscore >= 2 and currentpos == 0: # Short spread when its value rises above 2 st selfsellspread(bars, hedgeratio) def main(plot): instruments = ["gld", "gdx"] windowsize = 50 # Download the bars feed = yahoofinancebuild_feed(instruments, 2006, 2012, "") strat = StatArb(feed, instruments[0], instruments[1], windowsize) sharperatioanalyzer = sharpesharperatio() stratattachanalyzer(sharperatioanalyzer) if plot: plt = plotterstrategyplotter(strat, False, False, True) pltgetorcreatesubplot("hedge")adddataseries("hedge Ratio", stratgethedgeratiods()) pltgetorcreatesubplot("spread")adddataseries("spread", stratgetspreadds()) stratrun() print("sharpe ratio: %2f" % sharperatioanalyzergetsharperatio(005)) if plot: pltplot() if name == " main ": main(true) 本 例 输 出 结 果 如 下 : :02:35,136 yahoofinance [INFO] Creating data directory :02:35,136 yahoofinance [INFO] Downloading gld 2006 to data/gld-2006-yahoofinancecsv 68 Chapter 11 策 略 例 子

73 :02:35,899 yahoofinance [INFO] Downloading gdx 2006 to data/gdx-2006-yahoofinancecsv :02:36,637 yahoofinance [INFO] Downloading gld 2007 to data/gld-2007-yahoofinancecsv :02:37,265 yahoofinance [INFO] Downloading gdx 2007 to data/gdx-2007-yahoofinancecsv :02:37,881 yahoofinance [INFO] Downloading gld 2008 to data/gld-2008-yahoofinancecsv :02:38,462 yahoofinance [INFO] Downloading gdx 2008 to data/gdx-2008-yahoofinancecsv :02:39,243 yahoofinance [INFO] Downloading gld 2009 to data/gld-2009-yahoofinancecsv :02:39,996 yahoofinance [INFO] Downloading gdx 2009 to data/gdx-2009-yahoofinancecsv :02:40,577 yahoofinance [INFO] Downloading gld 2010 to data/gld-2010-yahoofinancecsv :02:42,630 yahoofinance [INFO] Downloading gdx 2010 to data/gdx-2010-yahoofinancecsv :02:43,397 yahoofinance [INFO] Downloading gld 2011 to data/gld-2011-yahoofinancecsv :02:44,153 yahoofinance [INFO] Downloading gdx 2011 to data/gdx-2011-yahoofinancecsv :02:44,901 yahoofinance [INFO] Downloading gld 2012 to data/gld-2012-yahoofinancecsv :02:45,965 yahoofinance [INFO] Downloading gdx 2012 to data/gdx-2012-yahoofinancecsv Sharpe ratio: -020 最 终 结 果 绘 制 如 下 图 所 示 : You can get better returns by tunning the window size as well as the entry and exit values for the z-score 1122 布 林 带 This example is based on: 均 值 回 归 69

74 from pyalgotrade import strategy from pyalgotrade import plotter from pyalgotradetools import yahoofinance from pyalgotradetechnical import bollinger from pyalgotradestratanalyzer import sharpe class BBands(strategyBacktestingStrategy): def init (self, feed, instrument, bbandsperiod): strategybacktestingstrategy init (self, feed) self instrument = instrument self bbands = bollingerbollingerbands(feed[instrument]getclosedataseries(), bbandsperiod, def getbollingerbands(self): return self bbands def onbars(self, bars): lower = self bbandsgetlowerband()[-1] upper = self bbandsgetupperband()[-1] if lower is None: return shares = selfgetbroker()getshares(self instrument) bar = bars[self instrument] if shares == 0 and bargetclose() < lower: sharestobuy = int(selfgetbroker()getcash(false) / bargetclose()) selfmarketorder(self instrument, sharestobuy) elif shares > 0 and bargetclose() > upper: selfmarketorder(self instrument, -1*shares) def main(plot): instrument = "yhoo" bbandsperiod = 40 # Download the bars feed = yahoofinancebuild_feed([instrument], 2011, 2012, "") strat = BBands(feed, instrument, bbandsperiod) sharperatioanalyzer = sharpesharperatio() stratattachanalyzer(sharperatioanalyzer) if plot: plt = plotterstrategyplotter(strat, True, True, True) pltgetinstrumentsubplot(instrument)adddataseries("upper", stratgetbollingerbands()getuppe pltgetinstrumentsubplot(instrument)adddataseries("middle", stratgetbollingerbands()getmid pltgetinstrumentsubplot(instrument)adddataseries("lower", stratgetbollingerbands()getlowe stratrun() print("sharpe ratio: %2f" % sharperatioanalyzergetsharperatio(005)) if plot: pltplot() if name == " main ": main(true) 70 Chapter 11 策 略 例 子

75 本 例 输 出 结 果 如 下 : :06:07,740 yahoofinance [INFO] Creating data directory :06:07,741 yahoofinance [INFO] Downloading yhoo 2011 to data/yhoo-2011-yahoofinancecsv :06:09,621 yahoofinance [INFO] Downloading yhoo 2012 to data/yhoo-2012-yahoofinancecsv Sharpe ratio: 071 最 终 结 果 绘 制 如 下 图 所 示 : You can get better returns by tunning the Bollinger Bands period as well as the entry and exit points 1123 RSI2 This example is based on a strategy known as RSI2 ( which requires the following parameters: An SMA period for trend identification We ll call this entrysma A smaller SMA period for the exit point We ll call this exitsma An RSI period for entering both short/long positions We ll call this rsiperiod An RSI oversold threshold for long position entry We ll call this oversoldthreshold An RSI overbought threshold for short position entry We ll call this overboughtthreshold 112 均 值 回 归 71

76 Save this code as rsi2py: from pyalgotrade import strategy from pyalgotradetechnical import ma from pyalgotradetechnical import rsi from pyalgotradetechnical import cross class RSI2(strategyBacktestingStrategy): def init (self, feed, instrument, entrysma, exitsma, rsiperiod, overboughtthreshold, oversoldt strategybacktestingstrategy init (self, feed) self instrument = instrument # We'll use adjusted close values, if available, instead of regular close values if feedbarshaveadjclose(): selfsetuseadjustedvalues(true) self priceds = feed[instrument]getpricedataseries() self entrysma = masma(self priceds, entrysma) self exitsma = masma(self priceds, exitsma) self rsi = rsirsi(self priceds, rsiperiod) self overboughtthreshold = overboughtthreshold self oversoldthreshold = oversoldthreshold self longpos = None self shortpos = None def getentrysma(self): return self entrysma def getexitsma(self): return self exitsma def getrsi(self): return self rsi def onentercanceled(self, position): if self longpos == position: self longpos = None elif self shortpos == position: self shortpos = None else: assert(false) def onexitok(self, position): if self longpos == position: self longpos = None elif self shortpos == position: self shortpos = None else: assert(false) def onexitcanceled(self, position): # If the exit was canceled, re-submit it positionexitmarket() def onbars(self, bars): # Wait for enough bars to be available to calculate SMA and RSI if self exitsma[-1] is None or self entrysma[-1] is None or self rsi[-1] is None: return bar = bars[self instrument] 72 Chapter 11 策 略 例 子

77 if self longpos is not None: if selfexitlongsignal(): self longposexitmarket() elif self shortpos is not None: if selfexitshortsignal(): self shortposexitmarket() else: if selfenterlongsignal(bar): shares = int(selfgetbroker()getcash() * 09 / bars[self instrument]getprice()) self longpos = selfenterlong(self instrument, shares, True) elif selfentershortsignal(bar): shares = int(selfgetbroker()getcash() * 09 / bars[self instrument]getprice()) self shortpos = selfentershort(self instrument, shares, True) def enterlongsignal(self, bar): return bargetprice() > self entrysma[-1] and self rsi[-1] <= self oversoldthreshold def exitlongsignal(self): return crosscross_above(self priceds, self exitsma) and not self longposexitactive() def entershortsignal(self, bar): return bargetprice() < self entrysma[-1] and self rsi[-1] >= self overboughtthreshold def exitshortsignal(self): return crosscross_below(self priceds, self exitsma) and not self shortposexitactive() and use the following code to execute the strategy: import rsi2 from pyalgotrade import plotter from pyalgotradetools import yahoofinance from pyalgotradestratanalyzer import sharpe def main(plot): instrument = "DIA" entrysma = 200 exitsma = 5 rsiperiod = 2 overboughtthreshold = 90 oversoldthreshold = 10 # Download the bars feed = yahoofinancebuild_feed([instrument], 2009, 2012, "") strat = rsi2rsi2(feed, instrument, entrysma, exitsma, rsiperiod, overboughtthreshold, oversoldth sharperatioanalyzer = sharpesharperatio() stratattachanalyzer(sharperatioanalyzer) if plot: plt = plotterstrategyplotter(strat, True, False, True) pltgetinstrumentsubplot(instrument)adddataseries("entry SMA", stratgetentrysma()) pltgetinstrumentsubplot(instrument)adddataseries("exit SMA", stratgetexitsma()) pltgetorcreatesubplot("rsi")adddataseries("rsi", stratgetrsi()) pltgetorcreatesubplot("rsi")addline("overbought", overboughtthreshold) pltgetorcreatesubplot("rsi")addline("oversold", oversoldthreshold) stratrun() 112 均 值 回 归 73

78 print("sharpe ratio: %2f" % sharperatioanalyzergetsharperatio(005)) if plot: pltplot() if name == " main ": main(true) 本 例 输 出 结 果 如 下 : :49:35,354 yahoofinance [INFO] Downloading DIA 2009 to /DIA-2009-yahoofinancecsv :49:36,388 yahoofinance [INFO] Downloading DIA 2010 to /DIA-2010-yahoofinancecsv :49:36,900 yahoofinance [INFO] Downloading DIA 2011 to /DIA-2011-yahoofinancecsv :49:37,457 yahoofinance [INFO] Downloading DIA 2012 to /DIA-2012-yahoofinancecsv Sharpe ratio: -011 最 终 结 果 绘 制 如 下 图 所 示 : You can get better returns by tunning the different parameters 74 Chapter 11 策 略 例 子

79 113 其 他 1131 Quandl 合 集 The purpose of this example is to show how to integrate price data along with any time-series data in CSV format from Quandl into a strategy We ll use the following CSV data from Quandl: Project/GOLD_2-LBMA-Gold-Price-London-Fixings-P-M from pyalgotrade import strategy from pyalgotrade import plotter from pyalgotradetools import quandl from pyalgotradefeed import csvfeed import datetime class MyStrategy(strategyBacktestingStrategy): def init (self, feed, quandlfeed, instrument): strategybacktestingstrategy init (self, feed) selfsetuseadjustedvalues(true) self instrument = instrument # It is VERY important to add the the extra feed to the event dispatch loop before # running the strategy selfgetdispatcher()addsubject(quandlfeed) # Subscribe to events from the Quandl feed quandlfeedgetnewvaluesevent()subscribe(selfonquandldata) def onquandldata(self, datetime, values): selfinfo(values) def onbars(self, bars): selfinfo(bars[self instrument]getadjclose()) def main(plot): instruments = ["GORO"] # Download GORO bars using WIKI source code feed = quandlbuild_feed("wiki", instruments, 2006, 2012, "") # Load Quandl CSV downloaded from quandlfeed = csvfeedfeed("date", "%Y-%m-%d") quandlfeedsetdaterange(datetimedatetime(2006, 1, 1), datetimedatetime(2012, 12, 31)) quandlfeedaddvaluesfromcsv("quandl_gold_2csv") mystrategy = MyStrategy(feed, quandlfeed, instruments[0]) if plot: plt = plotterstrategyplotter(mystrategy, True, False, False) pltgetorcreatesubplot("quandl")adddataseries("usd", quandlfeed["usd"]) pltgetorcreatesubplot("quandl")adddataseries("eur", quandlfeed["eur"]) pltgetorcreatesubplot("quandl")adddataseries("gbp", quandlfeed["gbp"]) mystrategyrun() 113 其 他 75

80 if plot: pltplot() if name == " main ": main(true) 本 例 输 出 结 果 如 下 : :00:00 strategy [INFO] {'USD': 5130, 'GBP': , 'EUR': } :00:00 strategy [INFO] {'USD': 53525, 'GBP': , 'EUR': } :00:00 strategy [INFO] {'USD': 54825, 'GBP': , 'EUR': } :00:00 strategy [INFO] {'USD': 56725, 'GBP': , 'EUR': } :00:00 strategy [INFO] {'USD': 56175, 'GBP': , 'EUR': } :00:00 strategy [INFO] {'USD': 5690, 'GBP': , 'EUR': } :00:00 strategy [INFO] {'USD': 5570, 'GBP': , 'EUR': 46378} :00:00 strategy [INFO] {'USD': 5517, 'GBP': , 'EUR': } :00:00 strategy [INFO] {'USD': 55415, 'GBP': , 'EUR': } :00:00 strategy [INFO] {'USD': 5650, 'GBP': , 'EUR': } :00:00 strategy [INFO] :00:00 strategy [INFO] :00:00 strategy [INFO] :00:00 strategy [INFO] {'USD': 16515, 'GBP': , 'EUR': } :00:00 strategy [INFO] :00:00 strategy [INFO] :00:00 strategy [INFO] :00:00 strategy [INFO] :00:00 strategy [INFO] {'USD': 16575, 'GBP': , 'EUR': } :00:00 strategy [INFO] 1541 最 终 结 果 绘 制 如 下 图 所 示 : 76 Chapter 11 策 略 例 子

81 113 其 他 77

82 78 Chapter 11 策 略 例 子

83 CHAPTER 12 Indices and tables genindex modindex search 79

84 80 Chapter 12 Indices and tables

85 Python 模 块 索 引 p pyalgotradebroker, 21 pyalgotrademarketsession, 26 pyalgotradestratanalyzer, 22 pyalgotradestratanalyzerdrawdown, 22 81

86 82 Python 模 块 索 引

87 索 引 B BOVESPA (pyalgotrademarketsession 中 的 类 ), 26 D DrawDown (pyalgotradestratanalyzerdrawdown 中 的 类 ), 22 F FTSE (pyalgotrademarketsession 中 的 类 ), 26 G getlongestdrawdownduration() (pyalgotradestratanalyzerdrawdowndrawdown 方 法 ), 22 getmaxdrawdown() (pyalgotradestratanalyzerdrawdowndrawdown 方 法 ), 23 gettimezone() (pyalgotrademarketsessionmarketsession 类 方 法 ), 26 M MarketSession (pyalgotrademarketsession 中 的 类 ), 26 MERVAL (pyalgotrademarketsession 中 的 类 ), 26 N NASDAQ (pyalgotrademarketsession 中 的 类 ), 26 NYSE (pyalgotrademarketsession 中 的 类 ), 26 P pyalgotradebroker ( 模 块 ), 21 pyalgotrademarketsession ( 模 块 ), 26 pyalgotradestratanalyzer ( 模 块 ), 22 pyalgotradestratanalyzerdrawdown ( 模 块 ), 22 S StrategyAnalyzer (pyalgotradestratanalyzer 中 的 类 ), 22 T TSE (pyalgotrademarketsession 中 的 类 ), 26 U USEquities (pyalgotrademarketsession 中 的 类 ), 26 83

88

电 信 与 互 联 网 法 律 热 点 问 题

电 信 与 互 联 网 法 律 热 点 问 题 2014 年 5 月 26 日 2014 年 8 月 14 日 电 信 与 互 联 网 法 律 热 点 问 题 即 时 通 信 工 具 公 众 信 息 服 务 发 展 管 理 暂 行 规 定 简 评 2014 年 8 月 7 日, 国 家 互 联 网 信 息 办 公 室 发 布 了 即 时 通 信 工 具 公 众 信 息 服 务 发 展 管 理 暂 行 规 定 ( 以 下 简 称 暂 行 规 定 ),

More information

广 东 培 正 学 院 2016 年 本 科 插 班 生 专 业 课 考 试 大 纲 基 础 英 语 课 程 考 试 大 纲

广 东 培 正 学 院 2016 年 本 科 插 班 生 专 业 课 考 试 大 纲 基 础 英 语 课 程 考 试 大 纲 广 东 培 正 学 院 2016 年 本 科 插 班 生 专 业 课 考 试 大 纲 基 础 英 语 课 程 考 试 大 纲 Ⅰ. 考 试 性 质 普 通 高 等 学 校 本 科 插 班 生 招 生 考 试 是 由 专 科 毕 业 生 参 加 的 选 拔 性 考 试 高 等 学 校 根 据 考 生 的 成 绩, 按 已 确 定 的 招 生 计 划, 德 智 体 全 面 衡 量, 择 优 录 取 该

More information

ifuzhen.com, ifortzone.com a product of Edgework Ventures Financial Management Software & Financial Wiki

ifuzhen.com, ifortzone.com a product of Edgework Ventures Financial Management Software & Financial Wiki ifuzhen.com, ifortzone.com a product of Edgework Ventures Edgework Ventures Limited Flat L 19th Floor, Goldfield Building 144-150 Tai Lin Pai Road Kwai Chung, Hong Kong Edgework Technology, Shanghai 中国

More information

A Brief Study on Cancellation of Late-Marriage and Late-Childbirth Leaves

A Brief Study on Cancellation of Late-Marriage and Late-Childbirth Leaves PRC Labor and Employment Law Newsflash February 2016 A Brief Study on Cancellation of Late-Marriage and Late-Childbirth Leaves On 27 th December 2015 an amendment to the PRC Population and Family Planning

More information

中 国 石 化 上 海 石 油 化 工 研 究 院 欢 迎 国 内 外 高 层 次 人 才 加 入

中 国 石 化 上 海 石 油 化 工 研 究 院 欢 迎 国 内 外 高 层 次 人 才 加 入 中 国 石 化 上 海 石 油 化 工 研 究 院 欢 迎 国 内 外 高 层 次 人 才 加 入 创 建 世 界 一 流 研 究 院 是 中 国 石 油 化 工 股 份 有 限 公 司 上 海 石 油 化 工 研 究 院 ( 以 下 简 称 上 海 院 ) 的 远 景 目 标, 满 足 国 家 石 油 石 化 发 展 需 求, 为 石 油 石 化 提 供 技 术 支 撑 将 是 上 海 院 的 使

More information

Master Program in Project Management Yunnan University of Finance & Economics, 2016

Master Program in Project Management Yunnan University of Finance & Economics, 2016 Master Program in Project Management Yunnan University of Finance & Economics, 2016 Part I About the Program Program Objectives Guided by Chinese government s development strategy One Belt, One Road and

More information

第 二 届 中 国 中 东 欧 国 家 投 资 贸 易 博 览 会 总 体 方 案

第 二 届 中 国 中 东 欧 国 家 投 资 贸 易 博 览 会 总 体 方 案 第 二 届 中 国 中 东 欧 国 家 投 资 贸 易 博 览 会 总 体 方 案 一 总 体 要 求 第 二 届 中 国 中 东 欧 国 家 投 资 贸 易 博 览 会 ( 简 称 中 东 欧 博 览 会 ) 顺 应 一 带 一 路 发 展 战 略, 以 中 国 - 中 东 欧 国 家 合 作 苏 州 纲 要 为 指 导, 以 深 化 合 作 互 利 共 赢 为 主 题, 通 过 举 办 会 议

More information

Synergy yet to be Seen, Maintain Accumulate

Synergy yet to be Seen, Maintain Accumulate : CRRC Corporation (1766 HK) Gary Wong 黄 家 玮 公 司 报 告 : 中 国 中 车 (1766 HK) +852 259 2616 [email protected] Synergy yet to be Seen, Maintain Accumulate 协 同 效 应 有 待 观 察, 维 持 收 集 GTJA Research 国 泰 君 安

More information

China Foreign Affairs University(CFAU)

China Foreign Affairs University(CFAU) Master Program in International Relations China Foreign Affairs University(CFAU) I - Program Description II - Program Features III- Program Structure IV- Application and Admissions 1 V- Contact Information

More information

Terms and Conditions of Purchase- Bosch China [ 采 购 通 则 博 世 ( 中 国 )]

Terms and Conditions of Purchase- Bosch China [ 采 购 通 则 博 世 ( 中 国 )] 1. General 总 则 Our Terms and Conditions of Purchase shall apply exclusively; Business terms and conditions of the Supplier conflicting with or Supplier s deviating from our Terms and Conditions of Purchase

More information

Slow Earnings Growth but Attractive Discount to A-Shares

Slow Earnings Growth but Attractive Discount to A-Shares : Tsingtao Brewery (00168 HK) Sunny Kwok 郭 日 升 公 司 报 告 : 青 岛 啤 酒 (00168 HK) +852 2509 2642 [email protected] Slow Earnings Growth but Attractive Discount to A-Shares 盈 利 低 速 增 长 但 与 A 股 折 让 较 大 GTJA

More information

4Q15 Results Beat Expectations, Upgrade to Accumulate

4Q15 Results Beat Expectations, Upgrade to Accumulate GTJA Research 国 泰 君 安 研 究 Company Report: Wynn Macau (01128 HK) Noah Hudson 公 司 报 告 : 永 利 澳 门 (01128 HK) +86 755 23976684 [email protected] 4Q15 Results Beat Expectations, Upgrade to Accumulate 2015

More information

Can someone speak some Korean to tell him where the aperture button is?

Can someone speak some Korean to tell him where the aperture button is? Adempiere 中文手册 Can someone speak some Korean to tell him where the aperture button is? 目录 ADempiere 项目...4 版权说明...4 ADempiere Business Suite...5 商业过程...5 Quote to Cash...6 商业文档规则...7 文档状态...7 文档顺序...7

More information

中 国 ( 南 京 ) 软 件 谷 简 介

中 国 ( 南 京 ) 软 件 谷 简 介 中 国 ( 南 京 ) 软 件 谷 简 介 中 国 ( 南 京 ) 软 件 谷 是 首 个 中 国 软 件 名 城 的 核 心 区 和 标 志 区, 位 于 南 京 主 城 南 部, 紧 邻 河 西 新 城 和 南 部 新 城, 总 面 积 70 平 方 公 里, 是 距 主 城 最 近 产 业 集 聚 度 最 高 生 态 资 源 最 好 交 通 最 为 便 捷 的 软 件 产 业 基 地 2011

More information

~1: 15 /;' J~~~~c...:;.--:.. I. ~ffi ~I J) ':~

~1: 15 /;' J~~~~c...:;.--:.. I. ~ffi ~I J) ':~ ~1: 15 /;' J~~~~c...:;.--:.. I ~ffi ~I J) ':~ _ Making CET Writing Sub-test Communicative A Thesis Presented to The College ofenglish Language and Literature Shanghai International Studies University In

More information

美 国 律 师 协 会 知 识 产 权 法 部 和 国 际 法 律 部 关 于 中 华 人 民 共 和 国 专 利 法 修 改 草 案 ( 征 求 意 见 稿 ) 的 联 合 意 见 书

美 国 律 师 协 会 知 识 产 权 法 部 和 国 际 法 律 部 关 于 中 华 人 民 共 和 国 专 利 法 修 改 草 案 ( 征 求 意 见 稿 ) 的 联 合 意 见 书 美 国 律 师 协 会 知 识 产 权 法 部 和 国 际 法 律 部 关 于 中 华 人 民 共 和 国 专 利 法 修 改 草 案 ( 征 求 意 见 稿 ) 的 联 合 意 见 书 2012 年 9 月 7 日 本 文 所 述 意 见 仅 代 表 美 国 律 师 协 会 (ABA) 知 识 产 权 法 部 和 国 际 法 律 部 的 意 见 文 中 的 评 论 内 容 未 经 美 国 律 师

More information

THE PEI CHUN STORY. 2016 Primary 4 Level Briefing for Parents 小 四 家 长 讲 解 会. 公 立 培 群 学 校 Pei Chun Public School

THE PEI CHUN STORY. 2016 Primary 4 Level Briefing for Parents 小 四 家 长 讲 解 会. 公 立 培 群 学 校 Pei Chun Public School 公 立 培 群 学 校 Pei Chun Public School THE PEI CHUN STORY 2016 Primary 4 Level Briefing for Parents 小 四 家 长 讲 解 会 23 January 2016 Vice-Principal, Ms Angela Goh 2015 and SG50 You have made our SG 50 activities

More information

PCS Educational Foundation Inc.

PCS Educational Foundation Inc. PCS Educational Foundation Inc. January 19, 2014 尊 敬 的 中 文 学 校 各 位 家 长 或 监 护 人, 一 年 一 度 的 匹 兹 堡 中 文 学 校 董 事 会 换 届 选 举 将 在 四 月 份 举 行, 将 要 选 出 三 位 选 任 董 事 填 充 因 届 满 而 空 缺 的 董 事 职 位 ( 家 长 教 师 会, 秘 书 长, 副

More information

http://www.paper.edu.cn

http://www.paper.edu.cn 5 10 15 20 25 30 35 40 Agent-based Monitoring Approach for Hybrid Cloud # LIU Yunchang, LI Chunlin, LIU Yanpei * (Department of Computer Science and Technology,Wuhan University of Technology, WuHan 430063)

More information

Romeo and Juliet 罗 密 欧 与 茱 丽 叶

Romeo and Juliet 罗 密 欧 与 茱 丽 叶 Romeo and Juliet 1 A Famous Love Story 驰 名 的 爱 情 故 事 Romeo and Juliet 罗 密 欧 与 茱 丽 叶 Although he died almost 400 years ago, William Shakespeare is still one of the most popular English writers in the world.

More information

FRESH PRODUCE FORUM CHINA, 1 JUNE 2016, CHENGDU, CHINA 新 鲜 果 蔬 行 业 中 国 高 峰 论 坛,2016 年 6 月 1 日, 成 都 EXHIBITOR REGISTRATION FORM 参 展 商 申 请 表 格

FRESH PRODUCE FORUM CHINA, 1 JUNE 2016, CHENGDU, CHINA 新 鲜 果 蔬 行 业 中 国 高 峰 论 坛,2016 年 6 月 1 日, 成 都 EXHIBITOR REGISTRATION FORM 参 展 商 申 请 表 格 FRESH PRODUCE FORUM CHINA, 1 JUNE 2016, CHENGDU, CHINA 新 鲜 果 蔬 行 业 中 国 高 峰 论 坛,2016 年 6 月 1 日, 成 都 EXHIBITOR REGISTRATION FORM 参 展 商 申 请 表 格 1. Exhibitor Data 参 展 商 信 息 (PLEASE COMPLETE IN CAPITAL LETTERS

More information

Bird still caged? China s courts under reform. Workshop, June 3-4, 2016, Vienna, Austria. (University of Vienna, Department of East Asian Studies)

Bird still caged? China s courts under reform. Workshop, June 3-4, 2016, Vienna, Austria. (University of Vienna, Department of East Asian Studies) Bird still caged? China s courts under reform Workshop, June 3-4, 2016, Vienna, Austria (University of Vienna, Department of East Asian Studies) At this workshop, expert participants will exchange information

More information

The Maryknoll Advantage With Pacific Aviation Museum Pearl Harbor

The Maryknoll Advantage With Pacific Aviation Museum Pearl Harbor S U M M E R C A M P 2 0 1 4 The Maryknoll Advantage With Pacific Aviation Museum Pearl Harbor Summer ESL/Pacific Aviation Museum at Maryknoll School, Hawaii July 12 July 31 Program will include: *16 hours

More information

中 国 国 家 留 学 基 金 管 理 委 员 会 CHINA SCHOLARSHIP COUNCIL 驻 外

中 国 国 家 留 学 基 金 管 理 委 员 会 CHINA SCHOLARSHIP COUNCIL 驻 外 中 国 国 家 留 学 基 金 管 理 委 员 会 CHINA SCHOLARSHIP COUNCIL 驻 外 2016/2017 学 年 接 受 以 色 列 来 华 留 学 生 计 划 表 一 国 别 计 划 名 额 : 2016/2017 学 年 中 国 向 以 色 列 政 府 提 供 5 人 / 年 的 奖 学 金 名 额, 其 中 在 华 继 续 学 习 占 名 额 者 0 人 1.2016/2017

More information

ANSYS HFSS 3D Layout 侯 明 刚

ANSYS HFSS 3D Layout 侯 明 刚 ANSYS HFSS 3D Layout 侯 明 刚 Introducing the New Layout Flow with HFSS Two Design Interfaces Mechanical CAD (MCAD) Both Require Electrical the Accuracy Layout (ECAD) of 3D and HFSS HFSS: 3D Parametric Design

More information

大 学 英 语 六 级 随 堂 听 简 答 篇

大 学 英 语 六 级 随 堂 听 简 答 篇 大 学 英 语 六 级 随 堂 听 简 答 篇 唐 启 明 第 一 节 简 答 题 概 况 简 答 题 在 大 纲 里 描 述 较 简 单 : 简 答 题 的 篇 章 后 有 若 干 个 问 题, 要 求 考 生 根 据 对 文 章 的 理 解 简 洁 地 ( 少 于 10 个 词 ) 回 答 问 题 或 完 成 句 子 在 2006 年 新 题 型 以 前 考 过 几 次 简 答, 但 与 现 在

More information

2013 年 6 月 英 语 六 级 真 题 及 答 案 ( 文 都 版 )

2013 年 6 月 英 语 六 级 真 题 及 答 案 ( 文 都 版 ) 真 题 园 ----http://www.zhentiyuan.com 2013 年 6 月 英 语 六 级 真 题 及 答 案 ( 文 都 版 ) 注 : 快 速 阅 读 暂 缺, 作 文 范 文 供 参 考 Part I Writing 2013 年 6 月 六 级 作 文 范 文 一 It is not exaggerating to say that habits determine how

More information

2013 首 届 国 际 营 养 与 健 康 大 会

2013 首 届 国 际 营 养 与 健 康 大 会 2013 首 届 国 际 营 养 与 健 康 大 会 时 间 :2013 年 10 月 12 日 -14 日 地 点 : 中 国 大 连 国 际 会 议 中 心 参 会 指 南 一. 报 到 和 注 册 注 册 时 间 :10 月 11 日 -14 日 8:00-17:00 注 册 地 点 : 大 连 国 际 会 议 中 心 1 楼 注 册 台 注 册 流 程 : 会 前 已 经 交 纳 会 务 费

More information

The transmission calculation by empirical numerical model and Monte Carlo simulation in high energy proton radiography of thick objects *

The transmission calculation by empirical numerical model and Monte Carlo simulation in high energy proton radiography of thick objects * The transmission calculation by empirical numerical model and Monte Carlo simulation in high energy proton radiography of thick objects * ZHNG Na ( 郑 娜 ) XU Hai-Bo ( 许 海 波 ) 1) Institute of Applied Physics

More information

Profession or passion?: Teaching Chinese in London Chinese complementary schools

Profession or passion?: Teaching Chinese in London Chinese complementary schools London Review of Education Volume 12, Number 1, March 2014 Profession or passion?: Teaching Chinese in London Chinese complementary schools Danlu Wang * Institute of Education, University of London, UK

More information

MySQL 備 份, 高 可 用 及 高 扩 展 解 决 方 案

MySQL 備 份, 高 可 用 及 高 扩 展 解 决 方 案 MySQL 備 份, 高 可 用 及 高 扩 展 解 决 方 案 MySQL 复 制 和 集 群 杜 修 文 Oracle MySQL Principle Sales Consultant [email protected] Backup and Restore Backup Strategies Comparison Method 1: Longest

More information

2015 年 12 月 大 学 英 语 六 级 考 试 真 题 优 化 卷 ( 第 二 套 ) 答 题 卡 1

2015 年 12 月 大 学 英 语 六 级 考 试 真 题 优 化 卷 ( 第 二 套 ) 答 题 卡 1 2015 年 12 月 大 学 英 语 六 级 考 试 真 题 优 化 卷 ( 第 二 套 ) 答 题 卡 1 考 生 填 写 答 案 后, 下 载 烤 鱿 鱼 英 语 四 六 级 APP, 通 过 模 考 部 分 拍 照 上 传 答 题 卡 即 可 获 取 自 动 评 分 和 答 案 解 析 拍 摄 答 题 卡 注 意 事 项 : 1. 黑 色 边 框 要 完 全 进 入 拍 摄 范 围 2. 拍

More information

Advancements in Slurry Gasification

Advancements in Slurry Gasification Advancements in Slurry Gasification Jason Crew, General Manager GE Power & Water, Gasification International Advanced Coal Technologies Conference 2012 Xi an June 4, 2012 Gasification is energy conversion

More information

2016 年 6 月 份 大 学 英 语 四 级 考 试 听 力 样 题

2016 年 6 月 份 大 学 英 语 四 级 考 试 听 力 样 题 2016 年 6 月 份 大 学 英 语 四 级 考 试 听 力 样 题 根 据 大 学 英 语 四 六 级 考 试 官 方 网 整 理 http://www.cet.edu.cn/news_show17.html 关 于 全 国 大 学 英 语 四 六 级 考 试 听 力 试 题 调 整 的 说 明 为 了 适 应 新 的 形 势 下 社 会 对 大 学 生 英 语 听 力 能 力 需 求 的 变

More information

新 东 方 大 学 英 语 四 级 考 试

新 东 方 大 学 英 语 四 级 考 试 新 东 方 大 学 英 语 四 级 考 试 全 国 统 一 模 拟 冲 刺 试 卷 COLLEGE ENGLISH TEST Band Four 试 题 册 注 意 事 项 一 将 自 己 的 校 名 姓 名 准 考 证 号 写 在 答 题 卡 1 和 答 题 卡 2 上 将 本 试 卷 代 号 划 在 答 题 卡 1 上 二 试 卷 册 答 题 卡 1 和 答 题 卡 2 均 不 得 带 出 考

More information

国 际 储 备 与 外 币 流 动 性 数 据 模 板 Template on International Reserves and Foreign Currency Liquidity

国 际 储 备 与 外 币 流 动 性 数 据 模 板 Template on International Reserves and Foreign Currency Liquidity Shocking Breakdown of China's Foreign Reserves is Bullish for Gold July 1, 2016 I want to focus on the composition of China s foreign reserves, explain why the liquid portion of the reserves may be much

More information

MARGINAL COST OF INDUSTRIAL PRODUCTION

MARGINAL COST OF INDUSTRIAL PRODUCTION 2011 POLISH JOURNAL OF MANAGEMENT STUDIES MARGINAL COST OF INDUSTRIAL PRODUCTION Abstract: One of the important issues of production management is the most efficient possible use of the production capacity

More information

MySQL High Availability. MMM & MHA in DP 卢钧轶

MySQL High Availability. MMM & MHA in DP 卢钧轶 MySQL High Availability MMM & MHA in DP 卢钧轶 Agenda Why we need a HA solution MMM in DP MHA in DP When We Need to Switch Server Server down Server maintenance Logical : DDL on big table Physical: memory

More information

Kingdom Tower: A New Icon for Saudi Arabia

Kingdom Tower: A New Icon for Saudi Arabia ctbuh.org/papers Title: Author: Subject: Keywords: Kingdom Tower: A New Icon for Saudi Arabia Talal Al Maiman, Chairman, Kingdom Real Estate Development Company Architectural/Design Construction Design

More information

酷 刑 和 其 他 残 忍 不 人 道 或 有 辱 人 格 的 待 遇 或 处 罚 问 题 特 别 报 告 员 曼 弗 雷 德 诺 瓦 克 的 报 告

酷 刑 和 其 他 残 忍 不 人 道 或 有 辱 人 格 的 待 遇 或 处 罚 问 题 特 别 报 告 员 曼 弗 雷 德 诺 瓦 克 的 报 告 联 合 国 大 会 Distr.: General 11 October 2010 Chinese Original: English A/HRC/16/52/Add.3 人 权 理 事 会 第 十 六 届 会 议 议 程 项 目 3 增 进 和 保 护 所 有 人 权 公 民 权 利 政 治 权 利 经 济 社 会 和 文 化 权 利, 包 括 发 展 权 酷 刑 和 其 他 残 忍 不 人 道

More information

Whole Genome Based Plant Breeding: Platforms and Technologies

Whole Genome Based Plant Breeding: Platforms and Technologies Whole Genome Based Plant Breeding: Platforms and Technologies Gengyun Zhang Ph.D. BGI-SZ Email: [email protected] www.genomics.org.cn From a single gene to the whole genome 1984 Discussions

More information

Mobile TV Target Audience Measurement (Report 1)

Mobile TV Target Audience Measurement (Report 1) Mobile TV Target Audience Measurement (Report 1) Executive Summary VisionChina Media Inc. (NASDAQ: VISN) commissioned CTR Market Research, one of China s largest market research providers, to generate

More information

Red Pandas in China Population and Habitat Viability Assessment Workshop. 11-14 June 2012, Beijing, China FINAL REPORT

Red Pandas in China Population and Habitat Viability Assessment Workshop. 11-14 June 2012, Beijing, China FINAL REPORT Red Pandas in China Population and Habitat Viability Assessment Workshop 11-14 June 2012, Beijing, China FINAL REPORT Workshop organized by: Chinese Academy of Sciences (CAS), Institute of Zoology (IOZ);

More information

A web-based vocabulary profiler for Chinese language teaching and research

A web-based vocabulary profiler for Chinese language teaching and research A web-based vocabulary profiler for Chinese language teaching and research Jun Da, Middle Tennessee State University This paper describes the design and development of a web-based Chinese vocabulary profiler

More information

1.1 Exploded view of indoor unit for KF-26GW/GX1b,KFR-26GW/GX1b,

1.1 Exploded view of indoor unit for KF-26GW/GX1b,KFR-26GW/GX1b, . Exploded view of indoor unit for KF-26GW/GXb,KFR-26GW/GXb, Figure - .2 Spare parts list for indoor unit for KF-26GW/GXb,KFR-26GW/GXb Table form - No. Description KF-26GW/GXb(30) B0202620005 Part Code

More information

English. Copyright DEWALT

English. Copyright DEWALT DWD01S English 3 9 Copyright DEWALT 2 Figure 1 d c g b a e f Figure 2 c g b a 1 2 Figure 3 Figure 4 ENGLISH VARIABLE SPEED REVERSIBLE DRILL DWD01S Congratulations! You have chosen a DEWALT tool. Years

More information

Word Alignment of English-Chinese Bilingual Corpus Based on Chunks

Word Alignment of English-Chinese Bilingual Corpus Based on Chunks Word Alignment of English-Chinese Bilingual Corpus Based on s Sun Le, Jin Youbing, Du Lin, Sun Yufang Chinese Information Processing Center Institute of Software Chinese Academy of Sciences Beijing 100080

More information

Key Words: United Nations Peacebuilding, protection of human security, liberal

Key Words: United Nations Peacebuilding, protection of human security, liberal United Nations Peacebuilding and the Protection of Human Security He Yin 1 Abstract: Peacebuilding has been the core task of the United Nations peace operations since the end of the Cold War. The discourse

More information

PROFILES OF SPEAKERS, DISCUSSANTS AND MODERATORS * 发 言 人 评 论 员 与 主 持 人 简 历 (in alphabetical order)

PROFILES OF SPEAKERS, DISCUSSANTS AND MODERATORS * 发 言 人 评 论 员 与 主 持 人 简 历 (in alphabetical order) PROFILES OF SPEAKERS, DISCUSSANTS AND MODERATORS * 发 言 人 评 论 员 与 主 持 人 简 历 (in alphabetical order) CHANG Xiuze Chang Xiuze, born in 1945 in Huimin County of Shandong Province of China, is a professor,

More information

Procedures to file a request to the JPO for Patent Prosecution Highway Pilot Program between the JPO and the HPO

Procedures to file a request to the JPO for Patent Prosecution Highway Pilot Program between the JPO and the HPO Procedures to file a request to the JPO for Patent Prosecution Highway Pilot Program between the JPO and the HPO 1. to the JPO When an applicant files a request for an accelerated examination under the

More information

LC Paper No. PWSC269/15-16(01)

LC Paper No. PWSC269/15-16(01) Legislative Council Public Works Subcommittee meeting on 11 June 2016 118KA Renovation works for the West Wing of the former Central Government Offices for office use by the Department of Justice and law-related

More information

Translation of Repetitions in Text: A Systemic Functional Approach

Translation of Repetitions in Text: A Systemic Functional Approach International Journal of English Linguistics; Vol. 4, No. 5; 2014 ISSN 1923-869X E-ISSN 1923-8703 Published by Canadian Center of Science and Education Translation of Repetitions in Text: A Systemic Functional

More information

2014 年 12 月 英 语 六 级 考 试 真 题 试 卷 ( 第 1 套 )

2014 年 12 月 英 语 六 级 考 试 真 题 试 卷 ( 第 1 套 ) 2014 年 12 月 英 语 六 级 考 试 真 题 试 卷 ( 第 1 套 ) Part I Writing (30 minutes) Directions: For this part, you are allowed 30 minutes to write an essay based on the picture below. You should start your essay with

More information

China M&A goes global

China M&A goes global China M&A goes global Hairong Li of Zhong Lun Law Firm explains the new regulations affecting inbound and outbound M&A, the industries most targeted by Chinese and foreign investors and the unique strategies

More information

路 面 供 电 电 动 汽 车 感 应 电 能 传 输 系 统 综 述. A Review on Inductive Power Transfer Systems for Roadway Powered Electric Vehicles

路 面 供 电 电 动 汽 车 感 应 电 能 传 输 系 统 综 述. A Review on Inductive Power Transfer Systems for Roadway Powered Electric Vehicles 2013 年 电 工 技 术 学 报 Vol.28 Sup.2 第 28 卷 增 刊 2 TRANSACTIONS OF CHINA ELECTROTECHNICAL SOCIETY 2013 路 面 供 电 电 动 汽 车 感 应 电 能 传 输 系 统 综 述 田 勇 1, 夏 必 忠 1*, 徐 智 慧 2, 孙 威 2, 郑 伟 伟 (1. 清 华 大 学 深 圳 研 究 生 院 深 圳 518055

More information

Wuhan University of Technology MBA Thesis

Wuhan University of Technology MBA Thesis Sort No. Secrete Level UDC University Code 10497 Wuhan University of Technology MBA Thesis Title Service Quality Analysis in the Five Stars Resort Hotels of Cape Verde Name of Postgraduate Hegel Lubrano

More information

Complexe Teaching Methods

Complexe Teaching Methods Fakultät Erziehungswissenschaften Institut für Berufspädagogik und Berufliche Didaktiken Complexe Teaching Methods History Beijing, September 2014 The Basic Idea of the Complex Teaching Methods to create

More information

南 京 农 业 大 学 农 业 资 源 与 生 态 环 境 研 究 所 土 壤 碳 氮 循 环 与 气 候 变 化 研 究 团 队 2009 年 报 2010 年 1 月 1 日, 南 京

南 京 农 业 大 学 农 业 资 源 与 生 态 环 境 研 究 所 土 壤 碳 氮 循 环 与 气 候 变 化 研 究 团 队 2009 年 报 2010 年 1 月 1 日, 南 京 南 京 农 业 大 学 农 业 资 源 与 生 态 环 境 研 究 所 土 壤 碳 氮 循 环 与 气 候 变 化 研 究 团 队 2009 年 报 2010 年 1 月 1 日, 南 京 写 在 前 面 的 话 在 新 年 的 钟 声 敲 响 的 时 候, 回 顾 过 去 一 年 我 们 走 过 的 里 程, 历 数 我 们 的 收 获, 无 不 感 受 国 家 发 展 带 给 我 们 的 机 遇,

More information

Wi-Drive User Guide. (for use with Amazon s Kindle Fire) Document No. 480WID4KF-001.A01 Kingston Wi-Drive Page 1 of 15

Wi-Drive User Guide. (for use with Amazon s Kindle Fire) Document No. 480WID4KF-001.A01 Kingston Wi-Drive Page 1 of 15 Wi-Drive User Guide (for use with Amazon s Kindle Fire) Document No. 480WID4KF-001.A01 Kingston Wi-Drive Page 1 of 15 Table of Contents Introduction... 3 Requirements... 3 Supported File Types... 3 Install

More information

SHAU KEI WAN GOVERNMENT SECONDARY SCHOOL

SHAU KEI WAN GOVERNMENT SECONDARY SCHOOL 香 港 柴 灣 道 42 號 42 Chai Wan Road, Hong Kong Tel : (852) 2560 3544 Fax : (852) 2568 9708 URL : www.sgss.edu.hk Email : [email protected] 筲 箕 灣 官 立 中 學 SHAU KEI WAN GOVERNMENT SECONDARY SCHOOL --------------------------------------------------------------------------------------------------------------------------------

More information

Transcription methods for consistency, volume and efficiency

Transcription methods for consistency, volume and efficiency Transcription methods for consistency, volume and efficiency Meghan Lammie Glenn, Stephanie M. Strassel, Haejoong Lee, Kazuaki Maeda, Ramez Zakhary, Xuansong Li Linguistic Data Consortium, University of

More information

Case Study of a New Generation Call Center

Case Study of a New Generation Call Center Case Study of a New Generation Call Center Chiung-I Chang* and tzy-yau lee** *Department of Information Management National Taichung Institute of Technology E-mail: [email protected] **Department of Leisure

More information

南 宁 二 中 2013 届 高 三 英 语 2 月 月 考 试 题

南 宁 二 中 2013 届 高 三 英 语 2 月 月 考 试 题 南 宁 二 中 2013 届 高 三 英 语 2 月 月 考 试 题 第 I 卷 第 一 部 分 : 听 力 ( 共 两 节, 满 分 30 分 ) 做 题 时, 先 将 答 案 划 在 试 卷 上 录 音 内 容 结 束 后, 你 将 有 两 分 钟 的 时 间 将 试 卷 上 的 答 案 转 涂 到 答 题 卡 上 第 一 节 : 听 下 面 5 段 对 话, 每 段 对 话 后 有 一 个 小

More information

WORKING PAPER. Analysis of China s overseas investment policies. Huang Wenbin Andreas Wilkes

WORKING PAPER. Analysis of China s overseas investment policies. Huang Wenbin Andreas Wilkes WORKING PAPER Analysis of China s overseas investment policies Huang Wenbin Andreas Wilkes Working Paper 79 Analysis of China s overseas investment policies Huang Wenbin World Agroforestry Centre, China

More information

Ex. Either we must get in line early to buy the tickets, or only scalpers INDEPENDENT CLAUSE 1 INDEPENDENT tickets will be available.

Ex. Either we must get in line early to buy the tickets, or only scalpers INDEPENDENT CLAUSE 1 INDEPENDENT tickets will be available. THIRTEENTH WEEK PAGE 1 COMPOUND SENTENCES II The COMPOUND SENTENCE A. A COMPOUND SENTENCE contains two or more INDEPENDENT clauses. B. INDEPENDENT CLAUSES CAN stand alone, so it is very easy to separate

More information

Microsoft SQL Server PDW 新世代 MPP 資料倉儲解決方案

Microsoft SQL Server PDW 新世代 MPP 資料倉儲解決方案 DBI304 Microsoft SQL Server PDW 新世代 MPP 資料倉儲解決方案 徐園程 Sr. Technical Account Manager [email protected] 微軟資料倉儲的願景 未來趨勢 Appliance PDW AU3 新功能 Hub & Spoke 架構運用 PDW & Big Data 大綱 客戶案例分享 與其他 MPP 比較 100%

More information

Chemistry I -- Final Exam

Chemistry I -- Final Exam Chemistry I -- Final Exam 01/1/13 Periodic Table of Elements Constants R = 8.314 J / mol K 1 atm = 760 Torr = 1.01x10 5 Pa = 0.081 L atm / K mol c =.9910 8 m/s = 8.314 L kpa / K mol h = 6.6310-34 Js Mass

More information

China s Agricultural Investment in Latin America. Margaret Myers Inter- American Dialogue November 21, 2013

China s Agricultural Investment in Latin America. Margaret Myers Inter- American Dialogue November 21, 2013 China s Agricultural Investment in Latin America Margaret Myers Inter- American Dialogue November 21, 2013 Main Points 1. China is commi@ed to achieving self- sufficiency in food produceon 2. But produceon

More information

JAPAN PATENT OFFICE AS DESIGNATED (OR ELECTED) OFFICE CONTENTS

JAPAN PATENT OFFICE AS DESIGNATED (OR ELECTED) OFFICE CONTENTS Page 1 JP JAPAN PATENT OFFICE AS DESIGNATED (OR ELECTED) OFFICE CONTENTS THE ENTRY INTO THE NATIONAL PHASE SUMMARY THE PROCEDURE IN THE NATIONAL PHASE ANNEXES Fees... Annex JP.I Form No. 53: Transmittal

More information

Application Guidelines for International Graduate Programs in Engineering

Application Guidelines for International Graduate Programs in Engineering Global 30: Future Global Leadership (FGL) 2016 Academic Year (April 2016 Enrollment) Application Guidelines for International Graduate Programs in Engineering International Mechanical and Aerospace Engineering

More information

Kingston MobileLite Wireless. (ßeta Release) Document No. 480WD+MLW.ß01 Kingston MobileLite Wireless (ßeta) Page 1 of 12

Kingston MobileLite Wireless. (ßeta Release) Document No. 480WD+MLW.ß01 Kingston MobileLite Wireless (ßeta) Page 1 of 12 Kingston MobileLite Wireless (ßeta Release) Document No. 480WD+MLW.ß01 Kingston MobileLite Wireless (ßeta) Page 1 of 12 Introduction MobileLite Wireless (simply referred to as MLW from this point forward)

More information

Intel RAID Premium Feature Key AXXRPFKSSD, AXXRPFKDE, and AXXRPFKSNSH Installation Guide

Intel RAID Premium Feature Key AXXRPFKSSD, AXXRPFKDE, and AXXRPFKSNSH Installation Guide Intel RAID Premium Feature Key AXXRPFKSSD, AXXRPFKDE, and AXXRPFKSNSH Installation Guide Order Number: E88588-001 E88588-001 IMPORTANT: Your Intel RAID Controller must be programmed with the latest Intel

More information

Mini-review Diagnosis and Treatment of Chinese Medicine and Western Medicine on Refractory Chronic Pelvic Pain 难 治 性 盆 腔 痛 的 中 西 医 诊 治

Mini-review Diagnosis and Treatment of Chinese Medicine and Western Medicine on Refractory Chronic Pelvic Pain 难 治 性 盆 腔 痛 的 中 西 医 诊 治 Sponsored by: Nanjing Municipal Hospital of Chinese Medicine (www. Njszyy.cn) and Nanjing Public Health Bureau (www.nanjing.gov.cn) International Union for Difficult-to-treat-Diseases (www.iudd.org) Mini-review

More information

Microsoft Big Data 解決方案與案例分享

Microsoft Big Data 解決方案與案例分享 DBI 312 Microsoft Big Data 解決方案與案例分享 Rich Ho Technical Architect 微軟技術中心 Agenda What is Big Data? Microsoft Big Data Strategy Key Benefits of Microsoft Big Data Demo Case Study What is Big Data? The world

More information

Machine Translation for Academic Purposes

Machine Translation for Academic Purposes Proceedings of the International Conference on TESOL and Translation 2009 December 2009: pp.133-148 Machine Translation for Academic Purposes Grace Hui-chin Lin PhD Texas A&M University College Station

More information

ASSESSING ACCESS TO INFORMATION IN CHINA 评 析 中 国 的 政 府 信 息 公 开 制 度 JENS F. REINERTSEN 专 业 : 国 际 法 学 研 究 方 向 : 国 际 经 济 法 教 师 : 莫 世 健 教 授

ASSESSING ACCESS TO INFORMATION IN CHINA 评 析 中 国 的 政 府 信 息 公 开 制 度 JENS F. REINERTSEN 专 业 : 国 际 法 学 研 究 方 向 : 国 际 经 济 法 教 师 : 莫 世 健 教 授 论 文 编 号 : ASSESSING ACCESS TO INFORMATION IN CHINA LEGAL DEVELOPMENT AND INTERNATIONAL STANDARDS 评 析 中 国 的 政 府 信 息 公 开 制 度 从 法 律 发 展 和 国 际 标 准 的 角 度 JENS F. REINERTSEN 专 业 : 国 际 法 学 研 究 方 向 : 国 际 经 济 法

More information

歐 洲 難 民 潮 對 經 濟 的 影 響 The Economic Implications of Europe s Refugee Influx

歐 洲 難 民 潮 對 經 濟 的 影 響 The Economic Implications of Europe s Refugee Influx 歐 洲 難 民 潮 對 經 濟 的 影 響 The Economic Implications of Europe s Refugee Influx 沈 旭 暉 副 教 授 香 港 中 文 大 學 國 際 事 務 研 究 中 心 聯 席 主 任 Dr Simon Shen Co-Director International Affairs Research Center Hong Kong Institute

More information

BETTER TREATMENT OPTIONS NOW FOR OVARIAN CANCER ...HELPING READERS TO ACHIEVE GOOD HEALTH. AN NCCS QUARTERLY PUBLICATION April June 2014

BETTER TREATMENT OPTIONS NOW FOR OVARIAN CANCER ...HELPING READERS TO ACHIEVE GOOD HEALTH. AN NCCS QUARTERLY PUBLICATION April June 2014 Issue No. 29 MICA (P) 40/03/204 AN NCCS UARTERLY PUBLICATION April June 204...HELPING READERS TO ACHIEVE GOOD HEALTH Salubris is a Latin word which means healthy, in good condition (body) and wholesome.

More information

EW-7438RPn Mini 安 裝 指 南. 07-2014 / v1.0

EW-7438RPn Mini 安 裝 指 南. 07-2014 / v1.0 EW-7438RPn Mini 安 裝 指 南 07-2014 / v1.0 I. 產 品 資 訊 I-1. 包 裝 內 容 - EW-7438RPn Mini - CD 光 碟 ( 快 速 安 裝 指 南 及 使 用 者 手 冊 ) - 快 速 安 裝 指 南 - 連 線 密 碼 卡 I-2. 系 統 需 求 - 無 線 訊 號 延 伸 / 無 線 橋 接 模 式 : 使 用 現 有 2.4GHz

More information

Grant Request Form. Request Form. (For continued projects)

Grant Request Form. Request Form. (For continued projects) Grant Request Form Request Form (For continued projects) NOTE: Check list of the needed documents Following documents should be prepared in Japanese. Continuing grant projects from FY2015(or FY2014) don

More information

北 京 地 区 成 人 本 科 学 士 学 位 英 语 统 一 考 试 2015.05.09

北 京 地 区 成 人 本 科 学 士 学 位 英 语 统 一 考 试 2015.05.09 更 多 内 容 请 查 看 精 品 文 库 网 www.jingpinwenku.com 北 京 地 区 成 人 本 科 学 士 学 位 英 语 统 一 考 试 2015.05.09 Part I Reading Comprehension (30%) Directions: There are three passages in this part. Each passage is followed

More information

The HKICPA Accounting and Business Management Case Competition 2015-16. Secondary School Group (Level 1)

The HKICPA Accounting and Business Management Case Competition 2015-16. Secondary School Group (Level 1) The HKICPA Accounting and Business Management Case Competition 2015-16 Secondary School Group (Level 1) The HKICPA Accounting and Business Management Case Competition 2015-16 Secondary School Group (Level

More information

JPShiKen.COM 全 日 本 最 新 の IT 認 定 試 験 問 題 集

JPShiKen.COM 全 日 本 最 新 の IT 認 定 試 験 問 題 集 JPShiKen.COM 全 日 本 最 新 の IT 認 定 試 験 問 題 集 最 新 の IT 認 定 試 験 資 料 のプロバイダ 参 考 書 評 判 研 究 更 新 試 験 高 品 質 学 習 質 問 と 回 答 番 号 教 科 書 難 易 度 体 験 講 座 初 心 者 種 類 教 本 ふりーく 方 法 割 引 復 習 日 記 合 格 点 学 校 教 材 ス クール 認 定 書 籍 攻

More information

轎 車 機 場 接 送 及 往 返 澳 門 與 香 港 機 場 接 送 服 務 禮 遇 ( 推 廣 ) 之 條 款 及 細 則 :

轎 車 機 場 接 送 及 往 返 澳 門 與 香 港 機 場 接 送 服 務 禮 遇 ( 推 廣 ) 之 條 款 及 細 則 : 一 般 條 款 及 細 則 Terms & Conditions : 轎 車 機 場 接 送 及 往 返 澳 門 與 香 港 機 場 接 送 服 務 禮 遇 ( 推 廣 ) 之 條 款 及 細 則 : (I) 一 般 條 款 : 1. 轎 車 機 場 接 送 及 往 返 澳 門 與 香 港 機 場 接 送 服 務 禮 遇 推 廣 由 即 日 起 至 2016 年 12 月 31 日 止 ( 推 廣

More information

Tradition and Ideology

Tradition and Ideology Ziying You The Ohio State University Tradition and Ideology Creating and Performing New Gushi in China, 1962 1966 It is well known that invented tradition played an important role in many nationalist political

More information

Customers' Trust and Purchase Intention towards. Taobao's Alipay (China online marketplace)

Customers' Trust and Purchase Intention towards. Taobao's Alipay (China online marketplace) Customers' Trust and Purchase Intention towards Taobao's Alipay (China online marketplace) By Wong Tak Yan, Isabella 08032084 & Yeung Yuen Ha, Rabeea 08037728 An Honours Degree Project Submitted to the

More information

Market Access To Taiwan. By Jane Peng TÜV Rheinland Taiwan Ltd.

Market Access To Taiwan. By Jane Peng TÜV Rheinland Taiwan Ltd. Market Access To Taiwan By Jane Peng TÜV Rheinland Taiwan Ltd. Content General Introduction Taiwan BSMI mark Products, Scope and approval scheme News Update TÜV Rheinland s One-Stop Services Contact info.

More information

Sentiment Analysis in Chinese. Master's Thesis. Presented to. The Faculty of the Graduate School of Arts and Sciences. Brandeis University

Sentiment Analysis in Chinese. Master's Thesis. Presented to. The Faculty of the Graduate School of Arts and Sciences. Brandeis University Sentiment Analysis in Chinese Master's Thesis Presented to The Faculty of the Graduate School of Arts and Sciences Brandeis University Department of Computer Science Nianwen Xue, Advisor In Partial Fulfillment

More information

2008 年 12 月 大 学 英 语 四 级 考 试 真 题

2008 年 12 月 大 学 英 语 四 级 考 试 真 题 2008 年 12 月 大 学 英 语 四 级 考 试 真 题 Part I Writing(30 minutes) Directions: For this part, you are allowed 30 minutes to write a short essay entitled Limiting the Use of Disposable Plastic Bag. You should write

More information

TUTORING SERVICE WITH CDAC 2016

TUTORING SERVICE WITH CDAC 2016 TUTORING SERVICE WITH CDAC 2016 Qualifications NIE-trained and/or Ex-MOE School Teachers (left service for not more than 5 years); or Trainee teachers; or A recognised General Degree holder with at least

More information

Graduate School of Engineering. Master s Program, 2016 (October entrance)

Graduate School of Engineering. Master s Program, 2016 (October entrance) Application Procedure for Foreign Student Admission to Graduate School of Engineering Master s Program, 2016 (October entrance) Tottori University 4-101 Koyama-Minami, Tottori, 680-8552 Japan Phone: +81-857-31-6761

More information

Request for Taxpayer Identification Number and Certification 納 税 者 番 号 および 宣 誓 の 依 頼 書

Request for Taxpayer Identification Number and Certification 納 税 者 番 号 および 宣 誓 の 依 頼 書 Substitute Form 代 替 様 式 W-9 Print or type Request for Taxpayer Identification Number and Certification 納 税 者 番 号 および 宣 誓 の 依 頼 書 英 字 活 字 体 またはタイプでご 記 入 下 さい 1 Name (as shown on your income tax return),

More information

Model 123A24. Rocket motor ICP pressure sensor, 1000 psi, 5 mv/psi, Helium bleed, Installation and Operating Manual

Model 123A24. Rocket motor ICP pressure sensor, 1000 psi, 5 mv/psi, Helium bleed, Installation and Operating Manual Model 123A24 Rocket motor ICP pressure sensor, 1000 psi, 5 mv/psi, Helium bleed, Installation and Operating Manual For assistance with the operation of this product, contact PCB Piezotronics, Inc. Toll-free:

More information

促 進 市 場 競 爭 加 強 保 障 消 費 者

促 進 市 場 競 爭 加 強 保 障 消 費 者 通 訊 事 務 管 理 局 辦 公 室 2013 14 年 營 運 基 金 報 告 書 5 Facilitating Market Competition and Strengthening Consumer Protection 處 理 和 調 查 有 關 具 誤 導 性 或 欺 騙 性 行 為 的 電 訊 服 務 投 訴 2012 年 商 品 說 明 ( 不 良 營 商 手 法 )( 修 訂 )

More information

weekly Our mission Our history Our footprint Our award-winning content 2015 Media Kit asian northwest

weekly Our mission Our history Our footprint Our award-winning content 2015 Media Kit asian northwest 2015 Media Kit asian Our mission Asian Pacific American communities have been called, The market of the 21st century. The Northwest Asian Weekly (NWAW) and our sister paper, The Seattle Chinese Post (SCP),

More information