SmartQuant Discussion
http://www.smartquant.com/forums/

Spread Trading Example (2 securities buy/sell orders)
http://www.smartquant.com/forums/viewtopic.php?f=46&t=5785
Page 1 of 3

Author:  mktwizard [ Thu Aug 02, 2007 3:00 am ]
Post subject:  Spread Trading Example (2 securities buy/sell orders)

Does anyone have an example of a spread strategy? ie creating a ratio/spread between 2 securities and then firing off orders on both securities based on thresholds of the ratio? wud be a great help. thnks

Author:  Dr. Anton Fokin [ Thu Aug 02, 2007 7:59 am ]
Post subject: 

Hi,

take a look at this thread

http://www.smartquant.com/forums/viewto ... ght=spread

Regards,
Anton

Author:  fliesch [ Thu Aug 02, 2007 3:18 pm ]
Post subject: 

I think ther once was an example with stocks listed on different exchanges or was it forex? Could you provide this one again?

Author:  Dr. Anton Fokin [ Thu Aug 02, 2007 3:56 pm ]
Post subject: 

I think it's one of FOREX strategies from TickJob discussed in the Strategies section of this forum.

Author:  fliesch [ Thu Aug 02, 2007 4:27 pm ]
Post subject: 

I dont think so. It was an example strategy on your homepage as I remeber - maybe 1-2 years ago.

Author:  Dr. Anton Fokin [ Thu Aug 02, 2007 4:36 pm ]
Post subject: 

I think it was a kind of correlation pair trading strategy, but it was for QuantStudio, predecessor of QuantDeveloper and OpenQuant (backtesting only).

Author:  fliesch [ Thu Aug 02, 2007 4:39 pm ]
Post subject: 

I think you are right. It would be helpful to have an example of this kind of system.

Author:  mktwizard [ Thu Aug 02, 2007 5:16 pm ]
Post subject:  spread trading example firing 2 orders simulataneously

hi Anton...i have looked at the link u referred me to but i was wondering if you have an example of firing off 2 simultaneous orders (at least the way you would do it).....there are lots of references to spread strategies in docs but cant find solid example (full strategy) of buying and selling a pair of securities..it wud be extremely helpful as any mismatch in logic cud really throw the timing off..thnks again

Author:  Dr. Anton Fokin [ Thu Aug 02, 2007 7:39 pm ]
Post subject: 

Something like this?

Code:
public class MyStrategy : Strategy
{
   Instrument DELL;
   Instrument CSCO;
   
   TimeSeries spread;
   
   public override void OnStrategyStart()
   {
      DELL = Instruments["DELL"];
      CSCO = Instruments["CSCO"];
       
      spread = new TimeSeries("DELL - CSCO", Color.Pink);
       
      SMA SMA = new SMA(spread, 14, Color.Blue);
       
      Draw(spread, 2);
      Draw(SMA, 2);
   }

   public override void OnBarSlice(long size)
   {
      if (Instrument == CSCO)
      {
         spread = CSCO.Bar.Close / DELL.Bar.Close;

         spread.Add(CSCO.Bar.DateTime, spread);

         if (spread > 0.1)
         {
            Buy(CSCO, 100);
            Sell(Dell, 100);
         }
      }
   }
}

Author:  mktwizard [ Thu Aug 02, 2007 8:05 pm ]
Post subject:  getting errors on example

i copy/pasted and tried running using CSCO and DELL daily data already included with initial download and got following errors?

Cannot implicitly convert type 'double' to 'OpenQuant.API.TimeSeries'

The best overloaded method match for "OpenQuant.API.TimeSeries.Add (Sytem.DateTime,double' has some invalid aruguments

Argument '2':cannot convert from 'OpenQuant.API.TimeSeries 'to 'double'

Operator '>' cannot be applied to operands of type 'OpenQuant.API.TimeSeries' and 'double'

The name 'Dell' does not exist in the current context

Author:  Dr. Anton Fokin [ Thu Aug 02, 2007 9:22 pm ]
Post subject: 

Code:
public class MyStrategy : Strategy
{
   Instrument DELL;
   Instrument CSCO;
   
   TimeSeries spread;
   
   public override void OnStrategyStart()
   {
      DELL = Instruments["DELL"];
      CSCO = Instruments["CSCO"];
       
      spread_series = new TimeSeries("DELL - CSCO", Color.Pink);
       
      SMA SMA = new SMA(spread_series, 14, Color.Blue);
       
      Draw(spread_series, 2);
      Draw(SMA, 2);
   }

   public override void OnBarSlice(long size)
   {
      if (Instrument == CSCO)
      {
         spread = CSCO.Bar.Close / DELL.Bar.Close;

         spread_series.Add(CSCO.Bar.DateTime, spread);

         if (spread > 0.1)
         {
            Buy(CSCO, 100);
            Sell(Dell, 100);
         }
      }
   }
}

Author:  mktwizard [ Thu Aug 02, 2007 9:44 pm ]
Post subject:  ugh..still getting errors

still getting errors. all the other strategy examples work great and i can tweak them to get what i want but i would love a working spread strategy example (entry & exit). if anyone out there has good example that enters and exits based on the spread of any 2 securities please post!! thanks!

errors?:
The name 'spread_series' does not exist in current context

Cannot implicitly convert type 'double' to 'OpenQuant.API.TimeSeries'

Operator '>' cannot be applied to operands of type 'OpenQuant.API.TimeSeries' and 'double'

The name 'Dell' does not exist in the current context

Author:  Dr. Anton Fokin [ Thu Aug 02, 2007 11:47 pm ]
Post subject: 

Well, I am writing this from my head, since I thought you want to get the idea of spread trading with OpenQuant, not just a code sample to copypaste. Could you look through the code? The errors are more or less obvious

TimeSeries spread;

should be changed to

TimeSeries spread_series;

spread variable should be defined

double spread = CSCO.Bar.Close / DELL.Bar.Close;

and then Dell should be in capital letters

Sell(DELL, 100);

That's it. Just syntax errors...

Code:
public class MyStrategy : Strategy
{
   Instrument DELL;
   Instrument CSCO;
   
   TimeSeries spread_series;
   
   public override void OnStrategyStart()
   {
      DELL = Instruments["DELL"];
      CSCO = Instruments["CSCO"];
       
      spread_series = new TimeSeries("DELL - CSCO", Color.Pink);
       
      SMA SMA = new SMA(spread_series, 14, Color.Blue);
       
      Draw(spread_series, 2);
      Draw(SMA, 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 (spread > 0.1)
         {
            Buy(CSCO, 100);
            Sell(DELL, 100);
         }
      }
   }
}

Author:  mktwizard [ Fri Aug 03, 2007 12:26 am ]
Post subject:  awesome

thanks for the quick responses Anton. I've been using your system for all of 2 days so I'm still trying to get a handle. great product as there is a large gap between low end retail systems and high end ones (which quite honestly many of them are overrated). i just wish there was better documentation with more details to walk me through a lot more features and examples. we are a small hedgefund looking to automate our models and this looks like a great product to get started with so we can grow into your other products. thanks again

Author:  Dr. Anton Fokin [ Fri Aug 03, 2007 9:42 am ]
Post subject: 

FYI. OpenQuant offers only one strategy development model and QuantDeveloper has something like four different models. One of them is dedicated to cross-market / correlation type of strategies and it's described in QuantDeveloper manual (together with strategy code samples).

Once you are comfortable with OpenQuant, I suggest you talk to QuantHouse to see if their product suite can help you trading more complex strategies.

Regards,
Anton

Page 1 of 3 All times are UTC + 3 hours
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/