<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          ZiplinePythonic 交易算法庫(kù)

          聯(lián)合創(chuàng)作 · 2023-09-30 16:13

          Zipline 是一個(gè) Pythonic 算法交易庫(kù)。 它是一個(gè)事件驅(qū)動(dòng)的系統(tǒng),支持回測(cè)檢驗(yàn)和實(shí)時(shí)交易。

          Zipline 目前在生產(chǎn)中用作 Quantopian(托管平臺(tái)) 的測(cè)試和實(shí)時(shí)交易引擎。

          特性

          • 使用簡(jiǎn)單,以便你可以專(zhuān)注于算法開(kāi)發(fā)

          • 帶有許多常見(jiàn)的統(tǒng)計(jì)數(shù)據(jù),包括常用統(tǒng)計(jì)方法如移動(dòng)平均和線性回歸

          • 歷史數(shù)據(jù)的輸入和性能統(tǒng)計(jì)的輸出基于 Pandas DataFrames,與現(xiàn)有 python 生態(tài)圈能很好融合

          • 一些常用統(tǒng)計(jì)和機(jī)器學(xué)習(xí)庫(kù),如 matplotlib、scipy、statsmodels 和 sklearn,支持交易系統(tǒng)的開(kāi)發(fā)、數(shù)據(jù)分析和可視化

          快速開(kāi)始

          下面的代碼實(shí)現(xiàn)了一個(gè)簡(jiǎn)單的雙重移動(dòng)平均算法。

          from zipline.api import (
              history,
              order_target,
              record,
              symbol,
          )
          
          
          def initialize(context):
              context.i = 0
          
          
          def handle_data(context, data):
              # Skip first 300 days to get full windows
              context.i += 1
              if context.i < 300:
                  return
          
              # Compute averages
              # history() has to be called with the same params
              # from above and returns a pandas dataframe.
              short_mavg = history(100, '1d', 'price').mean()
              long_mavg = history(300, '1d', 'price').mean()
          
              sym = symbol('AAPL')
          
              # Trading logic
              if short_mavg[sym] > long_mavg[sym]:
                  # order_target orders as many shares as needed to
                  # achieve the desired number of shares.
                  order_target(sym, 100)
              elif short_mavg[sym] < long_mavg[sym]:
                  order_target(sym, 0)
          
              # Save values for later inspection
              record(AAPL=data[sym].price,
                     short_mavg=short_mavg[sym],
                     long_mavg=long_mavg[sym])
          瀏覽 26
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報(bào)
          評(píng)論
          圖片
          表情
          推薦
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報(bào)
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  欧美亚洲色综久久精品国产 | 色五月 丁香 婷婷 | 激情五月综合 | 91精品久久久久久综合 | 亚洲天堂资源 |