What is is this Matlab typesafe interface vs Builder NE for DotNet CSharp vs Simulink C++ or FPGA HDL quant trading deployment
On 2014-04-17 10:37
> Have you done any tests using Matlabs TypeSafe interfaces vs their
> standard stuff?
> I can without a doubt say that going from .NET -> Matlab over their
> typesafe interface is slow as balls.
More info: http://blogs.mathworks.com/loren/2011/06/03/introducing-type-safe-apis-with-builder-ne/
It really has no impact on what I do. Or at least I hope not but I have not seen any degrade thus far.
I have not really tried this but as you call the standard seems be to decent performance wise. This is a decent result:
This is not the desired end target as we have been looking at FPGA via Simulink. We may generate from the Simulink model to C++ which is pretty efficient. I am also on the hunt for independent frameworks that do not step outside of Matlab code functions (i.e. other toolboxes) which enable me to have a full flexibility for FPGA or C/C++ code generation. Don’t forget I can embed Matlab custom M function into Simulink models.
Using currently the Builder NE or Builder Java is just a quick way to implement a Matlab M script with the REAL TIME market data capture and Interactive Brokers order management execution. I am just more focused on the strategy generation right now.
> So in short. You haven’t done a performance comparison of equivalent
> functions in a native library compared to calling Matlab and getting a
How do you mean equivalent functions? An interpreted version written in C# vs calling a Matlab function via a DLL?
This what I can tell you, Matlab offers many advantages in your workflow in developing trading ideas with models or strategies. Generate a DLL via Builder NE is the quickest and easiest way to do this. It is performant based to with so called 100% compatibility with most Matlab toolbox functions. You can also call worker pools for extra parallelization from within the .NET. or C#.
You could also generate C++ code via the Matlab Coder but the C++ is limited plus the Matlab Toolbox support is extremely limited. As mentioned Simulunk seems to be the best but the option via Builder NE for .NET DLLs is the easiest. I hope this helps.
Equivalent I mean run a regression, hypothesis test, etc.. with a
> quality C# library vs call Matlab.
Understanding your situation, there are not a lot of C# .NET libraries for standard math. They are very cumbersome to build and maintain. From my testing, using a library is definitely faster if done in 100% C++ or .NET but don’t forget many libraries are limited. I have done analysis looking at GSL and TA-LIB and even more complex libraries like Boost. The problem is they don’t play nice together so you need to convert from one or another if you hit a some limitation with any of these. Your other option is to develop your own but again, that is a lot of work. I am not sure what your primary goal is here but if you are wanting to move ahead to put a trading idea into a live production platform, you will run into even more headaches.
The nice thing about Matlab is you can rapidly develop your strategy in M script which can be extended in Excel, Java, or .Net. But as you say, you can run into various limitations with performance. The Matlab Coder with C++ generation will not help either due to the code generated is not really helpful in terms of maintenance. This is not a solid option for me. Don’t forget the Matlab Coder does not support all the important trading toolbox functions so that is its major drawback.
The nicest of all options is Simulink. You can visually design your model, control your state of the data through Stateflow, and execute your order in the ‘outflow’ part of the visual Simulink model. As said, it can call custom Matlab M scripts which can include those custom frameworks functions which are self contained. Also with the power of Simulink Coder/HDL Coder, you can deploy this same visual model to C, C++, or your HDL model code of your chosen FPGA all from the same model. As you know, going the FPGA route is the absolute lowest latency if you decide to go true HFT.
The generated C++ code is nice and efficient but there are configuration settings that enable you to encode the Matlab, Stateflow, or Simulink code as comments. This is an awesome way to trace back the Matlab or Simulink pieces within your code. This is why I really like this Simulink option for live trading. One of my members is currently investigating this option.
I am unsure if this is helpful but this is probably the easiest quickest way to market your trading idea. It is also potentially the fastest and lowest level you can generate using something like Matlab.
Outside of painful hand coding, this enables you to generate your idea very fast and probably the highest performance based code you can get. The code generation from Matlab seems pretty efficient as well.
Compared to cryptic non future path languages like R or Python (now even Java), it is a dangerous path to go if you plan to implement some form a ‘quant’ trading business for the future. This is why I like this Matlab Simulink path the best.
> Don’t really agree with those statements on R or Python. Both work
> fine, all languages have their limitations (including Matlab).
–> I have done numerous analysis on these languages and they are not very beneficial for how fast I bang out trading ideas. I just find them severely limited in a many ways but that could change in the future. As it stands, I care more about trading ideas than splitting hairs over the programming languages. I just use what works for me.
> There seem to be some decent libraries for C# (but they are
> commercial, which is fine).
–> There are some but from hard learned lessons from highly ‘successful’ indie traders (think London Quant) who do development, it seems rolling your own library solution is definitely the way to go. I just don’t have really the time or energy to focus on maintaining large APIs like this. I just want to use leverage the power and extensible deployment options that Matlab brings. I have not yet seen anything as good but again, that is my experience only as I no longer debate about it. People can use what they want as it is a free world but I do document what works for me. It is like arguing with fools who have nothing better to do.
> As for FPGA, if you need that type of timing in order to be
> profitable, you are already facing a lot of limitations given that you
> are retail e.g. competing against players who have privileged access
> to the order book or the ability to submit special order types.
> Doesn’t matter how fast you are. They get the information before
> you 🙂
–> This is being regulated and investigated now by the NY State of Attorney and FBI! It will change and be equalized sooner than we know. It is quite possible that this whole model will be built around how IEX works. And dontchya know it, Interactive Brokers now support than as a gateway option.
Again, what is you specific goal here that started this dialogue?
Join my FREE newsletter to see how proceed with this
I now post my TRADING ALERTS
into my personal FACEBOOK ACCOUNT
. Don't worry as I don't post stupid cat videos or what I eat!