SmartQuant Discussion

Automated Quantitative Strategy Development, SmartQuant Product Discussion and Technical Support Forums
It is currently Fri Feb 28, 2020 11:56 pm

All times are UTC + 3 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Thu Aug 04, 2011 4:45 am 
Offline

Joined: Tue Mar 15, 2011 7:15 pm
Posts: 80
Hello,

I have written a user indicator based on the Smoothed RSI Inverse Fisher Transform in a C# project and would like to pull it into an SQ strategy. When I reference the project in SQ, I am still unable to reference the indicator within my strategy. Figuring I did something incorrect, I copied the SQ built-in sample for the RSI user indicator and was successfully able to reference this within my strategy. My indicator code compiles correctly and I am not clear what I am doing wrong. I am posting my user indicator code below. Could one of the SQ tech guys please review and provide guidance as to what is causing my problem? Thanks.

Isaac

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenQuant.API.Plugins;
using OpenQuant.API;
using OpenQuant.API.Indicators;

namespace CustomIndicators
{
class SmoothedRsiInverseFisher : UserIndicator
{

#region properties
private int wmaLen;


public int WmaLen
{
get { return wmaLen; }
set { wmaLen = value; }
}

private int emaLen;


public int EmaLen
{
get { return emaLen; }
set { emaLen = value; }
}

private int rsiLen;


public int RisLen
{
get { return rsiLen; }
set { rsiLen = value; }
}

#endregion

#region constructors
public SmoothedRsiInverseFisher(ISeries series, int wmaLen, int risLen, int emaLen)
: base(series)
{
Name = "SmoothedRsiInverseFisher";

this.wmaLen = wmaLen;
this.emaLen = emaLen;
this.rsiLen = risLen;
}

#endregion

#region methods
public override double Calculate(int index)
{
double rainbowValue;
double smoothRsi;
smoothRsi = Double.NaN;
TimeSeries rainbowSeries = new TimeSeries();
TimeSeries rsiMod = new TimeSeries();

//calculate Weighted Averages
if (index >= wmaLen)
{
WMA wma0 = new WMA((BarSeries)Input, wmaLen);
WMA wma1 = new WMA(wma0, wmaLen);
WMA wma2 = new WMA(wma1, wmaLen);
WMA wma3 = new WMA(wma2, wmaLen);
WMA wma4 = new WMA(wma3, wmaLen);
WMA wma5 = new WMA(wma4, wmaLen);
WMA wma6 = new WMA(wma5, wmaLen);
WMA wma7 = new WMA(wma6, wmaLen);
WMA wma8 = new WMA(wma7, wmaLen);
WMA wma9 = new WMA(wma8, wmaLen);

//construct Rainbow weighted price curve
for (int i = 0; i < wmaLen; i++)
{

rainbowValue = (5 * wma0[i] + 4 * wma1[i] + 3 * wma2[i] + 2 * wma3[i] + wma4[i]
+ wma5[i] + wma6[i] + wma7[i] + wma8[i] + wma9[i]) / 20.0;

rainbowSeries.Add(wma0.GetDateTime(i), rainbowValue);
}

//RSI calc on Rainbow weighted curve
RSI rsi = new RSI(rainbowSeries, rsiLen);

//cacluate modified RSI curve and add to time series
for(int i = 0;i<wmaLen;i++){
rsiMod.Add(rsi.GetDateTime(i), .1 * rsi[i] - 50);
}

//compute Exponential moving averages
EMA ema1 = new EMA(rsiMod, emaLen);
EMA ema2 = new EMA(ema1, emaLen);

//Compute Vervoort Zero Lag
double difference = ema1[0] - ema2[0];
double zeroLagEMA = ema1[0] - difference;

//Compute Fisher Transformation
smoothRsi = ((Math.Exp(2*zeroLagEMA)-1)/(Math.Exp(2*zeroLagEMA)+1)+1)*50;


}//end if

//if not enought points in curve NA returned
return smoothRsi;

}
#endregion
}
}


Top
 Profile  
 
PostPosted: Thu Aug 04, 2011 9:08 am 
Offline

Joined: Tue Aug 05, 2003 3:43 pm
Posts: 6816
Quote:
When I reference the project in SQ


What do you do exactly?


Top
 Profile  
 
PostPosted: Thu Aug 04, 2011 3:53 pm 
Offline

Joined: Tue Mar 15, 2011 7:15 pm
Posts: 80
In SQ, I add a reference to the DLL via Tools/Options/ProjectionsAndSolutions/Build just as with any other library reference I have added to SQ.

I then reference the library with: "using myLibraryName;" at the top of my strategy project.

In my code, I then try to instantiate my indicator by:
"myLibraryName.SmoothedRsiInverseFisher sRsi = new myLibraryName.SmoothedRsiInverseFisher();"

I do not believe the way I reference the indicator is the problem as I was easily able to do this using the sample RSI user indicator that is included in the SQ samples. The problem is evidently with my user indicator class code. Could someone please review it and see if I am making some obvious error? Thanks.


Top
 Profile  
 
PostPosted: Fri Sep 02, 2011 11:46 pm 
Offline

Joined: Wed Aug 24, 2011 7:11 pm
Posts: 42
If you run Visual Studio while OpenQuant is open, and attach the debugger to OpenQuant process, then run a strategy that uses the indicator, you can debug.

I tried your code and got an error on this line:

Quote:
rainbowValue = (5 * wma0[i] + 4 * wma1[i] + 3 * wma2[i] + 2 * wma3[i] + wma4[i] + wma5[i] + wma6[i] + wma7[i] + wma8[i] + wma9[i]) / 20.0;


The error was

Quote:
System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
at System.Collections.Generic.SortedList`2.GetByIndex(Int32 index)
at SmartQuant.Data.MemorySeries`1.get_Item(Int32 index)
at SmartQuant.Series.TimeSeries.get_Item(Int32 index)
at SmartQuant.Series.DoubleSeries.get_Item(Int32 Index)
at SmartQuant.Indicators.Indicator.get_Item(Int32 Index)
at Abt.OpenQuant.Trading.Indicators.SmoothedRsiInverseFisher.Calculate(Int32 index) in D:\Andrew\Work - Programming\Ephemeris\Shared\Abt.OpenQuant\Abt.OpenQuant.Trading\Indicators\SmoothedRsiInverseFisher.cs:line 81
at OpenQuant.API.Plugins.UserIndicator.OnInputItemAdded(Object sender, DateTimeEventArgs args)


It seems the value [0] is indexed on the WMAs when they are only just set up with 1 value?


Top
 Profile  
 
PostPosted: Sat Sep 03, 2011 12:00 am 
Offline

Joined: Wed Aug 24, 2011 7:11 pm
Posts: 42
Ok, the problem is here:

Quote:
if (index >= wmaLen)
{
WMA wma0 = new WMA((BarSeries)Input, wmaLen);
WMA wma1 = new WMA(wma0, wmaLen);
WMA wma2 = new WMA(wma1, wmaLen);
WMA wma3 = new WMA(wma2, wmaLen);
WMA wma4 = new WMA(wma3, wmaLen);
WMA wma5 = new WMA(wma4, wmaLen);
WMA wma6 = new WMA(wma5, wmaLen);
WMA wma7 = new WMA(wma6, wmaLen);
WMA wma8 = new WMA(wma7, wmaLen);
WMA wma9 = new WMA(wma8, wmaLen);


The first time this code executes, if I set wmaLen=3 say then index is == 3.

wma0 is defined but wma1 is undefined. Basically each daisychain of the wma's requires more bars to define the WMAs

I played around with setting index > X where X is a number but got to several hundred and the exception was still occurring. Are you sure this is the correct implementation of SmoothedFisherInverseRSI?


Top
 Profile  
 
PostPosted: Thu Sep 08, 2011 6:07 pm 
Offline

Joined: Tue Mar 15, 2011 7:15 pm
Posts: 80
Presumably. I lifted the code from NinjaTrader. I will need to see if there is an alternate resource I can look at for the indicator.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC + 3 hours


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group