Back

Dividends data handler in QC

I am curious to know how to use dividends data in QC
Say on the day that SPY issues dividend, and I hold 100 shares of SPY, I would like to see the cash in my portfolio increases. I know there is a dividends data event, should I do something like this:

public void OnData(Dividends data)
{
Portfolio.Cash = Portfolio.Cash + 100*Securities["SPY"].Dividend
}

I know this is funky, but anyone has a sample showing how to use this event handler?
Update Backtest








Dividends get automatically applied to your portfolio depending on the DataNormalizationMode in the ApplyDividend method.

You can set the DataNormalizationMode using code like the following if you'd like to receive dividends as cash, you could also set it do DataNormalizationMode.Raw. Securities["SPY"].SetDataNormalizationMode(DataNormalizationMode.SplitAdjusted);
0

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.


Update Backtest





0

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.


Loading...

This discussion is closed