NYC Data Science Academy| Blog
Bootcamps
Lifetime Job Support Available Financing Available
Bootcamps
Data Science with Machine Learning Flagship ๐Ÿ† Data Analytics Bootcamp Artificial Intelligence Bootcamp New Release ๐ŸŽ‰
Free Lesson
Intro to Data Science New Release ๐ŸŽ‰
Find Inspiration
Find Alumni with Similar Background
Job Outlook
Occupational Outlook Graduate Outcomes Must See ๐Ÿ”ฅ
Alumni
Success Stories Testimonials Alumni Directory Alumni Exclusive Study Program
Courses
View Bundled Courses
Financing Available
Bootcamp Prep Popular ๐Ÿ”ฅ Data Science Mastery Data Science Launchpad with Python View AI Courses Generative AI for Everyone New ๐ŸŽ‰ Generative AI for Finance New ๐ŸŽ‰ Generative AI for Marketing New ๐ŸŽ‰
Bundle Up
Learn More and Save More
Combination of data science courses.
View Data Science Courses
Beginner
Introductory Python
Intermediate
Data Science Python: Data Analysis and Visualization Popular ๐Ÿ”ฅ Data Science R: Data Analysis and Visualization
Advanced
Data Science Python: Machine Learning Popular ๐Ÿ”ฅ Data Science R: Machine Learning Designing and Implementing Production MLOps New ๐ŸŽ‰ Natural Language Processing for Production (NLP) New ๐ŸŽ‰
Find Inspiration
Get Course Recommendation Must Try ๐Ÿ’Ž An Ultimate Guide to Become a Data Scientist
For Companies
For Companies
Corporate Offerings Hiring Partners Candidate Portfolio Hire Our Graduates
Students Work
Students Work
All Posts Capstone Data Visualization Machine Learning Python Projects R Projects
Tutorials
About
About
About Us Accreditation Contact Us Join Us FAQ Webinars Subscription An Ultimate Guide to
Become a Data Scientist
    Login
NYC Data Science Acedemy
Bootcamps
Courses
Students Work
About
Bootcamps
Bootcamps
Data Science with Machine Learning Flagship
Data Analytics Bootcamp
Artificial Intelligence Bootcamp New Release ๐ŸŽ‰
Free Lessons
Intro to Data Science New Release ๐ŸŽ‰
Find Inspiration
Find Alumni with Similar Background
Job Outlook
Occupational Outlook
Graduate Outcomes Must See ๐Ÿ”ฅ
Alumni
Success Stories
Testimonials
Alumni Directory
Alumni Exclusive Study Program
Courses
Bundles
financing available
View All Bundles
Bootcamp Prep
Data Science Mastery
Data Science Launchpad with Python NEW!
View AI Courses
Generative AI for Everyone
Generative AI for Finance
Generative AI for Marketing
View Data Science Courses
View All Professional Development Courses
Beginner
Introductory Python
Intermediate
Python: Data Analysis and Visualization
R: Data Analysis and Visualization
Advanced
Python: Machine Learning
R: Machine Learning
Designing and Implementing Production MLOps
Natural Language Processing for Production (NLP)
For Companies
Corporate Offerings
Hiring Partners
Candidate Portfolio
Hire Our Graduates
Students Work
All Posts
Capstone
Data Visualization
Machine Learning
Python Projects
R Projects
About
Accreditation
About Us
Contact Us
Join Us
FAQ
Webinars
Subscription
An Ultimate Guide to Become a Data Scientist
Tutorials
Data Analytics
  • Learn Pandas
  • Learn NumPy
  • Learn SciPy
  • Learn Matplotlib
Machine Learning
  • Boosting
  • Random Forest
  • Linear Regression
  • Decision Tree
  • PCA
Interview by Companies
  • JPMC
  • Google
  • Facebook
Artificial Intelligence
  • Learn Generative AI
  • Learn ChatGPT-3.5
  • Learn ChatGPT-4
  • Learn Google Bard
Coding
  • Learn Python
  • Learn SQL
  • Learn MySQL
  • Learn NoSQL
  • Learn PySpark
  • Learn PyTorch
Interview Questions
  • Python Hard
  • R Easy
  • R Hard
  • SQL Easy
  • SQL Hard
  • Python Easy
Data Science Blog > R Shiny > Timing the Stock Market with Congress

Timing the Stock Market with Congress

Brian Ralston
Posted on Mar 21, 2023

Presentation Video

App
GitHub

Background

This is an exploration and analysis of the trades made by Congress members over the past 9 years.

