NM LIMITED

NM stands for Numerical Method.

When I coded the first line of matrix multiplication algorithm, the classical O(n^3) one, in the attic of my London apartment in an evening back in 2009, it was nothing more than a hobby. I was coding up trading strategy in Java but could not find a good (e.g., professionally maintained, well documented with examples, solidly object-oriented, open data structure, extensive) Java math library to use. A large part of the strategy code was developed in R/MATLAB and the trade/order execution system was in Java. However, making Java talk to R/MATLAB and vice versa was a nightmare, let alone too many other IT nuisances (e.g., multi-thread safety, multi-instance, debugging, R/MATLAB *very* slow, mysterious who-know-why-not-working’s).

I thought that the world would be benefited from having a Java math library much like the then-ubiquitous “numerical recipes in C”. One easy way was to (auto) translate the C code into Java. Yet, this only gave me a bunch of functions (procedures) that did only what the functions did. There was no data structure or module or (sub-)algorithm that I could reuse to build my new data structures or new algorithms. A vector should not just be an array. It is a mathematical concept that (1) is well-defined with many operations and (2) that any algorithm that works with vector should understand it as in (1) and needs not to re-code the properties and operations.

While there were a few Java numerical library at the time, most notably Apache Commons Math, none of them was designed to be high performance. Modern computing has come a long way since the C/FORTRAN era. We now have concurrent programming, more efficient algorithms (for Matrix multiplication, etc.), new hardware like GPU and etc. Simple translation of C/FORTRAN code or textbook implementation of algorithms would not leverage on these advances. Performance would be bound to be very slow. We will need multi-threading, highly optimized data structures as well as most efficient algorithms. For example, instead of using the simple O(n^3) algorithm for matrix multiplication, we actually implemented a parallelized version of the Strassen algorithm (the picture shows part of the code). Along with a lot of team effort twisting, experimenting and testing things in these 10 years, the end result is that we now have probably the fastest linear algebra implementation in Java.

a parallelized version of the Strassen algorithm

Another problem that I had with the existing Java math libraries was that they were very limited in scope. A quantitative trading strategy can be as simple as moving average crossover, but it can also be very complicated involving solving stochastic differential equations. It certainly involves a lot of statistical analysis. Last but not least, it also takes a suite of solvers to optimize things like, say strategy parameters. Pretty much all statistical procedures involve some optimization, e.g., regression, maximum likelihood. There is no free/cheap optimizer that is good and is in Java. Professional ones such as Gurobi and Mosek are expensive.

Something might hit my head and made me out of my mind. I resigned from my high-paid trader job with the investment bank. I embarked on a great adventure. I set out to create a Java math library that is (1) well designed with data structure and software engineering, (2) easy-to-read for humans (not machines), (3) leverage on modern computing technologies, (4) high performance, (5) extensive including linear algebra, Calculus, statistics, time series analysis, optimization, stochastic differential equations, etc. I didn’t realize how difficult it was to do it when I quit my job. I didn’t know how many Herculean tasks there were to overcome. I didn’t expect that it would last for a decade and many more to come. I was quite naive and just thought that it was fun to create something to (hopefully) share with the world. When I was a teen, I used to write my own math books organizing notes of mathematics. I suppose organizing algorithms in code would be much more useful, a sort of continuation of my childhood hobby.

It didn’t take long for me to figure out that I needed more than a one-man team to do a start-up. God plans everything and God makes providence. I was very, very, very lucky to have Dr. Ken Yiu and Dr. Kevin Sun to join me in this venture. They are my partners and my brothers to go through all the ups and downs, laughs and tears, with me in this journey. Nothing would have been possible without their tremendous effort and resources. To them and God, I am grateful!

As fate had it. Ken didn’t want to relocate to London with the bank. Kevin just finished his Ph.D. at that time and didn’t want a 9 to 5 job to wake up in the morning. Otherwise, it was not possible for me to recruit any of these expensive, top-notch talents.

OK so now the team was ready: Let’s do it!

It turned out that building a math library, especially a good one, was very challenging. It was much more than translating math formulas into code. First, we needed to understand every single detail in the algorithms. For many of them, we read the original publications. Some old publications were like written in an ancient and arcane language that was so hard to understand. Many papers had details missing. Many papers had mistakes and typos. For each algorithm that we implemented, we had to re-derive every single step in the mathematics to make sure that (1) we understood all the details and that (2) the algorithm was correct. This was nothing like learning from a textbook, which was usually well written for education, illustrated with plenty of examples.

