SmartQuant Discussion

Automated Quantitative Strategy Development, SmartQuant Product Discussion and Technical Support Forums
It is currently Mon Sep 23, 2019 2:46 pm

All times are UTC + 3 hours




Post new topic Reply to topic  [ 15 posts ] 
Author Message
PostPosted: Fri Nov 30, 2007 3:18 pm 
Offline

Joined: Tue Aug 05, 2003 3:43 pm
Posts: 6816
The code below shows how to capture market (bar) data while running a strategy in live or paper trading mode.

Code:
using OpenQuant.API;

public class MyStrategy : Strategy
{
   public override void OnBar(Bar bar)
   {
      DataManager.Add(Instrument, bar);
   }
}


Note that you can capture quote and trade data as well by changing or adding corresponding methods

Code:
using OpenQuant.API;

public class MyStrategy : Strategy
{
   public override void OnQuote(Quote quote)
   {
      DataManager.Add(Instrument, quote);
   }
}


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 02, 2008 5:45 pm 
Offline

Joined: Thu Mar 20, 2008 4:41 pm
Posts: 273
Location: Sweden
Could someone please un-confuse me? :)

I was under the impression that I needed data to make the OnBar/OnQuote/Whichever-functions trigger.
Which I thought would mean that the data already was saved in the database.
Which in turn would make it useless to save again.


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 04, 2008 1:30 pm 
Offline

Joined: Tue Aug 05, 2003 3:43 pm
Posts: 6816
It says live or paper trading mode, not simulation :?:

Regards,
Anton


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 04, 2008 5:12 pm 
Offline

Joined: Thu Mar 20, 2008 4:41 pm
Posts: 273
Location: Sweden
I didn't mention simulation, nor did I mean to.

Sorry, I still don't understand. :)

Unless I'm already importing live data from somewhere, I don't understand how a strategy running live would know when to trigger for example OnBar.


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 04, 2008 5:36 pm 
Offline

Joined: Tue Aug 05, 2003 3:43 pm
Posts: 6816
Letharion wrote:
I didn't mention simulation, nor did I mean to.

Sorry, I still don't understand. :)

Unless I'm already importing live data from somewhere, I don't understand how a strategy running live would know when to trigger for example OnBar.


A strategy receives trades from a data provider, makes bars from trades and triggers OnBar when a bar is ready...


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 06, 2008 9:01 pm 
Offline

Joined: Mon Sep 10, 2007 9:05 pm
Posts: 16
If I want to save tick bars directly from my strategy code, should I write the code under OnTrade or OnBar?


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 06, 2008 9:11 pm 
Offline

Joined: Tue Aug 05, 2003 3:43 pm
Posts: 6816
OnBar... if you are talking about tick bars, not ticks (trades and quotes).

Regards,
Anton


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 09, 2008 3:38 pm 
Offline

Joined: Thu Mar 20, 2008 4:41 pm
Posts: 273
Location: Sweden
Dr. Anton Fokin wrote:
Letharion wrote:
I didn't mention simulation, nor did I mean to.

Sorry, I still don't understand. :)

Unless I'm already importing live data from somewhere, I don't understand how a strategy running live would know when to trigger for example OnBar.


A strategy receives trades from a data provider, makes bars from trades and triggers OnBar when a bar is ready...


Yes, precisely, and thats why I don't understand why it makes sense for OnBar to store data, hasn't this already happened along the way? Or isn't data automatically stored when it is received?

_________________
Asking smart qustions:
http://www.catb.org/~esr/faqs/smart-que ... html#intro

I don't mind when people PM me to see if I have the time to help, but please post in the forum FIRST, and then grab my attention so others can benefit aswell.


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 10, 2008 9:36 am 
Offline

Joined: Tue Aug 05, 2003 3:43 pm
Posts: 6816
Live data is (optionally) stored in memory in Strategy.Bars/Quotes/Trades arrays but not in the historical data base.


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 11, 2008 5:11 pm 
Offline

Joined: Thu Mar 20, 2008 4:41 pm
Posts: 273
Location: Sweden
Dr. Anton Fokin wrote:
Live data is (optionally) stored in memory in Strategy.Bars/Quotes/Trades arrays but not in the historical data base.

Then I had made erroneous assumptions about the underlying architecture of OQ. Thanks for clearing that up.

_________________
Asking smart qustions:
http://www.catb.org/~esr/faqs/smart-que ... html#intro

I don't mind when people PM me to see if I have the time to help, but please post in the forum FIRST, and then grab my attention so others can benefit aswell.


Top
 Profile  
 
PostPosted: Mon Jan 05, 2009 6:17 pm 
Offline

Joined: Fri Jan 02, 2009 9:31 pm
Posts: 16
hi! following this interesting discussion, there are now different versions of snippets in this thread about capturing live data into historical data. Is there maybe a really working complete script available doing this? thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 09, 2009 10:03 pm 
Offline

Joined: Tue Dec 16, 2008 1:03 am
Posts: 26
I tried running this code on live and it works great.

Quick question however, if I run a simulation run for backtesting with this code in the strategy, will it add all of the trades into the database (i.e adding them alongside the existing trades on which the backtesting is being run). obviously I would not want that as that would skew the volume.

for now, i just put the code in a separate project which I add or remove into the solution depending on whether I run Live or Sim


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 10, 2009 8:47 pm 
Offline

Joined: Thu Jun 08, 2006 3:56 pm
Posts: 537
Location: BC Canada
Here's code to only save bars when you're collecting them from a live source (paper or live):

Code:
    // ==============================
    // DATAMANAGER CAPTURE REAL TIME BARS
    // ==============================
    // save clock and strategy bars in live/paper mode to the db for replay
    if (this.Mode != StrategyMode.Simulation)
        DataManager.Add (Instrument, bar);


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 16, 2009 2:04 am 
Offline

Joined: Thu Jun 08, 2006 3:56 pm
Posts: 537
Location: BC Canada
I suppose that I could save incoming live trades into the historical database with something like this, right?

Code:
OnTrade (Trade trade) {
    // save incoming trades in live/paper mode to the db for replay
    if (this.Mode != StrategyMode.Simulation)
      DataManager.Add (Instrument, trade);
}


But if I have multiple strategy projects running within one OQ solution (all running against the same instrument), how can I prevent them from all trying to save incoming trades into the historical database and overwriting the trade data once for every strategy? It seems like I would require something for efficiently communicating between N strategies within one solution or something.

For now I'm just going to add the code to one strategy project in my paper trading set, so that I won't get collisions and overwrites.

Does anyone have a good idea for doing this? I'm trying to save the same trades that my strategy sees, so I can replay them for debugging and analysis... Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 16, 2009 2:10 am 
Offline

Joined: Thu Jun 08, 2006 3:56 pm
Posts: 537
Location: BC Canada
I just realized how to do it nicely. I forgot that I have this old empty strategy that I call BarSaver. It has no logic in it except the code fragment for saving bars (as shown earlier in this thread).

So I'll just add it to the paper trading set (or to a live trading set), and leave the bar-saving and trade-saving code out of my other strategy projects.

That way only one strategy project will try to save trades to the historical database.


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

All times are UTC + 3 hours


Who is online

Users browsing this forum: No registered users and 1 guest


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