LoginSignup
4
0

More than 5 years have passed since last update.

#Quantopian の get_pricing と Pipeline が返す値は一日ずれるよ。でもそれで正しいですよ。

Last updated at Posted at 2017-12-18

Pipeline と get_pricing

こんにちは。2018年はQuantopianヤクザになることをめざすshinseitaroです。
FinTech LT大会&忘年会に向けて、Quantopian Researchで作業していたところ
get_pricing が返すデータと、 Pipeline が返すデータが一日ずれていることに気づき( ゚д゚)!?となり
フォーラムを検索したところ、似たような問題を話し合ってるスレッドがあったので、質問してみました。

Research Updates - get_pricing and Jupyter Notebook Upgrade

以下、検証スクリプトです。

## Quantopian Research 

from quantopian.pipeline.data.builtin import USEquityPricing  
import pandas as pd  
from quantopian.pipeline import CustomFactor, Pipeline  
from quantopian.research import run_pipeline  
from quantopian.pipeline.filters import StaticSids

# SPYで検証
security = symbols(8554)  

def make_pipeline():
    # USEquityPricing の終値と始値の最新を取得してPipelineに流す
    latest_close = USEquityPricing.close.latest  
    latest_open = USEquityPricing.open.latest  
    return Pipeline(  
        columns = { 'Pipeline_close':latest_close,
                  'Pipeline_open':latest_open, },  
        screen = StaticSids([security])
    )

result = run_pipeline(make_pipeline(), '2017-11-30', '2017-12-13')
# multiindex を single index にする。
result = result.reset_index().set_index('level_0')  

# get_pricing を使って同期間のデータを取得
df=get_pricing(security, start_date='2017-11-30', end_date='2017-12-13',
            symbol_reference_date=None, frequency='daily', handle_missing='raise')
df = df.rename(columns = {"open_price": "get_pricing_open", "close_price": "get_pricing_close", })

# concatして比べる
pd.concat([result["Pipeline_open"], df["get_pricing_open"], result["Pipeline_close"], df["get_pricing_close"], ], axis=1)



こちらがその結果

Screenshot from 2017-12-18 09-47-04.png

Pipelineデータが一日遅れているのがわかると思います。

なぜ?!と質問したところ、どこかの優しいDanさんが速攻お返事くれました。

ただ、この返事ではピンとこない人には来ないと思うのでここで補足します。

Pipeline

  • 両方の関数ともに,DateTimeはUTC
  • Pipeline が返すデータは日足のみ.
  • Pipeline は日中いつのタイミングでも実行出来るが,返ってくる値は前日までの日足を使ったデータ.
  • 例えば、今日が2017/12/13(水)とし直近のOHLCを取得するように Pipeline を実行すると,前日の2017/12/12(火)のOHLCを取得し,2017/12/13(水)の行に格納する.(上記表の通り)
  • Research でも同様に振る舞う.
  • つまり、PipelineをResearchで実行するとき,引数として渡す start/end 日は,データの期間ではなく、Pipelineを実行する期間

get_pricing

  • get_pricing は、アルゴリズムで言えば、data.current にあたり、 実行された時に、そのタイミングのデータ(分足)を取得できる。
  • よって、get_pricing の start/end は、データの期間である

Quantopian のコミュニティ

Quantopianの Forum は非常にしっかりしていて、コミュニティの人たちがわかることはドンドン教えてくれます。
今回応えてくれたDanさんという人も、Quantopianの中の人ではなく,一ユーザーさんと思われます。本当にありがたい。
コミュニティがしっかりしているって大切ですね。

今後のイベント

Tokyo Quantopian User Group
次回はまだ決まっておりませんが来年の1月には何かしたいと思ってます(^^)

月刊フィントーク
2017/12/24 【女性限定ではない!】月刊フィントーク 山手線一周歩いて不動産について考える
2018/01/09 【女性限定】月刊フィントーク その9

フィントークも少しずつメンバーが増えており、本当にありがたいな。と思ってます。新しいお友達もできてとてもハッピーです\(^o^)/

4
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
0