
Trump2cash – A stock trading bot powered by Trump tweets - laktak
https://github.com/maxbbraun/trump2cash
======
djb_hackernews
>This bot watches Donald Trump's tweets and waits for him to mention any
publicly traded companies.

Ok, simple enough, go on.

> When he does, it uses sentiment analysis to determine whether his opinions
> are positive or negative toward those companies.

Eh, sentiment analysis isn't perfect but it has come a long way, plus Trump
does typically say what he means in simplistic language.

> The bot then automatically executes trades on the relevant stocks according
> to the expected market reaction.

Ah market psychology. Stop. Do not pass Go. Do not collect $200. This is the
tricky bit that a toy project will never get right and turns your slick
algorithmic trading project into a monkey and a dart board.

Though this is a sweet example of an API mashup.

~~~
muyuu
It's perfectly workable. The bot just needs to weigh its trades properly and
provided the sentiment signal has any alpha, it can be combined with other
analysis to run a profitable strategy.

I've seen this working and working very well (day job), although not
specifically with Trump tweets.

~~~
nostrademons
If it works, the last thing you want to do is post it on HN, because it'll
stop working once everyone starts using it. Everybody else running the bot
will bid up the prices of affected stocks before you can get to it, and so by
the time your bot gets around to executing its trade, you'll be buying at
inflated prices and lose money as everyone else takes their profits.

~~~
kcorbitt
Not necessarily. If you can get a bunch of unsophisticated traders on
relatively high-latency connections (AKA the readers here) to execute a known
strategy, you can actually make a lot of money by simply frontrunning them. :)

