Tag Archives: Builder Ne

Is Matlab Builder NE really fast with DotNet and CSharp vs the Production Server?

Is Matlab Builder NE really fast with DotNet and CSharp vs the Production Server?

Someone from my email newsletter responded so thanks to them:

Re “help out connect DotNet C Sharp to Matlab Production Server?”

 

I have no experience with Matlab Production server and C#, however I have experience with Matlab and C# and can give you another advice:

 

In one of your videos you refer to and demonstrate C# code exported from Matlab with NE Builder as running very slowly

 

In the video I saw your code being executed only once, which means that its execution suffered the performance penalty of the initial loading and initializing the Matlab Compiler Runtime (MCR). If you try more than one iteration of the execution, while the main program remains loaded and running in RAM you will see that the performance of exported C# code is blindingly fast

 Join our FREE newsletter to see how we implement this

NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!

Demo of Windows Application EXE built by Matlab 2014a Builder NE for DotNet deployment

Demo of Windows Application EXE built by Matlab 2014a Builder NE for DotNet deployment

Very cool new feature where I can now upload self contained Windows apps for you and members.

Here is a sample testBuildNE

Join my FREE newsletter to see what kind of applications we develop for you 

 

NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!

What is is this Matlab typesafe interface vs Builder NE for DotNet CSharp vs Simulink C++ or FPGA HDL quant trading deployment

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
> Bryan,
>
> 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
> result.

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

 

NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!

Preparing Matlab pair trading code for Dot NET CSharp calling with Builder NE toolbox

Preparing Matlab pair trading code for Dot NET CSharp calling with Builder NE toolbox

Watch this to understand it,  my Quant Elite members will get this

I refer to this

https://quantlabs.net/blog/2014/02/highlighted-matlab-source-code-walk-through-of-pair-trading-code-with-automated-trading-system-in-mind/

Join my FREE newsletter  on the announcement when this is complete

 

 

NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!

Matlab Builder NE Mean Reversion trading algorithm with DotNet and Interactive Brokers real time data and trading market execution coming soon

Matlab Builder NE Mean Reversion trading algorithm with DotNet and Interactive Brokers real time data and trading market execution coming soon
Here is what I am working on right now!
The Matlab Builder NE toolbox is proving to potentially be a  good addition to this upcoming automatic trading system. The performance has been decent against all the simulated tick data from Interactive Brokers.  I can still keep the IQFeed as well. Also, I am still working on the pricing end for my mean reversion algorithm test which came from a Mathworks webinar so it should be good to go. Everything is working and I will definite show a preview video. A detailed video with SOURCE will be available for my QuantLabs.net Premium  Members. I will also be part of this workshop in the works for this same Member. As usual, it is exciting days ahead.

Join my FREE newsletter on other trading models I got in the works

NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!

Can you speed up or parallelize your DotNet code in C# with Matlab code through the Builder NE toolbox?

Can you speed up or parallelize your DotNet code in C# with Matlab code through the Builder NE toolbox?

Want to learn more about this? Join my FREE newsletter

This just came in through a Youtube message:

Hello Bryan,

 

 I see you have some examples of how to use Matlab Builder NE.

 

 I’d like to ask you if the algorithm computation costs are largely increased when using a solution like this?

 

 I haven’t yet used I couldn’t get the software so far.

 

 The algorithm I’m interested in using with .NET can be a bit complex since it is a clustering algorithm.

 

 http://www.psi.toronto.edu/affinitypropagation/software/apclusterSparse.m

Sent to: Bryan Downing

 

Yes, using the Builder NE can be inefficient but since Matlab 2012a, you can now parallelize with Matlab’s workers ( from the Distributed Computing ) in your C# code. That may be a way to speed it up but I cannot say as I have not confirmed this. I have seen documentation on this in the Builder NE toolbox user guide PDF. In other words, parfor now is supported in the Builder NE.

 

NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!

Lack of example Multicharts.net Microsoft .NET C# source code for indicators and signals so using Matlab Builder NE toolbox

Lack of example Multicharts.net Microsoft .NET C# source code for indicators and signals so using Matlab Builder NE toolbox

I was surprised that there is little example code in C#. It seems that there is quite a bit of Easy Language code which is compatible with the Power Language version of Multicharts. I am starting to think it might be better just to switch the algorithms to Matlab M script and build .NET assemblies. I would do this through this the Matlab Builder NE toolbox. I am just thinking there is a bigger and better Matlab community versus the Multicharts. Lets see what happens with this approach. See my demo of integrating Multicharts.NET and Matlab/Simulink together.

Join my FREE newsletter to see how I approach with this approach

NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!

Matlab Builder NE q&a and why R blows the doors off it for quant and model development or strategy building

Matlab Builder NE q&a and why R blows the doors off it for quant and model development or strategy building

A Youtube video user asked:

Matlab builder NE

Hi quantlabs,

I like your videos about Matlab and how it can be integrated with .NET.
I’m not that much of a programmer but here’s what I’d like to do:
1. Use “deploytool” to create a .NET-Assembly
2. Integrate it in a .NET application to do calculations on an array containing a financial time-series.
Unfortunately I get a bit confused when and how to use MWArray, MWNumericArray (etc..) when declaring the variables and arrays I need for the calculation.

Below there’s the code for the “magic square” example. I’m wondering how I need to change this “prototype code” for my purposes – taking an array of financial prices, passing it to the matlab function and returning the result. Can you help me?

Thanks you very much…
andrew8w

Dim obj As MLTestClass = Nothing
Dim input As MWNumericArray = Nothing
Dim output As MWNumericArray = Nothing
Dim result As MWArray() = Nothing

Try
obj = New MLTestClass()

input = 4
result = obj.magic(1, input)

output = DirectCast(result(0), MWNumericArray)
Console.WriteLine(output)
Catch generatedExceptionName As Exception

Throw
End Try

My answer is:
Use R. There are many better ways to integrate into an external language including .NET languages like C# or Visual C++ or even Java. I find R is easier with cetain R packages like RCaller. ALso, it is free so this is why I switched.
NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!

Youtube demo on how to manipulating C# code examples with Matlab Builder NE and Matlab data types

Youtube demo on how to manipulating C# code examples with Matlab Builder NE and Matlab data types

Learn more here.

 

NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!

Youtube video demo Matlab Builder Ne Usage for .NET and C# with Visual Studio

Youtube video demo Matlab Builder Ne Usage for .NET and C# with Visual Studio

Learn more here http://quantlabs.net/membership.htm

NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!