HFT Low Latency C++ Interview Question - Template Metaprogramming

Поділитися
Вставка
  • Опубліковано 30 сер 2022
  • Most asked Low latency C++ interview question in HFT, Hedge funds and Investment Banks based on the concepts of template metaprogramming.
    If you are absolutely intrigued by this technique then you are meant to be in a trading firm.
    _________________________________________________________________________
    Follow me on Instagram: / shubham__cr7

КОМЕНТАРІ • 46

  • @harshpatel105
    @harshpatel105 Рік тому

    Awesome stuff bro. Please make more such videos

  • @Wswh123
    @Wswh123 Рік тому +2

    Thank you for your help.
    Can i ask why for line 15 there must be a ::value at the end? I understand :: is scope resolution, it takes the global's value of value. Hence its taking the struct gcd value?

    • @CodingInterviewPrep
      @CodingInterviewPrep  Рік тому +1

      value is a static member of the gcd class. Static variables are accessed using scope resolution operator ::
      Syntax is ClassName::variable
      Hence we do gcd::value

    • @Wswh123
      @Wswh123 Рік тому +1

      @@CodingInterviewPrep thank you so much man. Could I also ask
      1. I am coming from a java background, would say I'm quite decent with java hence the OOP, static type, etc. Is there a good book/tutorial/video to recommend for the transition between java -> cpp? Else what book would you recommend to learn cpp please?
      2. Also, as a starting project im trying to build a simple order book in cpp. However there isn't much useful youtube video/website guide to teach. Do you have any recommended resources or anything to build related projects in c++?
      thank you so much

  • @pramodreddy1358
    @pramodreddy1358 Рік тому +7

    Just adding 'constexpr' to the normal runtime gcd function would enable us to run this function in compile time. That is the static_assert would work as expected. Any reason that you had not used that approach seems more easy and concise. Just guessing there might be some limitations with the constexpr approach. If there are can you reply a couple scenarious where the 'constexpr' approach would fail?

    • @CodingInterviewPrep
      @CodingInterviewPrep  Рік тому +1

      Yes this can be solved using constexpr function but I did it this way because I wanted to teach a new technique. There are a lot of scenarios where a constexpr function can't be used and template metaprogramming is the only solution.
      Look at the implementation of std::is_same, std::is_class, std::is_pointer etc. on cppreference and then think if you can implement those using constexpr functions. I don't think you can. There are many type traits like that present in header which can only be implemented using a template metafunction.
      Also in some it is easier to write a template metafunction as compared to a constexpr function. For instance this question ua-cam.com/video/snIcfIrHSeI/v-deo.html

    • @CodingInterviewPrep
      @CodingInterviewPrep  Рік тому +2

      Watch my latest video: ua-cam.com/video/LjfsNyomtro/v-deo.html
      Do you think you can solve this question using a constexpr function? I don't think you can. Template metaprogramming is a very powerful technique.

    • @aniketbisht2823
      @aniketbisht2823 5 місяців тому

      @@CodingInterviewPrep You should use constexpr for computation involving only values. If types are involved in any way, only then you might need to use type traits and these sort of template techniques. Not to mention that template instantiation caused by these techniques leads to very slow compile times and therefore does not scale.
      Constexpr has become really capable, you can also allocate memory on the "heap" (C++20) and also use the entirety of (C++23). And when reflection becomes part of the standard (very likely in C++26) then these techniques would be made completely redundant and templates would only be used for Generic Programming (as they originally were intended too).

  • @JimmyKal
    @JimmyKal 8 місяців тому

    awesome video man, actually u don't need to be on HFT to learn this stuff, this can give u foundations to move your C++ knowledge to the next level

  • @harshpatel105
    @harshpatel105 Рік тому +1

    Does the quant companies use GCC or clang as a compiler? Are there any benefits of using either one?

    • @CodingInterviewPrep
      @CodingInterviewPrep  Рік тому +1

      GCC and Clang both are widely used. Some firms might be using a lot of other compilers as well like Intel ICC compiler

  • @maYank-nz3dt
    @maYank-nz3dt 10 місяців тому

    please make video on full roadmap to become quant dev after 12th

  • @romokdas8494
    @romokdas8494 Рік тому +5

    If the values of a and b are supplied from the user the compiler won't know the gcd at compile time. So the compile time results can only happen if the input values are constant. If the input values are constant why can't it be precomputed and used directly in our code?

    • @CodingInterviewPrep
      @CodingInterviewPrep  Рік тому +8

      You are missing the damn point. Template metaprogramming is a technique and it can be applied everywhere where recursion is involved. It is used to write code for complex dynamic programming problems where precomputing the result and storing it in the code will be a pain and also increase the binary size. Input might change and someone might forget to update the precomputed result and BOOM your code breaks in production. This happens a lot when new hires/interns make their way into the company as they are not aware about the systems end-to-end. If they forget to update the precomputed result then it wasn't their mistake. It was the mistake of the developer who came up with this idea of storing precomputed results. You gotta fire him. Think about it this way that why do we create macros and constant variables in C++ when we could just use hardcoded value everywhere in the program. Answer: maintainability, readability, flexibility etc.
      There are a shit load of other benefits of Template Metaprogramming.
      It also allows library developers to create ultra low latency libraries.

    • @romokdas8494
      @romokdas8494 Рік тому

      @@CodingInterviewPrep thanks for the explanation , makes sense now👍👍

  • @KillerMZE
    @KillerMZE 8 місяців тому

    const variables actually take memory, and constexpr is more like a macro where the compiler will just replace it. As for actual performance, this isn't very useful in real applications where things aren't known in advance

    • @therealg4197
      @therealg4197 4 місяці тому

      Do you work in HFT? This is very useful because you want to reduce latency at runtime as much as possible. Saying its not useful when thing aren't known in advance is like saying a car is useless when it comes to flying,. A car has its uses and a plane has its uses.

  • @MrGoose-fr1wp
    @MrGoose-fr1wp 2 місяці тому

    Do they face consequence for anything?

  • @SachinKumar-vi2dq
    @SachinKumar-vi2dq Рік тому +1

    Sir just wanted to ask you what resources should be used for being expert in C++. Also tell us how to become a good competitive programmer.
    Also if you don't mind tell us about your internship.

    • @CodingInterviewPrep
      @CodingInterviewPrep  Рік тому +2

      ua-cam.com/video/V-VZCtzYybg/v-deo.html

    • @CodingInterviewPrep
      @CodingInterviewPrep  Рік тому +3

      Don't call me Sir

    • @SachinKumar-vi2dq
      @SachinKumar-vi2dq Рік тому +1

      @@CodingInterviewPrep thanks shubham bhaiya.
      To big tech firms like MAANG or HFTs open up for electrical and electronics engineering students for SDE roles.
      Please reply

  • @swatideora5224
    @swatideora5224 Рік тому

    Hello, I am from tier 2 cllg and currently working as an SDE, can u pls guide how can I get a quant role in HFT firm?

    • @CodingInterviewPrep
      @CodingInterviewPrep  Рік тому +1

      Since you do not have any experience in trading you cannot directly switch into a Quant role. If you are working in Google, Meta or a likewise firm as an ML engineer or in their core infrastructure team then you might have a chance but otherwise no.
      Although you can get a job in Core Engineering division of trading firms. After that you can try to switch into quant role

  • @suryavirkapur
    @suryavirkapur Рік тому +1

    Isn’t there some way for LLVM to directly do this? I think it’s a optimisation that you can enable on regular programs somehow.
    I wrote the source code for factorials in Rust, and the result was hard coded into the binary. It isn’t template meta programming but it achieves the same result, right…

  • @sauda5557
    @sauda5557 Рік тому

    Please if you can guide properly as what can be a potential roadmap to get placed at these companies

    • @CodingInterviewPrep
      @CodingInterviewPrep  Рік тому +2

      "If I will wait for direction my lifetime will pass me by." - Celldweller (Lost in time)
      There's no roadmap. In my earlier videos I have listed all the resources for passing Quant/Core engineer interviews of trading firms. Study them, practice a lot of questions and try to pass the interview. Don't give up in just 2-3 rejections. That is common for most of the people.

  • @Wan_Destroyer
    @Wan_Destroyer Рік тому +1

    Hey i have a question, can i simulate latency or packet loss with this? When yes can u tell me?

    • @CodingInterviewPrep
      @CodingInterviewPrep  Рік тому +1

      I am sorry. I didn't understand this question. Could you please elaborate

    • @Wan_Destroyer
      @Wan_Destroyer Рік тому

      @@CodingInterviewPrep yes, i would to know how i can simulate a network like i want to do a network emulator, with zhis i can simulate in a network Bandwidth and packet loss, can u do this or is this video wrong for it?

    • @CodingInterviewPrep
      @CodingInterviewPrep  Рік тому

      This video is not for your problem.

    • @Wan_Destroyer
      @Wan_Destroyer Рік тому

      @@CodingInterviewPrep ok thanks

  • @piyushsahu3841
    @piyushsahu3841 Рік тому +1

    Bring more videos

  • @jackcapital7426
    @jackcapital7426 Рік тому

    Can I become a quant if I have a ms in finance from uk ,can I get jobs from big global companies?

    • @aashishc5287
      @aashishc5287 Рік тому

      Veryyyyyy hard!!! Try for some trading roles actually in Europe itself!! Also curious to know why do you wanna do masters in UK and comeback?

    • @jackcapital7426
      @jackcapital7426 Рік тому

      @@aashishc5287 i don't wanna come back ,I'm in my pre final year from a tier 3 engineering college . was planning to do masters in finance as I'm genuinely interested in it but idk the right way to get into quants so I was asking this question btw can i connect with you some how?

    • @aashishc5287
      @aashishc5287 Рік тому

      @@jackcapital7426 masters in finance isn't a degree to get into Quantitative finance
      You need to get masters in financial engineering or financial mathematics
      You have such programs in Imperial College London as well as Oxford
      You'll need to put lots of efforts in GRE and other skills to get your profile shortlisted for such programs because you mentioned that you are from tier 3 college
      All the best and do let me know if you have other queries

    • @jackcapital7426
      @jackcapital7426 Рік тому

      @@aashishc5287 any way to connect in private? Have tons of doubts here plz it will help me to develop my career

    • @aashishc5287
      @aashishc5287 Рік тому

      @@jackcapital7426 Instagram same username