SmartQuant Discussion

Automated Quantitative Strategy Development, SmartQuant Product Discussion and Technical Support Forums
It is currently Mon Mar 25, 2019 2:54 pm

All times are UTC + 3 hours




Post new topic Reply to topic  [ 34 posts ]  Go to page Previous  1, 2, 3
Author Message
 Post subject:
PostPosted: Wed Sep 12, 2007 5:33 pm 
Offline

Joined: Wed Oct 08, 2003 1:06 pm
Posts: 833
Hi,
Quote:
When will this newer version be avaible?

The new version will be available during this week.
Quote:
Is "bilateral" pairtrading possible?

I think the strategy by Mktwizard is a good example.. Probably we will include it in docs. Here is its corrected code:

Code:
using System;
using System.Drawing;

using OpenQuant.API;
using OpenQuant.API.Indicators;

public class MyStrategy : Strategy
{
   Instrument DELL;
   Instrument CSCO;

   TimeSeries spread_series;

   [Parameter("Order quantity (number of contracts to trade)")]
   double Qty = 100;

   [Parameter("Length of SMA")]
   int SMALength = 20;

   [Parameter("Order of BBU")]
   double BBUOrder = 2;

   [Parameter("Order of BBL")]
   double BBLOrder = 2;

   // indicators
   BBU bbu;
   BBL bbl;
   SMA sma;

   public override void OnStrategyStart()
   {
      DELL = Instruments["DELL"];
      CSCO = Instruments["CSCO"];

      spread_series = new TimeSeries("DELL - CSCO", Color.Pink);

      // set up the moving averages
      sma = new SMA(spread_series, SMALength);
      sma.Color = Color.Yellow;
      Draw(sma, 2);
      // set up bollinger bands
      bbu = new BBU(spread_series, SMALength, BBUOrder);
      bbu.Color = Color.Green;
      bbl = new BBL(spread_series, SMALength, BBLOrder);
      bbl.Color = Color.Green;
      Draw(bbu, 2);
      Draw(bbl, 2);
      Draw(spread_series, 2);
   }

   public override void OnBarSlice(long size)
   {
      if (Instrument == CSCO)
      {
         double spread = CSCO.Bar.Close / DELL.Bar.Close;
         spread_series.Add(CSCO.Bar.DateTime, spread);
         
         if (bbl.Count == 0)
            return;
         
         if (!HasPosition)
         {
            if (spread < bbl.Last)
            {
               Buy(CSCO, Qty);
               Sell(DELL, Qty);
            }
         }
         else
         {
            if (spread > bbu.Last)
            {
               Sell(CSCO, Qty);
               Buy(DELL, Qty);
            }
         }
      } 
   }
}


Btw, this strategy works fine in the current OQ version.

Regards,
Sergey.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 26, 2008 5:58 pm 
Offline

Joined: Mon May 26, 2008 5:50 pm
Posts: 1
Can this example be extended to use the bid price for both instruments? For example the spread value would always be (Instrument1.Bid - Instrument2.Bid).

Charting this value rather than using the last price for each instrument is much more useful, especially when using instruments with wide bid/ask spreads such as NYMEX natural gas or RBOB (gasoline) futures.

Also, are you restricted to time based periods in OQ when charting spreads? Specifically, I am interested in using cumulative tick periods across the spread instruments. That is, if you defined a period as consisting of 500 trade ticks (i.e., not bid/ask ticks), each tick for both instruments would be summed until 500 ticks were reached and then a new period would occur.

Thank you.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 27, 2008 11:57 am 
Offline

Joined: Wed Oct 08, 2003 1:06 pm
Posts: 833
Hi,

It is possible to implement similar strategy with spread based on Bid instead of bar.Close price - just override OnQuote instead of OnBarSlice.

But it is not so easy to plot the spreadSeries correctly. Our charting engine assumes that there is one main series on a chart (which is a BarSeries usually). All other series on a chart can be plotted only if they have elements with the same timestap as the main series. So, if you like to draw the spreadSeries - you would need to request 1 tick bars and be aware that the one part of the series will be drawn on DELL chart (elements that correspond to DELL quotes) and another on CSCO chart.

Regards,
Sergey.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 06, 2008 7:12 pm 
Offline

Joined: Thu Nov 06, 2008 3:13 pm
Posts: 8
Hello, ony just started looking at SmartQuant today and this code looks lke what I am looking for (MultiAsset Strategy).

I have a 3 questions though:

What bit of code registers the DELL and CSCO instruments into this Strategy instace event framework (ie so they can trigger events).
Is it the DELL = Instruments["DELL"]; statement?

What is the OnBarSlice method and is it crucial to call it instead of the OnBar method when coding multiasset strategies. I've just read the OpenQuant Strategy docs where all it sais is "OnBarSlice – called when all per-instrument bars have been emitted" and I am not sure I understand what this means

Could you point me to the most complete help document or help system with the OQ object model.

Thanks so much.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 34 posts ]  Go to page Previous  1, 2, 3

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