"Basic Statistical Arbitrage: Understanding the Math Behind Pairs Trading" by Max Margenot

แชร์
ฝัง
  • เผยแพร่เมื่อ 4 มิ.ย. 2024
  • This talk was given by Max Margenot at the Quantopian Meetup in Santa Clara on July 17th, 2017.
    To learn more about Quantopian, visit: www.quantopian.com.
    Video work was done by Matt Fisher, www.precipitate.media/.
    Max’s background is in applied mathematics, statistics, and quantitative finance. He runs the online lecture series at Quantopian and is responsible for workshop curriculums and educational content. In addition to having experimented with algorithmic trading of cryptocurrencies and Bayesian estimation of covariance matrices, Max has published work in theoretical mathematics. He works with top universities including Columbia, U Chicago, and Cornell and holds a MS in Mathematical Finance from Boston University.
    "Basic Statistical Arbitrage: Understanding the Math Behind Pairs Trading"
    In algorithmic trading, information is king. You can tease out an edge to trade on even by using only the most basic properties of time series. In this lecture, we will cover the statistics that ground the trading logic when conducting pairs trades and discuss how to find pairs.
    This talk is based on the following lectures from the Quantopian Lecture Series:
    • Pairs Trading
    • Integration, Cointegration, and Stationarity
    All lectures can be found here:
    www.quantopian.com/lectures
    To learn more about Quantopian, visit www.quantopian.com.
    Disclaimer
    Quantopian provides this presentation to help people write trading algorithms - it is not intended to provide investment advice.
    More specifically, the material is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory or other services by Quantopian.
    In addition, the content neither constitutes investment advice nor offers any opinion with respect to the suitability of any security or any specific investment. Quantopian makes no guarantees as to accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 108

  • @mattorrock4844
    @mattorrock4844 5 ปีที่แล้ว +93

    Incredibly well said for a topic that can easily drown a laymen of statistics in its mathematical foundations. This will save many aspiring quants a lot of time in their algo developments , if they take the time to check their assumptions regarding stationarity. Oh what a world we now live in, where such information is offered free to the average investor. Thanks!

    • @k.butler8740
      @k.butler8740 3 ปีที่แล้ว +7

      You need not only stationarity but also ergodicity for any sort of such forecasting. Max says that it's better to make many small denomination bets at a given set of odds (51% in this video) then one large denomination bet on the same set of odds. This is not true per se -- their outcomes have the same expected value because of the linearity of expectations. The reason why you want to make many small denom bets over the one large on the same odds is because of ergodicity: it is only the basket of pairs that you can make the ergodicity assumption about, not any single pair. What Max fails to note in this lecture is that it is the evolving basket of pairs or portfolio of pairs that themselves constitute a single emergent stationary and ergodic system.

  • @pozloadescobar
    @pozloadescobar 2 ปีที่แล้ว +6

    Good job Max. That was a great intro to pairs trading, particularly for folks with a few stats and time series classes. Max has a good sense of what stuff is OK to skip

  • @PurohitAnkit
    @PurohitAnkit 2 ปีที่แล้ว +4

    Hi Max. Thank you for providing us with your lecture. It is really insightful 🙂

  • @Gavinnnnnnnnnnnnnnn
    @Gavinnnnnnnnnnnnnnn 4 ปีที่แล้ว +176

    that guy in the front is on the first peak of the dunning-kruger effect

    • @TheCheukhin
      @TheCheukhin 4 ปีที่แล้ว +4

      yeh. how can he be hired?? Probably, he has a really good track record.

    • @Hahmzuh
      @Hahmzuh 3 ปีที่แล้ว +8

      @Nora Wilson scam spammed across many places by fake account

    • @jeevajeeva2481
      @jeevajeeva2481 3 ปีที่แล้ว +2

      @@Hahmzuh yes in every trading video they are commenting

    • @samuelhossain3267
      @samuelhossain3267 3 ปีที่แล้ว +3

      aren't we all

    • @rahulchembakasseril5876
      @rahulchembakasseril5876 3 ปีที่แล้ว

      Mount Stupid

  • @felipemiraflores2984
    @felipemiraflores2984 6 วันที่ผ่านมา

    Amazing job Max, loved it!

  • @navketan1965
    @navketan1965 9 หลายเดือนก่อน +1

    Sir, In forex pairs SPREAD TRADING do you recommend use of CCI (say on 4H chart--cci 7,cci 14, cci30,cci50 values & add all these values on each pairs to spread & compare overpriced/underpriced leg).The pairs got to have correlations of at least 90%(say aud/usd &nzd/usd--aud/jpy &nzd/jpy--eur/jpy & gbp/jpy--gbp/aud & gbp/nzd etc.).Sell the overpriced & buy underpriced. This would give trader starting edge, staying power, size choice & risk control. You would be comparing deflection of prices summed up on multiple time frames(added up/robust) for asset A & B. Your wisdom is appreciated..

  • @ceekay5262
    @ceekay5262 ปีที่แล้ว +1

    Very informative. Thanks

  • @babatundeakeredolu8187
    @babatundeakeredolu8187 ปีที่แล้ว +1

    Please can we have access to the notebook used for this lecture?

  • @amriksingh5003
    @amriksingh5003 ปีที่แล้ว

    Hi what is that balance( Traju) symbol on trading view chart

  • @Juanitoto
    @Juanitoto 3 ปีที่แล้ว +5

    the dude in the front has cemented in his brain GBM GOVERNS stock prices instead of it being a model.

  • @chandershekhar1076
    @chandershekhar1076 4 ปีที่แล้ว +1

    thank you

  • @mvterra6
    @mvterra6 ปีที่แล้ว +4

    Hi! Around 36:10 you say that you would buy 1 unit for each stock, wouldn't it be 1:1.5?

  • @uwu1337
    @uwu1337 3 ปีที่แล้ว +13

    At first I thought this was a bunch of useless maths, but when I got to the actual trading part I was pretty amazed how clever all of this actually applied in practice.

  • @kevinkim1778
    @kevinkim1778 3 ปีที่แล้ว +35

    16:20. BRUH you need to understand random variables before you come here...

  • @PotatoMan1491
    @PotatoMan1491 3 ปีที่แล้ว +1

    I like your stuff, especially when I am not much of an expert in statistic

  • @selmagray61
    @selmagray61 4 ปีที่แล้ว +18

    Max is a bright kid and no longer at Quantopian. Jump to 40:28 where he self-effacingly admits that example is flawed..and that enhancing/correcting the lecture is on his todo list.
    Still worthwhile at seeing whats 'canned' at Q. Good luck.

    • @sjhughes0313
      @sjhughes0313 3 ปีที่แล้ว +4

      Hm, but I think he corrects himself with another conceptual mistake. He says he should take the returns of each stock, then take the log of those returns, then find the linear combination, etc.. But I think he wants to be using log of the prices, in order to benefit from the log returns (log returns being different from log of the returns).
      So for him to properly get log returns, he'd be working with log of the prices, since log returns = log(1 + returns) = log(price 1) - log(price 2).
      Which mean he should be looking for some linear combination of log(price of stock 1) and log(price of stock 2). The way he describes it, he'd be looking for some linear combination of log(returns of stock 1) and log(returns of stock 2), which is incorrect.
      I think anyway..

    • @selmagray61
      @selmagray61 3 ปีที่แล้ว +1

      @@sjhughes0313 Samuel, sorry just saw your reply. Above my pay grade with the math. Hope all is well.

    • @fattiger5953
      @fattiger5953 2 ปีที่แล้ว +1

      @@sjhughes0313 I agree, cointegration on log returns doesn't really make sense.

    • @zwhizzo4185
      @zwhizzo4185 2 ปีที่แล้ว

      @@sjhughes0313 Indeed.

  • @Mrslykid1992
    @Mrslykid1992 4 ปีที่แล้ว +11

    Does Quantopian have any books that are recommend to learn quantitative finance field?

  • @yousef-4334
    @yousef-4334 4 ปีที่แล้ว +11

    I do not understand why he is admitting that he is making a mistake. because he is not making one. The pair trading requires the slope beta extracted from regression between the prices (NOT returns). The parameter beta used in CAPM, on the other hand, uses returns(NOT prices). Quantopian please correct me if I am wrong.

    • @zwhizzo4185
      @zwhizzo4185 2 ปีที่แล้ว +3

      I agree. He is not wrong by testing cointegration using difference of prices. I suspect what he meant was using testing cointegration with log returns - see Samuel's comment below John Gray.

  • @rahuljuliofernandes222
    @rahuljuliofernandes222 4 ปีที่แล้ว +3

    I'm starting writing my algos in 2019 does quantopian yet work?

    • @davidl.e5203
      @davidl.e5203 2 ปีที่แล้ว

      They've closed in 2020. I believe their team now works for Robinhood

  • @lucasplacides2007
    @lucasplacides2007 4 ปีที่แล้ว +5

    Does someone know the models he cites at 44:43? Can't really get the names based on his speech.

    • @michaelmorrison3614
      @michaelmorrison3614 4 ปีที่แล้ว +5

      He mentions Ornstein-Uhlenbeck processes and Kalman Filters

    • @lucasplacides2007
      @lucasplacides2007 4 ปีที่แล้ว

      @@michaelmorrison3614 thanks man! but what it's the other thing he mentions? common felters? common filters? hahah

    • @michaelmorrison3614
      @michaelmorrison3614 4 ปีที่แล้ว +3

      @@lucasplacides2007 No problem, I edited my reply and added the other one, which is a Kalman Filter.

    • @Eigus-BikeCo
      @Eigus-BikeCo 3 ปีที่แล้ว

      @@michaelmorrison3614 Thanks man, was wondering the same

  • @joshuadawson4952
    @joshuadawson4952 5 ปีที่แล้ว +7

    I have been writing code in python for about 7 months. I am still struggling to write in the IDE, any suggestions on how to get better at this? Would working through the zipline documentation help with this? I cannot get Zipline to run in Jupyter bc of the RLock . Any suggestions on how to fix this. On a personal note you do an awesome job man.

    • @Quantopianvideos
      @Quantopianvideos  5 ปีที่แล้ว +1

      Hi Joshua,
      Are you trying to use Zipline locally on your own computer? If so, it will be much easier to use Quantopian's online platform while learning the basics. Acquiring data, processing it into the right format, ingesting it, and getting useful output from your backtests is quite difficult.
      The best place to learn about the Quantopian platform is the tutorials. Specifically, the Getting Started and Pipeline Tutorials are designed to help people get started. They can be found at www.quantopian.com/tutorials.

    • @joshuadawson4952
      @joshuadawson4952 5 ปีที่แล้ว +2

      @@Quantopianvideos Thank you for that suggestion and I will start doing that. I really wish there was more tutorials on the IDE itself, not being negative I freaking love quantopian!!! I wish I had found it sooner. Thank you for doing what you do over there

    • @Quantopianvideos
      @Quantopianvideos  5 ปีที่แล้ว +2

      ​@@joshuadawson4952 Thank you for the suggestion. We are working on providing a tutorial for the IDE and can let you know when it's ready. In the meantime, we do have an "Understanding the Algorithm API Tutorial" video that might give you a better understanding of how to use the various features that can be found on Quantopian: th-cam.com/video/fzzdhw7lm8A/w-d-xo.html.

    • @ck88777
      @ck88777 3 ปีที่แล้ว +5

      dont code, stay away from trading, and get a normal job

  • @GF86123
    @GF86123 9 หลายเดือนก่อน

    This guy is genius.

  • @vansolo9794
    @vansolo9794 4 ปีที่แล้ว +26

    That guy in the front row sticks his hand up after every question!

    • @jinxy7869
      @jinxy7869 2 ปีที่แล้ว

      Because he knows stuff? Not everyone in the crowd is dumb as a potato.

  • @satyrn6047
    @satyrn6047 2 ปีที่แล้ว +1

    like non-stationary, just picture the probability density over time as a surface.

    • @satyrn6047
      @satyrn6047 2 ปีที่แล้ว

      like you can just use MAP estimation of parametric density function. then just split it up by spectrum.

    • @jeremyjohnson7537
      @jeremyjohnson7537 5 หลายเดือนก่อน

      Can ou explain this in a better way?

  • @user-qq8jm2dk7t
    @user-qq8jm2dk7t 6 หลายเดือนก่อน +1

    it would be better if he share that Jupyter notes

  • @jakobullmann7586
    @jakobullmann7586 4 ปีที่แล้ว +48

    Omg... don’t bother about quant trading if you don’t know what a p value is!

    • @hanst7218
      @hanst7218 3 ปีที่แล้ว +1

      Haha

    • @zam2050
      @zam2050 7 หลายเดือนก่อน +5

      Whats a p value

    • @AV24274
      @AV24274 หลายเดือนก่อน

      @@zam2050mines 7 inches

  • @xh3992
    @xh3992 4 ปีที่แล้ว +19

    please pick up basic stats concept before asking any questions

  • @bmebri1
    @bmebri1 ปีที่แล้ว +2

    There's always a guy near the front of a presentation that questions your knowledge.

  • @cusodha1
    @cusodha1 4 ปีที่แล้ว +6

    I don't know why but I always found drinking something during the presentation a bit strange.

    • @FelipeRuedaH
      @FelipeRuedaH 4 ปีที่แล้ว +3

      Throat can get really dry. But drinking coke?

    • @danielheckel2755
      @danielheckel2755 4 ปีที่แล้ว +12

      Maybe he has a long position, just like Buffett.

  • @christophercatchings162
    @christophercatchings162 3 ปีที่แล้ว

    Slides, Beautiful Slides.

  • @k.butler8740
    @k.butler8740 3 ปีที่แล้ว +14

    While most of his flubs are not worth correcting as he understands a lot that he fails to communicate, but I think it's valuable to point out Max's misunderstanding of ergodicity. You need not only stationarity but also ergodicity for any sort of such forecasting. Max says that it's better to make many small denomination bets at a given set of odds (51% in this video) then one large denomination bet on the same set of odds. This is not true per se -- their outcomes have the same expected value because of the linearity of expectations. The reason why you want to make many small denom bets over the one large on the same odds is because of ergodicity: it is only the basket of pairs that you can make the ergodicity assumption about, not any single pair. What Max fails to note in this lecture is that it is the evolving basket of pairs or portfolio of pairs that themselves constitute a single emergent stationary and ergodic system. Otherwise you're making the textbook gamblers fallacy lol. Also, a stationary distribution is noise, not white noise. White noise is sampling of a normal distribution and the others we call colored noise, the most common of which is pink noise. We call normal noise white because its uniform in the frequency domain.

    • @whoislewys3546
      @whoislewys3546 3 ปีที่แล้ว +10

      I'd just like to say I found this comment 6 months when I started learning algo trading, understood 10% of it, decided you deeply know your shit, and that if I could understand what you said here I have a chance of making it in the markets
      Took a several month long break, been studying hard again past couple of weeks, and now fully understand this comment
      So thanks for the butterfly wing flap homie

    • @testchannel4695
      @testchannel4695 2 ปีที่แล้ว +2

      @@whoislewys3546 I will do the same, I'm just starting out, but I will get back in 6 months to see if it makes more sense. For now, the comment just sounds cool

    • @wardm4
      @wardm4 2 ปีที่แล้ว +5

      @@testchannel4695 I wouldn't bother. The comment is mostly nonsense. Max isn't making the Gambler's fallacy. It's exactly the opposite. Ergodicity isn't needed here (and it has very little to do with expected value). It's just the law of large numbers. If you truly have 51% odds, then you can only see this by taking 1000's of bets. The fewer bets you make, the more variance will play a role in seeing your realized value being off from that 51%.

    • @adaelasm6467
      @adaelasm6467 ปีที่แล้ว +2

      I don't think his 51% comment is about ergodicity at all. It's just basic risk management. Expected value is not the only thing that matters when deciding on capital allocation.

    • @PowerALTube
      @PowerALTube 9 หลายเดือนก่อน +1

      @testchannel4695 yeah this comment is just utter dross masquerading as something more intelligent. Max's video is fine. Understanding that variance is additive for independent events is all that is required to decide that placing lots of small, independent bets is a good idea. No need to invoke all this ergodicity cringe...

  • @avinashdwivedi2015
    @avinashdwivedi2015 3 ปีที่แล้ว +1

    Guy at the front have seen it all

  • @hanst7218
    @hanst7218 3 ปีที่แล้ว +6

    39:05 Transaction costs will be huge.

  • @kylemusser7720
    @kylemusser7720 5 ปีที่แล้ว +6

    11:34 its a t-stat not a p-value

    • @Donvito293
      @Donvito293 4 ปีที่แล้ว +5

      www.statsmodels.org/dev/generated/statsmodels.tsa.stattools.adfuller.html not true

  • @carlosdesantiago1356
    @carlosdesantiago1356 3 ปีที่แล้ว +8

    17:35 - 17:45 *drops mic* *sips coke*

    • @xelhaku
      @xelhaku ปีที่แล้ว +1

      Someone lowered the volume, that's a shame it makes this video non stationary

  • @watchizee7246
    @watchizee7246 3 หลายเดือนก่อน

    He sounds exactly like Philip Gallagher.

  • @Ne3zyTV
    @Ne3zyTV 5 ปีที่แล้ว +9

    I understood about 20% lol interesting still

    • @gornostai4ik_lol
      @gornostai4ik_lol 5 ปีที่แล้ว +2

      really common for the first time.
      you will understand 100% of that after a few months watching that theme in non-stop :)

    • @ashleywatkins-clark1115
      @ashleywatkins-clark1115 5 ปีที่แล้ว +1

      me, 2% & best thing I watched all year.

    • @Cloxxki
      @Cloxxki 5 ปีที่แล้ว

      I'll all a bit theoretical and focusing on small bit to claw some profits from. Seems there are way easier ways to trade pairs and I've tested them to beabout as good as a leverage bet that you got right, long term. But without actual leveraged exposure, even without actual shorting. Just a partial re-distributing value after one asset has risen relative to the other. When you return to the mean, you are holding more units and thus more total portfolio value. It's hard to find volatile assets that cannot be easily exploited for this strategy. The hard part is to be into them only when they drop slower in value than you can milk them. With cryptos, the whole ride down to a fraction of peak values allowed to accumulate many X units. If they ever do run up ioin price somewhat, profits will be staggering. There are crazy efficient ways to exploit price fluctuations. I'm working on a strategy that get me off the job market.

  • @soykanilhan8349
    @soykanilhan8349 ปีที่แล้ว

    Can you add Turkish subtitles please

  • @petrovsimon
    @petrovsimon 4 ปีที่แล้ว +32

    "That was bait"... Zero laughs

  • @nikolai228
    @nikolai228 2 ปีที่แล้ว +9

    16:27 cringe

  • @maddiehad
    @maddiehad ปีที่แล้ว

    lmao nothing is random. good talk btw.

  • @selmagray61
    @selmagray61 4 ปีที่แล้ว

    52:12 also seems very telling if you are trying to submit at minimum a pairs trades.
    If you don't use co-integration versus correlation or covariance in a time series...your assumptions are mute.
    Max makes a punishing point about the inferences drawn from correlation & covariance as oppose to co-integration.
    Only a propeller head can make a joke about Kalman filters "being a rich mans moving average", pretty humorous.

    • @k.butler8740
      @k.butler8740 3 ปีที่แล้ว

      I, too, was a little offset by that at first, but you missed his point. All he's discussing regarding forecasting techniques is their utilization to synthesize stationary (and, via sublation, although this is beyond Max, ergodic) assets and then betting on the model having a smaller error term in the next few measurements then it is at a given measurement. In other words, we're betting on model error terms satisfying a limiting stationary distribution (which is kosher via CLT), that which we reductionistly call mean reversion, and therefore the model itself is only relevent inasmuch as it can synthesize a stationary and ergodic error distribution. You're much better off using some obscure and incorrect model as long as its error distribution converges to a stationary distribution as your pairs basket will be unique -- you can easily use a genetic algorithym to create a ton of examples and then back test them and loh and behold you'll get your own unique arb basis model. If you have the capital you take a bunch of these and use functional analysis/distribution theory to sublate your synthetic assets into a new even more forecastable asset.

    • @selmagray61
      @selmagray61 3 ปีที่แล้ว

      @@k.butler8740 Kyle your a beast.

    • @k.butler8740
      @k.butler8740 3 ปีที่แล้ว

      @@selmagray61 to a rollie pollie, so is the butterfly

    • @selmagray61
      @selmagray61 2 ปีที่แล้ว

      @@k.butler8740 I take issue, am I the rollie pollie in this metaphor?

    • @k.butler8740
      @k.butler8740 2 ปีที่แล้ว

      @@selmagray61 idk, but from most perspectives I'm not a beast ;)

  • @jtm7776
    @jtm7776 2 ปีที่แล้ว

    Dude was drinking the same coke the whole time

  • @jdavis85
    @jdavis85 3 ปีที่แล้ว +8

    The guy in front is so disruptive. Aggressively asking questions when he doesn't know what a p value is??? You'd think he'd have some sense of shame after that.

  • @TheFadime123
    @TheFadime123 4 ปีที่แล้ว +1

    a lot of inaccuracies with what he is saying.

  • @jacobsb374
    @jacobsb374 2 ปีที่แล้ว +1

    I didn't understand shit. I wish i was brighter.

    • @herikaniugu
      @herikaniugu 9 หลายเดือนก่อน

      Watch again and again, thats how we all do

  • @lancemartin1836
    @lancemartin1836 2 ปีที่แล้ว +1

    Great video, but the guy in the front row is so insufferable

  • @juliaalonzo5998
    @juliaalonzo5998 4 ปีที่แล้ว +9

    I think I'm missing something here. I feel like he's speaking japanese. I need to learn basic statistics. I feel that speaker is very smart, but he doesn't know his audience!!!!

    • @k.butler8740
      @k.butler8740 3 ปีที่แล้ว +1

      he miss-states basics on many things so you can't take him literally -- lol yeah you do need the basics to be able to wade through his miss-statements and get the gist

  • @toaninh9120
    @toaninh9120 6 หลายเดือนก่อน

    I'm sure this is pretty redundant rn but man Quantopian closing left a hole in my soul 🥲

  • @strawbryminiwheats
    @strawbryminiwheats ปีที่แล้ว

    thank you