I've written an algorithm that relies heavily on shorting. But in practice, some securities are shortable, and some aren't. How do I build that into my testing and/or my security selection? Thanks!
Alan
I've written an algorithm that relies heavily on shorting. But in practice, some securities are shortable, and some aren't. How do I build that into my testing and/or my security selection? Thanks!
Alan
In backtesting, it assumes that all stocks were shortable at the time, which isn't necessarily correct. There's more improvements we can make to the backtester and I think this is one of them!
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.
Thanks. When the algorithm is actually running, I assume I'll know what can't be shorted simply because the order will go unfilled. Will there be any more info than that?
Do you mean in live trading? When your algorithm is paper trading or real money trading with Interactive Brokers, the algorithm will attempt to place a short order. If it's accepted by the broker, the order will get filled. If the stock is not available for short sale that day, then the order will get rejected and the message will appear in your live trading dashboard.
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.
Is there a way to place a contingent order where by if I'm pair trading, the 'long' side of the pair will only execute iff the 'short' side is executed?
How I would go about doing this is to setup a boolean in initialize that keeps track of my short sides so something like:
def initialize(context):
context.stock_to_long = symbol("AAPL")
context.stock_to_short = symbol("SPY")
#: Instantiate some variables that will be used to store our states
context.short_executed = False
context.short_order_id = None
def handle_data(context, data):
#: Order my short and store the order id in a context variable
context.short_order_id = order(context.stock_to_short, -1)
#: Check if my short order has been executed so far
if get_order(short_order_id)['filled'] == -1:
#: Revert my variables to the state I want them to be in
context.short_executed = True
context.short_order_id = None
#: If my short has been executed, then go ahead and long
if context.short_executed == True:
order(context.stock_to_long, 1)
#: Change my short_executed boolean back to False
context.short_executed = False
Something like this should work well for minutely mode given you have all your order conditions in place
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.
Alan,
I'm no expert, but I did a quick google search and found that IB has a list:
We make the stocks listed under the following links available for shorting:
https://www.interactivebrokers.com/en/index.php?f=shortableStocks&p=shortable
I'd definitely dig deeper, since again, I have no expertise in this area.
Grant
Thanks, Grant -- that's useful and interesting. The list would be easy to capture and pull in as data. The "check availability" function should be reverse engineer-able, but on quick inspection they don't make it easy.
For those with the IB Portfolio Margin accounts, it can be checked in AQS Marketplace. Those with RegT can check the borrow rates within account management -> suport -> tools -> SLB (short stock availability tool).
If you can't automate this verification, my tip is to not short illiquid, volatile or heavily shorted stocks, as you can end up not being filled or getting bad execution.
Hello everyone,
I am attempting my first pairs strategy and happened to have this exactly question. Figured id just bump this . The thread is now 4 years old so I am just wondering if any enhancement have been made to this topic. I know Q has introduce the trading universes but are is there a way to confirm that all assets in them are shortable.