Back to Community
Issues brought up backtesting with VMIN

VMIN paid out a large dividend recently and correspondingly lowered the NAV value. This creates an issue when running a backtest because the account appears to have a large drawdown when it really doesn't. Likewise, the dividends seem to show up magically but in the backtest I don't see a way to see what they were (the cash balance simply increases).

It seems for the purposes of calculating account value and correspondingly drawdown, pending dividends should be factored in. In the backtest given, VMIN absolutely killed, but the drawdown appears much higher than it really was. Likewise, it would be nice to see when dividends show up in the account.

Clone Algorithm
Total Returns
Max Drawdown
Benchmark Returns
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
This is a template algorithm on Quantopian for you to adapt and fill in.
from quantopian.algorithm import attach_pipeline, pipeline_output
from quantopian.pipeline import Pipeline
from import USEquityPricing
from quantopian.pipeline.factors import AverageDollarVolume
from quantopian.pipeline.filters.morningstar import Q1500US
def initialize(context):
    Called once at the start of the algorithm.
    context.vmin = sid(49928)
    # Rebalance every day, 1 hour after market open.
    schedule_function(my_rebalance, date_rules.every_day(), time_rules.market_open(hours=1))
def my_rebalance(context,data):
    Execute orders according to our schedule_function() timing. 
    order_target_percent(context.vmin, 1.0)
def my_record_vars(context, data):
    Plot variables at the end of each day.
There was a runtime error.
6 responses

James, thanks for letting us know, we will take a look at the missing dividend.


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 Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian 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.

The dividend isn't missing, but that 33% dip is the difference between the NAV dropping and the dividend showing up in the account


Is there a way to pull the NAV into an algorithm programatically via Morningstar or something else? That is something I have wondered for a while but haven't been able to find.

@james, oops - you're right, I misread the statement. Looks like there's a bug where performance and risk calculations don't account for dividends that have been earned but not yet payed. It's been filed internally and we'll take a look at it, thanks for reporting.

@joseph, you can use 'context.portfolio.portfolio_value' to fetch your current value and use to determine the portfolio weights.

@Alisa - Thanks, but I actually am looking for the underlying Net Asset Value of an ETF, which could be different from the current value that the ETF trades at. Sorry if I wasn't clear!

Ah, we do not have morningstar fundamental data for ETFs, it is stock-only. You can try to approximate this information by calculating the NAV of the ETF constituents but you would need the weighting of the ETF.