SmartQuant Discussion

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

All times are UTC + 3 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Mon Sep 17, 2012 8:18 pm 
Offline

Joined: Mon Oct 04, 2010 5:13 pm
Posts: 362
Hi,

I'm wondering if the following is a bug or I'm doing something wrongly...

I have a BarSeries of daily bars that includes several days back but the current day (which is not yet over). I would like to add to that series the current day. So, naturally, I construct Bar object using my OHLC values and then use the .Add(Bar bar) method of BarSeries. But, though it works ok for 5 minutes bars, when I call Add for daily series I got an exception of "Unable to cast object of type 'SmartQuant.Data.Bar' to type 'SmartQuant.Data.Daily'."

Any suggestions? Actually what I'd like to do is to calculate the SMA value for the current day, while the day is not over yet...

Thanks in advance
Ed


Top
 Profile  
 
PostPosted: Tue Sep 25, 2012 11:23 am 
Offline

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

I guess the only solution is to manually create Daily object from Bar object and add this object to DailySeries. Daily is inherited from Bar, so that you can add Daily to BarSeries, but not vice versa.

Regards,
Anton


Top
 Profile  
 
PostPosted: Tue Sep 25, 2012 11:44 am 
Offline

Joined: Mon Oct 04, 2010 5:13 pm
Posts: 362
Thanks for reply. I'll try your suggestion. But an interesting fact I've discovered - if I take the BarSeries retrieved by GetHistoricalBars and clone it to a new BarSeries then I can add bars to the new series without problems...

So it seems that the BarSeries gotten from GetHistoricalBars and BarSeries constructed by the "new" operator behave differently. Here is the code...
Code:
       
BarSeries dailyBars = DataManager.GetHistoricalBars(Instrument, firstDayToRequest, lastDayToRequest, BarType.Time, CommonDefinitions.DAY_LENGTH_IN_SECONDS);

        //I don't know why but i cannot add a bar to dailyBars, so i have to create a new series
        //and copy all the bars to it first... maybe SQ bug..

        newDailyBars = new BarSeries();

        foreach (Bar tmp in dailyBars)
        {
            newDailyBars.Add(tmp);
        }


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 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