That One Time I Though I Cracked the Stock Market with the Department of Defense

Seven to five years ago, I was absolutely obsessed with the idea of beating the stock market. I dove headfirst into the world of investing, devouring books, blogs, and whatever information I could get my hands on. I was like a sponge, soaking up everything. After countless hours of research, I came to one clear conclusion:

To consistently beat the market, I needed a unique edge—some kind of knowledge advantage that others didn’t have.

It’s like insider trading, but, you know, without the illegal part. My plans to uncover obscure data and resources online that only a select few were using. That way, I’d have a significant edge over the average trader. In hindsight, I’m pretty sure that’s what big hedge funds, especially the short-selling ones, are doing—just with a ton more money and resources than I had. But I’ve always thought, “If someone else can do it, so can I.” At the end of the day, those hedge fund managers are just people too, right?

Around that time, I was really into the movie War Dogs. It had this fascinating angle that got me thinking about analyzing the weapons trade, aka the “defense” sector.

Here’s the interesting part: The United States is surprisingly transparent when it comes to defense spending. They even publicly list their contracts online (check out the U.S. Department of Defense Contracts page). The EU, on the other hand, is a completely different story. Getting similar information was like pulling teeth. You’d basically need to lawyer up and start writing formal letters to access anything remotely useful.

The Idea

Quite simply: Build a tool that scrapes the Department of Defense contracts website and checks if any of the publicly traded companies involved had landed massive new contracts or reported significantly higher income compared to the previous quarter.

Based on the findings, I’d trade CALL or PUT options. If the company performed poorly in the quarter or year, I’d go for a PUT option. If they performed exceptionally well, I’d opt for a CALL, banking on the assumption that these contracts would positively influence the next earnings report.

Theoretically, this seemed like one of those obvious, no-brainer strategies that had to work. Kind of like skipping carbs at a buffet and only loading up on meat to get your money’s worth.

Technologie

At first, I did everything manually with Excel. Eventually, I wrote a Python Selenium script to automate the process.

Here’s the main script I used to test the scraping:

// Search -> KEYWORD
// https://www.defense.gov/Newsroom/Contracts/Search/KEYWORD/
// -------
// Example:
// https://www.defense.gov/Newsroom/Contracts/Search/Boeing/
// ------------------------------------------------------------

// All Contracts -> PAGE (momentan bis 136)
// https://www.defense.gov/Newsroom/Contracts/?Page=PAGE
// -------
// Example:
// https://www.defense.gov/Newsroom/Contracts/?Page=1
// https://www.defense.gov/Newsroom/Contracts/?Page=136
// -------------------------------------------------------

// Contract -> DATE
// https://www.defense.gov/Newsroom/Contracts/Contract/Article/DATE
// -------
// https://www.defense.gov/Newsroom/Contracts/Contract/Article/2041268/
// ---------------------------------------------------------------------

// Select Text from Article Page
// document.querySelector(".body")

// get current link
// window.location.href



// ---> Save Company with money for each day in db

// https://www.defense.gov/Newsroom/Contracts/Contract/Article/1954307/
var COMPANY_NAME = "The Boeing Co.";
var comp_money = 0;
var interesting_div = document.querySelector('.body')
var all_contracts = interesting_div.querySelectorAll("p"),i;
var text_or_heading;
var heading;
var text;
var name_regex = /^([^,]+)/gm;
var price_regex = /\$([0-9]{1,3},*)+/gm;
var price_contract_regex =/\$([0-9]{1,3},*)+ (?<=)([^\s]+)/gm;
var company_name;
var company_article;

for (i = 0; i < all_contracts.length; ++i) {
  text_or_heading = all_contracts[i];

  if (text_or_heading.getAttribute('id') != "skip-target-holder") {
  	if (text_or_heading.getAttribute('style')) {
  		heading = text_or_heading.innerText;
  	} else {
  		text = text_or_heading.innerText;
	    company_name = text.match(name_regex)
	    contract_price = text.match(price_regex)
	    contract_type = text.match(price_contract_regex)

	    try {
	    	contract_type = contract_type[0];
	    	clean_type = contract_type.split(' ');
	    	contract_type = clean_type[1];
	    } catch(e) {
	    	contract_type = "null";
	    }
	    try {
	    	company_article = company_name[0];
	    } catch(e) {
	    	company_article = "null";
	    }
	    try {
	    	contract_amount = contract_price[0];
		    if (company_article == COMPANY_NAME){
		    	contract_amount = contract_amount.replace("$","")
		    	contract_amount = contract_amount.replace(",","")
		    	contract_amount = contract_amount.replace(",","")
		    	contract_amount = contract_amount.replace(",","")
		    	contract_amount = parseInt(contract_amount, 10)


		    	comp_money = contract_amount + comp_money
	    	}
	    } catch(e) {
	    	contract_amount = "$0";
	    }

	    console.log("Heading      : " + heading);
	    console.log("Text         : " + text);
	    console.log("Company Name : " + company_article);
	    console.log("Awarded      : " + contract_amount)
	    console.log("Contract Type: " + contract_type);
  	}
  }
}
console.log(COMPANY_NAME);
console.log(new Intl.NumberFormat('en-EN', { style: 'currency', currency: 'USD' }).format(comp_money));



