Monday, February 27, 2017

Buy or Sell? Stock Market Daily Tracker

With my life getting busier and busier, adding another item to the daily morning routine, no matter how short in the amount of time it takes, is to be avoided.  So as I have been observing the recent increases in the stock market and deciding that I should be paying attention more, I have been pondering about how I might do this in a more automated fashion.

Consequently, I decided to write a simple Python program that pulls some daily stock market information (e.g., today's opening, yearly high, yearly low), runs some calculations (e.g., opening / yearly high), and then after some simple conditional logic, tells me whether I should buy. This code runs on a daily schedule and opens up in a pop-up window automatically.

It is rather simplistic, but a quick glance at this every day is a simple way to keep an eye on the market and to be informed of action I should take in response.



The code is posted to GitHub if you are interested.

Friday, February 24, 2017

POS News Update: Best of 2016

In a previous post, I described an experiment with automating Twitter posts using news headlines with the nouns switched around.  I have been auto-Tweeting these posts since July 2015.  I did a previous "best of" post for 2015.  Now here are my 10 favorites from 2016 out of the close to 250 that were auto-Tweeted last year:

10. 'RARE NEWBORN REPORT MAY BE THE YOUNGEST EVER DETECTED'
  • It is a newborn report on newborns.
9.  'POOL IS ENDING PARENT END BREEDING'
  • Sorry parents, but no more breeding at your end of the pool.
8. 'CINCINNATI MAY PROLONG CHRONIC PAIN, CLINTON SUGGESTS'
  • If the science is sound and you have chronic pain, you probably want to avoid Cincinnati in the future.
7. 'SPUDS GROW HUMAN SPIES OUTSIDE OF CHINA FOR 13 DAYS'
  • For a long time humans have been growing potatoes.  Now potatoes are growing humans.  And not just any humans...
6. 'NORTH CHINA FIRES BALLISTIC PRESSURE INTO EATING'
  • Speaking of China, its efforts to push eating are akin to warfare.
5. 'NEW YORK GHOSTBUSTER CAN ENFORCE PUMP FEARS ON MENUS, U SAYS'
  • If you are a New York restaurant owner and your customers are feeling overly optimistic about the price of gasoline, who're you gonna call?
4. 'TWELVE MEAT RECOUNT PODS SHARE $43 MILLION IN [...] DENTAL JOB.'
  • As many as twelve groups responsible for counting meat products profited from some very expensive dental work.
3. 'MOST NEW GIRLS SAY THEY'LL VOTE TO RE-ELECT THEIR MAGIC WILDFIRES'
  • Despite what previous women have done, the younger generation is voting for mystical forest burning.
2. 'MICROSOFT'S 2016: DIPLOMATS 10 PRECAUTIONS AND INDIANS ARE THE BIG FEARS'
  • Microsoft's biggest worries in 2016? What foreign representatives are saying, and Indians.
1.  'GET YOUR CANADA MANIPULATION WITH FITBIT 'SLEEP SCHEDULE''
  • Finally, you can control Canada with a simple electronic device disguised as a sleeping aid.

Well, that was fun, but I am moving on to other kinds of coding experiments and automated Tweets.  So I'll be discontinuing the #POSNewsUpdate going forward.

Still, you can follow me on Twitter at @philanalytics to get the latest updates from the blog.

Thursday, February 16, 2017

2016 NFL Game Predictions: Season Recap



















The 2016 NFL season is over. How did I do in my predictions?  Here are the links to all predictions made:

2016 NFL Predictions:

Season Recap

Here are some summary statistics:
  • Correct Prediction %:
    • Whole season (regular and playoffs): 61%
    • Regular season: 61%
    • Playoffs: 55%
  • Statistical significance two-tailed binomial test (95% CI):
    • Whole season: 
      • p-value:  0.0006
      • CI: (0.55,0.67)
    •  Regular season:
      • p-value: 0.0006
      • CI: (0.55,0.67)
    • Playoffs:
      • p-value: 1
      • CI: (0.23,0.83)
My predictions were accurate about 61% of the time.  This was statistically significant.  I didn't do so well in the playoffs, but I am not surprised.  The playoffs are much harder to predict as the teams are better, more evenly matched, and there are fewer games to predict so each one counts for more in the percentages.

Comparison to FiveThirtyEight

In week 7 I compared my predictions to those being made by others.  Because 538.com took a similar approach to automating predictions and was doing the best at the time for all sites that I could find, I took 538.com to be a good benchmark to measure against. 
I should note that since then, the best overall predictions I have found have come from Elliot Harrison at NFL.com.  Assuming that he predicted the Patriots to win the Superbowl, he went 179-86-2 over the course of the whole season.  That is 68% correct predictions! 
This was not an automated approach so a direct comparison between what I have done/what 538.com has done and what Elliot Harrison has done is not entirely justifiable.  If we wanted to compare apples to apples, I would need to compare my own personal predictions (which may override my model's predictions) to what Elliot Harrison has done.  I did not keep track of this, but it is on my list to do for next season.
Consequently, I will focus on 538.  How did it do?
  • Whole season: 64%
  • Regular season: 64%
  • Playoffs: 72%
538 did do better.  That's ok.  With more time and investment in this, I'd hope that I could match or exceed it's performance, but given other commitments, that hasn't been possible.  Maybe next season...

Season Visualized

Here is a chart that shows my progress over the course of the season.  You can see that I started well, but had some low points in weeks 4 - 8.  After that, apart from week 13, the model did pretty well and the season win ratio increased.  Playoffs were a bit erratic, mainly due to a poor division week prediction, but this didn't really effect the overall trend.

Here are comparisons of the weekly win ratios and season win ratios between 538 and me.  On a weekly basis, I beat 538 6 times, I was beat 8 times, and I tied 6 times.  So there was good back and forth on a weekly basis. 
However, 538 beat me by more and lost by less, so 538 had a higher season win ratio pretty much all the way through.

Going Forward

Just like last year, there is always next year.  I still have a long list of improvements to make, especially in code management and automation, and data management and pipeline.  We'll see what happens :)

Thanks for joining me this season.  See you next year!

Thursday, February 9, 2017

2016 NFL Game Predictions: Best Team of the Season

The season is over and the Patriots have been crowned the SuperBowl champions.  But as I have asked in the past, which team was the "best" team this season?

Again, I use "best" in the sense that, according to my models, the team that is "best" would have the most wins in a tournament in which every team in the NFL played every other team in the NFL. There are 32 games total for each team (and playing yourself is a win), so the team with the most wins out of 32 would be the "best" team.  Note that my models assume that every player is healthy (i.e., no injuries).

In my previous analysis in week 14, the Cowboys, Seahawks, Chiefs, Broncos, and Patriots were the best (in that order) by expected value of wins when summing up probabilities.  Each of these teams was expected to win 21.x games out of 32.  By expected total number of wins (all or nothing),  the Cowboys, Chiefs, Broncos, Seahawks, and Raiders were the top 5 best.  The Patriots finished at number 6. 

What has changed since then?  Here are the final predictions of where each team would rank in a tournament of each team against every other team for the 2016 season:

 

Expected Value of Wins:


The Patriots are on top!  They moved up to 24.5 games won out of 32.  The Cowboys slide down to second at 23.9, while the Falcons take third at 22.8.  The Raiders, Chiefs, and Seahawks follow these.

The worst?  Browns finish last at 6.4 games out of 32.  The Browns are followed by the 49ers (7.2), Jaguars (7.4), Rams (7.6), and Bears (8.2) as being the worst teams this year.  Here are the full results:

Rank
Team
Expected Value
1
Patriots
24.544
2
Cowboys
23.926
3
Falcons
22.845
4
Raiders
22.799
5
Chiefs
22.729
6
Seahawks
22.281
7
Steelers
22.071
8
Giants
21.081
9
Lions
20.87
10
Dolphins
20.805
11
Packers
20.763
12
Texans
19.713
13
Titans
18.784
14
Redskins
18.438
15
Buccaneers
17.4
16
Colts
15.755
17
Ravens
15.566
18
Broncos
15.386
19
Cardinals
13.909
20
Saints
13.882
21
Vikings
13.881
22
Bills
13.386
23
Eagles
12.649
24
Bengals
11.664
25
Chargers
10.601
26
Jets
10.032
27
Panthers
9.274
28
Bears
8.242
29
Rams
7.628
30
Jaguars
7.437
31
49ers
7.237
32
Browns
6.422


 

Total Wins (All or Nothing):


With total wins, the Cowboys take the top slot as the only team predicted to beat the Patriots (52.2%) and to win all games.  Second are the Patriots, followed by the Raiders, Chiefs, Falcons, and Seahawks.  The worst are the Rams, followed by the Browns, Jaguars, 49ers, and Bears.  Here are the full results:
Rank
Team
Total Wins
1
Cowboys
32
2
Patriots
31
3
Raiders
30
4
Chiefs
29
5
Falcons
28
6
Seahawks
27
7
Giants
26
8
Steelers
25
9
Dolphins
24
10
Lions
23
11
Packers
22
12
Texans
21
13
Titans
20
14
Redskins
19
15
Buccaneers
18
16
Ravens
16
16
Colts
16
16
Broncos
16
19
Cardinals
14
20
Saints
13
21
Vikings
12
22
Bills
11
23
Eagles
10
24
Bengals
9
25
Chargers
8
26
Panthers
7
27
Jets
6
28
Bears
5
29
49ers
4
30
Jaguars
3
31
Browns
2
32
Rams
1

 

Conclusion:


I think it is safe to say that this year, the "best" team won the SuperBowl.  The only other contender for that title in my analysis was the Cowboys who finished second in expected value but first in total wins, trading spots with the Patriots.  It's too bad we didn't see a Patriots vs. Cowboys showdown in the SuperBowl.  But there is always next year...