Could you add a sample code for alpha 101 formula?
See original GitHub issueCould you add a sample code for alpha 101 formula?
I have bought the book “advanced trading strategies”. But I want to use the qstrader to write the sample code for worldquant alpha 101’s formula. I am not familiar the qstrader. I don’t know how to get the dataframe from 100 stock’s yahoo price. And I don’t know how to write the position sizer to reach the goal. Could you write the simpliest formula 101 on top 100 capital stocks? Alpha#101: ((close - open) / ((high - low) + .001))
It might use 2week or 1 month rebalance day that will be simple. The position size will use the profolio value to buy 100 stocks.
Thank you very much.
Uqer’s platform’s sample code:
import numpy as np
start = '2010-01-01' # 回测起始时间
end = '2016-03-20' # 回测结束时间
benchmark = 'HS300' # 策略参考标准
universe = set_universe("HS300") # 证券池,支持股票和基金
capital_base = 100000 # 起始资金
freq = 'd' # 策略类型,'d'表示日间策略使用日线回测,'m'表示日内策略使用分钟线回测
refresh_rate = 20 # 调仓频率,表示执行handle_data的时间间隔,若freq = 'd'时间间隔的单位为交易日,若freq = 'm'时间间隔为分钟
def foo(data, dependencies=['closePrice', 'openPrice', 'highPrice', 'lowPrice'], max_window=1):
today = (data['closePrice'].ix[-1]-data['openPrice'].ix[-1])/((data['highPrice'].ix[-1]-data['lowPrice'].ix[-1]) + 0.001)
return today
def initialize(account): # 初始化虚拟账户状态
a = Signal("worldquant_101", foo)
account.signal_generator = SignalGenerator(a)
def handle_data(account): # 每个交易日的买入卖出指令
# 只选信号,即worldquant_101计算结果大于0的股票,而且选前40只
# 平均仓位持仓
weight = account.signal_result['worldquant_101']
weight = weight[weight>0]
weight.sort(ascending=False)
weight = weight[0:40]
weight = weight/weight.abs()
weight = weight/weight.sum()
weight = weight.replace([np.inf, -np.inf], np.nan).dropna()
buy_list = weight.index
sell_list = account.valid_secpos
for stk in sell_list:
if stk not in buy_list:
order_to(stk, 0)
total_money = account.referencePortfolioValue
prices = account.referencePrice
for stk in buy_list:
if stk not in prices:
continue
if np.isnan(prices[stk]) or prices[stk] == 0: # 停牌或是还没有上市等原因不能交易
continue
order_num = int(total_money * weight[stk] / prices[stk] /100)*100
if order_num < 100:
order_num = 100
order_to(stk, order_num)
Issue Analytics
- State:
- Created 7 years ago
- Comments:14 (3 by maintainers)
Top Results From Across the Web
101 Formulaic Alphas - arXiv
In this paper we take another step and present explicit formulas – that are also computer code – for 101 real-life quant trading...
Read more >Improve the implementation of worldquant 101 alpha factors ...
Intuitively, the Pandas dataframe or NumPy matrix should fit the implementation of 101 alpha factors. Below is the best implementation using ...
Read more >101 Formulaic Alphas by Zura Kakushadze - SSRN Papers
Abstract. We present explicit formulas - that are also computer code - for 101 real-life quantitative trading alphas.
Read more >Automated Formulaic Alpha Generation for Quantitative ...
5.2.1 Trading Bot - using only the 101 Alphas . . . . . . . . . . 29 ... We can...
Read more >Pine Script (TradingView) - A Step-by-step Guide
How can I create a custom indicator with Pine script? Final Thoughts ... Having access to open-source code is a great way to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
There’s a fairly active thread on the 101 Formulaic Alphas at Quantopian (not sure if Mike approves of the link to them…): https://www.quantopian.com/posts/the-101-alphas-project Towards the bottom of the dicussion, there’s an implementation of at least 50 or so of the Alphas. General consensus is not so positive and given the factor weights that come with some of the Alphas, they seem (to me at least) highly optimized/fitted:
Alpha#69: ((rank(ts_max(delta(IndNeutralize(vwap, IndClass.industry), 2.72412), 4.79344))^Ts_Rank(correlation(((close * 0.490655) + (vwap * (1 - 0.490655))), adv20, 4.92416), 9.0615)) * -1)
– I mean, seriously?I use Shanghai 50 stocks to produce alpha 101’s formula.
You should type the cmd: python twentydays_liquidate_rebalance1.py --tickers=000001SS,600000SS,600016SS,600030SS,600050SS,600111SS,600519SS,600795SS,600893SS,601006SS,601169SS,601288SS,601336SS,601601SS,601669SS,601800SS,601901SS,601989SS,600010SS,600018SS,600036SS,600104SS,600150SS,600585SS,600837SS,600958SS,601088SS,601186SS,601318SS,601390SS,601628SS,601688SS,601818SS,601985SS,601998SS,600015SS,600028SS,600048SS,600109SS,600518SS,600637SS,600887SS,600999SS,601166SS,601211SS,601328SS,601398SS,601668SS,601766SS,601857SS,601988SS > log5.txt
You can see the figure below:
If you find the bug, please tell me. Thank you very much.