SmartQuant Discussion

Automated Quantitative Strategy Development, SmartQuant Product Discussion and Technical Support Forums
It is currently Tue Aug 20, 2019 11:57 pm

All times are UTC + 3 hours




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: Risk Management Project
PostPosted: Thu Aug 27, 2009 1:55 pm 
Offline

Joined: Mon Jul 27, 2009 3:28 pm
Posts: 24
Location: Ukraine
I want to make risk management project with following abilities:
2-3-4 sulutions project. RiskManager is among them.
smth like this
Strategy1
Strategy2
RiskManager

All money management calculation is being made in RiskManager
for example
Volatility Money Management
in Strategy1 I know stop-loss level = 1.3456, current price is 1.3470.
Before sending buy order, I'm sending message into RiskManager with information: 1.3470 - 1.3456 = .0014 to get number of shares for position opening. So it's smth like RiskManager.GetShares(.0014), and then waiting for reply.
RiskManager is calculating number of shares with following algorithm
[based on 1% risk]: TotalEquity*0.01/.0014 or if it volatility model
:TotalEquity*0.01/ATR(Length). After this RiskManager is sending message to Strategy1 : Strategy1.SetShares(TotalEquity*0.01/.0014)
And after this sendings/resendings I'm finally open position.

Will this michanism work quick? How I can implementate this in OQ.
Do delegates and events work in OQ? Or maybe less sophisticated mechanism is available in OQ? I need some code samples in this topic.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 27, 2009 1:56 pm 
Offline

Joined: Mon Jul 27, 2009 3:28 pm
Posts: 24
Location: Ukraine
2-3-4 projects in one solution :)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 27, 2009 3:15 pm 
Offline

Joined: Tue Aug 05, 2003 3:43 pm
Posts: 6816
I guess you can use statics to pass information between strategies, but I am not sure you can call a method of one strategy from another strategy...


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 27, 2009 3:38 pm 
Offline

Joined: Mon Jul 27, 2009 3:28 pm
Posts: 24
Location: Ukraine
Even with sm-th like this?
Code:
//delegate void Test();
   class A
   {
      public delegate void Test();
      public event Test test;
      public A(B obj)
      {
         test+=new Test(obj.Test);
      }
      public void Show()
      {
         if(test!=null)
            test();
      }
      ~A()
      {
         Console.WriteLine("Destructor A");
      }
   }
   class B
   {
      public void Test()
      {
         Console.WriteLine("Event!");
      }
   }

   class Class1
   {
      [STAThread]
      static void Main(string[] args)
      {
         B b=new B();
         A a=new A(b);
         a.Show();
         a=null;
         GC.Collect();
         Console.WriteLine("Exit...");
      }
   }


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 27, 2009 3:43 pm 
Offline

Joined: Tue Aug 05, 2003 3:43 pm
Posts: 6816
Who is going to call your Main in a strategy ? :) Also, you can think that your A and B classes live in different assemblies.

Though indeed you can try whatever you like. You can use any .NET / C# tricks in OQ strategies, no problem. The only thing you should keep in mind is that one strategy knows nothing about another strategy.

Regards,
Anton


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 28, 2009 5:07 am 
Offline

Joined: Thu Jun 08, 2006 3:56 pm
Posts: 537
Location: BC Canada
I could be wrong, but it seems to me that your desired model is not right. RiskManager is not, and cannot be a Strategy object.

Instead, why not write your RiskManager as an object that talks to a database (eg MSAccessDB) behind it? Then all of your strategies can make calls to the RiskManager object as they please, and the RM object will use the database to manage concurrent requests, shared info among strategies, etc.

The RM input method writes to the DB, then you call the RM.CalcAnswer function to get your RM answers to your questions.

You could also spawn a RM object in a separate thread, but then you have all sorts of interprocess communication and asynch process management issues to contend with.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 28, 2009 12:01 pm 
Offline

Joined: Mon Jul 27, 2009 3:28 pm
Posts: 24
Location: Ukraine
I guess object == class.? And where I should write this class? in every project of my solution? Or maybe I should make in VS dll or assembly, and then use it in OQ projects? What kind of DB (MSSQL or..)- and what kind of information should I write in DB?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 28, 2009 12:04 pm 
Offline

Joined: Mon Jul 27, 2009 3:28 pm
Posts: 24
Location: Ukraine
this link is useful http://www.smartquant.com/forums/viewtopic.php?t=7366
- in terms of separate RiskManager project


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 31, 2009 3:40 am 
Offline

Joined: Thu Jun 08, 2006 3:56 pm
Posts: 537
Location: BC Canada
Yes, you seem to have the idea---write a risk manager class as a separate DLL library, and then link to it by putting it in the References list of all your OQ projects that want to use the risk manager functions. (I configure VStudio to automatically export the DLL into ProgramFiles/SQ/OQ/Bin so it resides in the right place, using a Post-Build command in VS like the one below. OQ must NOT be running a strategy that links to the library, in order for this export command to work.
Code:
copy oq_utilities.dll "C:\Program Files\SmartQuant Ltd\OpenQuant 2\bin"


My point earlier was that only Strategy objects/projects can sit in the list of projects below an OQ solution, and that OQ strategy objects have no good way of talking to each other to share risk management info.

Once you have your risk manager class going, it will need some place to store its data when it is not executing, because it will only be "alive" when one of your strategy projects calls a function in that class.

I suggested that your RM class use an MSAccess database file to store info, because that is a general solution for large amounts of data, and because the DB will enforce good concurrency control among your (possibly many) strategies that will try to update and use the same information concurrently.


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 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