Back to Community
2018-04-03 22:00 WARN Your order for -629 shares of SDD failed to fill by the end of day and was canceled.

Hi,

I want to short SDD but got this message in log. Does this mean at this day the SDD can not be short?

5 responses

I am not sure if your database has problem with the paper 'SDD'. I wrote a simple code which just buy and sell 'SDD' everyday and I got everyday erros.

Clone Algorithm
2
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 is a template algorithm on Quantopian for you to adapt and fill in.
"""
import quantopian.algorithm as algo
from quantopian.pipeline import Pipeline
from quantopian.pipeline.data.builtin import USEquityPricing
from quantopian.pipeline.filters import QTradableStocksUS


def initialize(context):
    """
    Called once at the start of the algorithm.
    """
    
    context.stock = sid(33210)
    
    # Rebalance every day, 1 hour after market open.
    algo.schedule_function(
        rebalance,
        algo.date_rules.every_day(),
        algo.time_rules.market_open(hours=1),
    )

    algo.schedule_function(
        exit,
        algo.date_rules.every_day(),
        algo.time_rules.market_open(hours=1),
    )
    
    # Record tracking variables at the end of each day.
    algo.schedule_function(
        record_vars,
        algo.date_rules.every_day(),
        algo.time_rules.market_close(),
    )

    # Create our dynamic stock selector.
    algo.attach_pipeline(make_pipeline(), 'pipeline')


def make_pipeline():
    """
    A function to create our dynamic stock selector (pipeline). Documentation
    on pipeline can be found here:
    https://www.quantopian.com/help#pipeline-title
    """

    # Base universe set to the QTradableStocksUS
    base_universe = QTradableStocksUS()

    # Factor of yesterday's close price.
    yesterday_close = USEquityPricing.close.latest

    pipe = Pipeline(
        columns={
            'close': yesterday_close,
        },
        screen=base_universe
    )
    return pipe


def before_trading_start(context, data):
    """
    Called every day before market open.
    """
    context.output = algo.pipeline_output('pipeline')

    # These are the securities that we are interested in trading each day.
    context.security_list = context.output.index


def rebalance(context, data):
    """
    Execute orders according to our schedule_function() timing.
    """
    order_target_percent(context.stock, 0.99)

def exit(context, data):
    order_target_percent(context.stock, 0)
    
def record_vars(context, data):
    """
    Plot variables at the end of each day.
    """
    pass


def handle_data(context, data):
    """
    Called every minute.
    """
    pass
There was a runtime error.

Hi Thomas,

The error you are experiencing likely has to do with the fact that SDD is a very thinly traded security (i.e. low average daily volume). In fact, it looks like some days the security did not even trade. By default in the IDE, you cannot trade more than 10% of the volume on any given bar. You can change the volume limit using the set_slippage method. For example, to change the limit to 40%:

set_slippage(slippage.FixedBasisPointsSlippage(basis_points=5, volume_limit=0.4))

See the "Slippage Models" section of the Quantopian API documentation for more information.

Hi Thomas, Michael is correct. By default, our backtesting tools only buy or sell 2.5% (not 10%) of the shares that were traded during a given time period.

For example, let's say you want to buy 1,000 shares of company X, but the trading volume for company X is only 400 shares per day. 2.5% of 400 is 10, which means the backtester will only buy 10 shares per day, until it reaches 1,000. In this example, it would take 100 days for your original order to fill!

In this case, it looks like SDD is a relatively illiquid asset, and even had some days where it didn't trade at all. That is why the algorithm is behaving that way.

This is exactly why our built in trading universe, QTradableStocksUS, filters out stocks that are illiquid (don't trade frequently). As such, this particular asset has never passed the QTradableStocksUS() filter, and wouldn't affect contest algorithms.

Disclaimer

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.

My mistake, Cal. Thanks for clarifying!

Many thanks to all!