SmartQuant Discussion

Automated Quantitative Strategy Development, SmartQuant Product Discussion and Technical Support Forums
It is currently Tue Jul 14, 2020 8:26 pm

All times are UTC + 3 hours




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: Commission error
PostPosted: Sat May 28, 2016 5:56 am 
Offline

Joined: Thu Sep 17, 2015 5:52 am
Posts: 133
Hello,

I tried to add a commission to a backtest by adding these two lines of code to the Scenario.cs file

Code:
ExecutionSimulator.CommissionProvider.Type = CommissionType.PerShare;
ExecutionSimulator.CommissionProvider.Commission = 1.00;


Everything compiled successfully when I pressed the build button, however I got this message in the output window when I ran the backtest:

Quote:
Building MyStrategy
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object.
at OpenQuant.Backtest.Run()
at OpenQuant.Program.Main(String[] args)
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at OpenQuant.Projects.SolutionRunner.Run(Object obj)



Any idea what the issue could be?

Thanks

P.S.
The full Scenario.cs file is attached if you need to take a deeper look at it


Attachments:
Scenario.zip [513 Bytes]
Downloaded 201 times
Top
 Profile  
 
 Post subject: Re: Commission error
PostPosted: Tue May 31, 2016 12:12 pm 
Offline

Joined: Wed May 05, 2010 9:49 pm
Posts: 571
Hello M101,
I added line with commission to SMAcrossover and it works good.
Can you please reproduce situation with this scenario? Maybe your solution contains errors.
Attachment:
commission.png
commission.png [ 82.68 KiB | Viewed 4305 times ]


Top
 Profile  
 
 Post subject: Re: Commission error
PostPosted: Wed Jun 01, 2016 7:31 am 
Offline

Joined: Thu Sep 17, 2015 5:52 am
Posts: 133
Hi Skuvv,

I tried it again and the problem seems to have gone away.
Not sure what I changed exactly to fix it.
Will be in touch if it comes back

Thnks


Top
 Profile  
 
 Post subject: Re: Commission error
PostPosted: Wed Dec 14, 2016 12:19 pm 
Offline

Joined: Tue Oct 13, 2009 12:19 pm
Posts: 270
Dear all,

I have the same issue.

this is the error that I get. Even if I add the example code in the SMA example:
ExecutionSimulator.CommissionProvider.Type = CommissionType.PerShare;
ExecutionSimulator.CommissionProvider.Commission = 0.01;

Code:
Building MyStrategy
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object.
   at OpenQuant.Backtest.Run()
   at OpenQuant.Program.Main(String[] args)
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at OpenQuant.Projects.SolutionRunner.Run(Object obj)


Top
 Profile  
 
 Post subject: Re: Commission error
PostPosted: Wed Dec 14, 2016 2:48 pm 
Offline

Joined: Wed May 05, 2010 9:49 pm
Posts: 571
Hello Mike,
can you please try this code for scenario:
Code:
      public override void Run()
      {
         try
         {
            ExecutionSimulator.CommissionProvider.Type = CommissionType.PerShare;
            ExecutionSimulator.CommissionProvider.Commission = 1.00;
         }
         catch(Exception ex)
         {
            Console.WriteLine(ex);
         }
      }


Top
 Profile  
 
 Post subject: Re: Commission error
PostPosted: Wed Dec 14, 2016 2:56 pm 
Offline

Joined: Tue Oct 13, 2009 12:19 pm
Posts: 270
this is the result:

Building MyStrategy
System.NullReferenceException: Object reference not set to an instance of an object.
at OpenQuant.MyScenario.Run()


Top
 Profile  
 
 Post subject: Re: Commission error
PostPosted: Wed Dec 14, 2016 3:27 pm 
Offline

Joined: Wed May 05, 2010 9:49 pm
Posts: 571
Ok, then add this code:
Code:
         if (ExecutionSimulator == null)
            Console.WriteLine("ExecutionSimulator == null");
         
         if (ExecutionSimulator.CommissionProvider)   
         {
            Console.WriteLine("CommissionProvider == null");
            ExecutionSimulator.CommissionProvider = new CommissionProvider();   
         }
         
         ExecutionSimulator.CommissionProvider.Type = CommissionType.PerShare;
         ExecutionSimulator.CommissionProvider.Commission = 1.00;


Top
 Profile  
 
 Post subject: Re: Commission error
PostPosted: Wed Dec 14, 2016 4:15 pm 
Offline

Joined: Tue Oct 13, 2009 12:19 pm
Posts: 270
Code:
   if (ExecutionSimulator == null)
            Console.WriteLine("ExecutionSimulator == null");
         
         if (ExecutionSimulator.CommissionProvider == null)   
         {
            Console.WriteLine("CommissionProvider == null");
            ExecutionSimulator.CommissionProvider = new CommissionProvider();   
         }
         
         ExecutionSimulator.CommissionProvider.Type = CommissionType.PerShare;
         ExecutionSimulator.CommissionProvider.Commission = 1.00;

this code works.. added this: "if (ExecutionSimulator.CommissionProvider == null) "

and this is the code from Output:
Building MyStrategy
CommissionProvider == null


if I include it in my orig code, it works...
Now I only got the issue left from my topic: http://www.smartquant.com/forums/viewtopic.php?f=86&t=14664
which is unrelated it seems like.


Top
 Profile  
 
 Post subject: Re: Commission error
PostPosted: Wed Dec 14, 2016 4:19 pm 
Offline

Joined: Wed May 05, 2010 9:49 pm
Posts: 571
Thank for test!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 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