How to speed up TCA in Python

How to speed up TCA in Python

Somewhat abusing a quotation by Dickens, coding is the best of times and also the worst of times. The worst of times are those hours spent debugging, what appears to be some innocuous code, that throws an exception for some totally inexplicable reason. When you find the problem it is usually something which was incredibly trivial. Of course, something is always obvious after you've discovered it, but never beforehand. 

In between the bugs, the frustration and the tears (admittedly, the last part of that tricolon has been used purely for an exaggerated literary effect), there is the question of optimization. As Donald Knuth has noted, "premature optimization is the root of all evil". The priority is making your code work. However, once it works, if it is very slow and is likely to be executed repeatedly, it might be opportune to ask how you can speed it up. At the same time, we also want our code to be readable, to make maintenance easier. Open sourcing the project forces you to think about making your code to be as elegant as possible, given you know lots of folks will be looking at!

We recently open sourced tcapy, Cuemacro's transaction cost analysis library (download it from GitHub). It is one of the first open source libraries for TCA. Most solutions tend to be closed source, and if you want to build your own internal TCA library it is likely to cost many hundreds of thousands of dollars, if we also count the maintenance costs. Use tcapy and save hundreds of thousands of dollars! Essentially, tcapy takes in large amounts of market tick data and your own trade/order data. It then calculates various statistics using a combination of this data, to tell you how much you are paying for your trading activity. It allows you to compare between different liquidity providers, trading styles, algos etc. We are faced with several time consuming steps:

  • IO intensive: Loading large amounts of data from disk is slow
  • Compute intensive: Making calculations on large amounts of data is slow
  • Compute intensive: Generating graphical output on large amounts of data is slow

We also face constraints....

To read the rest of the article on the Cuemacro website, please click here!

要查看或添加评论,请登录

Saeed Amen的更多文章

  • Learning from running financial models live

    Learning from running financial models live

    Let's say you are the world's best burger chef (we all have ambitions, right). You'd be serving up all manner of…

    1 条评论
  • DeepSeek, objectives and constraints

    DeepSeek, objectives and constraints

    When a new burger joint opens up, there's often a buzz. Everyone (well, at least me) wants to try the new burger.

    1 条评论
  • Hundreds of quant papers from #QuantLinkADay in 2024

    Hundreds of quant papers from #QuantLinkADay in 2024

    I tweet a lot (from @saeedamenfx and at BlueSky at @saeedamenfx.bsky.

  • What we’ve learnt from reading thousands of Fed communications

    What we’ve learnt from reading thousands of Fed communications

    We recently had the last FOMC decision of 2024. Market l participants reacted to the hawkish tone including Powell’s…

    1 条评论
  • Takeaways from QuantMinds 2024 in London

    Takeaways from QuantMinds 2024 in London

    Over the past years, the quant industry has changed substantially. My first visit to Global Derivatives was just over a…

    12 条评论
  • Takeaways from Web Summit 2024

    Takeaways from Web Summit 2024

    Think of Lisbon and no doubt it’ll conjure images of explorers setting sail in centuries past across the ocean, the…

    1 条评论
  • FILS Europe 2024 Takeaways

    FILS Europe 2024 Takeaways

    Paris is home to many things, the Eiffel Tower, the Arc de Triomphe, burgers (ok, I made that one up!). In recent…

    4 条评论
  • Don't look back in hangar steak

    Don't look back in hangar steak

    I'm currently in the queue for Oasis tickets. Rather than mindlessly watching the counter of people in the queue ahead…

    5 条评论
  • The Olympic spirit for forecasting

    The Olympic spirit for forecasting

    The Olympics finally finished, and the Paralympics are about to begin. I managed to go to some of the Olympic football…

  • Eleven years of independence

    Eleven years of independence

    Regrets become ever more edged with the passing of time. Recalling a time long gone, when perhaps a decision made, was…

    5 条评论

社区洞察

其他会员也浏览了