There has been increased public scrutiny around insider trading in Congress. Being in that position of power and having insight into so many aspects of society can lead to a conflict of interest for investments made by people in Congress. It undermines public trust in the governmentโ€™s integrity in serving the public interest. This issue has been on my radar since March 2020 when a few prominent senators fell under heavy scrutiny over claims they used insider knowledge about the impending coronavirus crisis to sell shares before prices plummeted.1

I became even more intrigued once I realized that these trades were required to be reported to the public in a timely manner and that that investors referred to  these reports in deciding which stocks to buy and sell.This type of news gained so much traction that two ETFs started trading on the market on February 8th 2023 where tickers NANC and KRUZ buy and sell securities based on an analysis of the Financial Transaction Reports submitted by  Congress members.2

The entire situation is a giant gray area with a huge lack of enforced regulation.  The New York Times recently completed a massive analysis of  97 congress members and potential conflicts  between their committees and stock market activity.3 This investigation, which was a major inspiration for my project,  it took over 100 analysts thousands of hours to complete. Determining guilt of insider trading is an extremely complex form of litigation that I wouldn't be able to address within the constraints  of this project.  Instead, I decided to take a different angle in my analysis.

Approach

Through my analysis, I will aggregate all Congress membersโ€™ reported trades from 2014-2023 and determine the following:

  1. What is Congress' effectiveness at buying stocks
  2. Who are the top Congress traders?
  3. How can users explore this data on their own?

The Data

Congress members must submit a Periodic Transaction Report (PTR) every time they buy or sell a stock. Like many government programs, the data is publicly available but not easy to access. There is no central database, or API.  Instead a large collection of individual PDF's are submitted by each congress member. Luckily, there is a website sorting through each of those .pdf's into a central database. 4 5

From these PTRs I was able to gather the following data points:

Data Limitations

One major difficulty with this dataset is that   I am not able to gather the exact number of shares  of stocks traded or their exact value. As you can see in the PTR above, there is only a $value range that the trade is worth. And because the range is so large (i.e. $1,000,000 - $5,000,000) it is not possible to determine exactly how many stocks were bought/sold and at what price. I am also not able to accurately recreate each representative's stock portfolio.  Additionally, I do not know which stocks they held prior to 2012 when the requirement for reporting began.

 

Data Overview

After cleaning up the data, I was able to match around 16,000 transactions with the adjusted close price scraped from Yahoo Finance. The observations took place from January 31, 2014, to February 6, 2023, with an average of 12 trades per day and a maximum of 255 trades in a day on March 18, 2020.

Out of these 16,000 transactions, 8,793 trades were made by Democrats, and 7,591 were made by Republicans. When grouping the data by individuals, representatives made as few as 1 trade and as many as 1,050 trades throughout this time period. The average congress member traded 82.6 times, and the median number of trades was 17, implying a distribution curve skewed to the left.

The transactions themselves ranged from the minimum amount for reporting, which is $1,000, all the way up to a $25 million trade made by Senator Susan Collins from Maine, where she bought $25 million worth of the company 3M on March 3, 2015. The average transaction range was from $22,000 to $80,000, and the median transaction was in the $1,000 to $15,000 range.

How to Measure Success

Due to the fact that I was limited to stock value ranges instead of exact stock values, it was challenging to find a way to measure success. The way I decided to measure success was to take the adjusted close price of a stock that a representative traded on a specific day and calculate a percentage change on that same stock 7,30, 90, 365 days later, and also look at present value working on the  date  of 2/13/23. This way, every single trade could have a tangible value behind whether it was a good trade in the short, medium and long term.

However,  we see the limitations of the data given to us. If a representative purchases the stock, I don't really know when they will sell it or what the connection is to future transactions on that ticker.  The same is true for when they sell a stock, I don't really know how much of the stock they owned already or when they bought it previously and at what price. That is why I created these proxy percent change values and made some assumptions at different time intervals. My goal isn't to evaluate the exact gains or losses of congress members, but instead evaluate the TIMING of the trade itself.

Here is an example for clarification before moving forward:

Congress member Nancy Pelosi bought $1M-5M of AMZN on 01/16/20; the adjusted close price was $93.90. The price 30 days later was $106.74(+13.68%) and the price one year later was $155.21(+65.30%) This was a fantastic trade in the short and Long term! Again, I don't know if she held the stock for a year, but what matters is that the timing was good.

Congress Member Nancy Pelosi also sold $250k-500k of AMZN on the same date.  However, this was a poor trade in both the short term and long term. It would have been better to hold onto that stock longer.

Congress' Effectiveness ...at buying stocks