------
karangoeluw
I actually did some basic analysis of this recently - can you really make
money in the stock market trading on Trump's tweets.
[https://medium.com/karan/can-you-really-make-money-when-
real...](https://medium.com/karan/can-you-really-make-money-when-
realdonaldtrump-tweets-about-a-company-1f99a9e337ca#.d8q5fmp9c)

My answer was maybe but I'd rather not put my money at the mercy of a lunatic.

~~~
throwaway2048
Your entire economic system is at the mercy of said lunatic.

~~~
fnovd
As we've seen recently, the power of the POTUS is not unchecked.

~~~
ben010783
We've seen recently that it _can_ be checked. Our hope is that those that with
the ability to check him continue to do so.

------
dsacco
Very cool. Funds have been capitalizing on Trump's tweets since at least
December (but probably November) of 2016:
[https://www.bloomberg.com/view/articles/2016-12-07/flash-
cra...](https://www.bloomberg.com/view/articles/2016-12-07/flash-crashes-and-
trump-trading)

I'd be interested in learning why TradeKing was used , as I haven't used it
myself - was it for an especially solid API, or just because TradeKing is easy
to get set up and doesn't require a minimum investment? If anyone wants to
play around with this and has at least $10k to play with, Interactive Brokers
will give you better fees.

OP, you might be interested in Quantopian's Zipline algorithmic trading
library, which is also in Python:
[https://github.com/quantopian/zipline](https://github.com/quantopian/zipline)

Also, I feel like there should be a disclaimer that given how accessible this
strategy is (both in required skill and resources) and how much attention the
Trump tweets phenomenon has gotten, any alpha from this has been almost
certainly lost to other firms. This is a cool project, but it's probably not
actually an effective strategy anymore.

~~~
joeyspn
> OP, you might be interested in Quantopian's Zipline algorithmic trading
> library, which is also in Python:
> [https://github.com/quantopian/zipline](https://github.com/quantopian/zipline)

Or backtrader (backtesting and live trading with Oanda and IB)

[https://github.com/mementum/backtrader](https://github.com/mementum/backtrader)

~~~
dsacco
Nice, now I've got something else to play with this weekend.

------
thedrake
another version could be to capitialize on this:

"The efficient markets hypothesis may be "the best established fact in all of
social sciences," but the best established fact in all of financial markets is
that, when there is news about a big famous private company going public or
being acquired, the shares of a tiny obscure public company with a similar
name will shoot up. I don't know what that tells you about the efficient
markets hypothesis, but it happened to Nestor, Inc., and to Tweeter Home
Entertainment, and to Oculus VisionTech Inc., and now it has happened to SNAP
Interactive Inc.:

In what is almost surely a case of mistaken identity, investors sent shares in
a little known startup called SNAP Interactive Inc., ticker STVI, surging 164
percent in the four days since Snap Inc. filed for a $3 billion initial public
offering. The $69 million SNAP Interactive makes mobile dating apps, while the
IPO aspirant is the parent of the popular Snapchat photo-sharing app. These
stories are always less impressive when expressed in dollar terms than they
are in percentages. In the four trading days since Snap Inc. filed its S-1,
SNAP Interactive has traded 19,963 shares, worth less than $200,000, according
to Bloomberg data. If you had a cunning plan to buy up SNAP shares and sell
them for a quick profit when Snap filed to go public, it might have worked,
but not in particularly huge size."

article here: [https://www.bloomberg.com/view/articles/2017-02-09/quasi-
ind...](https://www.bloomberg.com/view/articles/2017-02-09/quasi-indexers-
growth-and-confusion)

~~~
warbiscuit
There was an article a while back --
[https://news.ycombinator.com/item?id=1144548](https://news.ycombinator.com/item?id=1144548)
\-- purporting that the efficient market hypothesis is true if and only if P =
NP. ... which I'd argue implies social science is overly optimistic about that
hypothesis.

~~~
idanoeman
That also implies that if the market is very close to efficient, you need
absolutely massive amounts of computational power to bring it even closer
(i.e. to make money). So even if it is inefficient, that doesn't mean anyone
can reasonably expect to find exploitable patterns.

------
chis
Pretty clever and effective message. I'd put money on this being shared by all
my friends on Facebook in a few days.

Trump's last couple tweets have backfired and actually increased his targets'
stock price though. You might have to flip the algorithm around if this
continues.

~~~
espadrine
I read it as the stock market betting on the constitution. Mr Trump is not
allowed to impact Nordstrom negatively for his daughter's sake.

But most of the other tweets are about cases where he could harm them as
POTUS.

~~~
phalangion
If he can't do anything, why would the stock change at all?

~~~
espadrine
Speculation again: it highlighted that Nordstrom would not be pressured into a
decision that would yield poorer results.

------
captainmuon
Brilliant. I've been thinking about something like this for a while.

Why don't you take it to the next level? Provoke Trump on Twitter, associating
yourself with a company. Then short that company's stock and wait until he
lashes out against them. Profit!

~~~
rtpg
It's weird because he probably doesn't read his mentions... except sometimes
he RT's someone in his mentions?

Is he looking?

~~~
angry-hacker
He's not the only one handing his Twitter account I'm sure.

~~~
imafish
Yes. Surely, he must have several other insane people helping him. I.e. that
much insanity cannot physically be contained in a single human being.

~~~
Kadin
Load-balanced insanity. Truly, we are living in the future.

~~~
droidist2
Hmm, Insanity as a Service might actually be lucrative.

------
butler14
An ad agency did this 3 weeks ago

[https://www.t-3.com/works/the-trump-and-dump-
bot/](https://www.t-3.com/works/the-trump-and-dump-bot/)

------
nodesocket
Novel project, but not useful. Trump tweeted thanks to Intel on Feb 8th which
was a super positive tweet. Since then $INTC is down about 2.6%.

~~~
xuki
He tweeted negatively about Nordstrom, stock went up. We might be onto
something here...

~~~
ISL
One can easily place bets on the volatility of a stock. If you expect it to
move, but you don't know which direction, that is tradeable knowledge.

~~~
BWStearns
Tweets seem to have an impact of around 1-3% lasting hours to days. Many
(most?) stocks have too high implied volatility to begin with for straddling
by tweet to be a productive strategy.

~~~
ISL
Even as an ensemble?

~~~
BWStearns
If you could spot the tweet and know the direction it'd move there might be
cheap enough options to make money on one side, but the "ensemble" aspect of a
straddle means that you need to make twice as much to cover the premiums
before you make any returns.

------
jnaddef
If many people use this bot, it will make Trump's comments actually effective,
which is a pretty bad idea imho.

What about a bot which would do just the opposite?

~~~
rhaps0dy
I think you have this backwards. If Trump tweets a negative sentiment, the bot
buys from the company. If everyone did that, the price would go up - just the
opposite of the current effect!

~~~
etatoby
I know very little of the stock market, but shouldn't the bot buy shares when
he tweets _positive_ comments? Because that's when the stock is expected to
rise and you can sell it later for a profit.

~~~
duozerk
Indeed, but the comment you're responding to was tongue-in-cheek, specifically
suggesting that Trump being positive of a stock is a negative indicator for
it.

------
alex-
As the poster doesn't this gives Trump the power to manipulate markets with
nothing more than a tweet?

You could argue he already has this power, but before the message needed to
resonate with a large collective of people. Any public figure (like Warren
Buffet, etc) can express an opinion that might effect the stock they are
commenting on.

However as this group of people automate trades on only the contents of his
tweets (and not say the contents of the tweet as well as past company
performance, current POTUS approval ratings, dividend plans etc) he gains a
scary amount of control over the markets.

To put another way. The only people who know what he will tweet earlier than
these bots are Trump and maybe a select group of people he tells before hand.

~~~
drak0n1c
Politicians impacting the stock market is nothing new. Pipeline and coal
companies plummeted with Obama's executive orders, and the executive branch
DOJ created a huge drop in prison stocks with what was effectively an indirect
tweet. Solar stocks zig zagged according to the latest Solyndra and renewables
subsidy activity. The only thing new is Twitter as a more easily machine-
readable mouthpiece.

Congress actually gets a free pass on buying and selling stocks with insider
information and many have done so for decades:
[http://www.cbsnews.com/news/congress-trading-stock-on-
inside...](http://www.cbsnews.com/news/congress-trading-stock-on-inside-
information/)

~~~
dlgeek
I think what's novel/different here is the examples you all cited are examples
of market reaction to government action, compared to, let's call it "executive
sentiment". The distinction here is people are anticipating future actions
based a politician expressing feelings rather than taking action.

------
martin-adams
This could make quite a fun experiment to see if it works. Crowdsource an
investment of something like $10,000 and let it run for a year. At the end,
donate all proceeds to charity.

~~~
grif-fin
Good idea! Where to begin?

Shall we go for refugee charity?

~~~
mc42
I would say to organizations that directly support people, be it Direct
Relief, The ACLU, or Charity: water.

Other good options are FIRST, Girls Who Code, and The Geek Group, all orgs
that focus on STEM Education and getting people into the STEM fields.

Just to name a few groups to directly counterbalance his behavior.

~~~
pc86
> _Other good options are FIRST, Girls Who Code, and The Geek Group, all orgs
> that focus on STEM Education and getting people into the STEM fields._

How do these technical organizations counterbalance anything he is doing?

------
rthomas6
(I know this is just for fun, but...) I believe this won't work because of
high-frequency trading. By the few seconds this latent python script will take
to get the tweet, analyze the tweet, and execute a trade, high-speed bots will
have already done something similar to a price level they decided was
appropriate using sophisticated algorithms.

So basically, instead of this bot betting that Trump's tweets will change
stock prices, you're actually betting on the HFT bots being wrong about how
much Trump's tweets change stock prices.

~~~
Paradigma11
This implies that HFT algos know of Trumps tweets. Is this really done?

------
swalsh
The fact that Trump has the vocabulary of an 8th grader makes this a lot
easier.

~~~
mikeash
From a brief search, most presidential candidates speak at around an 8th grade
level. (Which makes sense. They need to appeal to a broad audience, and
speaking at a higher level is usually counterproductive anyway unless you have
a specialized audience.) Trump's speaking level is more like 3rd or 4th grade.

~~~
wahern
From a recent Fresh Air interview with Trevor Noah. Earlier on he explains
with a more personal anecdote why simpler language matters. But is there such
a thing as too simple? Is 8th grade language more effective than 4th grade
language? Later on Trevor Noah says

    
    
      You know, funny enough, one of the biggest moments of
      realization was when Donald Trump won the election because
      when I came into the show, I said, I think this guy can win.
      This was when he first came down that escalator. He gave his
      first speech.
    
      And then I was like, wow, this guy's going to do well. And I
      remember people laughed at me. People were like, oh, you
      silly ignorant person who's just come to this world. You
      clearly shouldn't be at "The Daily Show" 'cause you don't
      know what you're talking about. And I was like, but I don't
      know. He seems like he connects with people. I can relate to
      him as a performer. I can see what tools he's using. He's
      good at riffing. He's good at taking the crowd on a journey.
      I can see what he's doing.
    
      And people would say - and all throughout the race - and
      there were times when, on the show, I would mention it. You
      know, I mean, that's why I said Trump reminds me of an
      African dictator. And that's where that came from because
      everyone said to me, this guy is - he's just a fool. He's
      just - he's a buffoon. I said, yeah, you can say that. But
      I've seen this before. I have seen this before. I've seen
      clowns that go on to take over their countries. I've seen
      buffoons who end up ruling their worlds. And it came to
      pass.
    
      Source: http://www.npr.org/2016/12/16/505847054/trevor-noah-says-he-grew-up-in-the-shadow-of-a-giant-his-mom

------
mhuffman
I have been doing the opposite.

Whenever Trump signs on executive order or signals an intention, I presume it
will either fail or will end in bad results for the poor and middle class.

Then, working as if that were true, I see if there are any stocks or ETFs that
would benefit from that and buy some.

I have been doing pretty good!

~~~
emcq
The market as a whole is going up. Are your seeing above market average
returns?

~~~
mhuffman
Very much so! [1]

You can even see on the chart how there was very little until inauguration,
giant leaps after unpopular EO's, and you can even see the portfolio drop when
Trump took a beat and eased up on the EOs after Feb 3rd.

[1] [http://i.imgur.com/OoeMEJF.png](http://i.imgur.com/OoeMEJF.png)

------
gliese1337

        This bot watches Donald Trump's tweets and waits for him to mention any publicly traded companies. When he does, it uses sentiment analysis to determine whether his opinions are positive or negative toward those companies. The bot then automatically executes trades on the relevant stocks according to the expected market reaction.
    

OK, so what's the expected market reaction? If Trump hates your company, does
that make your stock go up, or down?

~~~
jbmorgado
Down on the immediate, up after some hours:

The article just mentions how it ended the day (UP), but it started by going
DOWN quite a few % after Trump spoke against it:

[http://fox6now.com/2017/02/09/nordstrom-stock-defies-
preside...](http://fox6now.com/2017/02/09/nordstrom-stock-defies-president-
trump/amp/)

------
hmate9
I think Nordstrom stock went up after a negative tweet because it was seen as
good publicity for the company. Trump didn't actually "threaten" to retaliate
or anything, whereas for companies like Ford or GM he actually said he would
impose a heavy "border tax" if they opened factories elsewhere.

~~~
beaconstudios
perhaps further sentiment analysis could be used to determine whether the
tweet implies the company can expect government action for/against them.

~~~
hmate9
Maybe a bit difficult to do so because of the limited amount of data, but we
could maybe only look at the tweets with positive sentiment, in which case the
stock price will likely go up. As it is good publicity for the company and
Trump was positive about the stock as well.

------
gurgus
Cool project!

Makes me want to think of another fun way of crowdsourcing stock tips for fun.

Maybe something like TwitchPlaysWallStreet?

------
theocean154
I have one of these as well, but i would've died if it was live trading during
the nordstrom incident. They've gone up quite a bit since then.

------
carlmcqueen
Regardless of this bot being complete, there are better options already
mentioned using options instead of short term stock purchases.

Looks like deciding the sentiment of the tweet is still on the to-do list.

def get_sentiment(self, text): """Extracts a sentiment score [-1, 1] from
text."""

    
    
            # TODO: Determine sentiment targeted at the specific entity.

------
makerofthings
I like this. I think something similar for Theresa May and the GBP:EUR
exchange rate might be a good addition.

~~~
thenomad
Won't work as well: the market now prices in the drop in GBP after she speaks,
so as soon as there's even a hint she's going to say something substantive,
the market drops like a stone, then recovers a bit if she doesn't say anything
_too_ awful.

------
jagermo
Nordstrom went up after Trumps rant, didn't it? But all in all this looks like
a fun thing to do.

------
chatwinra
You know at the end of Men in Black it zooms out and our galaxy is just one
marble in a galactic game?

I feel like this game is just a small scale version of the one being played by
a higher force by making Trump president.

~~~
fredley
The higher force being Putin? /s (sort of)

------
Gupie
It would work better is you knew in advance what Trump is going to tweet, not
possible of course unless you work for twitter or for Trump?!

~~~
laumars
That would likely be classed as "insider trading":

[https://en.wikipedia.org/wiki/Insider_trading](https://en.wikipedia.org/wiki/Insider_trading)

~~~
ryanlol
For that you'd have to be an "insider" which obviously isn't the case here.

~~~
laumars
You don't need to be hired by the company to be classed as an insider (though
that obviously also counts). If you are privy to non-public information (which
you would be if you were forewarned about a Trump PR stunt before it happened)
and then you trade stock based on that information then legally you could be
classed as an insider.

In fact that wiki link I posted earlier previously says just this:
[https://en.wikipedia.org/wiki/Insider_trading#Definition_of_...](https://en.wikipedia.org/wiki/Insider_trading#Definition_of_.22insider.22)
(last paragraph on 'Definition of "Insider"')

~~~
ryanlol
Who is the "insider" in this context then?

Here's a hypothetical scenario:

My buddy Sean from the white house texted me a few days ago that "Trump is
going to make negative comments about Nordstrom soon", I shorted Nordstrom
stock based on this information and made huge profits when Trump said the
things Sean promised he would.

Do you think _someone_ would be guilty of insider trading here? Nobody
involved is connected to Nordstrom in any way.

~~~
hueving
Yes, you are guilty by trading using non public information about a material
event.

~~~
ryanlol
That information would have to come from a Nordstrom insider for it to be
"insider trading". Neither Trump or Sean are Nordstrom insiders.

It's also extremely important to note that the SEC and the courts have very
different definitions of "insider trading".

~~~
laumars
i don't mean to sound dogmatic but the source I cited does explicitly say that
the "insider" does not have to work inside the company specifically but rather
just be privy to non-public information.

Unless you can find another citation that contradicts my point then I'm going
to have to assume my point is correct. And I say that welcoming a correction
in the name of "science" :)

~~~
ryanlol
>In the United States, Canada, Australia and Germany, for mandatory reporting
purposes, corporate insiders are defined as a company's officers, directors
and any beneficial owners of more than 10% of a class of the company's equity
securities. Trades made by these types of insiders in the company's own stock,
based on material non-public information, are considered fraudulent since the
insiders are violating the fiduciary duty that they owe to the shareholders.
The corporate insider, simply by accepting employment, has undertaken a legal
obligation to the shareholders to put the shareholders' interests before their
own, in matters related to the corporation. When insiders buy or sell based
upon company-owned information, they are violating their obligation to the
shareholders.

Presumably it's not this chapter you're referring to.

>For example, illegal insider trading would occur if the chief executive
officer of Company A learned (prior to a public announcement) that Company A
will be taken over and then bought shares in Company A while knowing that the
share price would likely rise.

Probably not this one either

>In the United States and many other jurisdictions, however, "insiders" are
not just limited to corporate officials and major shareholders where illegal
insider trading is concerned but can include any individual who trades shares
based on material non-public information _in violation of some duty of trust_.
This duty may be imputed; for example, in many jurisdictions, in cases of
where a corporate insider "tips" a friend about non-public information likely
to have an effect on the company's share price, the duty the corporate insider
owes the company is now imputed to the friend and the friend violates a duty
to the company if he trades on the basis of this information.

Despite the fact that this chapter doesn't contain anything relevant either,
it's probably this one you're referring to. There's no corporate insiders or
relationships involving a duty of trust here.

I think you may be misinterpreting your source.

------
B1FF_PSUVM
> mention any publicly traded companies

How often did that happen in the past?

(Not paying attention, specialty of the house ;-)

~~~
redlum1
You can check that at
[https://twitter.com/Trump2Cash](https://twitter.com/Trump2Cash).

------
tmalsburg2
This is fun. However, does this bot perform better than a random bot? and if
yes, how much?

~~~
cxseven
According to [http://trump2cash.biz/](http://trump2cash.biz/) ,

"Overall, the algorithm seems to succeed more often than not: The simulated
fund has an annualized return of about 59% since inception. There are limits
to the simulation and the underlying data, so take it all with a grain of
salt."

~~~
tmalsburg2
Yes, I saw that. What we don't know is whether the bot just got lucky.
Inferential stats are needed to determine this.

------
DanBC
But see this, which says his tweets generally don't make much difference:
[https://www.ft.com/content/a962c1f8-ee44-11e6-930f-061b01e23...](https://www.ft.com/content/a962c1f8-ee44-11e6-930f-061b01e23655)

------
paulpauper
the problem is hedge funds are already on his twitter like white on rice.
Maybe there is hope in looking for breaking news from less-followed accounts.

------
AltGr
I can't state how stupid this is. As if that person's bullshit's power of
nuisance wasn't large enough, let's add automated echo chambers with a direct
effect on the economy!

Don't be surprised if this crazy economic system can collapse any seconds with
ideas like this.

------
AznHisoka
How many times do we have to go over this?

stocks are a random walk.

~~~
Kadin
That may or may not be true, but it's irrelevant in this case. The bot is
basically front-running the market, or trying to anyway, by trading directly
on a stimulus that the market (potentially) takes time to internalize and
react to.

If this worked, I'd expect the HF funds to start doing it too, and even
faster, and then the advantage would be destroyed.

~~~
lorenzhs
This is not front running (which is illegal). It's trying to be faster than
people who trade manually based on the same info. The term front running has a
pretty clear definition, it's roughly when a broker trades on your orders
before executing them.

