Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
trying to pipe twitter data

Hi guys, i'm trying the following

in initialize,
from quantopian.pipeline.data.psychsignal import twitter_noretweets as twitter

wrote:

class twitter_bull(CustomFactor):  
    inputs = [twitter.bull_scored_messages]  
...

and got this error, "Runtime exception: AttributeError: type object 'twitter' has no attribute 'bull_scored_messages' "

also tried:
class twitter_bull(CustomFactor): inputs = [twitter.bullish_intensity]

and got the same attribute error.

4 responses

Hi Toan, thanks for bringing this up. I was unable to produce your error, but if you have your twitter import line in your initialize function, you should move it outside that function so that twitter is accessible globally.

If you have the import line in the right place and you're still seeing this issue, would you mind providing an example algo that demonstrates the error? If you're not comfortable sharing an algo here you could send it to Support. Thanks in advance for your help.

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.

here's one that crashes.

from quantopian.algorithm import attach_pipeline, pipeline_output  
from quantopian.pipeline import Pipeline  
from quantopian.pipeline.factors import CustomFactor, SimpleMovingAverage, AverageDollarVolume, Latest, RSI  
from quantopian.pipeline.data.builtin import USEquityPricing  
from quantopian.pipeline.data import morningstar as mstar  
from quantopian.pipeline.filters.morningstar import IsPrimaryShare  
from quantopian.pipeline.data.psychsignal import stocktwits  
from quantopian.pipeline.data.psychsignal import twitter_noretweets as twitter  
from quantopian.pipeline.classifiers.morningstar import Sector  
from quantopian.pipeline.data import morningstar  
import numpy as np  
import pandas as pd  
import time

class twitter(CustomFactor):  
    inputs = [twitter.total_scanned_messages]  
    window_length = 50  
    def compute(self, today, assets, out, msgs):  
        out[:] =  np.nanmean(msgs[-5:], axis=0)/np.nanmean(msgs, axis=0)

class twitter_bull(CustomFactor):  
    inputs = [twitter.bullish_intensity]  
    window_length = 50  
    def compute(self, today, assets, out, msgs):  
        out[:] =  np.nanmean(msgs[-5:], axis=0)/np.nanmean(msgs, axis=0)

def make_pipeline():  
    pipe = Pipeline()  
    initial_screen = filter_universe()  
    pipe.add(twitter(mask=initial_screen), "twitter_momentum")  
    pipe.add(twitter_bull(mask=initial_screen), "twitter_bull")  
    return pipe

def initialize(context):  
    attach_pipeline(make_pipeline(), 'ranking_example')  
    context.dont_buy = security_lists.leveraged_etf_list  

def before_trading_start(context, data):  
    output = pipeline_output('ranking_example')  
def filter_universe():  
    common_stock = mstar.share_class_reference.security_type.latest.eq('ST00000001')  
    not_lp_name = ~mstar.company_reference.standard_name.latest.matches('.* L[\\. ]?P\.?$')  
    not_lp_balance_sheet = mstar.balance_sheet.limited_partnership.latest.isnull()  
    have_data = mstar.valuation.market_cap.latest.notnull()  
    not_otc = ~mstar.share_class_reference.exchange_id.latest.startswith('OTC')  
    not_wi = ~mstar.share_class_reference.symbol.latest.endswith('.WI')  
    not_depository = ~mstar.share_class_reference.is_depositary_receipt.latest  
    primary_share = IsPrimaryShare()  
    # Combine the above filters.  
    tradable_filter = (common_stock & not_lp_name & not_lp_balance_sheet &  
                       have_data & not_otc & not_wi & not_depository & primary_share)  
    high_volume_tradable = AverageDollarVolume(  
            window_length=21,  
            mask=tradable_filter  
        ).rank(ascending=False) < 1000

    mask = high_volume_tradable  
    return mask  



Hi Toan, this is happening because of the custom factor you named twitter, which is overriding the dataset imported under the same name. If you change the name of the custom factor this will work fine.

thanks!