Back to Community
Multi-factor long short with Twitter & StockTwits trader mood

This is a long-short multi-factor strategy based off the Goldman Sachs’ GSLC implementation by James Christopher. For those unfamiliar with long-short strategies, I highly recommend going over both the full lecture and accompanying algorithm before exploring this algorithm:

While James’ original algorithm used factors based off of momentum, value, volatility and quality (aka profitability), I chose to remove value (it didn't give great results) and replaced price momentum with a factor based off of trader mood sentiment. This new trader mood sentiment factor is the 30-day average bull minus bearish intensity score weighted by the number of StockTwits and Twitter messages. Each factor (trader mood sentiment, volatility, and quality) are weighted equally and ranked to determine long/short portfolios.

The raw trader mood sentiment data is provided by PsychSignal and made available through Pipeline. PsychSignal uses its own natural language processing (NLP) engine that analyzes messages from both StockTwits and Twitter in order to assign bullish and bearish sentiment scores for each security.


For questions on accessing this data, please email [email protected]

This algorithm is for education - the algorithm is not intended to provide investment advice.

Clone Algorithm
Backtest from to with initial capital
Total Returns
Max Drawdown
Benchmark Returns
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
# Backtest ID: 5806383429d34910511cd172
There was a runtime error.

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.

8 responses

@Seong - cool algo! Ran into an error tho when backtesting...seems it has something to do with the pipeline? Do I not have the current StockTwits data downloaded?

'Something went wrong. Sorry for the inconvenience. Try using the built-in debugger to analyze your code. If you would like help, send us an email. ConnectionError: [Errno None] None: None
There was a runtime error on line 79.'

Hi Daniel,

We've tried testing on a few accounts on our end and don't seem to be able to replicate the error. Were there any variables you changed while attempting to test?

We were also experiencing a few blips which may have resolved by now.

The first version didn't work, so I tried again and it now works. Thanks. Question - have you considered limiting the database of stocks to those that are much more liquid? Some of the trades made on this example are very illiquid and, if using retail platforms such as Robinhood, could have serious slippage and liquidity concerns if trying to unload shares.

Hi Daniel,

Thanks for the suggestion and you have a very good point. This algorithm was created to be used a simple example for the PsychSignal dataset.

As you suggested, it'd be different when trying to adjust for liquidity concerns.


Here's a tearsheet of the performance.

Some thoughts:

  • Beta is a little bit low (hoping to be between -.3 and .3)
  • Rolling Sharpe decreases as times goes on
  • Turnover is as expected, every month we're refreshing our portfolio
  • Drawdown is still under .20 at .15
  • Volatility could be better

I'll be updating this with a few liquidity stock improvements as well as running this factor through Andrew's factor tearsheet (

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

Great! Anxious to see the outcome of the updates!

Great share! Any idea how this perform in 2015-present?

Hello Seong - Thanks for sharing the algo.
I also ran into the same error as Daniel when running the backtest from 2014-01-04 to 2015-12-31 with $10,000 initial capital (minute data): Screenshot

Line 79: results = pipeline_output('factors').dropna()