View Full Version : Neural Networks
regen
05-09-2007, 05:20 AM
Hi,
is it possible to train and use a neural network within a strategy?
The main point is that a neural network needs the whole data series several times to train. So its not possible to use the bar event.
NinjaTrader_Dierk
05-09-2007, 05:45 AM
NT does not support neural nets. However you could try to interface any .NET assembly within your NinjaScript strategy
regen
05-10-2007, 01:58 PM
Thanks. An External Assembly sounds great.
But there is an error:
" ERROR: Failed to call method 'Initialize' for indicator 'MyCustomIndicator': Could not load file or assembly 'Net, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified."
There is definitely no reference or something in my Assembly. Just to the .Net Assemblys System, System.Data, System.Xml.
Also the error occurs whereever i put the assembly file in my filesystem.
Any suggestions?
NinjaTrader_Dierk
05-10-2007, 02:02 PM
Hmm .. I guess you would need to register it in the GAC. Putting it in <my documents>/NinjaTrader6/bin/Custom where the indicator assembly is, will not work since it will screw up NT.
regen
05-10-2007, 02:28 PM
Registering in the GAC works fine. Thanks.
noborimashu
05-28-2007, 09:59 AM
i am also trying sth with a dll, i
- added it to the script editor references to be able to compile the strategy
- added it to the GAC to be able to use it in a backtest
only one of the two does not seem to work. do i have any
chance to work with the GAC or the editor reference only ?
i did not find any.
also with the dll in the GAC it seems to be necessary to restart ninja trader after every dll change ...
NinjaTrader_Dierk
05-28-2007, 11:54 PM
We have limited experience with the GAC. For sure you need to reference the assembly in the editor. I would think (but I'm not sure) you have to the reference the instance in the GAC and not a different copy...
May be regen can contribute?
Yes you have restart NT every time you change the referenced assembly.
noborimashu
05-29-2007, 01:30 PM
thank you for your reply. so far i did two things:
1. add a postbuild event to the visual studio build config to register the created dll in the GAC. like "gacutil.exe /i TradingGEP.dll". it takes the created dll and puts it into the gac after each build.
2. add the generated dll in the bin/Debug folder to the references of the ninja script editor, no this is not the one in the GAC, but still it's the same as the one in the gac.
this way i can fire up the ninja trader and use some TradingGEP.dll class in the ninja script editor. in addition i can attach to the NinjaTrader.exe using the visual studio debugger and set breakpoints in my dll. they get hit. not the most convenient set up, but still a way to debug the integration code.
any suggestions for improvement are welcome.
NinjaTrader_Dierk
05-29-2007, 01:33 PM
Thanks for your feedback. However, due to bandwidth reasons we are unable to provide support to that technical level.
terenyi
09-04-2008, 12:03 AM
I'm currently working on an interface that links NT to Matlab (with the Neural Network Toolkit) and which provides a C# API for using feed-forward networks and self organizing maps. I should have my first version ready in a day or two and I could post this here if other people are interested in this too.
PS: Whoever made the design decision to use C# instead of a proprietary language in NT: Very good idea! ;)
mrlogik
09-04-2008, 05:57 AM
terenyi,
I'm interested in the development of NT to Matlab.
Please keep us posted.
Thanks
linzvb
09-05-2008, 01:44 AM
I'm interested too!Great Idea.
VB
terenyi
09-08-2008, 03:00 PM
Still working on it but looks good so far. Hopefully I'll have it finished within the week.
darthtrader
10-18-2008, 06:03 PM
hey terenyi, any update if you got the bridge to matlab working?
terenyi
10-26-2008, 05:07 AM
sorry that there were no updates but unfortunately i haven't had time to work on is during the past few weeks.
the good news is that i got it working and it's already about 90% finished. i've implemented feed-forward networks and self-organizing maps.
the bad news is that i don't know when i'll have the time to finish the last little 10%... there are just more pressing issues at the moment.
decus
10-28-2008, 04:55 AM
Anything we can help with?
I use Fann with Ninja, but would be interested in your matlab bridge.
I do a bit of matlab stuff at uni.
mrlogik
10-28-2008, 05:27 AM
Hey decus, can you elaborate on what Fann is?
Also, if any help is needed with the Neural Net programming, let me know.
Thanks
decus
10-28-2008, 06:09 AM
FANN = Fast Artificial Neural Network Library
http://leenissen.dk/fann/index.php
It's fairly straight forward to get working with Ninja. I've got some other opensource NN library's working as well, but I like FANN the most.
Now I just have to work out a good strategy that uses it....:)
GreenTrade
10-31-2008, 09:30 AM
How would someone go about developing a Neural Net that predicts the probability to an upward market move, say 60% and a probability of a downward move, say 20% and sideways (20%) and incorporating that into an entry/exit signal? I have done a little research on Neural Networks in trading but have not found anything that really goes much beyond theory and actually into development. Thanks for the insight!
GT
terenyi
11-01-2008, 04:38 AM
This is unfortunately not so easy. First you have to think about which input variables you want to use (e.g. price, RSI, MACD, ... or whatever you can think of that would have an influence on whether prices might rise or fall). Then you need to decide how to preprocess this data. And then you need to select data samples to train the network with.
Have a look at http://citeseer.comp.nus.edu.sg/rd/0%2C599806%2C1%2C0.25%2CDownload/http%3AqSqqSqwww.geocities.comqSqfrancorbusettiqSq KaastraArticle.pdf
This article explains the different factors that influence a NN. And keep in mind that NNs cannot predict the future either, they only do some sort of pattern recognition.
GreenTrade
11-04-2008, 06:54 PM
Thanks for the article, it has a lot of good information. I have ready a number of other books and articles on the same subject. I have also used another program in the past but was not able to customize it and I like using NT so when I found this post I was very interested. A couple of maybe obvious questions for you: how do you get the data from NT to stream into FANN and how do you get the output value back into NT to use in your strategy? Thank you very much for you information!
GT
terenyi
11-04-2008, 07:31 PM
I don't know how FANN works but I can tell you how my MATLAB interface works: A NinjaTrader indicator accesses an external DLL which in turn accesses MATLAB (via its COM interface). So the whole data transfer thing is transparent and automated.
As I said, I can't tell when I'll have time to finally finish it but I'll post it here once I do.
darthtrader
11-07-2008, 06:30 PM
I don't know how FANN works but I can tell you how my MATLAB interface works: A NinjaTrader indicator accesses an external DLL which in turn accesses MATLAB (via its COM interface). So the whole data transfer thing is transparent and automated.
As I said, I can't tell when I'll have time to finally finish it but I'll post it here once I do.
Ahh that is fantastic terenyi, what holds me back from getting more into matlab is not being able to play around with real data in real time without DDE..A small request if when your done you could post the simplest example of a ninja indicator that simply throws bar data into a matlab vector without requireing any additional toolboxes?
I also think the Ninja guys should think about this in an official context...
Ninja as a data pipe to matlab would be a KO punch to the competition. There is certainly opportunity there as the data feed toolbox from mathworks is simply not aimed at the retail level and there doesn't seem to be a solution for using the datafeeds that most who would be interested in this kind of thing actually use(ie. the ones Ninja already supports :).
terenyi
11-07-2008, 07:28 PM
My library encapsulates all communication with MATLAB so you're never directly accessing it.
But if you want to do so you could use:
Matlab.PutWorkspaceData(name, "base", variable);
Matlab.GetWorkspaceData(name, "base", out value);
Where "name" is a string (the name of the variable) and "variable" contains the data of the variable. Its type can be double, double[], double[,] or string depending on what you want to store (numeric variable, vector, matrix or text variable).
Of course first you need to get a reference to the MATLAB app:
MLApp.MLAppClass Matlab = new MLApp.MLAppClass();
For this to work you'll need to reference Interop.MLApp.dll.
Oh and commands can be executed with:
Matlab.Execute(command);
"command" is a string which contains your MATLAB command.
An example:
MLApp.MLAppClass Matlab = new MLApp.MLAppClass();
double x = 2;
double y = 3;
double z;
Matlab.PutWorkspaceData("x", "base", x);
Matlab.PutWorkspaceData("y", "base", y);
Matlab.Execute("z = x+y;");
object temp;
Matlab.GetWorkspaceData("z", "base", out temp);
z = (double) temp;
// z should now contain 5
My version of MATLAB (7.0.0.19920) comes with the bug that the interop libraries are not registered properly during the installation so you'll need to merge the following with your registry:
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Interface\{669 CEC93-6E22-11CF-A4D6-00A024583C19}]
@="DIMLApp"
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Interface\{669 CEC93-6E22-11CF-A4D6-00A024583C19}\NumMethods]
@="21"
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Interface\{669 CEC93-6E22-11CF-A4D6-00A024583C19}\ProxyStubClsid32]
@="{00020420-0000-0000-C000-000000000046}"
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Interface\{669 CEC93-6E22-11CF-A4D6-00A024583C19}\TypeLib]
@="{C36E46AB-6A81-457B-9F91-A7719A06287F}"
"Version"="1.0"
And if you want everything to work from within NinjaTrader then you first need to add Interop.MLApp.dll to the GAC (using gacutil for example) and then you also need to add a reference to this DLL in the NinjaScript editor.
auspiv
11-10-2008, 11:07 PM
My library encapsulates all communication with MATLAB so you're never directly accessing it.
But if you want to do so you could use:
Matlab.PutWorkspaceData(name, "base", variable);
Matlab.GetWorkspaceData(name, "base", out value);
have you shared your library anywhere yet?
iwannatoscript
05-03-2009, 10:31 PM
I'm currently working on an interface that links NT to Matlab (with the Neural Network Toolkit) and which provides a C# API for using feed-forward networks and self organizing maps. I should have my first version ready in a day or two and I could post this here if other people are interested in this too.
PS: Whoever made the design decision to use C# instead of a proprietary language in NT: Very good idea! ;)
Great
Is it possible to connet and add the capacity of
http://www.tradingsolutions.com/ '
tortexal
07-09-2009, 12:16 PM
i stumbled on this thread and think its fantastic. is this project still active?
terenyi
07-09-2009, 06:18 PM
i stumbled on this thread and think its fantastic. is this project still active?
yeah, it's definitely active. actually, the whole thing (the matlab interface as well as other things) turned into a bigger project (about 2 years of work going into it). so now i'm working on turning all of this into a commercial product to compensate at least a bit for all the work i put into this. i think i'll be able to offer quite some exciting new things for ninjatrader (matlab interface, neural networks, many advanced indicators, a complete strategy framework with features like simulated orders, elaborate statistical analysis using excel etc.). my plan is to go online at the beginning of fall.
tortexal
07-09-2009, 06:25 PM
sweet i'll buy it :cool:
astra
07-16-2009, 04:18 PM
yeah, it's definitely active. actually, the whole thing (the matlab interface as well as other things) turned into a bigger project (about 2 years of work going into it). so now i'm working on turning all of this into a commercial product to compensate at least a bit for all the work i put into this. i think i'll be able to offer quite some exciting new things for ninjatrader (matlab interface, neural networks, many advanced indicators, a complete strategy framework with features like simulated orders, elaborate statistical analysis using excel etc.). my plan is to go online at the beginning of fall.
terenyi,
Is this work primarily geared towards an NT - matlab/excel/NN/etc connectivity / utility package or is it a bunch of indicators/strategies that can make use of the above? The areas you mentioned above are so vast and complex so I am looking forward to see what you have garthered together. Good luck with your efforts!
astra
terenyi
07-17-2009, 02:17 AM
Well, my work covers different areas:
* Indicator framework: This framework adds some general features. For example, it allows to use commands (like in a console) to describe and chain indicators (of course indicators can still be added to a chart the traditional way). The purpose of this is to allow indicators to be calculated on other indicators (which can be theoretically chained indefinitely) and to be able to quickly try out things without it being necessary to write a spearate indicator (also for people who don't want to do any programming). For example, the command
StdDev(20)[WMA(14)[High]] ~2 -10pips, MUL(MAX(StdDev(20)[SMA(14)[High]], 200), 0.8){Red}
would display two indicators: First the 20 bar standard deviation of a 14 bar weighted moving average which has been calculated using the highs. Furthermore this indicator is horizontally displaced by 2 bars and vertically by -10 pips. The second indicator calculates the maximum of the first one within 200 bars and multiplies it by 0.8. The command also says to plot the second indicator in red (the settings of the plot can of course still be adjusted manually).
This is just a rather meaningless example but I think you get the point. You can chain any indicators (and also perform basic mathematical operations on them) without needing to explicitly program a separate one.
This command syntax works with any indicator (including the predefined NT ones and the ones you might have developed yourself). Using the workaround of a "strategy" it is also possible to plot indicators on one chart which have been calculated using different timeframes and/or instruments (e.g. plot the value of the SMA(20) from the daily chart on the hourly chart). This can also be used to directly compare instruments (e.g. how EUR/USD and EUR/GBP evolved in comparison to each other since day x).
* Indicators: Built on top of this framework I also developed some proprietary indicators. They don't do any exotic calculations I made up myself but mostly build on known concepts and extend them (i.e. add more features and calculate more data). This includes improving indicators which are already availiable in some other form as well as providing indicators for things for which no NT indicators exist yet. One focus lies for example on swing point and trend detection and analysis. All indicators are made both for being displayed on a chart and for being used in other indicators and strategies. Furthermore they all provide data which is especially geared towards being used in automated strategies (like the mentioned trend detection). Some indicators also use Excel to display their results, e.g. the average volatility depending on the time of the day.
* Strategy framework: I also built a framework for strategies which sits on top of the NT framework and can be used for custom strategies. This framework offers functions such as automatic handling (i.e. no need to explicitly code that) of OCO and bracket (i.e. stop loss and take profit) orders. Simulated orders are also possible. The framework also automatically gathers lots of data about each trade and stores it in a separate external database (if the data gathered by the framework is not enough for you then you can also add your own custom data). This data can then be analyzed in myriad of ways to optimize the strategies. Excel is used to show the analyses and the associated graphs. Not only the results of a single strategy can be analyzed but also of portfolios of strategies at once.
* MATLAB Interface: This interface allows NT and MATLAB to interact (exchange data, execute commands). This is for people who want to do their own stuff in MATLAB and who wish to connect that to NT.
* Excel Interface: This interface is similar to the one above and allows data to be sent to and read from Excel. This can be, for example, used to use Excel's charting features to display data or to perform calculations in Excel and read the result back into NT.
* Neural Network Kit: This kit allows to define, train, analyze and use neural networks. Two kinds of networks are supported: feed-forward networks (the classic NNs) and self-organizing maps. This kit uses MATLAB (and its neural network toolkit) to perform the necessary calculations (hence the user is required to have a MATLAB installation). However, it is completely integrated into NT (the neural networks are encapsulated in NT indicators) and it is transparent to the user how the calculations are actually done. So no MATLAB knowledge is required (however you need to understand how neural networks work in general and what you want to do with them).
So far I haven't seen any of this offered by any other 3rd party vendor (that's why I have started to develop this for myself in the first place) so I'm quite excited about it (also to use it in my own strategies) and hope it sounds exciting to other people too.
There are, however, also a few things my work does not cover: All these things are supposed to be tools for (semi-)professionals to help them with both their discretionary and especially their automated trading. However, all of the tools are just building blocks to better enable people to make their own strategies. There will be no magic indicators, black box strategies, holy grails or other get rich quick schemes (opposed to what most other 3rd party vendors seem to be trying to sell). I might include some strategies as examples of how to get most out of the strategy framework and the indicators but I don't plan on selling any strategies per se. Developing those will be up to you. I will also only provide the tools to create and use neural networks but no predefined networks.
Since, as you have mentioned, these things are all rather complex, it will still take a little while for me to finish everything. And then I also have to set up a website, write a proper documentation for everything (so people can get the most out of it) etc.
Operandi
07-17-2009, 03:01 AM
You are promising some superb functionality .
If you can actually build and reliably deliver all this, then NinjaTrader should buy the technology from you and use it as the basis for an "NinjaTrader Pro" product.
Chris
astra
07-17-2009, 04:31 PM
terenyi,
Thanks for the outline. It sounds very interesting. The building block method choosen to develop your work and access these areas is an excellent idea. Good luck.
whself beginner
09-07-2009, 03:19 PM
here is a link to call matlab in c#
http://www.codeproject.com/KB/dotnet/matlabeng.aspx?fid=26267&df=90&mpp=25&noise=3&sort=Position&view=Quick&fr=26
http://www.mathworks.com/matlabcentral/fileexchange/8274
darthtrader
09-10-2009, 09:51 AM
* MATLAB Interface: This interface allows NT and MATLAB to interact (exchange data, execute commands). This is for people who want to do their own stuff in MATLAB and who wish to connect that to NT.
* Excel Interface: This interface is similar to the one above and allows data to be sent to and read from Excel. This can be, for example, used to use Excel's charting features to display data or to perform calculations in Excel and read the result back into NT.
* Neural Network Kit: ....
Honestly terenyi, you should consider focusing on the top two more than the 3rd...Turning ninja into basically a COM bridge between ninja supported data vendors and matlab/excel would be sick...Not to mention you could also use matlab to basically bypass ninjas database and use any database you want, seamlessly..
The NN kit I'm sure would find some interest..right up until people figure out how much it costs for matlab plus the needed toolkits...then the sticker shock would send them running ASAP.
Gaffney
09-20-2009, 04:45 PM
I don't know what brokers you all use, but you can set up code in Matlab to work directly with IB's API, and for data feeds you can either subscribe for IB's or you can just scrape Yahoo Finance. You can also set it up to export that data into Excel (not recommended) or whatever other database you want. Excel usually explodes after a few hours of continuous data.
r2kTrader
11-10-2009, 10:25 AM
I second that motion.
You are promising some superb functionality .
If you can actually build and reliably deliver all this, then NinjaTrader should buy the technology from you and use it as the basis for an "NinjaTrader Pro" product.
Chris
r2kTrader
11-10-2009, 10:28 AM
Darth,
The total cost would be a good morning of trading for anyone who even gets what this thread is about. (in my opinion).
"You wan't win Darth" (no reason, I just had to quote that line from Obi Wan.)
The NN is attractive to me.
Honestly terenyi, you should consider focusing on the top two more than the 3rd...Turning ninja into basically a COM bridge between ninja supported data vendors and matlab/excel would be sick...Not to mention you could also use matlab to basically bypass ninjas database and use any database you want, seamlessly..
The NN kit I'm sure would find some interest..right up until people figure out how much it costs for matlab plus the needed toolkits...then the sticker shock would send them running ASAP.
terenyi
01-02-2010, 12:34 AM
Haven't been in this forum for a while but I wanted to report that I'm finally working on this project again! :)
dgoverde
01-16-2010, 02:05 PM
Keep us posted, terenyi. A dll that links to Matlab is something that I'd definitely be interested in buying.