Is ChatGPT The Future of Trading?
279 views
Dec 11, 2024
Is #ChatGPT the future of #trading? I test its trading knowledge and discover what it can do in #python. Find out my thoughts. š Subscribe for more: https://bit.ly/3lLybeP š Episodic Pivot: https://analyzingalpha.com/episodic-pivot š PEAD Anomaly: https://analyzingalpha.com/post-earnings-announcement-drift ā±ļø Video Chapters 0:00 Intro 0:30 Can ChatGPT Create Trading Algos? 1:14 You NEED a Market Philosophy 1:48 Components of a Trading System 3:41 Components of an Algorithmic Trading System 4:53 Trading Strategy Examples 6:15 Trend Following System in Python 9:05 GPT Strategy Python Walkthrough Analysis 13:25 PEAD Anomaly Strategy Request 14:15 Episodic Pivot 18:40 Outro ---
View Video Transcript
0:00
hello everyone today we're going to use
0:01
open ai's chat GPT to attempt to create
0:04
a python trading strategy now for those
0:07
of you that don't know my name's Leo I'm
0:09
an actual algorithmic Trader so the
0:11
point of this video is you're going to
0:12
get to walk alongside me as I see the
0:15
chat GPT responses and I'll comment as
0:18
an actual professional Trader and see if
0:21
it just pumps out lame you know Golden
0:23
Cross moving average trading strategies
0:26
all right let's see what we get here so
0:29
first things first can you create
0:32
trading strategy geez
0:35
all right let's see what it says yes I
0:39
can certainly help you with training
0:40
strategies so uh chat GPT I believe was
0:43
trained on Wikipedia and GitHub if I'm
0:46
not mistaken I haven't really dived too
0:49
much into it I'm gonna actually start
0:51
diving more into it because it's you
0:52
know the new hot thing and there's
0:54
things that we could do to potentially
0:56
do sentiment analysis and stuff like
0:57
that but let's go ahead and go back to
1:00
the prompt here
1:01
okay some prefer to start off by a set
1:04
of technical or fundamental analysis
1:06
tools that will use to guide their
1:08
trades others may prefer beginning to
1:09
find the response okay I'm going to tell
1:11
you that this is a financer but the real
1:14
truth is you need a market philosophy if
1:16
you don't have a market philosophy where
1:18
do you you know believe fundamentals
1:20
Drive the market emotions Drive the
1:22
market uh you know psychology
1:24
you know the FED drives Market if you
1:27
don't have an underlying philosophy of
1:29
what moves the market you need to get
1:31
one right because what will happen is
1:33
you start trading things will go against
1:35
you you need to have those core root
1:37
beliefs to be able to stick with your
1:38
trading systems and understand why
1:40
things work right uh so anyways okay
1:42
fine an okay answer something I'd expect
1:45
to be on Wikipedia how about we ask it
1:48
give us the components of a trading
1:50
system here I'm looking for it to
1:52
respond with like a a data model Alpha
1:55
model risk models uh reporting
1:57
management things like that so give me
1:58
the components
2:01
of a trading system
2:05
okay let's see what it says the trading
2:07
system a set of rules or guidelines that
2:09
Traders use to make decisions when a buy
2:11
and sell financial instruments the
2:13
components of a trading system can vary
2:14
depending upon the specific approach and
2:15
goals the trader but some common
2:17
elements of a trading system include
2:21
Market selection yes that's important
2:23
you know different markets have
2:26
different properties some are more mean
2:28
reverting and some are more trending you
2:32
know that's one of the reasons why uh
2:34
you know all of this knowledge passed
2:36
down from Trader to Trader sometimes
2:38
incorrect is because you can't apply
2:40
them over various markets entry rules
2:43
exit rules position sizing uh you know
2:46
not really what well risk management
2:51
okay what else does it say
2:53
I'm not so sure I'm happy with this
2:55
answer
2:56
oh you know what I have a trading system
2:58
you know what
2:59
I think I made the mistake here
3:02
um it should be an algorithmic trading
3:04
system right because I just asked for a
3:05
trading system my mind is so used to
3:08
algorithmic trading systems
3:10
um that uh I think I made the mistake
3:13
um
3:14
please give me the components of an algo
3:19
rhythmic trading system all right so in
3:22
regards to a regular trading system yes
3:25
I would argue that coming up with um
3:28
trading systems to generate profits is a
3:33
lot easier than this one right here
3:34
psychological management this is one of
3:36
the reasons why I got actually into well
3:39
I love Tech and computers but one of the
3:41
reasons why I got into algorithmic
3:43
trading was to conquer that and uh
3:46
uh execution right all right yes I
3:50
understand this
3:52
okay trading strategy that's fine that's
3:55
I will call that the alpha strategy data
3:58
inputs data model
4:00
execution logic sure that you'd want an
4:03
execution model that's when you you know
4:05
decide you know basic things like how
4:07
you buy it you buy it in chunks do you
4:09
buy it over time uh you know so that's
4:11
view app or t web things like that very
4:13
basic risk management maximum amount of
4:16
capital performance evaluation okay so
4:19
wouldn't necessarily be the way that I'd
4:21
phrase it but these are good answers
4:25
um so so far uh from a you know from my
4:28
perspective if I was a new Trader this
4:31
would be uh pretty fantastic right it's
4:33
giving good answers maybe not extremely
4:37
nuanced answers and obviously that comes
4:39
with experience but pretty good answers
4:42
for a beginner okay
4:46
all right give give me some examples of
4:49
an underlying rating strategy then
4:55
right because it says you know only as
4:57
good as the underlying training strategy
4:58
there are many different underlying
5:00
training strategies that can be used
5:01
Trend following uh biased financial
5:03
instruments that are rising mean
5:05
reversion
5:06
mm-hmm
5:08
Arbitrage
5:11
news based okay again very good general
5:15
information
5:17
machine learning yep
5:21
okay yeah there's typically those would
5:24
be the ones that I'd classify as the
5:26
primary so you're either you know these
5:28
are traditional Trend following the
5:30
interversion Arbitrage is typically
5:32
using computers news based you can do
5:34
that you sort of still need
5:36
now you can still do that based uh you
5:39
know discretionary right uh after
5:41
trainings announcements you have to be
5:43
really quick though and machine learning
5:45
essentially you're actually tackling the
5:47
thing in Reverse instead of having a
5:48
market philosophy and trading uh based
5:51
on that you're actually trying to find
5:55
patterns in the data and reverse
5:57
engineering that without actually an
5:59
understanding of why they work that'd be
6:01
like Jim Simons and Renaissance Capital
6:05
management using machine learning and
6:07
all of that so okay so far so good so
6:10
let's see if it can give us a very basic
6:13
Trend following system in Python give me
6:15
a basic Trend following system in Python
6:19
using Tesla's
6:23
talk as an example
6:28
here's a simple example of a trend
6:30
falling system
6:31
okay we're importing pandas
6:34
where do we get the data Tesla CSV we'll
6:38
see if we can actually import that
6:39
automatically
6:40
from my finance
6:42
but let's see the moving average rolling
6:46
with no size mean where's yep it's up
6:48
there trade size by
6:51
100 each trade zero shares cash
6:55
okay so it's just going to iterate
6:57
through and by
7:01
after let's see here
7:09
so we're just doing is just iterating
7:10
through each row which is each day I
7:13
would assume if that's daily
7:15
um you know saying the trade size is the
7:18
shares that's 100 shares how much cash
7:21
do we have initial capital
7:26
trade size times row close
7:29
okay where's the cash yep so okay so
7:32
that seems like it seems interesting
7:36
um
7:37
and then what we do is the current price
7:40
is below the moving average the sell the
7:42
shares that makes sense okay and then
7:44
print the portfolio value okay so let's
7:47
instead of using
7:49
um you know the CSV let's see if we can
7:51
say let's use y Finance instead and then
7:53
we'll actually put it into Jupiter
7:55
notebook and see if it works all right
7:57
so uh give me
7:59
um use y Finance in the above instead of
8:04
a CSV file
8:08
here's an example of how you modify the
8:10
trend falling system to use y Finance
8:13
import pandas import y Finance ticker
8:17
Tesla
8:18
period Max
8:20
interesting so so far so good let's
8:23
actually test this in uh and in jupyter
8:29
Notebook which is just you know
8:30
web-based way of sharing python code and
8:34
see what some of these inputs and
8:37
outputs look like right
8:38
once this is done
8:42
so my initial take so far is if you're a
8:45
new Trader if you're a discretionary
8:47
Trader and you're interested in getting
8:49
into algorithmic trading this is
8:50
fantastic
8:51
we'll see later if it can exploit like
8:55
um post earnings announcement drift and
8:57
other anomalies that you know are proven
8:59
to work
9:00
momentum is one momentum is actually a
9:03
very strong
9:04
anomaly but anyways I'm digressing let's
9:08
just copy this we'll put it in here
9:11
Untitled
9:13
okay let's just first see if we have
9:16
those we'll input get our Imports we do
9:18
have it in our python virtual
9:20
environment all right let's grab the
9:22
data so you can see what that data looks
9:25
like
9:26
so we see open high low close volume
9:28
dividend stock splits I don't know even
9:30
though I've created a video on how to
9:32
use my finance I use polygon and so I
9:37
don't actually use Wi-Fi Finance I don't
9:38
know if this is the adjusted close that
9:40
incorporates uh dividends and other
9:42
corporate actions like splits but you
9:44
need to make sure whenever you are back
9:46
testing that this is an adjusted close
9:48
and not a close otherwise when the price
9:50
drops 50 due to split the algorithm
9:52
actually thinks that you've lost half
9:55
your capital or uh you know had a great
9:58
short which indeed it's actually nothing
10:00
of the sort all right so then we've got
10:02
window size roll uh ma so
10:05
all we're doing here is we're creating a
10:07
moving average of the close we'll see a
10:09
bunch of nands until we get to this
10:11
window size of 50 so
10:13
on here on the 50th row we'll get
10:18
um you know data here and we can see
10:20
it's a moving average right here of the
10:23
close
10:25
okay so far so good we'll set the
10:28
initial Capital to 10 000 trade size
10:31
it's a hundred
10:34
um
10:37
set the number of shares up by initial
10:39
capital is cash
10:41
so that's uh interesting here so
10:45
obviously a hundred
10:47
so here's here's what I'm looking at
10:49
right now right so say 173 why is that
10:52
moving average 173 I must have had a big
10:55
drop
11:00
interesting you'd have to add I'd
11:02
actually take a look and check here uh
11:04
2022 yeah had a big drop we're in 2022
11:07
has been crazy so I was looking at the
11:09
data and this is I guess just one of
11:11
those things after you've been looking
11:12
at it for a while to look and see if the
11:14
numbers look normal I see that the
11:16
clothes is down here and the moving
11:18
average is way up here and I'm like whoa
11:19
that's a pretty big drop and then
11:21
obviously uh lately uh with all you know
11:24
Tesla has been dropping significantly so
11:26
I'll assume that that's correct all
11:28
right so let's see 110 uh times
11:33
100
11:35
obviously we know the reason I was
11:37
showing you this is uh simply because
11:40
this is 11
11:42
000 and this is ten thousand so we'll
11:44
see we're not going to actually be able
11:46
to purchase that initial trade size
11:49
um so we'll see what happens with that
11:52
so cash is the initial capital is cash
11:54
so we've got ten thousand
11:57
for index row it arose if the row closes
12:01
above the row EMA so if the close price
12:03
is above them Ma and shares a zero
12:05
shares equal trade size so somehow we're
12:08
going to buy
12:09
a hundred
12:12
so shares is a hundred cash minus trade
12:15
size
12:16
which would be 100 times row
12:19
so
12:20
um
12:20
okay so let's just do this before we
12:23
print the portfolio value I'll run this
12:26
and then here's what I was talking about
12:30
cash I would I'd be curious uh this you
12:34
know if we can go above and below
12:36
balances obviously if the trade size is
12:39
this much so we're saying the initial
12:43
capital is ten thousand but we're
12:44
trading this many shares each time let's
12:47
see what happens here so there's clearly
12:49
a bug in this code where it doesn't
12:51
actually check to see if you have the
12:53
ability to purchase that much Capital
12:55
but for the most part so far you know as
12:58
a beginner that's pretty interesting
13:01
um so what else could we do
13:03
um
13:04
give me well we can't do that with
13:07
python because you likely don't have the
13:10
uh let's see here
13:14
give uh give me a
13:18
give me when you want give me the python
13:20
code to exploit
13:23
uh the pad post earnings announcement
13:26
drift anomaly uh only where we will buy
13:32
immediately at the open
13:35
after the first
13:38
after
13:40
a close above the first five minute bar
13:45
um
13:49
let's see here selling selling when a
13:52
price moves below the 20-day moving
13:57
average
14:00
I didn't say python uh
14:04
oh it doesn't like to exploit
14:06
exploit the pet anomaly content but it
14:10
still gave it to me anyways let's see
14:12
what happens here so if you're not
14:13
familiar let me just go to my website
14:16
analyzing Alpha
14:21
so this is episodic pivot this is a
14:24
trade setup where
14:26
um you know there's been many of traders
14:28
that have turned thousands of dollars
14:29
into millions of dollars exploiting this
14:31
anomaly and it's based on the post
14:34
earnings announcement drift where humans
14:37
under react to good information
14:41
typically and essentially what we find
14:44
is when a company has a really good
14:47
earnings announcement price continues to
14:51
move in that direction I've detailed how
14:53
to do that and some of the trainers who
14:55
are successful at making loads of money
14:57
off it on this blog post if you're
14:59
interested but anyways let's get back
15:03
let's see here
15:05
I'm going to do so we have Tesla
15:09
okay shift five minute bar
15:12
well where's the five minute bar
15:14
open eye lock
15:17
so we don't actually have the data for
15:19
that so it looks like it gives us
15:21
example code but it doesn't give us
15:24
exactly what we need
15:26
um
15:28
how else could I use this give me uh
15:31
your rationale
15:35
why the head anomaly Works in stocks
15:43
let's see some surface nominal stock
15:45
market
15:50
okay
15:54
yep so it tends to underreact to new
15:56
information especially when it's
15:57
unexpected
15:59
yeah
16:01
so this is interesting so here's here's
16:03
my initial take
16:05
um
16:06
I think this is phenomenal for beginners
16:09
I think it's exactly sort of what I had
16:12
expected it to be from a language model
16:13
right it's trained on Wikipedia and
16:15
GitHub so it understands you know the
16:18
basic stuff
16:21
um
16:22
it's also interesting because it can
16:24
give you give me like give me the top
16:28
five Market anomalies
16:34
if I could spell
16:36
a-n-o-m-a-l-y-s
16:39
okay there are many different Market
16:40
anomalies are deserved in the financial
16:42
markets consider the top ones of course
16:45
okay let's see
16:47
yeah
16:50
Market size value momentum
16:54
quality it's going to give me all the
16:56
basic stuff
16:59
it's momentum
17:02
quality I wonder if it'll add the
17:03
liquidity
17:06
we can defend
17:09
effect calendar anomaly okay
17:12
so interesting so you know this could be
17:15
an interesting way to dig into this
17:18
right
17:19
um
17:21
let me see if it'll give me the code
17:22
give me
17:24
give me this we don't have the data but
17:26
give me the code
17:29
the python code
17:31
through back test the uh the weekend
17:36
effect
17:38
the weekend effect is an effect that
17:41
it's funny because most companies will
17:44
tend to report
17:46
poor news or terrible news over the
17:49
weekend right if I recall it correctly
17:52
it's not one that I use in my trading
17:55
but essentially you know you want to
17:58
sell on the weekend and buy uh Monday
18:02
morning because again bad news comes
18:06
over the weekend companies hope that
18:08
investors forget about it right
18:11
okay let's see weekday shares okay so
18:14
it's interesting so so far so good if
18:17
you're a new Trader absolutely fantastic
18:20
let me go ahead and call it quits on
18:24
this one and what I'll do is I'll create
18:26
the same thing for non-python Traders
18:29
only a little bit different in trading
18:31
view if you're interested in that so
18:33
hopefully this is informative if you
18:34
think that this is it is informative and
18:36
you want me to create more videos on
18:37
chat GPT
18:39
please let me know and we can really
18:40
dive in maybe we'll do some type of
18:42
Twitter sentiment trade analysis or use
18:45
uh you know earnings announcement uh you
18:48
know stream you know putting them
18:50
through chat GPT and you know combine
18:52
price with sentiment to trade uh you
18:55
know post earnings so anyways hopefully
18:57
you enjoyed this one and I will see you
18:59
in the next thanks bye
#Brokerages & Day Trading
#Investing