国外量化平台-quantopian体验

文章目录

  • 整体感觉
  • 开始(Getting Started)

https://www.quantopian.com

整体感觉

优点:
1,功能较全,现在还没有太多感触。但国内的量化平台都是仿照国外的,很多东西也是从国外引进来的。
2,分享策略。上面有人分享他的策略,并且免费看源代码。相比而言,国内的全都要钱,一个还不知道效果怎么样的策略,要充会员才能看。不得不说,就开源和分享而言,国外做的好得多,如GitHub。
缺点:
1,全英文。对大部分国人来说,具有语言障碍。
2,不支持A股。不过我现在仅以学习为主,无所谓了。
3,有时候有些地方太卡了。部分页面可能需要fq。打开notebook也忒慢了。

下面就要开始我的量化入门了。

开始(Getting Started)

https://www.quantopian.com/tutorials/getting-started

在https://www.quantopian.com/research/notebooks上新建一个notebook,并复制下面代码,运行。
可以得到和文档一样的图片和结果。

from quantopian.pipeline.data.factset import Fundamentals, EquityMetadata

is_share = EquityMetadata.security_type.latest.eq('SHARE')
is_primary = EquityMetadata.is_primary.latest
primary_shares = (is_share & is_primary)
market_cap = Fundamentals.mkt_val.latest

universe = market_cap.top(1000, mask=primary_shares)

from quantopian.pipeline.data import EquityPricing
from quantopian.pipeline.factors import SimpleMovingAverage

# 1-month (21 trading day) moving average factor.  1个月的移动平均因子
fast_ma = SimpleMovingAverage(inputs=[EquityPricing.close], window_length=21)

# 6-month (126 trading day) moving average factor. 6个月的移动平均因子
slow_ma = SimpleMovingAverage(inputs=[EquityPricing.close], window_length=126)

# Divide fast_ma by slow_ma to get momentum factor and z-score.
momentum = fast_ma / slow_ma  # 快的/慢的 = 动量因子
momentum_factor = momentum.zscore()


from quantopian.pipeline import Pipeline
from quantopian.pipeline.domain import US_EQUITIES

# Create a US equities pipeline with our momentum factor, screening down to our universe.
pipe = Pipeline(
    columns={
        'momentum_factor': momentum_factor,
    },
    screen=universe,
    domain=US_EQUITIES,
)

# Run the pipeline from 2016 to 2019 and display the first few rows of output.
from quantopian.research import run_pipeline
factor_data = run_pipeline(pipe, '2016-01-01', '2019-01-01')
print("Result contains {} rows of output.".format(len(factor_data)))
factor_data.head()


from quantopian.pipeline.factors import Returns

# Create and run a Pipeline to get day-over-day returns.
returns_pipe = Pipeline(
    columns={
        '1D': Returns(window_length=2),
    },
    domain=US_EQUITIES,
)
returns_data = run_pipeline(returns_pipe, '2016-01-01', '2019-02-01')

# Import alphalens and pandas.
import alphalens as al
import pandas as pd

# Shift the returns so that we can compare our factor data to forward returns.
shifted_returns = al.utils.backshift_returns_series(returns_data['1D'], 2)

# Merge the factor and returns data.
al_returns = pd.DataFrame(
    data=shifted_returns, 
    index=factor_data.index,
    columns=['1D'],
)
al_returns.index.levels[0].name = "date"
al_returns.index.levels[1].name = "asset"

# Format the factor and returns data so that we can run it through Alphalens.
al_data = al.utils.get_clean_factor(
    factor_data['momentum_factor'],
    al_returns,
    quantiles=5,
    bins=None,
)

from alphalens.tears import create_full_tear_sheet

create_full_tear_sheet(al_data)

国外量化平台-quantopian体验_第1张图片
代码跑通了,但内容还不是很懂,后续学习。

你可能感兴趣的:(量化)