For the below graph, I compare the average returns of congress as a whole versus the returns of the S&P 500 on the same dates.

On average, throughout all 9 years of data, Congress outperforms the S&P 500 in the one year or less categories, but does not outperform the "to date" category.

 

However, transaction type is not considered in the previous chart. As previously mentioned, if there is a lower percentage increase on a SELL, that is actually BETTER. So I have created a new plot below in which I have faceted by transaction type as well as political party.

Here are some insights I gained from the graph above:

  1. For BUYS of less than 1 year, Congress has better timing.
  2. For BUYS greater than a year,the S&P 500 did better.
  3. For SELLS overall, representatives had worse timing compared to transacting on the S&P 500 (remember a smaller percentage % increase on sales is better).
  4. Republicans Overall had MUCH greater returns compared to Democrats.

Top Traders

I isolated the dataset to just the buy transactions and grouped it by each individual representative to get an average return rate at different time intervals. Greg Gianforte - R(MT) came to the top of the one week average return with an impressive 5.86% average return. Austin Scott - R(GA) led the average one month and three month return with an average return of 12.91%  and 35.41% across 31 buy transactions. Susan Davis - D(CA) had a potential average return of 91.09% over a year across 13 buy transactions. Lastly, Jack Reed - D(RI) had a potential to date return of 185% across 58 buy transactions.

Again the big assumption here is that the representative would hold onto that stock and sell at a specified time interval later. Although that is a big assumption, I'd argue that it still gives us a very interesting data point about how effective the Congress member is at timing a trade and some potential knowledge they might have about that industry or even that specific stock.

Top Trades

In addition to pointing out the best average traders, I wanted to identify some of the top trades from the past three years. The stock market has been particularly volatile over the past three years., which opens the potential for large wins and losses. It is interesting to identify the individual trades that made the most potential return, and who those traders are.

 

The App

I have created a shiny app to allow an individual user to sort through this mountain of information and start their own investigation. In the app, you can filter by individual Congress member and explore overall trading activity as well as specific trades to find out who is the best or worst at buying/selling stocks.

Credits:

Data: Timothy Carambat (StockWatchers) - Senate API / House API

Photo: Dan Nelson 

Thanks to all my mentors at NYCDSA

 

About Author

Brian Ralston

Experienced Data Scientist and Database Administrator with 3 years experience in SQL, Python, and R. Strong understanding of data warehousing, modeling, mining techniques, and dedicated to staying up to date with the latest technologies and industry trends. Excited...
View all posts by Brian Ralston >

Related Articles

Capstone
Catching Fraud in the Healthcare System
Data Analysis
Car Sales Report R Shiny App
Data Analysis
Injury Analysis of Soccer Players with Python
Capstone
Acquisition Due Dilligence Automation for Smaller Firms
R Shiny
Forecasting NY State Tax Credits: R Shiny App for Businesses

Leave a Comment

No comments found.

View Posts by Categories

All Posts 2399 posts
AI 7 posts
AI Agent 2 posts
AI-based hotel recommendation 1 posts
AIForGood 1 posts
Alumni 60 posts
Animated Maps 1 posts
APIs 41 posts
Artificial Intelligence 2 posts
Artificial Intelligence 2 posts
AWS 13 posts
Banking 1 posts
Big Data 50 posts
Branch Analysis 1 posts
Capstone 206 posts
Career Education 7 posts
CLIP 1 posts
Community 72 posts
Congestion Zone 1 posts
Content Recommendation 1 posts
Cosine SImilarity 1 posts
Data Analysis 5 posts
Data Engineering 1 posts
Data Engineering 3 posts
Data Science 7 posts
Data Science News and Sharing 73 posts
Data Visualization 324 posts
Events 5 posts
Featured 37 posts
Function calling 1 posts
FutureTech 1 posts
Generative AI 5 posts
Hadoop 13 posts
Image Classification 1 posts
Innovation 2 posts
Kmeans Cluster 1 posts
LLM 6 posts
Machine Learning 364 posts
Marketing 1 posts
Meetup 144 posts
MLOPs 1 posts
Model Deployment 1 posts
Nagamas69 1 posts
NLP 1 posts
OpenAI 5 posts
OpenNYC Data 1 posts
pySpark 1 posts
Python 16 posts
Python 458 posts
Python data analysis 4 posts
Python Shiny 2 posts
R 404 posts
R Data Analysis 1 posts
R Shiny 560 posts
R Visualization 445 posts
RAG 1 posts
RoBERTa 1 posts
semantic rearch 2 posts
Spark 17 posts
SQL 1 posts
Streamlit 2 posts
Student Works 1687 posts
Tableau 12 posts
TensorFlow 3 posts
Traffic 1 posts
User Preference Modeling 1 posts
Vector database 2 posts
Web Scraping 483 posts
wukong138 1 posts