There are many concepts that we are so used to using them without even thinking the details behind. For example, we use eigenvalues and eigenvectors of a matrix all the time but few of us care how decomposing a matrix actually works. To code up a linear algebra package, we needed to understand the many different decompositions and factorizations of a matrix, their pros and cons, precision, numerical stability, debugging and testing, API design, user friendliness, all little details. This process was non-trivial.

Second, we had to verify that our code was correct. If the paper came with examples, we reproduced them to make sure that our results matched the theirs. They were usually simple illustrative examples and few. We needed to try for a wide range of test cases, corner cases, stress tests and performance tests. Our benchmark was R. We would always match our results with R’s. When there were differences, we had to explain every single one of them. We were very serious about the accuracy of our code and were constantly fixing bugs in each release. In some cases, our code was even more accurate than R’s. For example, we didn’t know that R has for Johansen tests only a few critical points, e.g., 10%, 5%, 1%, and did a linear interpolation between them for the other values (from R’s source code). We, on the other hand, computed the asymptotic distribution for Johansen tests using the exact distribution functions. That was many hours of debugging and reading the R source code.

Third, we designed the software so that it was user friendly and in line with good software engineering principles. Most popular math libraries, e.g., NETLIB, were written decades ago in FORTRAN/C. They were neither user friendly nor good programming (because there was not much computer science at that time). One most annoying thing to me was that a function often took dozens of parameters with impossible-to-decipher-and-remember names (because the concept of ‘object’ and data structure did not exist back then; names were limited to up to 8 characters). I often could not remember what the variables meant, missed putting in some arguments and messed up their orders. They were just so user-unfriendly to use by the modern standard.

