Expression Templates for Efficient, Generic Finance Code - Bowie Owens - CppCon 2019

แชร์
ฝัง
  • เผยแพร่เมื่อ 3 ต.ค. 2019
  • CppCon.org
    Discussion & Comments: / cpp
    Presentation Materials: github.com/CppCon/CppCon2019
    -
    Expression Templates for Efficient, Generic Finance Code
    Our legacy code for pricing financial options suffered from being written in a style that made the logic of the code difficult to follow and created performance bottlenecks. This presentation will show how a small expression template library can allow mathematical code to be updated so that even complex expressions are clear to the reader and allows code to operate on both scalars and vectors enabling substantial performance optimisations. Additionally, it will show that these updates can be done without substantially disturbing the existing code or duplicating it which simplifies testing and decreases the chances that bugs and inconsistencies are introduced. The presentation will also look at how features of C++17/C++20 make expression templates easier to implement than ever before and some implementation details so as to give the audience a starting point should they wish to utilise expression templates in their own code.
    -
    Bowie Owens
    Data61
    Bowie Owens is a software developer working at Data61, a part of the Australian government funded research organisation CSIRO. The team he works in develops complex mathematical models for pricing financial options. The software developed at Data61 is integrated into a larger trading and risk management system that is used by hundreds of financial institutions around the world.
    -
    Videos Filmed & Edited by Bash Films: www.BashFilms.com
    *-----*
    Register Now For CppCon 2022: cppcon.org/registration/
    *-----*
  • วิทยาศาสตร์และเทคโนโลยี

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

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

    Nice video !

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

    For an excellent application of this in finance I can really recommend Anotine Savines book "Modern Computational Finance: AAD and Parallel Simulations "
    for an application to this to AAD (adjoint automatic differentiation). The book is quite demanding, but in a pedagogicay descrbies how to implement a professional AAD system.
    The very last chapter describes how to use expression templates to improve the speed of the application by a factor 2-3.

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

    NIce talk!!

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

    Excellent presentation. This is pretty novel use for templates

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

    Haven't seen this talk until now, yet somehow I landed at pretty much the same implementation alone. 🤣 My only question is, do you ever need anything else than chain of binary/unary expressions?

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

    It all makes perfect sense, which sadly I cannot grasp yet.

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

    at 10:17, can someone explain what the reasoning for not using universal references (and then forwarding them) is?

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

      Thanks for your interest in my talk. The main reason is that in my case I didn't need the flexibility that comes from universal references. When you have an expression such as:
      z = a + b + c.
      The objects represented by a, b and c are often fine to be captured by const reference as the assignment of the result into z isn't going to mutate them. As the expression gets transformed into something like:
      for (...)
      z[i] = a[i] + b[i] + c[i]
      I have generally set things up such that z is already initialised with enough storage to hold the result so I don't move the storage from one vector to another. That is I don't try do something equivalent to the following assuming a can be moved from:
      for (...)
      a[i] += b[i];
      for (...)
      a[i] += c[i];
      z = std::move(a);
      Which would be useful for some cases.
      I realised too late that a 30 minute talk is quite limiting in what you can cover. So I tried to cover what I thought was essential and had to leave some things for people to discover on their own.

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

    For the subscript() function, what about checking if the type is subscriptable by using decltype(std::declval()[0]) instead of is_array_or_expression?

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

    I wish, given the speaker works in finance, he tackled not only the dimensionality of the operands (vector/matrix), but also the nature of the underlying scalar type: expression template is a popular technique for algorithmic differentiation, which is widely used in the financial sector. At least a mention or insight on it would have been much appreciated.

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

      Thanks for your interest in my talk. I only asked for a 30 minute time slot and as a result I could not include everything I wanted to. I'll keep your request in mind because I would like to follow on from this talk in the future. I was thinking about talking about how expression templates can cooperate with cuda and open mp.

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

      @@bowieowens7 Please give a longer version of this talk! Auto parallelization and vectorization are obviously points of interest. I would also be curious to know which upcoming or imaginary C++ features you think would make writing and maintaining this kind of code easier.

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

    Very interesting talk. But not sure how to make it work in a more generic way, where you have a dynamic array and you don't know exactly the size of the result vector from the expression.

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

      Thanks for your interest in my talk. Sorry it took so long for me to see your comment. I don't get notifications of comments here. Say you have a statement like:
      z = a + b + c;
      The right and left hand sides of the = need to have the same size after the statement has executed. You need to decide which side of the = is going be the definitive value on entry to the statement.
      If you decide that the right hand side has the definitive value, you ensure that the capacity of z is appropriate (either resize z to be the right size or assert that it is already). In this case you might use the size of a and add in asserts that b and c are also the same size. So the code does something like:
      z.resize(a.size());
      assert(a.size() == b.size());
      assert(a.size() == c.size());
      for (...)
      z[i] = a[i] + b[i] + c[i]
      If you decide that the left hand side has the definitive value, you need to ensure that it is sized properly before the statement. At least in my experience there is usually a convenient way to calculate the size of the vectors you are working with from the inputs. The advantage of taking the size from the left hand side is you can do things like:
      z = 1;
      To assign the value 1 to each element of z. In this way you can mix scalars which don't have a size with vectors that do.

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

    @bowieowens7 It's better late than never : thanks a lot for this talk. I have tried your ideas (for a dense matrix class) and had performance issues. I resumed them on the issues of the github page of cppcon 2019. I would be interested in having your opinon.