// --> Save all Links to Table in Database
for (var i = 1; i >= 136; i++) {
	var url = "https://www.defense.gov/Newsroom/Contracts/?Page=" + i

	var  page_links = document.querySelector("#alist > div.alist-inner.alist-more-here")
	var all_links   = page_links.querySelectorAll("a.title")

	all_links.forEach(page_link => {
		var contract_date = Date(Date.parse(page_link.innerText))
		var contracvt_link = page_link.href
	});
}

The main code is part of another project I called “Wallabe“.

The stack was the usual:

  • Python: The backbone of the project, handling the scraping logic and data processing efficiently.
  • Django: Used for creating the web framework and managing the backend, including the database and API integrations.
  • Selenium & BeautifulSoup: Selenium was used for dynamic interactions with web pages, while BeautifulSoup handled the parsing and extraction of relevant data from the HTML.
  • PWA (“mobile app”): Designed as a mobile-only Progressive Web App to deliver a seamless, app-like experience without requiring actual app store deployment.

I wanted the feel of a mobile app without the hassle of actual app development.

One of the challenges I faced was parsing and categorizing the HTML by U.S. military branches. There are a lot, and I’m sure I didn’t get them all, but here’s the list I was working with seven years ago (thanks, JROTC):

millitary_branch = {'airforce',
                    'defenselogisticsagency',
                    'navy',
                    'army',
                    'spacedevelopmentagency',
                    'defensemicroelectronicsactivity',  
                    'jointartificialintelligencecenter',      
                    'defenseintelligenceagency',
                    'defenseinformationsystemagency',
                    'defensecommissaryagency',
                    'missiledefenseagency',
                    'defensehealthagency',
                    'u.s.specialoperationscommand',
                    'defensethreatreductionagency',
                    'defensefinanceandaccountingservice',
                    'defenseinformationsystemsagency',
                    'defenseadvancedresearchprojectsagency',
                    'washingtonheadquartersservices',
                    'defensehumanresourceactivity',
                    'defensefinanceandaccountingservices',
                    'defensesecurityservice',
                    'uniformedservicesuniversityofthehealthsciences',
                    'missledefenseagency',
                    'defensecounterintelligenceandsecurityagency',
                    'washingtonheadquartersservice',
                    'departmentofdefenseeducationactivity',
                    'u.s.transportationcommand'}

I tried to revive this old project, but unfortunately, I can’t show you what the DoD data looked like anymore since the scraper broke after some HTML changes on their contracts website. On the bright side, I can still share some of the awesome UI designs I created for it seven years ago:

Imagine a clean, simple table with a list of companies on one side and a number next to each one showing how much they made in the current quarter.

How it works

Every day, I scrape the Department of Defense contracts and calculate how much money publicly traded companies received from the U.S. government. This gives me a snapshot of their revenue before quarterly earnings are released. If the numbers are up, I buy CALL options; if they’re down, I buy PUT options.

The hardest part of this process is dealing with the sheer volume of updates. They don’t just release new contracts—there are tons of adjustments, cancellations, and modifications. Accounting for these is tricky because the contracts aren’t exactly easy to parse. Still, I decided it was worth giving it a shot.

Now, here’s an important note: U.S. defense companies also make a lot of money from other countries, not just the U.S. military. In fact, the U.S. isn’t even always their biggest contributor. Unfortunately, as I mentioned earlier, other countries are far less transparent about their military spending. This lack of data is disappointing and limits the scope of the analysis.

Despite these challenges, I figured I’d test the idea on paper and backtest it to see how it performed.

Conclusion

TL;DR: Did not work.

The correlation I found between these contracts and earnings just wasn’t there. Even when the numbers matched and I got the part right that “Company made great profit,” the market would still turn around and say, “Yeah, but it’s 2% short of what we expected. We wanted +100%, and a measly +98% is disappointing… SELLLL!”

The only “free money glitch” I’ve ever come across is what I’m doing with Bearbot, plus some tiny bond tricks that can get you super small monthly profits (like 0.10% to 0.30% a month).

That said, this analysis still made me question whether everything is truly priced in or if there are still knowledge gaps to exploit. The truth is, you never really know if something will work until you try. Sure, you can backtest, but that’s more for peace of mind. Historical data can’t predict the future. A drought killing 80% of cocoa beans next year is just as possible as a record harvest. Heck, what’s stopping someone from flying to Brazil and burning down half the coffee fields to drive up coffee bean prices? It’s all just as unpredictable as them not doing that (probably, please don’t).

What I’m saying is, a strategy that’s worked for 10 years can break tomorrow or keep working. Unless you have insider info that others don’t, it’s largely luck. Sometimes your strategy seems brilliant just because it got lucky a few times—not because you cracked the Wall Street code.

I firmly believe there are market conditions that can be exploited for profit, especially in complex derivatives trading. A lot of people trade these, but few really understand how they work, which leads to weird price discrepancies—especially with less liquid stocks. I also believe I’ve found one of these “issues” in the market: a specific set of conditions where certain instruments, in certain environments, are ripe for profit with minimal probability if risk (which means: high risk that almost never materializes). That’s Bearbot.

Anyway, long story short, this whole experiment is part of what got Bearbot started. Thanks for reading, diamond hands 💎🙌 to the moon, and love ya ❤️✌️! Byeeeee!

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *