AAII Sentiment At New Spx 21 Week Highs

Nothing quantitative here, just taking a look at how the AAII setiment has been when Spx is making new 21 week rolling highs. The recent AAII setiment has turned siginificantly negative even as Spx is plowing up and wanted to see when has that happened in the past.

import quandl
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns

%matplotlib inline

aaii = quandl.get("AAII/AAII_SENTIMENT", authtoken="YOUR_KEY")
aaii.rename(columns={"S&P 500 Weekly High":"weekly_close"}, inplace=True)
weekly_max = aaii["weekly_close"].rolling(21).max()

bull_mean = (aaii["Bullish"] - aaii["Bullish"].rolling(21).mean()) / aaii["Bullish"].rolling(21).std()
bear_mean = (aaii["Bearish"] - aaii["Bearish"].rolling(21).mean()) / aaii["Bearish"].rolling(21).std()

fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(16, 10), sharex=True)

ax1.set_title("AAII sentiment at Spx rolling 21 week highs")
ax1.plot(aaii["weekly_close"], color="#555555", label="_no_label_")

ax1.fill_between(aaii.index, 0, aaii["weekly_close"],
where=((bull_mean>=0) & (weekly_max == aaii["weekly_close"])),
color="forestgreen", alpha=0.34, label="Bullish sentiment dominant")
ax1.fill_between(aaii.index, 0, aaii["weekly_close"],
where=((bear_mean>=0) & (weekly_max == aaii["weekly_close"])),
color="crimson", alpha=0.96, label="Bearish sentiment dominant")
ax1.legend(loc="upper left")

ax2.set_title("Standardized AAII setiment")
ax2.plot(bull_mean, linewidth=1, color="darkseagreen", label="Bullish")
ax2.plot(bear_mean, linewidth=1, color="crimson", label="Bearish")
ax2.legend(loc="upper left")



Thanks your time and feel free to leave a comment


5 thoughts on “AAII Sentiment At New Spx 21 Week Highs

  1. Quantocracy's Daily Wrap for 03/12/2017 | Quantocracy

  2. try to run your python codes,
    bull_mean, bear_mean not defined names when i ran you code

  3. Thanks for you quick response and very generous post your codes.
    Appreciating your works and codes.

  4. No prob, i updated the post and added notebook link. Ill also add notebook links to other posts in the coming days

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s