SmartQuant Discussion

Risk Management Project
Page 1 of 1

Author:  kot [ Thu Aug 27, 2009 1:55 pm ]
Post subject:  Risk Management Project

I want to make risk management project with following abilities:
2-3-4 sulutions project. RiskManager is among them.
smth like this

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.

Author:  kot [ Thu Aug 27, 2009 1:56 pm ]
Post subject: 

2-3-4 projects in one solution :)

Author:  Dr. Anton Fokin [ Thu Aug 27, 2009 3:15 pm ]
Post subject: 

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

Author:  kot [ Thu Aug 27, 2009 3:38 pm ]
Post subject: 

Even with sm-th like this?
//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()
         Console.WriteLine("Destructor A");
   class B
      public void Test()

   class Class1
      static void Main(string[] args)
         B b=new B();
         A a=new A(b);

Author:  Dr. Anton Fokin [ Thu Aug 27, 2009 3:43 pm ]
Post subject: 

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.


Author:  kkkwj [ Fri Aug 28, 2009 5:07 am ]
Post subject: 

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.

Author:  kot [ Fri Aug 28, 2009 12:01 pm ]
Post subject: 

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?

Author:  kot [ Fri Aug 28, 2009 12:04 pm ]
Post subject: 

this link is useful
- in terms of separate RiskManager project

Author:  kkkwj [ Mon Aug 31, 2009 3:40 am ]
Post subject: 

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

Page 1 of 1 All times are UTC + 3 hours
Powered by phpBB® Forum Software © phpBB Group