NexusFi: Find Your Edge


Home Menu

 





Got Accord.net coding experience?


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one NJAMC with 9 posts (0 thanks)
    2. looks_two ericson with 8 posts (4 thanks)
    3. looks_3 gsapir with 3 posts (1 thanks)
    4. looks_4 ratfink with 2 posts (2 thanks)
    1. trending_up 7,903 views
    2. thumb_up 7 thanks given
    3. group 7 followers
    1. forum 22 posts
    2. attach_file 3 attachments




 
Search this Thread

Got Accord.net coding experience?

  #1 (permalink)
 ericson 
Sacramento, CA
 
Experience: Advanced
Platform: NinjaTrader
Broker: NA
Trading: Stocks, Forex
Posts: 64 since Nov 2013
Thanks Given: 14
Thanks Received: 19

Hey so I got Accord.net up and running on NT8, but the documentation on its code is very limited. I want to work with it more, who has experience coding with it, examples, doesn't necessarily have to be with NT. Simply how to use its functions and what they can do.

Framework modules

Accord.NET Machine Learning Framework

https://github.com/accord-net/framework

Started this thread Reply With Quote
Thanked by:

Can you help answer these questions
from other members on NexusFi?
Futures True Range Report
The Elite Circle
New Micros: Ultra 10-Year & Ultra T-Bond -- Live Now
Treasury Notes and Bonds
My NT8 Volume Profile Split by Asian/Euro/Open
NinjaTrader
Are there any eval firms that allow you to sink to your …
Traders Hideout
Exit Strategy
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Get funded firms 2023/2024 - Any recommendations or word …
61 thanks
Funded Trader platforms
39 thanks
NexusFi site changelog and issues/problem reporting
26 thanks
Battlestations: Show us your trading desks!
26 thanks
The Program
18 thanks
  #3 (permalink)
 ericson 
Sacramento, CA
 
Experience: Advanced
Platform: NinjaTrader
Broker: NA
Trading: Stocks, Forex
Posts: 64 since Nov 2013
Thanks Given: 14
Thanks Received: 19


Ok Ill get this going so more people can start working and developing with Accord Net. I created two indicators to show how its done., linear and polynomial regression. Please use this to learn how to code for Accord Net for indicators. There is so much more potential with this add on, neural networks, machine learning, regression, complicated mathematics.

If you have trouble adding the dlls to NT, please let me know. Also, these indicators are for NT8 only! Pass on the good will.

Attached Files
Elite Membership required to download: AccordNet.zip
Started this thread Reply With Quote
Thanked by:
  #4 (permalink)
 ericson 
Sacramento, CA
 
Experience: Advanced
Platform: NinjaTrader
Broker: NA
Trading: Stocks, Forex
Posts: 64 since Nov 2013
Thanks Given: 14
Thanks Received: 19

I am currently working on a multi linear regression indicator, but no dice. Anyone can figure it out? I am trying to use past price data, 1, 2 bars ago, as inputs, and 0 bars ago as outputs. NT8 with Accord Net only.

Attached Files
Elite Membership required to download: MultiLinReg.zip
Started this thread Reply With Quote
Thanked by:
  #5 (permalink)
 
NJAMC's Avatar
 NJAMC 
Atkinson, NH USA
Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader 8/TensorFlow
Broker: NinjaTrader Brokerage
Trading: Futures, CL, ES, ZB
Posts: 1,970 since Dec 2010
Thanks Given: 3,037
Thanks Received: 2,394


ericson View Post
Ok Ill get this going so more people can start working and developing with Accord Net. I created two indicators to show how its done., linear and polynomial regression. Please use this to learn how to code for Accord Net for indicators. There is so much more potential with this add on, neural networks, machine learning, regression, complicated mathematics.

If you have trouble adding the dlls to NT, please let me know. Also, these indicators are for NT8 only! Pass on the good will.

Hi @ericson,

Looks like some great work, I have some older Accord DLLs and need to update before I can try these. I haver 3.0.2 but looks like you are using a few newer classes such as "PolynomialLeastSquares()" which from the manual requires:
Assembly: Accord.Statistics (in Accord.Statistics.dll) Version: 3.4.0

I will update a bit later and try this out. You are right, Accord brings a lot of power to .NET and NinjaTrader.

Nil per os
-NJAMC [Generic Programmer]

LOM WIKI: NT-Local-Order-Manager-LOM-Guide
Artificial Bee Colony Optimization
Visit my NexusFi Trade Journal Reply With Quote
  #6 (permalink)
 ericson 
Sacramento, CA
 
Experience: Advanced
Platform: NinjaTrader
Broker: NA
Trading: Stocks, Forex
Posts: 64 since Nov 2013
Thanks Given: 14
Thanks Received: 19

The biggest issue is figuring out how to use its functions. It was trial and error to figure the first two out. The poly is not as smooth as i hoped for. Also, copy the dlls to your NT bin program file location. Reference from there.

Started this thread Reply With Quote
  #7 (permalink)
 
NJAMC's Avatar
 NJAMC 
Atkinson, NH USA
Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader 8/TensorFlow
Broker: NinjaTrader Brokerage
Trading: Futures, CL, ES, ZB
Posts: 1,970 since Dec 2010
Thanks Given: 3,037
Thanks Received: 2,394


ericson View Post
The biggest issue is figuring out how to use its functions. It was trial and error to figure the first two out. The poly is not as smooth as i hoped for. Also, copy the dlls to your NT bin program file location. Reference from there.

Ya, had to find the ZIP version for 3.4 on Github, got everything setup but broke my older code with 3.0.2, some major changes in this release. I had some matrix math functions that I had to disable, will get back to that later.