The code was often so hard to read. Good code should read like English and should be easy to be maintained by another professional programmer without the author sitting next to him. When we coded our math library, we made every effort to have the lines mirroring the paper so that another person can follow our logic by comparison. This was so that others could fix our bugs, extend our work, translate it to another language (e.g., C#) and port it to other hardware (e.g., GPU). They needed to understand our code to do so. My opinion was that it was next-to-impossible to do so for those decades’ old FORTRAN/C code. I bet that once the author is gone, no one would be able to do anything with that code other than running it, putting faith in that it had no bug. I coded up ALGORITHM AS 288 in Java from reading the original paper. I tried to understand the AS 288 FORTRAN code for comparison but still failed to do so to this date. It just seemed to move variables around for no obvious reason and somehow got it right magically.

difficult to remember the meanings and order of those A, B, C, K, N, X, Y (AS108)

Our first attempt in building such a library was SuanShu. Since 2009, it had been a decade of effort. It started just as a basic linear algebra package and then grew to be an extensive library covering Calculus, optimization algorithms, statistical analysis, differential equations, and etc. It started being my personal hobby and then dozens of experts, professors, Ph.Ds., students, practitioners, around the world had contributed to the library. It had been adopted by some big-name commercial organizations as well as academic institutions.

In 2018, we decided to discontinue the sale and support for SuanShu. We made open source the code base as of 2012 June to show how our software design approach is so different from our competitors’ products. (We don’t recommend using that version for production because there are many bugs, the performance very slow and no support.)

SuanShu
SuanShu

Leveraging on our decade of experience of numerical programming, NM DEV is a fresh ground up new numerical library that succeeds SuanShu. We have collected a large amount of feedback from users and bug reports in the last 10 years. We want to have a new software foundation and architecture to account for all these good suggestions.

We are also very lucky to have experts from multiple disciplines joining our team. For instance, Prof. Anthony So, a prominent expert in the field of optimization, will be leading our effort in re-developing our suite of optimizers. There are so many improvements that we can make to make our solvers orders of magnitude faster. In Anthony’s words, optimizers are foundation for AI and Big Data Analysis. We want to give the world a first class suite of tools to “make things better”.

NM DEV
NM DEV

Beginning as an IT start-up building numerical software, NM has expanded way beyond that. NM today now is a group company, having a number of subsidiary and associate companies in a number of different industries.

Coming from the background of quantitative trading, our very first application of the library was to implement quantitative trading strategies. We tried out many trading ideas using paper and real money in the last decade. To list a few: very high frequency market making strategy based on solving a mixed regular/impulse control problem in a regime switching jump-diffusion model, optimal trend following based on stochastic control, mean reversion based on an insightful discrete volatility model, mean reversion portfolio construction based on rate maximization rather than the classical, very strictive cointegration, post-earning announcement drift based on regression, non-linear portfolio construction using options and futures, etc. There were many failures and tears and despairs along the way. We learnt from our lessons and always came back up. We believe that we have found something good.

For the US market, our last few years’ returns are as follows. In 2017, our return was 45.44% while SPX went from 2276 to 2673 (17.44%); in 2018, our return was 19.6%, while SPX went from 2743 to 2760 (0.6%). We didn’t trade the US market in 2019 until November because of structuring and preparing for new operation. Our return still beats the market so far. In China 2019, our best product made a stunning return of 60% with a max drawdown of 3.5%.

Today, our wealth management business partners include family offices and funds. We cover a wide range of assets: equities, bonds, commodity futures, index futures and options. We don’t do anything in FX (yet).

USD account as of 2018/09/28
Atomus track record 2017-2020
Atomus fund track record 2017-2020
market making rebar and iron ore commodity futures
market making rebar and iron ore commodity futures

NM FinTech LTD is a spin off of NM. Its mission is to bridge the financial industry and the academia. Although there are many (types of) trading strategies in the Street, to name a few, technical analysis, regression model, event driven, fundamental analysis, volatility trading, random guess, only details are different for practitioners. We don’t think we are smarter (or luckier) than everyone out there if we tread the same path. We want to do something different. We are scientists, right? We read a lot of academia publications. But we never see many of them applied in trading (Markowitz, Fama-French, factor model, cointegration and etc. being the most notable exceptions). There are papers on trading strategies and wealth management being published incessantly in a large quantity. It is not easy to publish a paper (esp. in the top tier journals). The trading ideas published in top academic journals are years of work (sometimes lifetime work) from experts in the field. Wall Street traders seldom borrow ideas from them. Or, it takes very long time to do so. Prof. Markowitz published his portfolio optimization theory in 1952, but he didn’t get the Nobel Prize until 1990. Industrial adaptation of academic ideas is very slow. Reasons are: most traders don’t have a Ph.D. to understand the papers; even if they do, most of them don’t have the time to reproduce the results; even if they do, almost all of them won’t bother to do it because it is too much work to do the programming to verify if an idea actually works for real.

AlgoQuant, built on top of NM DEV, is a large collection of quantitative finance models and algorithms from academic papers. We survey and read a lot of journal papers and select those we think useful (esp. to our own trading). We do all the heavy work for the world: re-derive the mathematics to make sure that they are correct (often with typos and mistakes in the papers) and that we understand it, get the data and do the cleaning, code up algorithms to reproduce the paper for verification, run the trading strategy on our data set to see if it is profitable. Over the last decade, we have collected a large number of useful algorithms in many areas: portfolio optimization, trend following, mean reversion, market making, etc. To host these strategies, we have developed a framework for data cleaning, simulation, back testing, performance/risk analysis and reporting. This framework together with a collection of quantitative trading models is AlgoQuant.

Today, NM FinTech has added a few more products: NM Risk Management System and a database of factor values and alternative data. We continue to provide our customers with the latest quantitative trading tools so that they are not bogged down to the boring and complex technical details of mathematics and programming. They can focus on the interesting and most important task in their job: coming up with good insights about the financial market, hence innovative trading strategies. We handle the technicalities for them.

NM FinTech
NM FinTech
AlgoQuant
AlgoQuant

NM FinTech Shenzhen China is a subsidiary of NM FinTech LTD. We see an opportunity in the fixed income market in China. The biggest share in the Chinese finanical market is in bonds. The central government, local governments, major banks, local banks, big and small corporations and factories all issue bonds to fuel the economy to sustain their operations. Bonds account for a large chunk of a bank’s asset, which cannot be lower than a threshold by law. The pricing of these bonds, however, is problematic. The official prices for all listed bonds in China are published by China Central Depository & Clearing Co., Ltd. Every bank uses their prices to report asset valuation at the end of the day. Yet, every trader knows that their prices are problematic and don’t use them for trading. There is even a hotline that you can call to complain if you think their pricing is way too off. The Chinese bond market is still at its infancy. There is even no good quality yield curve that is publicly available. (There are 3 published yield curves but I think that they are not right.) Yield curve is the foundation for all fixed income pricing.

We were very honoured to have Raphael Douady, a very established mathematician in financial mathematics, on our team and Antoine Savine, a very established quant and my ex-boss at the onset of my quant career, to be our advisor. Together with Kevin and myself, management and supporting staff, we basically did nothing for 3 months other than to come up with a theory, code it up and test a zero-coupon curve for the Chinese bonds. The process was nothing smooth at all. In the last month, we literally locked up everyone in office until the curve result was satisfactory; people getting sick, stomach pain, fever; sleeping on sofa in office, etc. (Hey, team spirit!) Unlike the U.S. market, the Chinese market has so many data problem, to mention a few, illiquidity, missing and wrong data, not having enough bonds. Standard models from the U.S. don’t work. Supercurve is the brain child of many experts, Ph.Ds., our dedicated team and management. Supercurve is the first publicly available yield curve that is accurate, having a solid mathematical underpinning, the best yield curve for the Chinese fixed income market.

supercurve example
Super Curve

NM OPTIM is our first attempt to apply mathematics outside finance. There are hundreds of thousands of factories in China. Their success comes from hard working, wit and the Chinese reform and opening up in the last 40 years. Many are still very labour intensive. A factory can easily employ thousands of workers in 3 shifts. To survive the technology revolution and to compete in the international stage, Chinese factories must upgrade themselves. There are literally hundreds of steps in a manufacturing process like steelmaking. Every step can be improved and optimized. We have talked to dozens of manufacturing plants and summarized a few common problems: scheduling, resource allocation, raw material sourcing, inventory control, sales, pricing. Each of them can be modelled and optimized using mathematics.

resource scheduling

Dr. Sherry Xue-Ying Ni is leading the team to help factories and companies optimize their workflow and resource planning. We are very proud to be a working partner with Nanjing Iron and Steel Co., Ltd. (SHA:600282), a major steel making company in China. We are working with them to build mathematical models for the steel manufacturing process, collect data, apply (stochastic) optimization theory in improving each step in the process, improve resource allocation.

I knew nothing about manufacturing before. The learning process is fascinating and daunting. It was not an easy experience to move from Wall Street white collar to factory blue collar. There was a week that I needed to catch the first plane in the morning flying to a different city every day for the whole week. Not only that, after landing, I needed to take the high speed railway and then hired a car to travel 100km to reach a factory in a remote suburb. All clients might say after the meeting was that they would think about it.

Other interesting projects that we are working on include: labour and machine scheduling for a major chemical fibre plant, smart parking spot allocation and dynamic pricing in a smart city.

Nanjing Iron and Steel Co., Ltd.

While I didn’t expect entrepreneurship is a cruise in the park to success, I also didn’t realize that it would take so much (financially, psychologically, personally). There have been so many obstacles. My favourite childhood hero is Son Goku. I pretty much read again the comic series every summer before finishing school. Unlike Superman, Goku is not invincible nor the strongest. In fact, he is often defeated but by antagonists (who later become friends and join the team). The main story of Dragon Ball is how Goku (and his friends) train up and repeatedly get up from where they fail, never give up. You can only lose when you give up.

Like Goku, I have also made a lot of friends who have joined me in this great adventure. Without their help, I would have not survived till now. Other than the sense of achievement and fulfilment, the great joy of doing a start-up is to build something together with your good friends, partners, comrades and brothers. We overcome and survive the battles together. These stories are our history, our life. All in all, there are losses and gains, probably more gain than loss.
Goku and friends
Goku and friends
Future, as always, remains uncertain. It is a thin veil yet we can’t even see beyond one second of it. Our goal remains firm: we want to use mathematics to make the world better. We want to be the bridge between the academia and industries so useful ideas can be adopted quickly rather than waiting for decades.
 
We are very excited about our recent performance and initiatives. We have found a good trading strategy that has proven track record and that has billions of dollars capacity. We are developing the fastest and highest performance optimizers for both research (AI and Big Data) and industrial needs. We are working with some major players in their fields to mathematical-ize their work flow and streamline their operations. We are looking forward to give the world a new set of modern mathematical tools to upgrade the industries in China and beyond.

NM, having started in my little apartment in London, has grown to a galaxy of companies each serving her own mission. I am very grateful for everyone who is with me in this journey. 愛と勇気と誇りを持って闘うよ。The journey goes on!

If you are still with me after reading this long article, can you figure out how many companies that NM has? 😀

Happy counting!

NM LIMITED
Make the World Better Using Mathematics

Dr. Haksun Li
2020/02/02, Osaka, Japan