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

Saving state
http://www.smartquant.com/forums/viewtopic.php?f=44&t=8409
Page 1 of 1

Author:  darklingg [ Wed Sep 22, 2010 5:58 pm ]
Post subject:  Saving state

Hello,

I'm trying to write a strategy that requires a state to be loaded when the strategy starts and saved when the strategy shuts down.

The state is a list of doubles.

How can I save this state?
I thought the easiest way would be to write it to a text file but when I try I get:
Access to the path 'XXX' is denied.

What can I do?

Thank you

Author:  Dr. Anton Fokin [ Wed Sep 22, 2010 7:19 pm ]
Post subject:  Re: Saving state

Hi,

could you post the protion of your code that reads/writes strategy state?

Regards,
Anton

Author:  darklingg [ Thu Sep 23, 2010 3:54 pm ]
Post subject:  Re: Saving state

Hi,

Sure:

Code:
public override void OnStrategyStart()
    {
        if(File.Exists("state"+ Instrument +".txt"))
        {
            StreamReader SR;
            string S;
            SR=File.OpenText("state"+ Instrument +".txt");
            S=SR.ReadLine();
            while(S!=null)
            {
                S=SR.ReadLine();
                stateList.Add(Double.Parse(S));
            }
            SR.Close();
        }
   
    }
    public override void OnBar(Bar trade)
    {
        bool write = false;
        ....
        if(write)
        {
            StreamWriter SW;
            SW=File.AppendText("state"+ Instrument +".txt");
            SW.WriteLine((stateList[stateList.Count-1]));
            SW.Close();
        }


Thanks

Author:  Alexei Kurov [ Thu Sep 23, 2010 4:55 pm ]
Post subject:  Re: Saving state

Hello,

you need to specify absolute path to the file, because the following line of the code
Code:
SR=File.OpenText("state"+ Instrument +".txt");

tries to open file from the current working directory of the program. For OpenQuant such directory is C:\Program Files\SmartQuant Ltd\OpenQuant2 and access to this directory is denied under windows 7 . You can write to your Documents folder or to any other directory where you have read/write access.

Regards,
Alex

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