Nil per os
-NJAMC [Generic Programmer]

LOM WIKI: NT-Local-Order-Manager-LOM-Guide
Artificial Bee Colony Optimization
Visit my NexusFi Trade Journal Reply With Quote
  #8 (permalink)
 
NJAMC's Avatar
 NJAMC 
Atkinson, NH USA
Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader 8/TensorFlow
Broker: NinjaTrader Brokerage
Trading: Futures, CL, ES, ZB
Posts: 1,970 since Dec 2010
Thanks Given: 3,037
Thanks Received: 2,394

Hummm..... One of the reasons I stopped using Accord.NET were a few bugs I found and couldn't get corrected. I am starting to think after a quick review, there may be bugs in the " PolynomialLeastSquares()" class... The Intercept just makes no sense even when I set the input/output data to a straight line (0,0), (1,1), ... (Period-1,Period-1). Also, the sign seems inverted and might be off by one degree of freedom.

I have modified the PolyRegression OnBarUpdate() to include the following, using the Transform() value of the point we wish to predict (-1.0) as you have time running backwards to point 0.0. I first started to work with predicting the next PolyRegressionLine[] point to smooth the line, to no avail. It just doesn't seem to be working right based upon the output of the 3rd degree fit:

 
Code
			ols = new PolynomialLeastSquares();
			ols.Degree = Degree;
			
			for(i = 0; i < Period; i++)
			{
				inputs[i] = Convert.ToDouble(i);//0,1,2,3....
				if (PolyRegressionLine.IsValidDataPoint(i) && false)
					outputs[i] = PolyRegressionLine[i+1];//most recent price [0], then back 1,2,3 bars ago
				else
					outputs[i] = inputs[i];//Input[i];//most recent price [0], then back 1,2,3 bars ago
			}

			// Use OLS to learn the regression
			reg = ols.Learn(inputs, outputs);

			PolyRegressionLine[0] = reg.Transform(-1.0);
			Print(ols.Degree+"  "+reg.ToString()+"  Int "+ reg.Intercept);
The sample output is:

 
Code
3  y(x) = 2.37812678233955E-17x^2 + 1x^1 + 2.77718345656259x^0  Int -2.77718345656258
You can see the Intercept doesn't match, the sign is inverted. Also, it is a 3rd Degree Polynomial so there should be an X^3 term and doesn't show. Not exactly sure what might be wrong, but seems like the "Learn()" didn't work right maybe because of the missing X^3 in the hypothesis?


For the Linear case "OrdinaryLeastSquares()" things seem to work with this codeblock:

 
Code
			ols = new OrdinaryLeastSquares();
			ols.IsRobust = true;
			
			for(i = 0; i < Period; i++)
			{
				inputs[i] = Convert.ToDouble(i);//1,2,3....
				outputs[i] = inputs[i];//Input[i] //most recent price [0], then back 1,2,3 bars ago
			}

			// Use OLS to learn the simple linear regression
			regression = ols.Learn(inputs, outputs);

			LinearRegressionLine[0] =  regression.Transform(-1.0);
			Print(regression.ToString()+"  Int "+ regression.Intercept);
 
Code
y(x) = 1x + 3.33066907387547E-15  Int 3.33066907387547E-15
You can see this is a 1st degree equation, linear, and the Intercept matches and has the X^1 term.

Nil per os
-NJAMC [Generic Programmer]

LOM WIKI: NT-Local-Order-Manager-LOM-Guide
Artificial Bee Colony Optimization
Visit my NexusFi Trade Journal Reply With Quote
  #9 (permalink)
 ericson 
Sacramento, CA
 
Experience: Advanced
Platform: NinjaTrader
Broker: NA
Trading: Stocks, Forex
Posts: 64 since Nov 2013
Thanks Given: 14
Thanks Received: 19

Here is my output from my original code. The weights are either extremely small or large, intercept very big. but the line is more or less similar to other poly regs.

Attached Files
Elite Membership required to download: NinjaScript Output 2_17_2017 9_39 AM.zip
Started this thread Reply With Quote
  #10 (permalink)
 
NJAMC's Avatar
 NJAMC 
Atkinson, NH USA
Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader 8/TensorFlow
Broker: NinjaTrader Brokerage
Trading: Futures, CL, ES, ZB
Posts: 1,970 since Dec 2010
Thanks Given: 3,037
Thanks Received: 2,394



ericson View Post
Here is my output from my original code. The weights are either extremely small or large, intercept very big. but the line is more or less similar to other poly regs.


@ericson,

I think your code covers some of the problem with the base class so I wouldn't trust it. The Intercept shouldn't be that big, it should be around the Final Time Point (as X=0 at that point).

A look at Github, not entirely sure but don't see how he is handling the Degree with X^0 included in the LeastSquares():
https://github.com/accord-net/framework/blob/development/Sources/Accord.Statistics/Models/Regression/Linear/Fitting/PolynomialLeastSquares.cs

I don't think it is your code, you should use the "Transform" to make sure you are doing the vector math correctly... Usually it is A1*X^1+A2*X^2... I think you may have reversed it to get a reasonable answer: A1*X^3+....

I also don't think the Intercept should appear (even with the wrong sign) in the weights, so I just think there is a calculation problem in Accord.

Nil per os
-NJAMC [Generic Programmer]

LOM WIKI: NT-Local-Order-Manager-LOM-Guide
Artificial Bee Colony Optimization
Visit my NexusFi Trade Journal Reply With Quote




Last Updated on August 10, 2017


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts