SmartQuant Discussion

Automated Quantitative Strategy Development, SmartQuant Product Discussion and Technical Support Forums
It is currently Sat Sep 19, 2020 6:09 pm

All times are UTC + 3 hours




Post new topic Reply to topic  [ 11 posts ] 
Author Message
PostPosted: Tue Jul 16, 2013 5:11 pm 
Offline

Joined: Sat Jul 13, 2013 3:57 am
Posts: 52
I've encountered the following exception twice. It has occurred twice within about an hour of starting my strategy. On another instance, I was able to run my strategy overnight without error. Any advice would be greatly appreciated.

Notes:

1) I'm using the OnTrade event to create the open bar in real-time. I then use Bars.Last.Remove() and Bars.Add to update the current bar.

2) Line 75 of my custom indicator is the following:

myTimeSeries.Add(Input.GetDateTime(index), 0);


Exception:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> 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.RemoveAt(Int32 index)
at System.Collections.Generic.SortedList`2.Remove(TKey key)
at SmartQuant.Data.MemorySeries`1.Remove(DateTime datetime)
at SmartQuant.Indicators.Indicator.Add(DateTime DateTime, Double Data)
at SmartQuant.Indicators.EMA.Calculate(Int32 index)
at SmartQuant.Indicators.EMA.OnInputItemAdded(Object sender, DateTimeEventArgs EventArgs)
at SmartQuant.Indicators.Indicator.OnInputItemAdded2(Object sender, DateTimeEventArgs EventArgs)
at SmartQuant.Series.ItemAddedEventHandler.Invoke(Object sender, DateTimeEventArgs e)
at SmartQuant.Series.TimeSeries.EmitItemAdded(DateTime dateTime)
at SmartQuant.Series.DoubleSeries.Add(DateTime DateTime, Double Data)
at Jordan_Indicator.Calculate(Int32 index) in c:\Users\Administrator\Documents\OpenQuant\Projects\Jordan_Indicator\code.cs:line 75
at OpenQuant.API.Plugins.UserIndicator.OnInputItemAdded(Object sender, DateTimeEventArgs args)
at SmartQuant.Series.ItemAddedEventHandler.Invoke(Object sender, DateTimeEventArgs e)
at SmartQuant.Series.TimeSeries.EmitItemAdded(DateTime dateTime)
at SmartQuant.Series.BarSeries.Add(Bar bar)
at SmartQuant.Instruments.BarSeriesList.nu3ogAtIQh(Instrument , Bar )
at SmartQuant.Instruments.DataManager.itPuRrloC(Object , BarEventArgs )
at SmartQuant.Providers.ProviderManager.FITf8H8Ipj(Object , BarEventArgs )
at SmartQuant.Providers.BarEventHandler.Invoke(Object sender, BarEventArgs args)
at SmartQuant.FIXApplication.QuickFIX42Provider.TYKqnK4uH(Object , BarEventArgs )
at SmartQuant.Providers.BarFactory.BOW1aPpNtM(Bar , IFIXInstrument )
at SmartQuant.Providers.BarFactory.Rn813ovF1f(ReminderEventArgs )
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeType typeOwner)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at SmartQuant.Clock.LxgwO7C7Ux(DateTime )


Top
 Profile  
 
PostPosted: Tue Jul 16, 2013 9:23 pm 
Offline

Joined: Sat Jul 13, 2013 3:57 am
Posts: 52
And just to clarify:

The line of code that I provided is within the Calculate() procedure in my custom indicator:

public override double Calculate(int index)
...
myTimeSeries.Add(Input.GetDateTime(index), 0);
...

Possibly the error is being thrown because an internal onBar() procedure is called in order to update the indicator values at the close of each bar. While the code in my indicator is being executed, the OnTrade() procedure is called and it is removing then re-adding the last bar so it's always current. This could cause the Index to go out of range if we were in the middle of executing the Calculate() procedure.

If so, any suggested workarounds?


Top
 Profile  
 
PostPosted: Wed Jul 17, 2013 6:05 am 
Offline

Joined: Sat Jul 13, 2013 3:57 am
Posts: 52
Also, I'm not sure if this could have caused the issue or not with improper times loaded on historical bars. But, I just found/corrected this issue:

viewtopic.php?f=60&t=10553


Top
 Profile  
 
PostPosted: Wed Jul 17, 2013 6:03 pm 
Offline

Joined: Sat Jul 13, 2013 3:57 am
Posts: 52
I just encountered the error again after about 30 minutes running a 5 minute chart in Paper Trade mode. After I acknowledge the exception, it looks like the code continues to run. My code on line 77 is as follows:

myTimeSeries2.Add(Input.GetDateTime(index), myValue2);

A few lines above this code is:

myTimeSeries1.Add(Input.GetDateTime(index), myValue1);

So, the existence of the index array element seems to be changed during the execution of the Calculate() procedure, possibly due to the code being executed in my OnTrade() procedure.

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> 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.RemoveAt(Int32 index)
at System.Collections.Generic.SortedList`2.Remove(TKey key)
at SmartQuant.Data.MemorySeries`1.Remove(DateTime datetime)
at SmartQuant.Indicators.Indicator.Add(DateTime DateTime, Double Data)
at SmartQuant.Indicators.EMA.Calculate(Int32 index)
at SmartQuant.Indicators.EMA.OnInputItemAdded(Object sender, DateTimeEventArgs EventArgs)
at SmartQuant.Indicators.Indicator.OnInputItemAdded2(Object sender, DateTimeEventArgs EventArgs)
at SmartQuant.Series.ItemAddedEventHandler.Invoke(Object sender, DateTimeEventArgs e)
at SmartQuant.Series.TimeSeries.EmitItemAdded(DateTime dateTime)
at SmartQuant.Series.DoubleSeries.Add(DateTime DateTime, Double Data)
at Jordan_Indicator.Calculate(Int32 index) in c:\Users\Administrator\Documents\OpenQuant\Projects\Jordan_Indicator\code.cs:line 77
at OpenQuant.API.Plugins.UserIndicator.OnInputItemAdded(Object sender, DateTimeEventArgs args)
at SmartQuant.Series.ItemAddedEventHandler.Invoke(Object sender, DateTimeEventArgs e)
at SmartQuant.Series.TimeSeries.EmitItemAdded(DateTime dateTime)
at SmartQuant.Series.BarSeries.Add(Bar bar)
at SmartQuant.Instruments.BarSeriesList.nu3ogAtIQh(Instrument , Bar )
at SmartQuant.Instruments.DataManager.itPuRrloC(Object , BarEventArgs )
at SmartQuant.Providers.ProviderManager.FITf8H8Ipj(Object , BarEventArgs )
at SmartQuant.Providers.BarEventHandler.Invoke(Object sender, BarEventArgs args)
at SmartQuant.FIXApplication.QuickFIX42Provider.TYKqnK4uH(Object , BarEventArgs )
at SmartQuant.Providers.BarFactory.BOW1aPpNtM(Bar , IFIXInstrument )
at SmartQuant.Providers.BarFactory.Rn813ovF1f(ReminderEventArgs )
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeType typeOwner)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at SmartQuant.Clock.LxgwO7C7Ux(DateTime )


Top
 Profile  
 
PostPosted: Wed Jul 17, 2013 7:06 pm 
Offline

Joined: Sat Jul 13, 2013 3:57 am
Posts: 52
With the script still running after acknowledging the previous error, I just received the following error about an hour later. All of the following is in my OnTrade() procedure.

First off:
DateTime currentBarTime;
currentBarTime = RoundDateTimeDown(trade.DateTime, barPeriod);

I confirmed the above always rounds down to the proper bar start time.

Line 210 of my script:

Bars.Remove(currentBarTime);

Line 211 of my script:

Bars.Add(currentBarTime, b.Open, Math.Max(b.High, trade.Price), Math.Min(b.Low, trade.Price), trade.Price, curTradeVol, trade.Size);

I'm going to try to comment out the Bars.Remove function. I hope that Bars.Add() will trigger the indicator to still be updated in real time. If so, I think this will solve my issue since the index should always exist.


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.RemoveAt(Int32 index)
at System.Collections.Generic.SortedList`2.Remove(TKey key)
at SmartQuant.Data.MemorySeries`1.Remove(DateTime datetime)
at SmartQuant.Indicators.Indicator.Add(DateTime DateTime, Double Data)
at SmartQuant.Indicators.EMA.Calculate(Int32 index)
at SmartQuant.Indicators.EMA.OnInputItemAdded(Object sender, DateTimeEventArgs EventArgs)
at SmartQuant.Indicators.Indicator.OnInputItemAdded2(Object sender, DateTimeEventArgs EventArgs)
at SmartQuant.Series.ItemAddedEventHandler.Invoke(Object sender, DateTimeEventArgs e)
at SmartQuant.Series.TimeSeries.EmitItemAdded(DateTime dateTime)
at SmartQuant.Series.DoubleSeries.Add(DateTime DateTime, Double Data)
at Jordan_Indicator.Calculate(Int32 index) in c:\Users\Administrator\Documents\OpenQuant\Projects\Jordan_Indicator\code.cs:line 74
at OpenQuant.API.Plugins.UserIndicator.OnInputItemAdded(Object sender, DateTimeEventArgs args)
at SmartQuant.Series.ItemAddedEventHandler.Invoke(Object sender, DateTimeEventArgs e)
at SmartQuant.Series.TimeSeries.EmitItemAdded(DateTime dateTime)
at SmartQuant.Series.BarSeries.Add(Bar bar)
at Jordan_Indicator.OnTrade(Trade trade) in c:\Users\Administrator\Documents\OpenQuant\Projects\Jordan_Indicator\code.cs:line 211
at OpenQuant.Trading.StrategyRunner.SetNewTrade(Instrument instrument, Trade trade)


Top
 Profile  
 
PostPosted: Thu Jul 18, 2013 4:51 pm 
Offline

Joined: Sat Jul 13, 2013 3:57 am
Posts: 52
Things seem to be running fine once I removed the Bars.Remove() function for the last bar. Also, Using Bars.Add() and updating the current bar still seems to be updating the graph in real-time. So, that was the solution to this issue.


Top
 Profile  
 
PostPosted: Wed Apr 30, 2014 12:25 pm 
Offline

Joined: Wed Sep 18, 2013 10:50 am
Posts: 67
Location: London
Hi

Can you please tell me how you managed to paper trade using TT FIX?

Looking forward to some help.

Regards
Madhur


Top
 Profile  
 
PostPosted: Wed Apr 30, 2014 12:27 pm 
Offline

Joined: Tue Aug 05, 2003 3:43 pm
Posts: 6817
Hi,

what is your actual question? How to setup TT FIX for paper trading or you have issues similar to those discussed in this thread?

Regards,
Anton


Top
 Profile  
 
PostPosted: Wed Apr 30, 2014 12:54 pm 
Offline

Joined: Wed Sep 18, 2013 10:50 am
Posts: 67
Location: London
Hi Anton

Yes, I want to know how to set up TTFIX for paper trading.

Regards
Madhur


Top
 Profile  
 
PostPosted: Wed Apr 30, 2014 1:16 pm 
Offline

Joined: Tue Aug 05, 2003 3:43 pm
Posts: 6817
Well, if you are in OpenQuant's paper trading mode, you use a realtime market data provider and OpenQuant's built in execution simulator. This means you basically should not do anything special if you have an account with TT and receive market data via TT FIX.

Perhaps I don't completely understand your question and you are asking how to setup "paper trading with TT", so that order execution is simulated on TT servers?

Regards,
Anton


Top
 Profile  
 
PostPosted: Wed Apr 30, 2014 1:24 pm 
Offline

Joined: Wed Sep 18, 2013 10:50 am
Posts: 67
Location: London
Hi Anton

Thanks for the reply. That clears my doubt.

Regards
Madhur


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

All times are UTC + 3 hours


Who is online

Users browsing this forum: No registered users and 4 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