Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Go Crypto Trading

Yo-An Lin
November 21, 2020

Go Crypto Trading

In the slides, we introduce the background of Bitcoin's origin, explain public finance, and why decentralized finance might work. Lastly, introduce BBGO's trading framework and the strategies.

Yo-An Lin

November 21, 2020
Tweet

More Decks by Yo-An Lin

Other Decks in Technology

Transcript

  1. Yo-An Lin (c9s) 2020 Nov 1
    Go Crypto Trading
    Build your own crypto trading bot in few minutes.

    View Slide

  2. Cryptos? Really?

    View Slide

  3. 2008 Bitcoin

    View Slide

  4. Let’s go back to 2008

    View Slide

  5. View Slide

  6. Bank-based Financial System

    View Slide

  7. Public
    Finance

    View Slide

  8. How Government Bond Works
    Interest

    View Slide

  9. How Corporate Bond Works?
    Interest
    Issue corporate bond
    Corporate Fund
    Individuals
    Individuals
    Individuals

    View Slide

  10. How Junk Bond Works?
    Interest (high yield)
    Issue corporate bond
    Corporate

    (Low Credit Rating)
    Bank
    Investor
    High yield bond

    View Slide

  11. Securitization
    Bundled Mortgages
    Bank
    Investor
    Investor
    Investor

    View Slide

  12. Government National
    Mortgage Association
    吉利美

    View Slide

  13. Government
    Sponsored Enterprise
    房地美

    View Slide

  14. 名稱都有 Government

    View Slide

  15. 其實都是私⼈機構

    View Slide

  16. 房利美可以購買非政府擔保的房貸債權
    並證券化來發⾏抵押債券

    View Slide

  17. 吉⼒美只為抵押債券提供擔保
    沒有美國政府信⽤擔保

    View Slide

  18. View Slide

  19. Bank Run
    銀⾏擠兌

    View Slide

  20. QE
    Corporation

    (Low Credit Rating)
    Corporation
    Financial Institutions
    Lower Interest Rate

    View Slide

  21. View Slide

  22. Yes, Your Bank Can Fail

    View Slide

  23. This is not the first time

    View Slide

  24. 存在銀⾏裡的錢
    銀⾏會拿去投資

    View Slide

  25. 不同銀⾏的投資比例不同

    View Slide

  26. 虧錢的投資變成壞帳

    View Slide

  27. 授信弊案也會變成壞帳

    View Slide

  28. View Slide

  29. 1930 年經濟⼤蕭條

    View Slide

  30. Glass-Steagall Act
    格拉斯-斯蒂格爾法案

    View Slide

  31. 對美國銀⾏系統進⾏改⾰的法律,描述了
    1933年銀⾏法分離商業銀⾏和投資銀⾏
    業務的四個規定
    美國聯邦存款保險公司是依此法成立。這
    部法律的⽬的在於對投機採取⼀些控制措
    施。

    View Slide

  32. 允許聯邦儲備系統調節存儲帳號的利息,
    被1980年儲蓄機構解除管制和貨幣控制
    法取消
    禁⽌銀⾏控股公司擁有其它⾦融公司的規
    定被1999年11⽉12⽇⽣效的⾦融服務法
    現代化法案取消

    View Slide

  33. 那 2008 年之後呢?

    View Slide

  34. 沃爾克法則
    由美聯儲1979-1987年的前主席、前任美國
    總統經濟複蘇顧問委員會主席 Paul
    Volcker 提出

    View Slide

  35. 禁⽌銀⾏從事⾃營性質的投資業務
    禁⽌銀⾏擁有、投資或發起對沖基⾦和私募
    基⾦

    View Slide

  36. 那現在呢?

    View Slide

  37. View Slide

  38. View Slide

  39. 歷史⼀直在重演

    View Slide

  40. ⽤區塊鏈達成去中⼼化⾦融
    Decentralized Finance

    View Slide

  41. 由機器來⾃動處理轉帳、放貸

    View Slide

  42. View Slide

  43. 有⼈把 Bitcoin 視為

    View Slide

  44. 美元或歐元以外的避險資產

    View Slide

  45. View Slide

  46. Bitcoin 2019~2020 1w interval

    View Slide

  47. 為何要做加密貨幣交易?

    View Slide

  48. 傳統⾦融市場

    View Slide

  49. 開盤時間 收盤時間

    View Slide

  50. 交易額度限制

    View Slide

  51. 漲停跌停

    View Slide

  52. 相對封閉的市場

    View Slide

  53. 加密貨幣⾦融市場

    View Slide

  54. 24H 全年無休交易所

    View Slide

  55. 可隨時轉出轉入全球交易所

    View Slide

  56. 新世代的交易系統

    View Slide

  57. 以及更有效率的撮合引擎

    View Slide

  58. 相對透明的交易市場

    View Slide

  59. View Slide


  60. View Slide

  61. 為什麼要⾃動交易?

    View Slide

  62. 情緒⼲擾交易

    View Slide

  63. View Slide

  64. View Slide

  65. View Slide

  66. View Slide

  67. 正確的交易⼼態 Trading Attitude

    View Slide

  68. 我對錢沒有興趣

    View Slide

  69. Algorithmic Trading

    View Slide

  70. Algorithmic trading is a method of executing orders using
    automated pre-programmed trading instructions accounting for
    variables such as time, price, and volume.

    This type of trading was developed to make use of the speed and
    data processing advantages that computers have over human
    traders.

    View Slide

  71. Quantitative analysis is the use of mathematical and statistical
    methods (mathematical finance) in finance. Those working in the field
    are quantitative analysts (or, in financial jargon, a quant).

    View Slide

  72. View Slide

  73. James Simons
    American mathematician,
    Billionaire hedge fund manager,
    Former research staff of the
    Communications Research
    Division of the Institute for
    Defense Analyses (IDA)

    View Slide

  74. ⽂藝復興是全世界名氣最響的對沖基⾦公司之⼀,其創始⼈詹姆斯·
    ⻄蒙斯 (James Simons) 堪稱傳奇⼈物。他有很多外號,比如“華爾
    街最賺錢的數學家”、“全球最賺錢的基⾦經理”、“量化交易之
    ⽗”等。
    Renaissance Technologies

    View Slide

  75. 根據彭博社億萬富翁指數 (Bloomberg Billionaire Index) 顯⽰,Simons 在 2016
    年的⾝家⼤約值 155 億美元左右。根據 Hedge Fund Research 報導,James
    Simons 在 2016 年的收入為 16 億美元,位於世界對沖基⾦經理收入榜單⾸位。

    View Slide

  76. ⼤獎章對沖基⾦

    成立於 1988 年。“⼤獎章”是⼀個典型的量化“⿊盒⼦”基⾦,其交易策
    略都是基於複雜的電腦程式碼和演算法,外⼈無從知道它的交易規
    則。
    Medallion

    View Slide

  77. The Man Who Solved the Market:
    How Jim Simons Launched the
    Quant Revolution

    View Slide

  78. 交易策略 Trading Strategy

    View Slide

  79. 選擇交易商品

    View Slide

  80. 定義進場與出場條件

    View Slide

  81. • Market neutral strategy

    • Swing trading strategy

    • News trading strategy

    • Signal trading strategy

    • Day trading

    • ……

    View Slide

  82. Market Neutral Strategy

    View Slide

  83. Pure Market Making

    View Slide

  84. Place Sell Order
    Place Buy Order

    View Slide

  85. Cross Exchange Market Making

    View Slide

  86. Hedging is a strategy for reducing exposure to investment risk.
    An investor can hedge the risk of one investment by taking an
    offsetting position in another investment. The values of the
    offsetting investments should be inversely correlated.

    View Slide

  87. Cross Exchange Market Making

    View Slide

  88. Cross Exchange Market Making

    View Slide

  89. SELL
    BUY
    BUY BACK
    SELL
    Hedge
    Low Risk

    View Slide

  90. Swing Trading

    View Slide

  91. View Slide

  92. Grid Trading

    View Slide

  93. View Slide

  94. Bollinger-Band Grid Trading

    View Slide

  95. upper price
    lower price

    View Slide

  96. BBGO
    The Open Source Crypto Trading Framework

    View Slide

  97. BBGO
    Trading framework
    • Open Source & Transparency - you run what you can see.

    • KISS principle designed framework - simple, easy to use for users.

    • Minimalist design strategy interface - ~20 lines go code to implement a new
    strategy.

    • One config to rule them all.

    • Multi-exchange session support.

    • Run multiple strategies in one process.

    View Slide

  98. View Slide

  99. Exchange
    RESTful API
    WebSocket
    FIX protocol
    BBGO
    Balance Update
    Trade Update
    Order Update
    Place Order
    Matching Engine
    Order Book
    Strategy #1
    Strategy #2
    Strategy #3
    Public Market Data

    View Slide

  100. Public Market Data?

    View Slide

  101. View Slide

  102. Bid Orders Ask Orders

    View Slide

  103. 買單掛的價格未成交,會被掛在買單簿上 = maker 賣單掛的價格未成交,會被掛在賣單簿上 = maker

    View Slide

  104. Best Bid Best Ask

    View Slide

  105. Best Bid
    Sell Order @ 16,342.75
    賣單直接與買單成交 = taker

    View Slide

  106. Best Ask
    Buy Order @ 16,342.76
    買單直接與第⼀檔賣單成交 = taker

    View Slide

  107. One Config File to Run Multiple
    Strategies

    View Slide

  108. exchangeStrategies:
    - on: binance
    bollgrid:
    symbol: BTCUSDT
    interval: 5m
    gridNumber: 20
    quantity: 0.01
    profitSpread: 30.0
    策略可以掛在任何⼀個交易所

    View Slide

  109. exchangeStrategies:
    - on: binance
    bollgrid:
    symbol: BTCUSDT
    interval: 5m
    gridNumber: 20
    quantity: 0.01
    profitSpread: 30.0
    策略設定檔

    View Slide

  110. 基礎風險控制

    View Slide

  111. riskControls:
    sessionBased:
    # "binance" is the session name that you want to configure the risk control
    binance:
    # orderExecutor is one of the risk control
    orderExecutor:
    # symbol-routed order executor
    bySymbol:
    BTCUSDT:
    # basic risk control order executor
    basic:
    minQuoteBalance: 100.0
    maxBaseAssetBalance: 3.0
    minBaseAssetBalance: 0.0
    maxOrderAmount: 1000.0
    下單的風險控管

    View Slide

  112. 開發⾃⼰的交易策略?
    Writing your own trading strategy?

    View Slide

  113. You Only Need Two Methods

    View Slide

  114. type Strategy struct {
    Symbol string `json:"symbol"`
    }
    func (s *Strategy) Subscribe(session *bbgo.ExchangeSession) {
    }
    func (s *Strategy) Run(ctx context.Context,
    orderExecutor bbgo.OrderExecutor,
    session *bbgo.ExchangeSession) error {
    return nil
    }

    View Slide

  115. Connecting Your Strategy

    View Slide

  116. func init() {
    bbgo.RegisterStrategy("skeleton", &Strategy{})
    }
    type Strategy struct {
    Symbol string `json:"symbol"`
    }
    func (s *Strategy) Subscribe(session *bbgo.ExchangeSession) {
    session.Subscribe(types.KLineChannel, s.Symbol, types.SubscribeOptions{Interval: "1m"})
    }
    func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, session *bbgo.ExchangeSession) error {
    session.Stream.OnKLineClosed(func(kline types.KLine) {
    _, err := orderExecutor.SubmitOrders(ctx, types.SubmitOrder{
    Symbol: kline.Symbol,
    Side: types.SideTypeBuy,
    Type: types.OrderTypeMarket,
    Quantity: 0.01,
    })
    if err != nil {
    log.WithError(err).Error("submit order error")
    }
    })
    return nil
    }
    註冊交易策略

    View Slide

  117. func init() {
    bbgo.RegisterStrategy("skeleton", &Strategy{})
    }
    type Strategy struct {
    Symbol string `json:"symbol"`
    }
    func (s *Strategy) Subscribe(session *bbgo.ExchangeSession) {
    session.Subscribe(types.KLineChannel, s.Symbol, types.SubscribeOptions{Interval: "1m"})
    }
    func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, session *bbgo.ExchangeSession) error {
    session.Stream.OnKLineClosed(func(kline types.KLine) {
    _, err := orderExecutor.SubmitOrders(ctx, types.SubmitOrder{
    Symbol: kline.Symbol,
    Side: types.SideTypeBuy,
    Type: types.OrderTypeMarket,
    Quantity: 0.01,
    })
    if err != nil {
    log.WithError(err).Error("submit order error")
    }
    })
    return nil
    }
    策略的 struct, ⽤來讀設定

    View Slide

  118. func init() {
    bbgo.RegisterStrategy("skeleton", &Strategy{})
    }
    type Strategy struct {
    Symbol string `json:"symbol"`
    }
    func (s *Strategy) Subscribe(session *bbgo.ExchangeSession) {
    session.Subscribe(types.KLineChannel, s.Symbol, types.SubscribeOptions{Interval: "1m"})
    }
    func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, session *bbgo.ExchangeSession) error {
    session.Stream.OnKLineClosed(func(kline types.KLine) {
    _, err := orderExecutor.SubmitOrders(ctx, types.SubmitOrder{
    Symbol: kline.Symbol,
    Side: types.SideTypeBuy,
    Type: types.OrderTypeMarket,
    Quantity: 0.01,
    })
    if err != nil {
    log.WithError(err).Error("submit order error")
    }
    })
    return nil
    }
    策略訂閱 K-line 資料

    View Slide

  119. func init() {
    bbgo.RegisterStrategy("skeleton", &Strategy{})
    }
    type Strategy struct {
    Symbol string `json:"symbol"`
    }
    func (s *Strategy) Subscribe(session *bbgo.ExchangeSession) {
    session.Subscribe(types.KLineChannel, s.Symbol, types.SubscribeOptions{Interval: "1m"})
    }
    func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, session *bbgo.ExchangeSession) error {
    session.Stream.OnKLineClosed(func(kline types.KLine) {
    _, err := orderExecutor.SubmitOrders(ctx, types.SubmitOrder{
    Symbol: kline.Symbol,
    Side: types.SideTypeBuy,
    Type: types.OrderTypeMarket,
    Quantity: 0.01,
    })
    if err != nil {
    log.WithError(err).Error("submit order error")
    }
    })
    return nil
    }
    K-line 結束就下單

    View Slide

  120. 內建布林網格通道策略
    Built-in Bollinger Grid Strategy

    View Slide

  121. 網格到底賺錢嗎?

    View Slide

  122. 固定價格區間網格

    View Slide

  123. 固定價位網格獲利能⼒

    View Slide

  124. BTC HODL

    View Slide

  125. 抱著 BTC 不動
    都賺得比固定網格多

    View Slide

  126. 鄉⺠曬單通常都曬 ETH
    因為波動比 BTC ⼩

    View Slide

  127. 答案是可以
    但是可以賺更多嗎?

    View Slide

  128. 讓網格不要再進場

    View Slide

  129. 價格拉升速度快突破 EWMA 很多的時候預計會有拉回,不要再下買單

    View Slide

  130. 獲利多⼀倍

    View Slide

  131. Thank You

    View Slide

  132. Disclaimer:
    TradeAtYourOwnRisk

    View Slide

  133. 投資⼀定有風險,基⾦投資有賺有賠,申購前應詳閱公開說明書。

    View Slide

  134. 可能沒時間 Q & A
    但可以來我們公司找我討論

    View Slide

  135. View Slide

  136. 全台第⼀家加密貨幣實體⾨市
    ⾨市⼈員與客⼾⾯對⾯介紹交易
    平台產品
    同時活動展演廳不定時會舉辦區
    塊鏈主題講座與知識課程,活絡
    加密貨幣社群與開拓新會員。

    View Slide

  137. MAX 9USDT
    REFERAL
    https://bit.ly/max-9usdt

    View Slide