Our Recent Popular Posts

AI 4 AI: ChatGPT Unifies My Blog Posts
by Vinod Chugani
Dec 18, 2022
Meet Your Machine Learning Mentors: Kyle Gallatin
by Vivian Zhang
Nov 4, 2020
NICU Admissions and CCHD: Predicting Based on Data Analysis
by Paul Lee, Aron Berke, Bee Kim, Bettina Meier and Ira Villar
Jan 7, 2020

View Posts by Tags

#python #trainwithnycdsa 2019 2020 Revenue 3-points agriculture air quality airbnb airline alcohol Alex Baransky algorithm alumni Alumni Interview Alumni Reviews Alumni Spotlight alumni story Alumnus ames dataset ames housing dataset apartment rent API Application artist aws bank loans beautiful soup Best Bootcamp Best Data Science 2019 Best Data Science Bootcamp Best Data Science Bootcamp 2020 Best Ranked Big Data Book Launch Book-Signing bootcamp Bootcamp Alumni Bootcamp Prep boston safety Bundles cake recipe California Cancer Research capstone car price Career Career Day ChatGPT citibike classic cars classpass clustering Coding Course Demo Course Report covid 19 credit credit card crime frequency crops D3.js data data analysis Data Analyst data analytics data for tripadvisor reviews data science Data Science Academy Data Science Bootcamp Data science jobs Data Science Reviews Data Scientist Data Scientist Jobs data visualization database Deep Learning Demo Day Discount disney dplyr drug data e-commerce economy employee employee burnout employer networking environment feature engineering Finance Financial Data Science fitness studio Flask flight delay football gbm Get Hired ggplot2 googleVis H20 Hadoop hallmark holiday movie happiness healthcare frauds higgs boson Hiring hiring partner events Hiring Partners hotels housing housing data housing predictions housing price hy-vee Income industry Industry Experts Injuries Instructor Blog Instructor Interview insurance italki Job Job Placement Jobs Jon Krohn JP Morgan Chase Kaggle Kickstarter las vegas airport lasso regression Lead Data Scienctist Lead Data Scientist leaflet league linear regression Logistic Regression machine learning Maps market matplotlib Medical Research Meet the team meetup methal health miami beach movie music Napoli NBA netflix Networking neural network Neural networks New Courses NHL nlp NYC NYC Data Science nyc data science academy NYC Open Data nyc property NYCDSA NYCDSA Alumni Online Online Bootcamp Online Training Open Data painter pandas Part-time performance phoenix pollutants Portfolio Development precision measurement prediction Prework Programming public safety PwC python Python Data Analysis python machine learning python scrapy python web scraping python webscraping Python Workshop R R Data Analysis R language R Programming R Shiny r studio R Visualization R Workshop R-bloggers random forest Ranking recommendation recommendation system regression Remote remote data science bootcamp Scrapy scrapy visualization seaborn seafood type Selenium sentiment analysis sentiment classification Shiny Shiny Dashboard Spark Special Special Summer Sports statistics streaming Student Interview Student Showcase SVM Switchup Tableau teachers team team performance TensorFlow Testimonial tf-idf Top Data Science Bootcamp Top manufacturing companies Transfers tweets twitter videos visualization wallstreet wallstreetbets web scraping Weekend Course What to expect whiskey whiskeyadvocate wildfire word cloud word2vec XGBoost yelp youtube trending ZORI

NYC Data Science Academy

NYC Data Science Academy teaches data science, trains companies and their employees to better profit from data, excels at big data project consulting, and connects trained Data Scientists to our industry.

NYC Data Science Academy is licensed by New York State Education Department.

Get detailed curriculum information about our
amazing bootcamp!

Please enter a valid email address
Sign up completed. Thank you!

Offerings

  • HOME
  • DATA SCIENCE BOOTCAMP
  • ONLINE DATA SCIENCE BOOTCAMP
  • Professional Development Courses
  • CORPORATE OFFERINGS
  • HIRING PARTNERS
  • About

  • About Us
  • Alumni
  • Blog
  • FAQ
  • Contact Us
  • Refund Policy
  • Join Us
  • SOCIAL MEDIA

    ยฉ 2025 NYC Data Science Academy
    All rights reserved. | Site Map
    Privacy Policy | Terms of Service
    Bootcamp Application