Q4: Portfolio Optimization – Risk Preferences In, Trades Out · Scott Sanderson — Transcript
Full transcript
- 0:00Chat With Traders collaboration with
- 0:02Quantopian, episode four.
- 0:13What's happening, crew? Your host, Aaron
- 0:16Fifield here. Thank you for joining me.
- 0:18I really hope you've been enjoying these
- 0:21special episodes in collaboration with
- 0:23Quantopian up to this point and learning
- 0:26lots along the way.
- 0:28Right now, you're listening to the
- 0:30fourth installment. And as you'll soon
- 0:33hear, I'm again speaking with Delaney
- 0:35and also Scott Sanderson. Scott is a
- 0:38software engineer at Quantopian, and
- 0:41he's the one largely responsible for
- 0:44writing Zipline, which is an open-source
- 0:47Python library that supports the
- 0:49Quantopian backtesting and live trading
- 0:52system. Uh the topics we get into during
- 0:54this particular episode revolve around
- 0:57portfolio optimization, optimizing for
- 1:00maximum returns and minimal risk. We
- 1:04also talk about constraints that a quant
- 1:06may implement at a portfolio level,
- 1:09other considerations, and we step
- 1:11through how a researched, news-driven
- 1:13strategy, which trades gun
- 1:15manufacturers, could be optimized to
- 1:17better work within a portfolio. Now,
- 1:20just a couple reminders, as per usual,
- 1:23any questions that you would like to
- 1:24ask, please submit them at
- 1:26quantopian.com/questions.
- 1:30Uh so we can answer these for you on the
- 1:32Q&A episode. This will be part six.
- 1:35Uh for a full list of all the resources
- 1:37referenced during this episode and any
- 1:40previous episode, visit
- 1:42quantopian.com/chatwithtraders.
- 1:46And lastly,
- 1:48I'd like to give a big shout out to
- 1:50DataCamp. They're the ones who are
- 1:52backing this series. DataCamp is the one
- 1:56resource I always recommend to traders
- 1:58for whenever I get asked, "Where do I
- 2:00begin learning how to program?"
- 2:03The reason being, and the reason that
- 2:05DataCamp's courses are so good, is that
- 2:07they teach you the skills necessary to
- 2:10work with and understand data, which is
- 2:13of course exactly what you're doing when
- 2:15you do any form of quantitative research
- 2:17as a trader. So, visit datacamp.com
- 2:21and create a free account. You can start
- 2:24any one of their courses for free, and
- 2:26they even have some courses which are
- 2:28entirely free.
- 2:30Just to repeat the link once more,
- 2:32that's datacamp.com.
- 2:34Jump on it.
- 2:35All right. Well, I think that's
- 2:36everything. Uh, please welcome Delaney
- 2:39and Scott Sanderson.
- 2:44And we're back again, episode number
- 2:46four. Delaney, how's it going?
- 2:48Pretty good. About the same as last
- 2:50time. No no major changes. Excellent.
- 2:53And we're joined by Scott for this
- 2:55episode. Scott, I'm thrilled to have you
- 2:57here, man. Thanks for doing it. Yeah,
- 2:58thanks for having me on.
- 3:00Scott, tell us a little bit about your
- 3:01backstory. Like, how did you get into
- 3:03this? Yeah, so I had sort of an
- 3:05interesting introduction to finance. So,
- 3:09I got introduced to Faust, who's the CEO
- 3:12here at Quantopian, because his brother
- 3:14coached wrestling with my brother
- 3:17at
- 3:18day school in Newton, which is where I
- 3:20grew up. Um, and Faust was in like early
- 3:23stages of prototyping the original
- 3:25version of Quantopian when it was like
- 3:26a, you know, live He was working out of
- 3:28his garage and sort of had this big idea
- 3:31of what he wanted to be, and he was
- 3:33looking for people with uh, for students
- 3:36with math backgrounds or with sort of
- 3:38math and science backgrounds, which is
- 3:40what I was studying at the time in
- 3:41college. Um, and so we met up, we had
- 3:43coffee, and we talked about a bunch of
- 3:45stuff. We got along well, and so I was
- 3:46the original beta tester for the like
- 3:50early early early versions of
- 3:51Quantopian. Um, back when you couldn't
- 3:54do things like get the exception if your
- 3:56program crashed. You just had to sort of
- 3:57squint at the program and hope that
- 4:00your thing hope you could figure out
- 4:02what it what had gone wrong. Um so for a
- 4:05summer I was the original beta tester
- 4:07Quantopian and then the next summer I
- 4:09interned and
- 4:10actually helped build some of the tools
- 4:12for doing things like error reporting
- 4:14and getting logs out of your algorithms
- 4:18and then that experience sort of
- 4:19convinced me that I wanted to pursue
- 4:21software engineering as a career. So I
- 4:23ended up doing a whole bunch of computer
- 4:25science classes in college
- 4:27got really interested in game design and
- 4:29graphics as well from that and so when I
- 4:30graduated I actually worked for a game
- 4:32studio for about 9 months. Um but I
- 4:34found that I missed Quantopian, I missed
- 4:36finance, I missed working on open source
- 4:38software
- 4:39and so about 3 and 1/2 years ago now I
- 4:44came back to Quantopian and I've been an
- 4:45engineer here ever since. Very cool man.
- 4:48And prior to get involved with
- 4:50Quantopian right back in the early
- 4:52stages, did you have any interest in
- 4:56trading or quant finance or anything
- 4:58like that at the time?
- 5:00I mean you know I was aware of it as a
- 5:02thing that existed but I and I like I
- 5:05said I my academic background is in
- 5:07mathematics but it's actually pretty
- 5:09strongly on the pure mathematics side
- 5:11rather than the applied math side. So a
- 5:13lot of the math that's relevant to
- 5:15finance or for trading
- 5:17I wasn't actually all that familiar
- 5:19with. So it was really you know getting
- 5:21introduced to the platform and to foss
- 5:23and to the to this community of people
- 5:25who were excited about the idea that got
- 5:27me interested and engaged with the
- 5:29problem and I actually in part sort of
- 5:31fell in love with the problem because it
- 5:32is such a hard problem. You know doing
- 5:35quantitative finance well there's such a
- 5:37large incentive to do it and it's such a
- 5:39hard problem for a variety of reasons
- 5:41that I sort of fell in love with the
- 5:43challenge of it as much as anything
- 5:45else.
- 5:46Right. Yeah. Yeah, I can see how that
- 5:47would happen. Tell us a little bit about
- 5:50how what you're actually working on at
- 5:52Quantopian there. Like I Correct me if
- 5:54I'm wrong, but I feel as though I think
- 5:56you had a pretty big part to play in
- 5:57actually developing the Zipline package.
- 6:00Is that correct? Yep. Yeah, so
- 6:03one of the things that I did in that
- 6:04original internship was when we were
- 6:06first working towards open-sourcing
- 6:07Zipline. And so I did a lot of the
- 6:11Zipline began its life actually as this
- 6:13like strange very agnostic stream
- 6:15processing library and eventually
- 6:17morphed into being much more financially
- 6:20focused,
- 6:21which is sort of where it is now that
- 6:23it's pretty firmly a toolkit for just
- 6:25doing
- 6:27backtesting. And so
- 6:29most of what my responsibilities are
- 6:32right now is designing, building, and
- 6:35implementing the APIs that our users who
- 6:38are writing algorithms interact with. So
- 6:41if you're writing an algorithm, you
- 6:43know, an algorithm's a Python file and
- 6:44you can say like, you know, I want to
- 6:46order five shares of Apple and that
- 6:47order function has a bunch of things
- 6:49that go into it. So you might say, all
- 6:51right, I want to order this many shares
- 6:52or I want to order this dollar amount or
- 6:55you know, I want to order subject to
- 6:57different kinds of constraints or
- 6:58something like that.
- 7:00And so a lot of what my job is to sort
- 7:01of think about conceptually how should
- 7:03people be thinking about constructing
- 7:05their algorithms and then figuring out
- 7:08how to provide APIs that make it easy
- 7:10and clean for
- 7:12people to express their ideas in code
- 7:14without having to jump through a whole
- 7:15bunch of hoops. And so some of that
- 7:16stuff happens in Zipline. We try I like
- 7:20personally try to do as much of it as in
- 7:22Zipline as I can cuz I think it's
- 7:23valuable to us and to the community to
- 7:26have
- 7:27those parts of the code be open-source
- 7:29and be available and be resources to
- 7:31people who want to learn about quant
- 7:33finance or who want to do their own
- 7:34thing.
- 7:36So in general
- 7:38most of the work I do these days is is
- 7:40in Zipline and the pieces that I do on
- 7:42Quantopian tend to be things that are
- 7:43around like
- 7:45touching proprietary data sources or
- 7:47building like back-end infrastructure
- 7:49for us. Something I'll just add on to
- 7:51that is that something that's often
- 7:53times the the importance of APIs are
- 7:56often lost and um APIs namely like the
- 8:00way you interface with a problem or
- 8:03interface with some data
- 8:05is incredibly important and it's imagine
- 8:08that you were kind of talking about a
- 8:10problem but just using the wrong words
- 8:12and not just getting a clear picture of
- 8:14it. Um it's very easy to get into those
- 8:17kind of situations. So
- 8:18uh Scott does a really good job of kind
- 8:20of using his uh pure math background to
- 8:23kind of try to figure out ways to
- 8:25elegantly express things um and kind of
- 8:27like group cases as much as possible.
- 8:29And so as a result we've had some pretty
- 8:32nice pretty nice API work done in the
- 8:34last last couple years and I think the
- 8:36site has has vastly improved uh as a
- 8:39result. I think we is your one of your
- 8:42How official is the title of API Tsar?
- 8:44Cuz I know that's been thrown around.
- 8:47I think it's it's unofficially official.
- 8:49Unofficially official.
- 8:50Yeah. He is our our in-house API Tsar.
- 8:53Yeah, one of the one of the things that
- 8:55uh you'll hear me say in in meetings
- 8:57around here a lot is that uh there's a
- 8:59famous joke that there's only two hard
- 9:00problems in computer science which is
- 9:02cache invalidation and naming things.
- 9:05Uh and I actually would argue that
- 9:06naming things is often harder because
- 9:08you know, putting a name on something,
- 9:10putting a box on something, figuring out
- 9:12how am I going to refer to this thing
- 9:15often sort of dictates where the rest of
- 9:17the design goes and figuring out trying
- 9:20to what the the ontology of your system
- 9:22is like what are all the different
- 9:23entities and how are they going to talk
- 9:25to each other and how are they going to
- 9:25relate to each other. If you do that
- 9:28well then
- 9:30a lot of the rest of the system just
- 9:31falls out naturally and sort of models
- 9:34the way that you'd want to talk about
- 9:35something or think about something in
- 9:36the real world. And conversely, if you
- 9:38do that poorly, you end up kind of
- 9:40having to retroactively bolt on, you
- 9:42know, weird, strange things that don't
- 9:44make sense or don't seem natural. And
- 9:46so, we spend a lot of time, especially
- 9:48because we run other people's code, and
- 9:50so it's very hard for us to break or to
- 9:52make changes that are breaking, we spend
- 9:54a lot of time thinking about how do we
- 9:56get things right and do it right the
- 9:58first time and build designs that are
- 10:00elegant and simple and, you know, easy
- 10:02to use without being broken in various
- 10:04ways. Absolutely. Yeah, yeah, that's
- 10:06very important. And I think it was
- 10:09uh maybe earlier in 2016 you rolled out,
- 10:12was it Quantopian like sort of 2.0? What
- 10:14what was some of the bigger changes you
- 10:16you made then?
- 10:18Yeah, so the the big change with that is
- 10:20we had been
- 10:22uh increasingly trying to build tools
- 10:25that allowed people to trade more
- 10:28dynamic portfolios. So, the original
- 10:30earliest versions of Quantopian,
- 10:32basically, you had to, ahead of time,
- 10:35declare that you cared about these 10
- 10:36assets or something like that, and then
- 10:39you could place orders against those
- 10:40assets. And so, with that, you could do
- 10:43kind of simple basket trades or pair
- 10:45trades or very limited kinds of
- 10:47statistical arbitrage, but you couldn't
- 10:49do a lot of the more sophisticated
- 10:52quantitative strategies that we've been
- 10:54working towards encouraging people to
- 10:56do, where you're doing dynamic universe
- 10:58selection or you're building factor
- 10:59models or you're doing interesting, you
- 11:02know, risk hedging and that sort of
- 11:03thing. Um because the idea of those
- 11:06models is you're holding, you know,
- 11:07hundreds to thousands of positions, and
- 11:08you're making lots of small uncorrelated
- 11:11bets. And the idea is if I can make lots
- 11:13of those bets and I have a small chance
- 11:14of, you know, making money on each one
- 11:16of those, then in the aggregate, I can
- 11:18end up making a lot of money. And so,
- 11:20the goal for something like that, or the
- 11:22goal of those APIs was to make it easy
- 11:24and pleasant and intuitive to do this
- 11:27kind of dynamic universe selection. Um
- 11:29and so, the original system that we had
- 11:31had, you had to explicitly statically
- 11:34refer to some set of assets, and then we
- 11:36had grown
- 11:38um a series of APIs that
- 11:42had kind of been duct-taped onto that
- 11:44where you could implicitly set some
- 11:47universe of things behind the scenes
- 11:48based on a couple simple criteria, but
- 11:51then we had all these API functions
- 11:52where you could like ask for windows of
- 11:54data or ask for the current data or ask
- 11:56for fundamental data, and it was
- 11:59implicitly depending on this universe
- 12:01that was either set at the start of your
- 12:03program or set in one of these various
- 12:05few limited ways.
- 12:07And as people tried to do more
- 12:08sophisticated dynamic algorithms,
- 12:11those APIs weren't really serving the
- 12:14needs that they had. And so, the big
- 12:16change in Q2 was that we moved away from
- 12:18this notion that your algorithm has some
- 12:20implicit universe that you have to set
- 12:22in like specific places, and instead, we
- 12:24gave people a lot more flexible APIs for
- 12:28querying for data based on mathematical
- 12:30criteria. So, things like I want, you
- 12:31know, the top 10% of US equities by
- 12:35market cap or by trailing dollar volume
- 12:38or by some other interesting statistical
- 12:40property. And then, you could use those
- 12:42APIs to dynamically select for sets of
- 12:44stocks, and then you could pass those
- 12:46sets of stocks into other API functions
- 12:48to ask them for data.
- 12:50Um and so, that was a kind of a big
- 12:52conceptual shift in how the backtester
- 12:55and how the platform worked, and uh
- 12:57there were a bunch of internal changes
- 12:58that had to go along with it so that it
- 13:00could handle those dynamic queries.
- 13:03Right, very good, man. Very good.
- 13:05Well, let's get into this. Um you know,
- 13:07the last two episodes have revolved a
- 13:09lot around alpha factors, uh combining
- 13:12alpha factors, uh and classifiers. So, I
- 13:16think this episode's going to mostly be
- 13:18about sort of the next step. Like, what
- 13:20comes next? So, Delaney, do you want to
- 13:23take it away? I mean, what is the next
- 13:25step from this point onwards?
- 13:27I mean, obviously, this is going to be
- 13:29talking about it from a high level. Um
- 13:31so, you know, it's not always going to
- 13:34be exactly like this. You may have
- 13:36slightly different flow in your
- 13:38algorithm, but in general, once you've
- 13:40constructed
- 13:42uh
- 13:43your final model, uh and that model is
- 13:46usually, you know, some combination of
- 13:48of smaller models. Um once you've
- 13:50constructed your final model, which is
- 13:52kind of
- 13:53glomming together a bunch of smaller
- 13:54things, making one big overall
- 13:56prediction for each asset. Well, now you
- 13:59have uh a forward prediction for each
- 14:02asset. And that forward prediction could
- 14:05be that it's going to go up. It could be
- 14:07that it's going to go up 3% tomorrow.
- 14:09Like, whatever your prediction is, you
- 14:11know, whether it's a weak or strong
- 14:13prediction, you have a prediction. And
- 14:14the next step is, okay, well, how do you
- 14:16actually translate that prediction into
- 14:20something that you can trade? Because
- 14:23just the prediction itself isn't
- 14:25sufficient. Um
- 14:28you know, that's just saying, here's
- 14:29what I think will happen, but then the
- 14:31next step is, how do you actually place
- 14:33bets such that if you are correct, you
- 14:36will make money.
- 14:38Um and if you are incorrect, you won't
- 14:40lose all your money and and blow up. So,
- 14:43um that process of of deciding what bets
- 14:47to place and what positions to take out
- 14:49is a complicated process in and of
- 14:51itself, and it it's known as portfolio
- 14:54construction. So, when people talk about
- 14:56portfolio construction, they're talking
- 14:58about how do I construct a portfolio
- 15:01that, based on my expectation of where
- 15:05assets are going to go, will kind of try
- 15:08to make me the most money, while at the
- 15:10same time not exposing me to excess
- 15:14sources of risk. And so, this question
- 15:15has kind of been posed in many different
- 15:17ways using many different words. Um and
- 15:21uh what people do in quantitative
- 15:23finance is just try to really condense
- 15:26it down into very simple mathematical
- 15:28ways of talking about these constraints.
- 15:32And so that's going to be kind of one of
- 15:33the one of the subjects that we're going
- 15:35to talk about today. It's like how do
- 15:36you actually express that? So,
- 15:39I think Scott actually has a really good
- 15:41story that he actually walked through in
- 15:44a notebook. So he's actually and I'll
- 15:46let him talk about this, but I'll
- 15:47briefly I'll briefly sell it. He's
- 15:49actually working on a new API right now,
- 15:51which I think it's going to be amazingly
- 15:53useful.
- 15:55And what it is is it's a portfolio
- 15:57construction and optimization API. It
- 16:00allows you to do everything we're going
- 16:01to talk about today.
- 16:03Um,
- 16:04kind of from a from a from a very easy
- 16:06to use perspective. And so he's
- 16:08encapsulating all of these notions of
- 16:10trying to maximize expected profits
- 16:13based on predictions, trying to reduce
- 16:15risk exposure and and and
- 16:18um,
- 16:19trying to you know, put them all in
- 16:20quantitative mathematical terms. And he
- 16:23recently released kind of a an alpha
- 16:26version of this API. It's not on the
- 16:28platform yet, but he released an alpha
- 16:29version of what it might look like. You
- 16:32you can actually play with it right now.
- 16:33It's quantopian.experimental.optimize.
- 16:36Oh, we have like we have a we have a try
- 16:38at your own risk section now. Yeah. Got
- 16:40you. Okay, so you can actually play with
- 16:43it. And what we'll do is again as always
- 16:44we'll link to that.
- 16:47If you go to
- 16:47quantopian.com/chatwithtraders
- 16:49we'll have all of the content for all of
- 16:51each episodes linked. And so that will
- 16:53be
- 16:54one of the things you can access on the
- 16:56episode four section.
- 16:58And
- 17:00you can go and check it out if you want.
- 17:02And but in the meantime I'll let I'll
- 17:04let Scott actually kind of talk through
- 17:06this story of what happens if you have
- 17:09some kind of expected returns for a set
- 17:12of assets and then you try to naively
- 17:14construct a portfolio based on that.
- 17:17Yeah, so think it comes down to the idea
- 17:20that Dwayne he mentioned earlier, which
- 17:21is that when you're when you have some
- 17:24quantitative trading strategy, you reach
- 17:27a point in your model where you've built
- 17:29some prediction of what's going to
- 17:30happen,
- 17:31but you're not sure about that
- 17:33prediction, right? So you your your
- 17:35model might have a belief that various
- 17:37different assets are going to go up and
- 17:39down, but there's some amount of
- 17:41uncertainty around that. In addition In
- 17:43addition to the uncertainty about the
- 17:44particular assets, you also might have
- 17:47some amount of some amount of
- 17:49uncertainty around how different assets
- 17:50tend to move together, or you might have
- 17:52some prediction about how different
- 17:54assets tend to move together.
- 17:56And so you have two kind of competing
- 18:00objectives
- 18:01as you think about what trades am I
- 18:03going to place or what portfolio am I
- 18:05going to hold? So on the one hand, you
- 18:07want to put as much of your money as you
- 18:09can in the assets that you believe are
- 18:13going to go up or you know, put as large
- 18:15a short position as you can into the
- 18:17assets that you believe are going to go
- 18:18down.
- 18:19But on the other hand, you want to
- 18:21mitigate the possible risk that one of
- 18:24your predictions is wrong, especially if
- 18:26it might be badly wrong, right? So if I
- 18:28have some There's some asset that I
- 18:30think is going to go up, you know, 10%
- 18:33over the next month or something like
- 18:35that. But I think there's 30% standard
- 18:39deviation around that, right? So I have
- 18:40some prediction it's centered super
- 18:42high, but I'm actually really uncertain
- 18:44about where exactly it's going to land.
- 18:47I might be ambivalent about how much
- 18:49money I want to put in that asset
- 18:50because I have these competing desires
- 18:53to on the one hand put my money in
- 18:54things that are going to go up, but on
- 18:55the other hand not want to put my money
- 18:57my money in things that I have
- 18:58uncertainty about.
- 19:00And so one of the ways that you can
- 19:02mitigate the that second aspect, which
- 19:06is the the risk aversion, is to force
- 19:10yourself to place bets in lots of assets
- 19:13that you believe to be
- 19:16that you believe will move independent
- 19:17of one another. So, if I have three
- 19:19different assets, I think they're each
- 19:20going to go up, you know, 3% over some
- 19:22time period,
- 19:24and I place I could just place, you
- 19:26know, all of my money in one of them
- 19:27and, you know, roll the dice and hope
- 19:30that I do well on that asset, but a
- 19:32smarter strategy might be to do
- 19:34something like put, you know, a third of
- 19:36my money in each of them because if they
- 19:38all move independently
- 19:40then I can be right about
- 19:42about two of them and wrong about one of
- 19:43them, and I I won't, you know, I'll
- 19:46still end up ahead overall.
- 19:49And so,
- 19:50thinking about a simple example of this,
- 19:53if you imagine we have some model that
- 19:55produces
- 19:57expected returns predictions for, you
- 19:59know, a set of assets over some time
- 20:01frame. And I might say that, all right,
- 20:02I think Twitter is going to go up 2% and
- 20:04Apple's going to go up 1% and
- 20:05Microsoft's going to go down 1%, you
- 20:08know, etc. etc. etc. I have, you know,
- 20:10predictions against some array of
- 20:12assets.
- 20:13And I have some fixed amount of capital
- 20:15that I want to deploy to those assets.
- 20:17So, that's the other constraint that
- 20:18we're generally operating under is that
- 20:20we only have so much money to dole out
- 20:22among all the different assets we have,
- 20:24right? If we If we were perfectly
- 20:25confident in some prediction about a
- 20:27particular asset, we might say, "Well,
- 20:28we're going to put as much money as we
- 20:29possibly can into that."
- 20:31That's That won't work for other reasons
- 20:34cuz it'll The act of putting our money
- 20:36into the asset will move the price of
- 20:38that asset, but that's kind of
- 20:39bracketing that concern for a second.
- 20:42In the real world, we only have so much
- 20:44capital that we can put towards any
- 20:46single asset or towards some portfolio
- 20:48of assets. So, that's another constraint
- 20:50that we operate under.
- 20:51But so, if we imagine we're in this
- 20:53world, right, where we have a set of
- 20:56assets and we have expected returns
- 20:57predictions about them,
- 20:59if all we were trying to do was maximize
- 21:03our expected return and we had no
- 21:04concern for risk, then the optimal
- 21:07portfolio for us would be to put all of
- 21:09our money in the asset that had the
- 21:12largest expected returns. Again, that's
- 21:13I'm sort of bracketing the concern of
- 21:16slippage that goes into actually
- 21:17entering that position, but if we could
- 21:19wave a magic wand and have whatever
- 21:21portfolio we wanted, the optimal best
- 21:23possible portfolio for us would be all
- 21:26of our money in the asset that we think
- 21:27is going to go up
- 21:29by the the largest amount. But, for all
- 21:31the reasons we just talked about,
- 21:33uh
- 21:34we often don't want to do that, right?
- 21:36Because we're not that confident in any
- 21:38single one of our predictions. And so,
- 21:40we'd rather try to spread out our
- 21:43allocation to a smaller number of
- 21:45assets. And so, one way of thinking
- 21:47about this is to frame our problem as
- 21:50what's called a constrained optimization
- 21:52problem.
- 21:53And the idea here is we have some
- 21:55objective, which is something like
- 21:57maximize returns,
- 21:59and we have some uh set of constraints
- 22:03on that objective, right? So,
- 22:05I have I'm trying to choose the
- 22:08portfolio that maximizes my objective,
- 22:11but that portfolio has to respect
- 22:13certain constraints that I'm putting on
- 22:15it.
- 22:15And so, those constraints could be
- 22:17things like I only want to put I I don't
- 22:20want to put any more than 5% of my
- 22:22portfolio in any single asset or 1% of
- 22:24my portfolio in any single asset. And
- 22:27they can get more sophisticated. So, I
- 22:28might care about things like I want to
- 22:30be market neutral, right? So, I want to
- 22:32have about as much long exposure as I
- 22:34have short exposure because I don't have
- 22:37a strong belief about whether the market
- 22:39is going to go up or down over some
- 22:40period. Or, even if I do, I don't want
- 22:42my portfolio to be correlated with that.
- 22:45Um and you can build progressively more
- 22:48complex constraints that you can place
- 22:50on your on the portfolios that you'll
- 22:53allow yourself to hold. And the effect
- 22:55that that has is you can
- 22:58uh there's actually sort of really
- 22:59beautiful robust mathematical theory for
- 23:01how we can say, "If I freeze my problem
- 23:05as this optimization problem with
- 23:08certain constraints, then there are good
- 23:11libraries and there's good mathematical
- 23:13theory for how to find the portfolio
- 23:15that sort of probably mathematically
- 23:18will maximize the expected return
- 23:20without violating any of those
- 23:21constraints." Well, I I feel like
- 23:23something maybe it would be useful just
- 23:25to to talk about the this notion of
- 23:28optimization briefly and like
- 23:31one because it's a really central
- 23:34concept to a lot of engineering,
- 23:37but it's something that is outside of
- 23:39engineering not really well understood,
- 23:41I would say.
- 23:42And also it's very misapplied often
- 23:45times because for instance, people often
- 23:48talk about maximizing return when they
- 23:51forget that what they're really
- 23:52maximizing is estimated return, right?
- 23:55Because there's some model which is
- 23:57estimating what their return will be.
- 23:59And that model may be wrong. So, you
- 24:01know, there's another failure point that
- 24:02you have to be aware of.
- 24:04But I want to just get into this notion
- 24:06of optimization briefly because I think
- 24:08it's a really useful concept to
- 24:09understand and and we'll start from like
- 24:11the simplest example, which is
- 24:14imagine that you have some
- 24:17some you know, box in front of you and
- 24:20you have
- 24:22you know, a dial on the box that can be
- 24:24one in one of 100 positions, right?
- 24:27And then on the other side of the box
- 24:29there's a light bulb and you can record
- 24:32how bright that light bulb is, right?
- 24:33And and an optimization problem in this
- 24:36case would be figure out a dial position
- 24:39to
- 24:41maximize the brightness of the bulb,
- 24:43right? I want to optimize the brightness
- 24:46of the bulb and the control I have over
- 24:48the system is this dial. So, this is a
- 24:50very simple it's like a one-dimensional
- 24:52optimization problem because the dial is
- 24:55just one dimension. You can kind of move
- 24:57the dial to one position between one and
- 24:59100. So, a naive solution to this might
- 25:03be doing something very simple, which is
- 25:04just you try all the positions on the
- 25:06dial, and then you pick the best one,
- 25:10right?
- 25:11In this case, that's pretty feasible
- 25:13because there's only 100 positions. You
- 25:14can probably do that by hand,
- 25:17uh, you know, pretty easily. But, the
- 25:19net The next thing that I think is
- 25:21important to to pull out of this is,
- 25:22"Okay, well, then imagine that you
- 25:24plotted the brightness for each dial
- 25:27position in a graph." So, now you have
- 25:30on the x-axis the dial position, and on
- 25:33the y-axis the brightness of the light
- 25:35bulb, right? And,
- 25:38uh, what this gives you is kind of you
- 25:40can start looking at how the brightness
- 25:42of the bulb corresponds with the input
- 25:45that you put into the system. And so,
- 25:47you might notice that maybe it's uh
- 25:49quadratic dependence, or maybe it's a
- 25:51linear dependence on the dial or
- 25:53something like that. You know, you don't
- 25:54know what it is yet. So, this is one of
- 25:56the ways that engineers and quants will
- 25:59start attempting to understand systems
- 26:01is they'll look at how they respond to
- 26:02the inputs they put into the system. So,
- 26:05if you have this problem, uh it's fairly
- 26:08easy to imagine how you might go about
- 26:09solving this optimization problem,
- 26:11right? Where you just kind of you could
- 26:12just try all the options, or maybe if
- 26:14there were too many options to try, you
- 26:16could look at the curve that it
- 26:18produced, and then just kind of try to
- 26:19figure out where the maximum point on
- 26:21that curve was, and
- 26:24generalizing this, um all that a
- 26:26mathematical optimization is doing is
- 26:29just saying, "Well, now the box is a
- 26:30function, and the function has some
- 26:32inputs, which are your controls, and it
- 26:35has an output, right?" And so, in our
- 26:37case, we design a function, which is,
- 26:41let's say that we hold this portfolio,
- 26:44we hold this weight of each asset. So,
- 26:47if there's 100 assets we could hold, now
- 26:49the function has 100 variables as inputs
- 26:53and each variable can just be, you know,
- 26:55the weight that we're holding of that
- 26:56asset in our portfolio. And then the
- 26:59output is what our expected return is
- 27:03given that model we're using. And you
- 27:05know, that the model is model is in this
- 27:07case your your your your forecasting
- 27:10model, your alpha model.
- 27:12Um
- 27:13And what you're trying to do is you're
- 27:14just trying to tweak the weights
- 27:18uh such that you maximize that expected
- 27:20return. And again, in the
- 27:21one-dimensional case,
- 27:23uh it's a very simple problem. You can
- 27:25kind of imagine you can put it in your
- 27:26head how you might solve that. And as
- 27:28soon as but even if you move to say like
- 27:30a two-dimensional case where you have
- 27:32two variables you can tweak, you start
- 27:34seeing that well, now you can't
- 27:36represent it
- 27:38as a graph. You actually have to
- 27:39represent it as like uh
- 27:41as a a graph that has a third axis, you
- 27:43know, like one of the three-dimensional
- 27:44graphs you may have seen at some point.
- 27:47Um and then imagine like four variables
- 27:49as inputs. Well, now we're up to a
- 27:50four-dimensional graph and that's a
- 27:52problem cuz we can't really think in
- 27:55four dimensions, right? Humans just have
- 27:57no capacity to visualize four
- 27:59dimensions. And of course, like when
- 28:01we're talking about portfolio, that's
- 28:03actually like thousands of dimensions
- 28:05because there are often thousands of
- 28:06assets that you could hold. So,
- 28:08optimization, and I'm not going to go
- 28:10into like the the the nuts and bolts of
- 28:12it too much. We'll put some resources
- 28:14again at quantopian.com/chatwithtraders.
- 28:16We'll put some links to tutorials we
- 28:18think are really good, visualizations we
- 28:20think are really good um to help help
- 28:23explain this. But without going into the
- 28:24nuts and bolts too much, uh generally
- 28:27optimization is just a mathematical way
- 28:29of expressing, given any number of
- 28:31dimensions, try to kind of walk along
- 28:34this space of how bright that light bulb
- 28:37is, how how much my expected returns
- 28:40are. Try to walk along walk through that
- 28:43space. You can have imagine it as a
- 28:44landscape. Try to walk through that
- 28:46space and find like the highest point in
- 28:49that space. And that's the notice that's
- 28:51the notion of an optimization. And then
- 28:53when you add constraints into it,
- 28:55constraints are just like putting fences
- 28:57in that space, which say that you can
- 28:59walk through the space, but sometimes
- 29:00you hit fences which are I can't hold
- 29:03more than this of this asset or I'm not
- 29:05allowed to move the dial past this point
- 29:07because there's a physical blockage
- 29:09there. And so you hit that fence you
- 29:11say, "Okay, well,
- 29:12um I can't move into that space. And so
- 29:14now let me try tweaking my parameters in
- 29:16another way." So, again, without going
- 29:18into the nuts and bolts of how this is
- 29:20actually done under the hood of an
- 29:21optimizer, uh I think it's really
- 29:23important just to get that intuition for
- 29:25what an optimization is actually doing.
- 29:28Did that make any semblance of sense?
- 29:30Yeah, yeah, absolutely. Uh you you
- 29:32brought up an interesting point towards
- 29:33the end there about constraints that you
- 29:35might have um when you're optimizing
- 29:38your portfolio.
- 29:39You know, you gave a few analogy for
- 29:41some constraints. What about some like
- 29:43actual real-world um examples of some
- 29:46constraints that a quant might put into
- 29:49uh their portfolio or their their risk
- 29:51model? Sure, I can talk about that a
- 29:53little bit. So, one one constraint that
- 29:54actually has a really nice geometric
- 29:56intuition actually is uh the
- 30:00your maximum leverage constraint. Uh you
- 30:02you only have so much capital to deploy.
- 30:05Um and so again, if we if we think back
- 30:08to say Granny's uh
- 30:11Granny's doing it.
- 30:12Uh Delaney's graph example I think
- 30:14a long day for him. I combined graph and
- 30:16Delaney in my head there. If we think
- 30:17back to Delaney's graph example, right,
- 30:19where we're imagining say plotting, you
- 30:23know, the expected returns of some
- 30:24portfolio as a function of the portfolio
- 30:28weights that we choose,
- 30:29um
- 30:30what it means to say that we're going to
- 30:31constrain our leverage, right, we're
- 30:33going to constrain the amount of capital
- 30:35we're going to deploy is to draw a
- 30:37circle if we're in 2D or a a sphere if
- 30:39we're in 3D or, you know, as we get to
- 30:42higher dimensions, we have hyperspheres
- 30:44or something like that, which again we
- 30:45sort of lose the ability to visualize,
- 30:47but we can fall back on our intuition
- 30:49for circles and spheres, but it bounds
- 30:51the region of possible portfolios that
- 30:53we'll allow ourselves to choose. So,
- 30:56one that's one almost everyone in some
- 30:59capacity will have a a capital
- 31:02constraint on their portfolio.
- 31:04Um but then some other common ones, so
- 31:06often you'll see um market neutral
- 31:09constraints if that's the style of
- 31:10strategy you're uh pursuing. You know,
- 31:12not everyone tries to be market neutral,
- 31:14but it's it's a common thing in the
- 31:16quant space.
- 31:17Um another common class of constraints
- 31:19is people concerned with uh sector
- 31:22exposures. So, you might believe that
- 31:24companies that are in similar sectors or
- 31:26similar industries tend to move in
- 31:30correlated ways because their underlying
- 31:33exposures are similar, right? So, Apple
- 31:35and Microsoft, all things being equal,
- 31:38are more likely to move together than
- 31:41Apple and McDonald's. One one might
- 31:43hypothesize saying a rationale you might
- 31:46have for that is both Apple and
- 31:48Microsoft might be sensitive to changes
- 31:50in the price of silicon or changes in
- 31:52the amount of capital that US consumers
- 31:54have available to them to to spend or
- 31:57for any number of other reasons you
- 31:59might have reason to believe that
- 32:01companies that are in similar businesses
- 32:03will tend to have the their values
- 32:05fluctuate uh
- 32:07more together than companies that are in
- 32:09dissimilar businesses. And so, one of
- 32:12the corollaries of that is that if I put
- 32:14all of my money in companies that are
- 32:15similar in similar businesses, I'm not
- 32:18actually reaping very many of the
- 32:20diversification benefits that I might
- 32:22get if I had a portfolio with lots of
- 32:24different companies in it
- 32:26because again, the whole point of
- 32:29uh diversifying a portfolio is that I'm
- 32:31going to put my money into lots of
- 32:33different assets that I I are going to
- 32:35move
- 32:36in an uncorrelated way. And so, it's
- 32:39very unlikely, statistically speaking,
- 32:41that my portfolio will have a very big
- 32:44uh movement up or down, right? I'm I'm
- 32:47sort of constraining the likelihood that
- 32:49I'm going to have a big movement up in
- 32:50exchange for a better belief that I'm
- 32:52not going to have a big movement down.
- 32:54And
- 32:55humans being risk-averse tend to be
- 32:56willing to make that trade-off. They're
- 32:58tend to be willing to
- 33:00accept a smaller but more secure benefit
- 33:03in exchange for not having the
- 33:06possibility of a very bad thing
- 33:07happening to them.
- 33:08Um and so, one reason why you might be
- 33:11interested in constraining sector
- 33:12exposure is this intuition that
- 33:14different stocks that are in the same
- 33:16sector
- 33:17uh still tend to move together. And so,
- 33:19I might not want to put too much of my
- 33:21portfolio in any single stock. So, you
- 33:23can go from kind of very basic,
- 33:26easy-to-visualize constraints like how
- 33:29much how much money you're going to put
- 33:30in your portfolio and and kind of making
- 33:33sure that you're sector neutral. And and
- 33:35a way to again, another way to kind of
- 33:37visualize this, maybe get the intuition
- 33:39behind it, is you can imagine the
- 33:41optimization process as like a
- 33:42negotiation or a discussion between two
- 33:45people, right? And so, the one part of
- 33:47it says, "Hey, I came up with this great
- 33:50idea for how to weight my portfolio."
- 33:53And shows it to the risk constraints.
- 33:55And the risk constraints say, "You know,
- 33:57you can't actually trade this because
- 34:00this is going to put a lot of weight in
- 34:02your portfolio into the energy sector."
- 34:05Um and then, the person who's in charge
- 34:07of constraint coming up with the
- 34:09portfolio uh comes says, "Okay. Well,
- 34:12okay, let me let me try again." And it
- 34:13tweaks it a bit and it and it basically
- 34:15it's a discussion between these two
- 34:17parts where, you know, one is trying to
- 34:19keep their returns being maximized and
- 34:22the other one is just saying, "You can't
- 34:23do this. You can't do this. You can't do
- 34:25this." Um
- 34:27in terms of constraints, you can go all
- 34:29the way up to like uh
- 34:31uh some pretty sophisticated and hard to
- 34:33visualize constraints. So, I'm going to
- 34:36be pretty technical for a second, so
- 34:38please bear with me, but remember in the
- 34:40last episode we talked about risk
- 34:41factors. Risk factors being return
- 34:44streams, sometimes computed as the
- 34:46returns of a portfolio
- 34:49based on an alpha factor. So, if you
- 34:51traded an alpha factor, what would your
- 34:53returns be on that portfolio? So, like
- 34:55when you look at these risk factor
- 34:57return streams, often times you'll want
- 34:58to make sure that your portfolio doesn't
- 35:01have excessive correlation to these
- 35:02other known return streams. Uh the
- 35:05market is one example of this, where you
- 35:06want your portfolio maybe not to have
- 35:08excessive correlation with the market.
- 35:10You might also want it not to have
- 35:11excessive correlation with value. You
- 35:14might want to make sure it doesn't have
- 35:15excessive correlation with momentum. So,
- 35:17this is where the notion of kind of
- 35:18factor risk modeling comes in, where you
- 35:21can also have as constraints on your
- 35:22portfolio, "Okay, now let's look at this
- 35:25new set of weights. Let's compute the
- 35:27returns had I held this portfolio for
- 35:29the last 90 days." And then let's do a
- 35:31linear regression where I look at my
- 35:33portfolio
- 35:35uh versus all these other factors I'm
- 35:37worried about having excessive exposure
- 35:38to, and if any of these factors have
- 35:41betas above some cutoff, I I can't enter
- 35:44into that portfolio. So, that's that's
- 35:46another set of constraints that quants
- 35:48might apply um and and is a much more
- 35:51kind of sophisticated way of thinking
- 35:52about it. Another one that's more
- 35:53mid-range is uh I'm sure a lot of people
- 35:56might be familiar with VAR and CVAR uh
- 35:59and so you can put for instance that the
- 36:01the CVAR
- 36:03uh the conditional value at risk uh of
- 36:05your portfolio
- 36:07um
- 36:08cannot exceed a certain amount. And
- 36:10that's another constraint that would be
- 36:11very reasonable to put on your
- 36:12portfolio, which is really just a
- 36:13measure of the of the volatility. So,
- 36:16there's a lot you can basically think of
- 36:18like any constraint you want you can put
- 36:19in your portfolio. A constraint could be
- 36:21you can't be invested in fossil fuel
- 36:24companies. That's a perfectly valid
- 36:25constraint and is you know, kind of
- 36:27something that people are starting to
- 36:28think about now, um,
- 36:30especially like as endowments are being
- 36:32pressured to divest from fossil fuels.
- 36:34So,
- 36:35a constraint can really be anything, and
- 36:36it really just depends on how on your
- 36:38risk tolerances and your style of
- 36:40investing.
- 36:42One of the things I also want to
- 36:43emphasize there is the way he's talking
- 36:44about,
- 36:46uh, so you're limiting my my C-bar, or
- 36:48limiting my exposure to some linear
- 36:50aggression. Um, and
- 36:53it's important to remember that we're
- 36:54always The only thing we can ever do is
- 36:57limit our expected exposures to things,
- 36:59our expected movements to stuff. So,
- 37:02you know, we talk as though we have the
- 37:03ability to maximize our returns, or
- 37:06minimize our variance, or something like
- 37:08that. But all we can do is build models
- 37:10of what we think the world is going to
- 37:11do, and then try to assume that our
- 37:14functions are good enough, or that our
- 37:15models are good enough, that we can
- 37:18choose portfolios that would minimize
- 37:20our models if they turned out to be
- 37:21correct, or would maximize our models if
- 37:23they turned out to be correct.
- 37:25Sure. Now, Delaney, you brought up, uh,
- 37:28risk factors in your answer there.
- 37:31Uh, we spoke about risk factors a bit
- 37:32more on episode two. So, I think it
- 37:34might be, uh, beneficial just to save
- 37:37any confusion, maybe if you could
- 37:39differentiate between what is a risk
- 37:41factor and what is a actual risk model.
- 37:44Sure. So, again, a risk factor is just a
- 37:47return stream. Um, so it's it's really
- 37:50just kind of the returns on some asset.
- 37:52And the asset is usually, um,
- 37:56some known thing, a known phenomena in
- 37:58the market. Uh, and examples would be
- 38:01the market itself. That's probably the
- 38:03most commonly used risk factor is just
- 38:05the returns on the broad market. The
- 38:06notion being that if your portfolio is
- 38:09highly correlated with the market, then
- 38:11you are taking on a lot of market risk.
- 38:13If the market crashes, you are more
- 38:15likely to crash if you have experienced,
- 38:17you know, high historic correlation with
- 38:18the market. Um, again, like Scott said,
- 38:21this is all estimates, right? And so
- 38:23when we're estimating this is all
- 38:24estimating future risk. This is not
- 38:26exactly quantifying future risk. So,
- 38:30another example is value in which you
- 38:34would say
- 38:35compute high value stocks using your
- 38:37formula and compute low value stocks
- 38:40using your formula. And so now you have
- 38:42an alpha factor, right? This is the
- 38:44alpha factor which ranks everything by
- 38:45value. Then you construct a portfolio
- 38:48where you go long on high value stocks,
- 38:50short on low value stocks. That's your
- 38:52value portfolio. You look at the returns
- 38:55of that portfolio and now because we're
- 38:57back to a return stream, we're back to a
- 38:59risk factor. And so what you can then do
- 39:01is you can say, well, I've come up with
- 39:03this interesting new strategy. But it
- 39:06has very high correlation with value,
- 39:09this known value risk factor. Well, that
- 39:11means that maybe what you're doing isn't
- 39:12that interesting. It's just taking on
- 39:15risk exposure to value. So, a risk model
- 39:19just tries to estimate future risk
- 39:23exposure to these risk factors. And
- 39:26usually how they do it is they look at
- 39:27like a the trailing window. So, they'll
- 39:29look at the last say 90 days or 200
- 39:31days, whatever makes the most sense.
- 39:33They'll look at say like the last 90
- 39:35days and they'll say, over the last 90
- 39:37days, if we run a linear regression
- 39:41between your portfolio's return stream
- 39:44and the return stream of these known
- 39:47risk factors, what are the betas, the
- 39:49estimated dependencies between your
- 39:52portfolio and these known risk factors?
- 39:54And the betas represent a quantification
- 39:56of the amount of risk you're exposing
- 39:59yourself to from each factor. So, that's
- 40:01that's one form of a factor risk model.
- 40:05And and again, like the notion of a risk
- 40:06model in general can be anything. A risk
- 40:09model is just trying to measure how much
- 40:10risk you're taking on. This is just one
- 40:12common way to do it.
- 40:14Uh one one way that I often find helpful
- 40:17for thinking about this idea that I'm
- 40:19interested in quantifying my portfolio's
- 40:22exposure to these various risk factors
- 40:25is to think about the idea that
- 40:27usually in some algorithm you have some
- 40:30investment thesis, right? You have a
- 40:32belief that certain stocks are going to
- 40:34move in some way or that stocks that
- 40:38have some statistical property to them
- 40:40will tend to outperform stocks that
- 40:42don't have that statistical property.
- 40:44Um and if you can encode that idea in a
- 40:47trading algorithm and deploy it uh one
- 40:49of the things that you want to be sure
- 40:52of or that you're interested in
- 40:53understanding is whether
- 40:56the reason if you're algo say your algo
- 40:57does well in a back test or your algo
- 40:59starts doing well in live trading
- 41:01you might be interested in trying to
- 41:03understand whether
- 41:04the reason your algorithm does well is
- 41:06because your investment thesis was true
- 41:09or because or whether it's because your
- 41:11the decisions that your investment
- 41:13thesis implies
- 41:14tend to just really be subscribing you
- 41:17to some other risk factor, right? Or you
- 41:19just happen to be making decisions that
- 41:21were correlated with uh
- 41:24some other industry, right? So uh an
- 41:26example of this might be that I might
- 41:28look at a whole bunch of company
- 41:29fundamentals and decide that I think
- 41:33that companies with high price-to-book
- 41:35ratios or high uh earnings-to-capital
- 41:38ratios are going to do well in over some
- 41:41time period. And so I build a portfolio
- 41:44that you know has a whole bunch of
- 41:45company that's long a whole bunch of
- 41:46companies that have you know these high
- 41:49fundamental ratios and then shorts a
- 41:51bunch of companies that have these low
- 41:52fundamental ratios. Um but one of and
- 41:54you might deploy that and it might do
- 41:55well or it might not do well. Um but
- 41:58either way one of the things that you
- 41:59might not realize about that portfolio
- 42:02if you looked at it is that
- 42:03often again coming back to the sector
- 42:05case often companies that report these
- 42:08financial metrics are for or report
- 42:09these uh
- 42:11you know these these different
- 42:12attributes of themselves, the way that
- 42:14those attributes are reported in
- 42:16different industries or in different
- 42:17sectors or the way they're calculated
- 42:19can be different. And so, it might be
- 42:21that say tech stocks report or tend to
- 42:24have higher returns on certain kinds of
- 42:26investments or lower returns on certain
- 42:28kinds of investments than say natural
- 42:30gas companies. And so, I might have
- 42:32thought that I was building this
- 42:33portfolio that was interestingly
- 42:35optimizing over some fundamental ratio,
- 42:37but really I just accidentally built a
- 42:39portfolio of all tech stocks, right? And
- 42:42one way that I might come to notice that
- 42:44is if I looked if I built a factor model
- 42:47or a risk model of all these different,
- 42:49you know, return streams and I might
- 42:51look at my returns and look at the
- 42:53returns of all these different risk
- 42:54models and realize that oh, I'm actually
- 42:57not really doing anything interesting
- 42:58here. I'm basically just getting the
- 43:00returns that I would get by trading in
- 43:02the tech industry. And so, one one of
- 43:04the things that a risk model can be good
- 43:06for I think is sort of understanding
- 43:08what asset classes you're subscribed to
- 43:12and especially understanding what asset
- 43:13classes you might have accidentally
- 43:14subscribed yourself to when that wasn't
- 43:17your intended investment thesis. Yeah,
- 43:19that's a classic failure mode for quants
- 43:21is doing something really complicated
- 43:23and fancy and then just finding it at
- 43:25the end of the day that it's just a
- 43:28combination of three already known
- 43:30things. So, you know, you come up with
- 43:32some fancy ranking method and then at
- 43:34the end of the day it's the same as if
- 43:36you had just gone long and the consumer
- 43:40cyclical sector or something, you know,
- 43:42and and and the factor models give you a
- 43:44way to figure that out.
- 43:45Okay, so this might be a good point to
- 43:48bring up biases. I mean, this is
- 43:50something we spoke about in episode one
- 43:54of this of this series.
- 43:56You know, when quants are designing
- 43:59their their risk models and building
- 44:02constructing portfolios,
- 44:04is that something is this a stage we you
- 44:06to be mindful of biases again or not so
- 44:10much?
- 44:12Yeah, I mean absolutely. I mean anytime
- 44:14you're doing any kind of statistics on
- 44:17data,
- 44:18you have to be mindful of biases. And
- 44:20and again like
- 44:21biases creep in in really subtle ways
- 44:23and and I'll just I'll say it again.
- 44:25I've said it before like one of the
- 44:27things that I am commonly doing is I'll
- 44:29do like tours and and kind of lectures
- 44:32at the subject of you don't know how
- 44:34wrong you are again like the subject of
- 44:36our first podcast and and really just
- 44:38trying to drive home how easy it is to
- 44:41miss a lot of biases. So I'll give you a
- 44:44really great example of this
- 44:46which is actually like so I'm sure that
- 44:48a lot of people are familiar with this
- 44:50notion of Markowitz portfolio
- 44:51optimization.
- 44:54When Markowitz portfolio optimization
- 44:55was developed, the notion was was simple
- 44:58which was let's say that I have some set
- 45:01of assets that I can invest in
- 45:04and what I'm going to do is I'm going to
- 45:05look at the historical returns of those
- 45:07assets and the historical volatility of
- 45:10those assets and I'm going to do a
- 45:11clever optimization which gives me
- 45:14weights that maximize my
- 45:18you know historical returns and
- 45:21maximizes the average of the historical
- 45:23returns while minimizing the average of
- 45:25the historical volatility of the assets.
- 45:28So it's just this was kind of one of the
- 45:29first implemented or published forms of
- 45:32portfolio optimization and it's taught
- 45:35in kind of like every investment
- 45:38curriculum these days.
- 45:40And and that if you try implementing
- 45:42that, it just does not work at all right
- 45:45now. And and the reason for that is what
- 45:49you're doing is you've implicitly made
- 45:51an assumption which is that you are
- 45:53assuming that historic returns are
- 45:58predictive of future returns and what
- 46:01does that mean? Well, there's a there's
- 46:03a strategy which does that and it's
- 46:04called momentum. Momentum says if things
- 46:07are doing well in the past, I think that
- 46:09they're going to keep doing well in the
- 46:10future. So, a momentum investor is is
- 46:13placing these kind of bets. Now,
- 46:14momentum still exists, but it you know,
- 46:16you have to be careful about the time
- 46:18frame and the industry and like you have
- 46:20to kind of caveat it a lot more now than
- 46:22you used to. Um
- 46:24and and back when Markowitz portfolio
- 46:26optimization was developed, there was so
- 46:28much like there was so much free free
- 46:31money in the market basically and and
- 46:33things weren't as efficient, things
- 46:34weren't as arbitraged away that you
- 46:35could still make money trading off of
- 46:37like a simple momentum factor. Um and
- 46:41so,
- 46:42it basically is important to realize,
- 46:44well,
- 46:45you you you've done something which
- 46:46seems cool, but you've made an
- 46:48assumption which is
- 46:50historical returns imply future returns.
- 46:52Therefore, you're actually if you ran a
- 46:54return stream, if you like did this and
- 46:56then looked at your return stream, you
- 46:58should find yourself highly exposed to
- 47:00the momentum risk factor.
- 47:02Um and that would be an example of oh,
- 47:04maybe you did this and then you looked
- 47:05at your return stream and you found a
- 47:06high dependency on the momentum risk
- 47:08factor and then that would warn you oh,
- 47:11oh, I might I'm probably doing something
- 47:13weird if that's my high dependence.
- 47:14You're also making the same assumption
- 47:16for volatility. You're assuming that
- 47:17historical volatility forecasts future
- 47:20volatility. That may or may not be true.
- 47:22You need to figure that out and validate
- 47:24that. So, that's an example of like how
- 47:26easy it is for kind of biased
- 47:28assumptions to sneak into your model.
- 47:30I'll talk about one more which is if
- 47:33you're trying to estimate the future
- 47:35risk of something,
- 47:37um often times you'll like construct
- 47:39some model which uses some input
- 47:41variables to try to forecast
- 47:43uh the risk at some point in the future
- 47:45for some asset. Um and often times that
- 47:48will be done by looking at the
- 47:49volatility and you'll say, "Okay, let's
- 47:51look at the last 30 days volatility and
- 47:53see how predictive that is of the next
- 47:5510 days volatility." And you know, maybe
- 47:57that that's your model. What's going to
- 47:59be really easy to do is
- 48:02introduce say something like look ahead
- 48:04bias into that validation process in
- 48:06which you accidentally
- 48:08don't shift your data in the right way
- 48:10or you provide your your your model
- 48:13access to future data by accident. And
- 48:15so when you think you're looking at the
- 48:17last 30 days, maybe you're looking at
- 48:19like day minus 20 to day plus 10 by
- 48:22accident. And so you're actually
- 48:23including the volatility of the period
- 48:26that you want to forecast in your model.
- 48:28And and and it's it's kind of tricky to
- 48:30visualize this, but for anybody who
- 48:32actually has ever tried this, this is a
- 48:34problem that I guarantee you you'll
- 48:36you'll have run into is is is biases
- 48:38like look ahead bias. And again,
- 48:40just remember that everything is an
- 48:42estimate and and it's very easy when
- 48:45you're
- 48:46constructing estimates, when you're
- 48:47constructing models to have biases sneak
- 48:50their way in. Yeah. Well, but yeah,
- 48:52biases and
- 48:55I would also often phrase it as you have
- 48:57biases, you also have sort of implicit
- 48:58assumptions, which are I guess synonyms
- 49:00here. So like another assumption that
- 49:03often sneaks into statistically based
- 49:05models
- 49:07is like assumptions about how
- 49:11random variables that we're modeling are
- 49:13distributed, right? So most statistics
- 49:16gets a lot simpler to calculate if you
- 49:18assume that lots of things are normally
- 49:19distributed. And normally a normal
- 49:21distribution is the the nice bell curve
- 49:23that you see in on the front of every
- 49:25statistics book and it lots of formulas
- 49:27sort of work out nicely
- 49:29if you believe that assets kind of or
- 49:33that returns or that volatilities or
- 49:36that any other kind of thing that you're
- 49:38trying to
- 49:39predict is going to be sort of shaped
- 49:41like this nice bell curve.
- 49:44But in practice that often tends turns
- 49:46out not to be the case. And it's easy to
- 49:50look at a formula that comes out of a
- 49:52statistics textbook or that comes out of
- 49:54a paper and not realize that that
- 49:57formula that's trying to build a model
- 49:59for how something's going to work in the
- 50:01future is making assumptions about say
- 50:04whether certain variables are normally
- 50:06distributed or distributed in some other
- 50:08way that may not actually be an accurate
- 50:11reflection of how the world actually
- 50:12works. Yeah, and and just as a as a
- 50:15quick last point, like this is a very
- 50:17common thing to do.
- 50:19Very very common thing to do and and it
- 50:21just is again, if you don't check all
- 50:23your assumptions, just always check your
- 50:25assumptions, but if you don't check your
- 50:26assumptions, you might try to compute
- 50:27something like value at risk, but in
- 50:30such a way that you say, "I'm assuming
- 50:32that everything's going to be normally
- 50:33distributed." We actually have
- 50:35a lecture in the lecture series. We'll
- 50:38link to it. And basically the lecture
- 50:40shows that how different real returns
- 50:43distributions are from normal
- 50:45distribution. So if you use an assumed
- 50:47normal distribution to estimate, you
- 50:49know, the conditional value of risk of
- 50:51your portfolio, you'll just be way off
- 50:54from the actual amount you could expect
- 50:55to lose on your portfolio and in the
- 50:58wrong direction, which is you think that
- 50:59you will lose a lot less than you
- 51:01actually will.
- 51:03In practice, very very few things in
- 51:05finance are normally distributed. So
- 51:07this is that's a great example of of a
- 51:08bias that can sneak in. Sure. Sure.
- 51:11Now Dalania, I know you wanted to bring
- 51:13up the gun trading strategy. I'm not
- 51:16sure what the proper title for it is,
- 51:18but uh
- 51:19inflammatory title.
- 51:23So
- 51:24yeah, let let's go into that. I think
- 51:26this is also very interesting and it
- 51:27might help to kind of bring some of
- 51:29these subjects we've been talking about
- 51:31together and kind of um
- 51:34yeah, bring it all together and talk
- 51:35about how things are actually
- 51:36implemented in the real world. So maybe
- 51:39if we just start by talking about what's
- 51:40the actual hypothesis of this trading
- 51:42strategy.
- 51:44Sure, and again we'll we'll we'll link
- 51:45to this quantopian.com/chatwithtraders
- 51:48so you can actually go check it out and
- 51:50you know, read the article. But this was
- 51:52actually some work that we did in
- 51:54collaboration with a reporter at
- 51:56Reuters. And
- 51:59um
- 51:59they this was back
- 52:02I When was this published? Early this
- 52:03year
- 52:04in in February. And this was at a time
- 52:08when there was a lot of public debate
- 52:11and very unfortunately a lot of public
- 52:14debate about mass shootings, especially
- 52:18in the US where there's a lot of debate
- 52:19about you know, like does this make
- 52:21sense? Do we need to implement reforms?
- 52:23There's you know, there's just a lot of
- 52:25debate on both sides.
- 52:27And so one thing that people have
- 52:29started to think about is well, what how
- 52:31can we actually quantify this? So that
- 52:33rather than you know, like talking
- 52:34points, we can actually maybe draw some
- 52:36conclusions based on the data. An
- 52:38offshoot of this was a reporter was
- 52:39interested in if you tried to make a
- 52:43trading strategy,
- 52:46you know, based on these mass shooting
- 52:48events, how would that work? And And
- 52:50they're basically testing this
- 52:52hypothesis that people tend to buy more
- 52:56guns in the states when mass shootings
- 53:00occur. So
- 53:02what we did is we did we did some work
- 53:04specifically James Christopher who's a
- 53:06an intern at Quantopian did some work
- 53:08and
- 53:10on on this and they they came up with a
- 53:12strategy that
- 53:15says if you if you experience news
- 53:19of a mass shooting event,
- 53:21buy into stocks of gun companies, gun
- 53:26manufacturers, ammo manufacturers, etc.
- 53:29Um
- 53:30So this is a strategy, right? And it's
- 53:32based on a hypothesis. And again, I just
- 53:34want to draw back to this notion of like
- 53:36hypothesis based strategy design where
- 53:38you have a hypothesis, you you kind of
- 53:40like throw a bunch of stuff at the wall
- 53:42and see what works in a back test, but
- 53:43you have a hypothesis. The hypothesis is
- 53:45that people buy guns after mass shooting
- 53:48events. And so you're going to say,
- 53:50well, can I actually trade off that? Do
- 53:52I do I notice the difference? And so um
- 53:55they tested that and they found that um
- 53:58it seems in the data set that they have
- 54:01uh you do experience
- 54:03um a fairly good returns if you invest
- 54:07in
- 54:08um gun companies after either mass
- 54:10shootings or political events. Um
- 54:13political events are things where maybe
- 54:16um
- 54:17uh politicians say that they're going to
- 54:18implement gun control and then that can
- 54:20also be a driver of people going to buy
- 54:23uh buy weapons. So it's just an
- 54:26interesting example of a strategy and
- 54:29uh
- 54:31I think that it has some interesting
- 54:32flaws which fall into the topic of
- 54:35portfolio construction and um can kind
- 54:38of show us some of the ideas of like,
- 54:40okay, well, here's a strategy which is
- 54:43looking at, how do I optimize returns
- 54:46based on my models? So my model in this
- 54:48case says that after this point in time,
- 54:53you know, after after these events, I'm
- 54:55going to forecast that these companies
- 54:57will will get good returns. These these
- 55:00gun companies will get good returns. And
- 55:03um
- 55:04the other companies I'm not really
- 55:05making a forecast on them. Let's just
- 55:07say that they're going to stay neutral,
- 55:09whatever. I don't I don't know what's
- 55:10going to happen. Um so that's your
- 55:12model. And then your your your your
- 55:15challenge is how do you actually turn
- 55:16that into something that trades? So
- 55:18naively, you might say, okay, we'll just
- 55:20after each event buy into all those
- 55:23companies and just sit and hold them
- 55:24long.
- 55:25Right? There are some problems with this
- 55:28as as we've discussed. Basically that if
- 55:30you just naively construct your
- 55:31portfolio this way,
- 55:34uh well, not only are you exposed long
- 55:37only to the market,
- 55:39but you're also invested completely in
- 55:41one sector,
- 55:43and you're also invested completely in
- 55:45companies that are likely to all be very
- 55:48correlated because they're all producing
- 55:50the same thing, the same good. So,
- 55:54um
- 55:55this would be a good example of like
- 55:57maybe we can briefly talk about how you
- 55:59might go from this model which forecast
- 56:02that gun companies will go up to a more
- 56:04reasonable portfolio,
- 56:07and how the constraints that we talked
- 56:09about earlier might start driving your
- 56:11portfolio into a more reasonable place
- 56:14based on based on, you know, like
- 56:17how how you constrained the problem. So,
- 56:20did you have any like questions about
- 56:21what I talked about or maybe we can just
- 56:23jump into talking about how the
- 56:24constraints might reshape your
- 56:25portfolio. Well, yeah, I I think that'd
- 56:27be really interesting to hear about
- 56:29because obviously you pointed out there
- 56:30are a couple flaws to this
- 56:32hypothesis-driven
- 56:34trading strategy. So,
- 56:36how would you actually go about
- 56:38implementing that into a portfolio and
- 56:40something that would be worthwhile
- 56:42trading?
- 56:44So, I'll I'll let Scott jump in after
- 56:46this, but the idea would be that let's
- 56:48say that you had Scott's API ready to
- 56:50go. And you know, you just you get this
- 56:53signal of I want to trade these stocks
- 56:55cuz I think they're going to go up,
- 56:57right?
- 56:58Well, okay, then you say, but I'm also
- 57:00going to constrain that no
- 57:04I can't put more than
- 57:071% of my capital in any individual
- 57:09asset. That's a reasonable constraint,
- 57:12but let's say that there are 10 10 gun
- 57:14companies total that were interested in
- 57:16investing in. Well,
- 57:19what's going to happen? Well, what's
- 57:20going to happen is that
- 57:24that optimizer is going to say, I'm
- 57:26trying to get into the gun companies.
- 57:28I'm trying to put all my money into the
- 57:29gun companies, but the constraints
- 57:31aren't letting me. They're saying I'm
- 57:33going to max out at 1% of my portfolio
- 57:35in each gun company, and then I'm going
- 57:37to have to put the rest of it somewhere
- 57:38else.
- 57:39And so, you'll probably get like kind of
- 57:41an even distribution across other assets
- 57:44in in your universe. They just may may
- 57:46or may not be in the same industry,
- 57:48could be all over the place. And then
- 57:49we'll talk about maybe we'll put in
- 57:50another constraint, which is I cannot be
- 57:54exposed to any sector. Right? And so,
- 57:57what does that mean? Well, we have a
- 57:58bunch of
- 58:00long bets in whatever sector gun
- 58:02companies live in.
- 58:04Um so, that means that we also have to
- 58:06put in place a bunch of short bets in
- 58:08the same sector
- 58:10to bring our to bring our exposure in
- 58:12that sector back down to zero. We're not
- 58:14exposed to that sector. And so, now the
- 58:17constraints say, um because you have to
- 58:19be kind of even across the sector, it's
- 58:21going to push you into having some short
- 58:23positions in the same sector, companies
- 58:25in the same sector that aren't the gun
- 58:27companies you wanted to be long in. So,
- 58:30already now we're starting to get into
- 58:31these interesting, you know, we've only
- 58:33put in place two constraints, but we've
- 58:35already switched from a portfolio that
- 58:36holds 10 assets to a portfolio that
- 58:38holds, let's say, like 500 assets, and a
- 58:41portfolio which has longs and shorts,
- 58:43just based on these two constraints.
- 58:46Does that make sense?
- 58:48I think so, yeah.
- 58:49And maybe if you could just repeat that
- 58:51part about why you need to take short
- 58:53trades. Is that just a just an example
- 58:56of a constraint that you might put into
- 58:58your portfolio that that means that you
- 59:00can't just be long only?
- 59:03So, so I think
- 59:05uh and this algorithm's a little bit
- 59:07interesting because it's it's an event
- 59:08study and and at least as it was
- 59:10originally implemented, it actually has
- 59:12long periods of time where it doesn't
- 59:13hold any positions at all. And so, uh
- 59:16that's very different than some of the
- 59:18styles of strategies that we were
- 59:19talking about right now. But I I think
- 59:21the reason why you might be interested
- 59:24in optimization or something like it for
- 59:27a strategy like this goes back to the
- 59:29idea that I was talking about a little
- 59:31bit earlier, which is that you want to
- 59:32make sure that what you're trading is
- 59:34actually your original hypothesis and
- 59:37not something that merely happens to
- 59:38coincide with the hypothesis.
- 59:41Um so in this algorithm, right, our
- 59:44hypothesis is that
- 59:46gun companies specifically, you know,
- 59:47these 10 or these I don't know how many
- 59:49assets this trades off the top of my
- 59:51head, but I have a specific hypothesis
- 59:54about a about the behavior of these
- 59:55specific assets when these specific
- 59:58events happen.
- 59:59Um
- 1:00:00and so
- 1:00:01if I'm if that's the hypothesis I have,
- 1:00:04what I want to make sure that I'm doing
- 1:00:05is actually trading on that hypothesis.
- 1:00:09And so it might be, for example, that
- 1:00:12all of the uh gun companies that I'm
- 1:00:15trading also all
- 1:00:17say belong, I don't I don't know how gun
- 1:00:19companies get classified by by sector by
- 1:00:21industry, but
- 1:00:23uh they might also all have similar
- 1:00:25returns or similar risk profiles to
- 1:00:28um
- 1:00:29uh let's say like the retail market,
- 1:00:31right? They're probably sort of behave
- 1:00:32kind of similarly to sporting goods in a
- 1:00:34lot of ways. Um
- 1:00:35so
- 1:00:37one thing that we might
- 1:00:39one way of phrasing our hypothesis,
- 1:00:41right, is that
- 1:00:43when mass shootings happen, gun
- 1:00:45companies will go up. And that might be
- 1:00:46the extent of our hypothesis.
- 1:00:49Um but that's actually quite hard to
- 1:00:50say, right? Because if the market is
- 1:00:52tanking, then even if gun companies do
- 1:00:55better than everybody else, our our
- 1:00:57strategy might not do well, right? If it
- 1:00:59happened to be that mass shootings
- 1:01:02always happened at the same time as the
- 1:01:04economy was tanking, then even if our
- 1:01:06hypothesis was in some sense true,
- 1:01:08right, that gun companies do better on
- 1:01:11average than other companies when a
- 1:01:13shooting happens, we still might
- 1:01:14actually lose money on the strategy
- 1:01:16because
- 1:01:17the whole market was tanking, so gun
- 1:01:19companies went down as well, they just
- 1:01:20went down less than other companies. And
- 1:01:22so, we might move from our hypothesis
- 1:01:25being merely that, you know, when a
- 1:01:28shooting happened a gun happens a gun
- 1:01:29company goes up to when a shooting
- 1:01:31happens a gun company will do better
- 1:01:33than other similar company or other
- 1:01:35companies that otherwise might behave
- 1:01:37similarly, right? And so, that's where
- 1:01:39you start to be interested in this sort
- 1:01:41of hedging idea or this
- 1:01:43sector neutrality or market neutrality
- 1:01:44idea, right? Is that my hypothesis is no
- 1:01:47longer just that gun companies will
- 1:01:49unconditionally go up. It's that they
- 1:01:51will do better than similar companies or
- 1:01:54they will do better than the market as a
- 1:01:56whole.
- 1:01:57Well, and so, if I wanted to trade on
- 1:01:59that more refined hypothesis, then I
- 1:02:02might be interested in this idea that,
- 1:02:04okay, when I enter into a long position
- 1:02:06in, you know,
- 1:02:08these gun companies as a result of a
- 1:02:10mass shooting, I might simultaneously
- 1:02:12enter into a corresponding short
- 1:02:14position in, you know, other companies
- 1:02:16that are in the retail sector or just in
- 1:02:18a broad market
- 1:02:20set of companies based on certain risk
- 1:02:22criteria. And then,
- 1:02:24once I start if I go to that latter
- 1:02:26route, right, where I'm saying, all
- 1:02:27right, I'm going to enter into a a small
- 1:02:29number of longs in these specific
- 1:02:31companies,
- 1:02:32and I'm going to enter into a large
- 1:02:34number of shorts in these other
- 1:02:35companies to be to be, say, diversified
- 1:02:37there or to ensure that they're sort of
- 1:02:39stable,
- 1:02:40then I might start to be interested in
- 1:02:43some of the more sophisticated exposure
- 1:02:44measures that we were talking about
- 1:02:46earlier, where I want to make sure that
- 1:02:47I'm not accidentally just going super
- 1:02:50short the food service industry or going
- 1:02:52super short the telecom industry or
- 1:02:54something like that, but that what I'm
- 1:02:55really doing is just hedging out the
- 1:02:58overall market effect or the overall
- 1:03:00consumer cyclical effect. Okay. Yeah,
- 1:03:03yeah, I think that that makes it a
- 1:03:04little clearer.
- 1:03:06Um Delaney, is there anything you'd like
- 1:03:07to add more onto the this particular
- 1:03:10trading strategy um an example?
- 1:03:15Um no, I think that Scott like really
- 1:03:18kind of touched on all the points that I
- 1:03:19want to touch on and and I would just
- 1:03:20say, like,
- 1:03:22just to reiterate, there's like a
- 1:03:23tremendous number of constraints you can
- 1:03:25put on a portfolio and they all kind of
- 1:03:28get at different ways you could, you
- 1:03:30know, you could fall apart. And
- 1:03:34this is just talking about a few
- 1:03:36different constraints you could put on
- 1:03:37to avoid a few, you know, try to avoid a
- 1:03:39few different sources of risk. And at
- 1:03:42the end of the day, like, the number of
- 1:03:44constraints that a professional quant
- 1:03:47shop is going to be putting on their
- 1:03:49portfolios is probably going to be, you
- 1:03:51know, a lot more than just saying, "We
- 1:03:53want to be neutral in each sector. We
- 1:03:55want to be neutral in the market. We
- 1:03:57want to invest this amount of money and
- 1:03:58we want to be exposed to these factors."
- 1:04:00You might have a a few more a few more
- 1:04:02things than that, depending on your
- 1:04:03investment thesis. You might not be
- 1:04:05allowed to trade certain stocks for
- 1:04:06legal reasons because one of your board
- 1:04:08members owns some company and, you know,
- 1:04:11there's there's more complex constraints
- 1:04:13that you you you can have to put on on
- 1:04:15portfolios sometimes.
- 1:04:17But yeah, I think one of the things I do
- 1:04:19I would want to add to that is that
- 1:04:21I wouldn't want to say that, you know, a
- 1:04:23sector-neutral portfolio or a
- 1:04:24market-neutral portfolio or or some
- 1:04:26other sort of more fancifully
- 1:04:27constructed portfolio is categorically
- 1:04:29better than, you know, a more simple
- 1:04:31event strategy or or more simply
- 1:04:33constructed portfolio. But what what
- 1:04:36these more sophisticated tools allow you
- 1:04:38to do is refine hypotheses, right? It
- 1:04:41makes sure that when I'm trying to trade
- 1:04:44a strategy that I am focused on
- 1:04:48building a strategy that actually
- 1:04:50reflects the specific idea or the
- 1:04:53specific thesis that I have, right? It
- 1:04:54allows us to narrow down the sources of
- 1:04:58possible reasons why an algorithm might
- 1:05:00do well, so that we have a better reason
- 1:05:03to believe that if an algorithm does
- 1:05:05does well, it's because we were actually
- 1:05:07correct about some feature of the market
- 1:05:09or some feature of particular companies.
- 1:05:12Mhm. Okay.
- 1:05:14Um now, I'm just curious um I know there
- 1:05:16was an article about this strategy on uh
- 1:05:18Reuters.
- 1:05:20Um I'm not sure if the article itself
- 1:05:22actually kind of laid out how the
- 1:05:25strategy actually traded around the
- 1:05:27events. Is there anywhere we can get
- 1:05:29more info on that?
- 1:05:30Yeah, we'll link to the actual
- 1:05:32Quantopian forum post, which goes along
- 1:05:34with the article, and that actually
- 1:05:36gives you the full source code of the
- 1:05:38strategy. So, you can actually see
- 1:05:39exactly what it's doing. Yeah, that'd be
- 1:05:42great. That'd be great. And um you know,
- 1:05:44obviously we can we can check that out,
- 1:05:46but just while we got this opportunity,
- 1:05:48how were the actual trading signals
- 1:05:50generated? Like, obviously this was not
- 1:05:52so much a uh
- 1:05:54a
- 1:05:55a strategy that's based on price action.
- 1:05:57It was based on um events and news and
- 1:06:00that sort of thing. Uh was it still
- 1:06:02obviously still an automated strategy?
- 1:06:05How
- 1:06:06how was it getting the trade signals?
- 1:06:07Was there a a news reading algorithm of
- 1:06:09some sort?
- 1:06:11So, um in this case, we were just
- 1:06:12looking at a historical window. We
- 1:06:14weren't trading this thing live. Uh and
- 1:06:16so what we did is we just went back and
- 1:06:19with the help of Reuters, we just
- 1:06:22um before looking at the returns, we
- 1:06:24just laid out the events that we were
- 1:06:26concerned with, right? We just laid out
- 1:06:28all the events which they would say like
- 1:06:31they classified as yes, we believe that
- 1:06:33this is an event um you know, after
- 1:06:35which uh
- 1:06:37the returns on gun companies would be
- 1:06:38higher than comparable companies. And um
- 1:06:41so, we had just like a CSV of the dates,
- 1:06:44and um
- 1:06:46whenever one of those dates came along,
- 1:06:48we would just jump into uh jump into uh
- 1:06:52gun companies. And so, it was basically
- 1:06:54what you'd have to do if you wanted to
- 1:06:56switch that to something that could
- 1:06:57trade live is yes, you'd have to have um
- 1:07:01an automated way of pulling in news of
- 1:07:05these events, classifying the events as,
- 1:07:08yes, this is an event which I believe is
- 1:07:10likely to influence,
- 1:07:13um, you know, gun companies positively,
- 1:07:15uh, or not, and then kind of have that
- 1:07:18event feed in live rather than have it
- 1:07:20be a static CSV file. You could also
- 1:07:22just have a a human press a button
- 1:07:25whenever they thought that this was an
- 1:07:27event, and then that would also, you
- 1:07:29know, add it to the queue. Um, that's
- 1:07:31perfectly reasonable as long as, you
- 1:07:32know, the rest of the chain is still is
- 1:07:35still quantified. I think that's an
- 1:07:36interesting idea because, um, you don't
- 1:07:38have to always be fully quantified.
- 1:07:40There are some things that humans still
- 1:07:42do better. And if your strategy is
- 1:07:44trading on a frequency which is still
- 1:07:45reasonable, like it's not like, you
- 1:07:47know, tons of times a minute, if it's
- 1:07:48trading like once a day or whatever,
- 1:07:50well, you can have a human press a
- 1:07:52button that says, I believe this event
- 1:07:53has happened, and then the nice thing is
- 1:07:55that the strategy will still go and do
- 1:07:57all the portfolio optimization and risk
- 1:07:59analysis and everything and construct a
- 1:08:01good portfolio and trade on that
- 1:08:02portfolio and get into it quickly. Um,
- 1:08:05and it's a way of just like saying, I'm
- 1:08:06going to take the best part of what a
- 1:08:08human can do, and also the best part of
- 1:08:10what a strategy and a computer can do,
- 1:08:12and kind of combine them together. So,
- 1:08:14you can you can get a little bit more
- 1:08:15flexibility around that. Yeah, sure.
- 1:08:17Okay, excellent. Well, guys, let's leave
- 1:08:20it at that for now. Um, next episode,
- 1:08:23uh, last one before we do the episode
- 1:08:26number six, which will be Q&A. So,
- 1:08:28episode five, uh, what are the key
- 1:08:30topics we'll be discussing, uh, on that
- 1:08:32one, Delani?
- 1:08:34Well, uh, we're going to talk about good
- 1:08:36and bad uses of machine learning in
- 1:08:39quantitative finance or finance in
- 1:08:40general, because turns out there are a
- 1:08:42lot of bad uses, but there are also a
- 1:08:44lot of great uses. And, uh, I think that
- 1:08:47people who enter in, especially people
- 1:08:49who enter in with, um, some machine
- 1:08:51learning under their belt, uh,
- 1:08:53oftentimes will not have a good
- 1:08:56distinction of what are the good uses
- 1:08:58and bad uses, because finance actually
- 1:09:00behaves very differently from a lot of
- 1:09:01other classical applications of machine
- 1:09:04learning. There's a lot of
- 1:09:05non-stationarity, conditions change all
- 1:09:07the time.
- 1:09:08Um you can think of this machine
- 1:09:10learning algorithm is like trying to
- 1:09:11learn about the world, but by the time
- 1:09:13it's figured out how the world works,
- 1:09:14the world has changed. Um that's a
- 1:09:16classic failure mode. And also, often
- 1:09:19times machine learning algorithms
- 1:09:20operate in situations where the risk
- 1:09:22isn't really a huge problem. So, for
- 1:09:23instance, if you're trying to like
- 1:09:25maximize the number of people who will
- 1:09:27respond to an email that you send out as
- 1:09:29a marketing firm. Um you know, there's
- 1:09:32not a huge risk necessarily in that
- 1:09:35case. Like, nobody's directly losing
- 1:09:37money if you screw up. Um I guess if you
- 1:09:39send out something really inappropriate
- 1:09:41in the email, then like you could face
- 1:09:43reputational damage, but often times
- 1:09:45machine learning techniques fit focus on
- 1:09:47maximizing reward. Um and and a big
- 1:09:50thing in finance is you need to talk
- 1:09:52about minimizing risk as well. So, um
- 1:09:55we'll just talk a lot about kind of like
- 1:09:57if you're approaching finance from a
- 1:09:59machine learning perspective, what are
- 1:10:00some concerns, what are some good
- 1:10:02applications, what are some bad
- 1:10:03applications, um and uh you know, how to
- 1:10:07approach that. Excellent. And you're
- 1:10:09bringing in Is it Thomas for that one?
- 1:10:11Uh depends. I think Thomas may still be
- 1:10:13on vacation at this point. Uh I think
- 1:10:16I'm going to try to bring in um Max,
- 1:10:18who's the guy who runs the lectures here
- 1:10:20for us. And and his background is in um
- 1:10:23stats and and and all this good stuff.
- 1:10:26He's actually worked on
- 1:10:28uh startups before that were trading
- 1:10:29cryptocurrencies, cryptocurrency
- 1:10:31options, I think. So,
- 1:10:33um he has some really good experience in
- 1:10:36in this kind of stuff and um
- 1:10:38is is is right up there with Thomas when
- 1:10:40it comes to uh evaluating these kind of
- 1:10:43uh applications of machine learning.
- 1:10:45That's awesome. Well, I'm keen to hear a
- 1:10:46bit more about his backstory, too. That
- 1:10:48sounds uh pretty interesting.
- 1:10:50Yes, we finally convinced him to work
- 1:10:52here.
- 1:10:53All right, guys. Well, thank you very
- 1:10:55much for doing this again. And Scott,
- 1:10:56awesome to have you on and get your
- 1:10:57input on these topics. So, yeah,
- 1:10:59appreciate it, man. Thank you. Thanks
- 1:11:01for having me on.
About this transcript
This page contains the full transcript of Q4: Portfolio Optimization – Risk Preferences In, Trades Out · Scott Sanderson by Chat With Traders, generated from the public captions YouTube serves with the video. The transcript has 13,047 words across 1,998 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.
What you can do with it
Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to choose a caption track available on the video.
Free YouTube transcript tool
YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, caption language selection, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.