Back to Community
Met all Q Contest Requirements with Accern's Weekly Aggregated Strategy built on DS2 Dataset

Recently I have been working with Accern's DS2 dataset to create Accern's proprietary data-driven strategies to demonstrate DS2 dataset's predictive capability and flexibility for strategy development and integration.

Below is a weekly-aggregated strategy built on Accern's daily DS2 dataset, which passed all required tests for entering Quantopians' contest. Any feedbacks and insights will be appreciated. For more DS2 related strategy posts and info, feel free to check my another post here.

Clone Algorithm
11
Loading...
Backtest from to with initial capital
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
# This time, let me switch the commissions model to the default version.

import quantopian.algorithm as algo
import quantopian.optimize as opt
from quantopian.pipeline import Pipeline
from quantopian.pipeline.data.builtin import USEquityPricing
from quantopian.pipeline.filters import QTradableStocksUS
from quantopian.pipeline.data.user_575f0e61946dff77e500080f import ds2_weekly_data_mean_day_shifted_back

#Set Maximum portfolio Leverage
MAX_GROSS_EXPOSURE = 1
#Set Maximum Position sizes for individual longs and shorts
MAX_SHORT_POSITION_SIZE = 0.02
MAX_LONG_POSITION_SIZE = 0.02

def initialize(context):
    set_slippage(slippage.FixedBasisPointsSlippage(basis_points=2.5, volume_limit=0.1))
    set_commission(commission.PerShare(cost=0.001, min_trade_cost=0))
    
    schedule_function(morning_execution,
                      date_rules.week_start(),
                      time_rules.market_open(hours = 0, minutes = 5))
    
    # Create our dynamic stock selector.
    algo.attach_pipeline(make_pipeline(), 'pipeline')


def make_pipeline():
    # Base universe set to the QTradableStocksUS
    base_universe = QTradableStocksUS()

    pipe = Pipeline(
        columns={
            'score': ds2_weekly_data_mean_day_shifted_back.score.latest,
        },
        screen=(base_universe & ds2_weekly_data_mean_day_shifted_back.score.latest.notnull())
    )

    return pipe


def before_trading_start(context, data):
    context.output = algo.pipeline_output('pipeline')


def morning_execution(context, data):
    # Set objective for our Optimizer
    objective = opt.MaximizeAlpha(context.output['score'])
    
    # Set Constraints
    constrain_gross_leverage = opt.MaxGrossExposure(MAX_GROSS_EXPOSURE)
    dollar_neutral = opt.DollarNeutral(tolerance=0.02)
    constrain_pos_size = opt.PositionConcentration.with_equal_bounds(
        -MAX_SHORT_POSITION_SIZE,
        MAX_LONG_POSITION_SIZE,
    )
    
    algo.order_optimal_portfolio(
        objective=objective,
        constraints=[
            constrain_gross_leverage,
            dollar_neutral,
            constrain_pos_size,
        ],
    )
There was a runtime error.
3 responses

Attached is the tearsheet with the round_trip = True.

Loading notebook preview...
Notebook previews are currently unavailable.

Here is another version of the same strategy with default commissions and slippage costs, which also passed all contest tests.

Clone Algorithm
11
Loading...
Backtest from to with initial capital
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
# This time, let me switch the commissions model to the default version.

import quantopian.algorithm as algo
import quantopian.optimize as opt
from quantopian.pipeline import Pipeline
from quantopian.pipeline.data.builtin import USEquityPricing
from quantopian.pipeline.filters import QTradableStocksUS
from quantopian.pipeline.data.user_575f0e61946dff77e500080f import ds2_weekly_data_mean_day_shifted_back

#Set Maximum portfolio Leverage
MAX_GROSS_EXPOSURE = 1
#Set Maximum Position sizes for individual longs and shorts
MAX_SHORT_POSITION_SIZE = 0.02
MAX_LONG_POSITION_SIZE = 0.02

def initialize(context):
    # set_slippage(slippage.FixedBasisPointsSlippage(basis_points=2.5, volume_limit=0.1))
    # set_commission(commission.PerShare(cost=0.001, min_trade_cost=0))
    
    schedule_function(morning_execution,
                      date_rules.week_start(),
                      time_rules.market_open(hours = 0, minutes = 5))
    
    # Create our dynamic stock selector.
    algo.attach_pipeline(make_pipeline(), 'pipeline')


def make_pipeline():
    # Base universe set to the QTradableStocksUS
    base_universe = QTradableStocksUS()

    pipe = Pipeline(
        columns={
            'score': ds2_weekly_data_mean_day_shifted_back.score.latest,
        },
        screen=(base_universe & ds2_weekly_data_mean_day_shifted_back.score.latest.notnull())
    )

    return pipe


def before_trading_start(context, data):
    context.output = algo.pipeline_output('pipeline')


def morning_execution(context, data):
    # Set objective for our Optimizer
    objective = opt.MaximizeAlpha(context.output['score'])
    
    # Set Constraints
    constrain_gross_leverage = opt.MaxGrossExposure(MAX_GROSS_EXPOSURE)
    dollar_neutral = opt.DollarNeutral(tolerance=0.02)
    constrain_pos_size = opt.PositionConcentration.with_equal_bounds(
        -MAX_SHORT_POSITION_SIZE,
        MAX_LONG_POSITION_SIZE,
    )
    
    algo.order_optimal_portfolio(
        objective=objective,
        constraints=[
            constrain_gross_leverage,
            dollar_neutral,
            constrain_pos_size,
        ],
    )
There was a runtime error.

Here is the tearsheet for this version with default trading costs model.

Loading notebook preview...
Notebook previews are currently unavailable.