Changing dividend values in strategy with SetContext
Author: KGo
Creation Date: 5/20/2020 1:52 AM
profile picture

KGo

#1
This strategy will change dividend values on the performance report for QQQ when QQQ is the primary symbol. The adjustment is lost when any other symbol is primary.

How can I click on SPY and still have QQQ dividend values adjusted?
CODE:
Please log in to see this code.
profile picture

KGo

#2
How can dividends be temporarily changed during strategy execution? Save cache? Any ideas?
profile picture

Eugene

#3
What's the purpose?
profile picture

KGo

#4
Currency conversion. All values need to be multiplied by a currency conversion factor.
In Historical Trades the SplitFactorDividends method placeholder would contain the code posted above if it worked. Looking for an alternative.
CODE:
Please log in to see this code.
profile picture

Eugene

#5
Cannot reproduce any issue here. I click on SPY (which is in the same DataSet as QQQ) or on QQQ alike and get identical correct results.

CODE:
Please log in to see this code.
profile picture

KGo

#6
Need to buy QQQ. Buy was removed. Yes the values can be accessed, changed and printed but strategy needs to actually buy QQQ and see changed QQQ dividends received on the performance report and as part of profit. Profit should change when sf is changed with QQQ or SPY as primary symbol.

From post #1
QUOTE:
change dividend values on the performance report

To be better that should have said change dividends received and net profit on the performance report.
profile picture

Eugene

#7
Oh you're talking about "Apply dividends to backtest results when using Portfolio Simulation mode". If I comment out this line the amount of dividends collected becomes identical if I click either on SPY or QQQ:
CODE:
Please log in to see this code.

Maybe it's an oversight that user is allowed to modify this collection at all (i.e. it's not read-only). That's my point of view. Not seeing anything terribly wrong here.
profile picture

KGo

#8
QUOTE:
If I comment out this line the amount of dividends collected becomes identical if I click either on SPY or QQQ:

I agree but need that line to modify the collection. Here are 4 runs with setup. I think your referencing equivalent of Run 1 below equals Run 3. They don't modify any data.

Run 2 and 4 modify data via sf=2. Run 2 with red is wrong. It should be 7.25 same as Run 4. Is there a cache or other technique to make Run 2 yield 7.25?

profile picture

Eugene

#9
I leave finding another technique up to you. Nothing comes to mind at the moment. Sorry.

P.S. Can't resist leaving this comic here as it's what I'm thinking about Run 2 being wrong (to my mind, Run 4 should be wrong not be allowed):



Workflow comic
profile picture

superticker

#10
Love that comic. I particularly like how he has configured EMACS to monitor cpu temperature changes as a command stroke.

I agree, fi.Value should have been made read-only so side effects from misbehaving code can't corrupt objects. Only the class that owns that object is allowed to modify it.

The take away is to practice good modern program design to avoid side effects like we see here.
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).