Below is a simple market making algorithm:

- It takes the 300 least liquid stocks from the QTradableStocksUS universe
- Every 10 minutes and on each of those stocks, it places a bid at price-0.01 and an offer at price +0.01.

With contest commissions and slippage (but 1M$), this algo supposedly generated a Sharpe ratio of 7.29 YTD.

Clone Algorithm

126

Loading...

There was an error loading this backtest.

Backtest from
to
with
initial capital

Cumulative performance:

Algorithm
Benchmark

Custom data:

Total Returns

--

Alpha

--

Beta

--

Sharpe

--

Sortino

--

Max Drawdown

--

Benchmark Returns

--

Volatility

--

Returns | 1 Month | 3 Month | 6 Month | 12 Month |

Alpha | 1 Month | 3 Month | 6 Month | 12 Month |

Beta | 1 Month | 3 Month | 6 Month | 12 Month |

Sharpe | 1 Month | 3 Month | 6 Month | 12 Month |

Sortino | 1 Month | 3 Month | 6 Month | 12 Month |

Volatility | 1 Month | 3 Month | 6 Month | 12 Month |

Max Drawdown | 1 Month | 3 Month | 6 Month | 12 Month |

from quantopian.pipeline import Pipeline, CustomFilter from quantopian.algorithm import attach_pipeline, pipeline_output from quantopian.pipeline.factors import Latest from quantopian.pipeline.data.builtin import USEquityPricing from quantopian.pipeline.experimental import QTradableStocksUS from quantopian.pipeline.factors import AverageDollarVolume import numpy as np def initialize(context): set_commission(commission.PerShare(cost=0.001, min_trade_cost=0)) #set_slippage(slippage.FixedSlippage(spread=0)) pipe = Pipeline() #pricing = USEquityPricing.close.latest dollar_volume = AverageDollarVolume(window_length=30) pipe.set_screen(QTradableStocksUS()) pipe.add(dollar_volume,'ADV') attach_pipeline(pipe, 'pipe') schedule_function(flush_portfolio, date_rules.month_start(), time_rules.market_close(minutes=50)) for i in range(1,300,10): schedule_function(limit_orders, date_rules.every_day(), time_rules.market_open(minutes=i)) schedule_function(flush_orders, date_rules.every_day(), time_rules.market_open(minutes=(i+9))) def before_trading_start(context, data): context.output = pipeline_output('pipe').nsmallest(300,'ADV') def limit_orders(context,data): currprice = data.current(context.output.index,'price') nstocks = max(10,len(context.output)) for stock in currprice.iteritems(): try: order_target_percent(stock[0],1./nstocks,style = LimitOrder(stock[1]-0.01)) order_target_percent(stock[0],-1./nstocks,style = LimitOrder(stock[1]+0.01)) except: pass def flush_orders(context,data): for stock, orders in get_open_orders().iteritems(): for order in orders: cancel_order(order) def flush_portfolio(context,data): for stock in context.portfolio.positions: order_target_percent(stock,0)