Hi everyone, quick question: if I am using minute resolution, is there a simple way to get the total volume so far in the day for a security (in other words, the sum of the volume for all previous minutes in the day, up to and including the current minute)? Or can this only be done by adding up all of the individual volumes at each minute?
Michael Handschuh
We'll need to add up the individual volumes. This can be done in a variety of ways, my favorite would be to define an indicator that represents the daily running volume as this would be the most isolated solution. Other solutions, such as manually aggregating the volume in a variable may get unwieldy with multiple securities. He's an example of an indicator that gives the daily running volume:
Simon Bray
Is there something like this in Python?
Alexandre Catarino
An alternative to Micheal's solution is the use of consolidator:
# In Initialize: consolidator = TradeBarConsolidator(TimeSpan.FromDays(1)) consolidator.DataConsolidated += self.DailyConsolidator self.SubscriptionManager.AddConsolidator(self.spy, consolidator)
When a daily bar is consolidated, it will appear at the DailyConsolidator event handler:
def DailyConsolidator(self, sender, bar): self.Log("{0} {1}".format(str(bar), bar.Volume))
Please checkout the working example below.
For other examples, take a look at the open-source project.
James Parrish
Hello- any chance you could provide an example in python of the same? Would be greatly appreciated
Jing Wu
Hi James,
Michael's example can be done in Python with the custom indicator.
class DailyVolumeIndicator: def __init__(self, name): self.Name = name self.date = datetime.min self.Value = 0 self.IsReady = False # Update method is mandatory def Update(self, input): if input.EndTime.date() != self.date: self.volume = 0 self.date = input.EndTime.date() else: self.volume += input.Volume self.Value = self.volume
You can retrieve the indicator volume with "self.sum_volume.Value". Please see the attached algorithm.
Brendan Driscoll
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!