SmartQuant Discussion

Automated Quantitative Strategy Development, SmartQuant Product Discussion and Technical Support Forums
It is currently Sat Sep 26, 2020 6:12 pm

All times are UTC + 3 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Saving state
PostPosted: Wed Sep 22, 2010 5:58 pm 
Offline

Joined: Wed Sep 22, 2010 5:46 pm
Posts: 2
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


Top
 Profile  
 
 Post subject: Re: Saving state
PostPosted: Wed Sep 22, 2010 7:19 pm 
Offline

Joined: Tue Aug 05, 2003 3:43 pm
Posts: 6817
Hi,

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

Regards,
Anton


Top
 Profile  
 
 Post subject: Re: Saving state
PostPosted: Thu Sep 23, 2010 3:54 pm 
Offline

Joined: Wed Sep 22, 2010 5:46 pm
Posts: 2
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


Top
 Profile  
 
 Post subject: Re: Saving state
PostPosted: Thu Sep 23, 2010 4:55 pm 
Offline
Site Admin

Joined: Thu Jul 17, 2003 10:39 am
Posts: 1478
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

_________________
SmartQuant Development Team


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC + 3 hours


Who is online

Users browsing this forum: No registered users and 2 guests


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