Split and Dividend Adjusted Prices? (Custom cumulative dividend series)
Author: Sammy_G
Creation Date: 7/13/2010 9:37 AM
profile picture

Sammy_G

#1
I need to calculate split and dividend adjusted prices [O, H, L, C] which I use in several of my WL4 scripts. I have not been able to find a WL5 script that discusses this conversion; the Wizard only does split-unadjusted prices.

I will be happy to share my WL4 code, with the underlying logic, if somebody can please help me out. I **really** need this if I have to have any success in converting my WL4 scripts to WL5.
profile picture

Eugene

#2
QUOTE:
the Wizard only does split-unadjusted prices.

Incorrect. The condition "Price is below a value (backtest)", if being converted to code, shows how to obtain a split-adjusted series.

Assuming you have a condition like this in your script and you want to take the price at its pre-split level to be valid for backtesting:
CODE:
Please log in to see this code.

Add this line to the top of the strategy:
CODE:
Please log in to see this code.

Adjust the Close like this:
CODE:
Please log in to see this code.

Finally, change your condition:
CODE:
Please log in to see this code.
profile picture

Sammy_G

#3
I am aware of that method, Eugene, and that is creating split-unadjusted prices [the raw prices are split-adjusted]. I know its confusing...

But more importantly, I need to go one step further and create prices that have also been adjusted for dividends. Its very important to me.
profile picture

Eugene

#4
Use FundamentalDataSeries to get the fundamental series for the "dividend" item and adjust the prices as you like.
profile picture

Sammy_G

#5
Its not quite so simple. The dividend needs to be split-adjusted, and then expressed as a fraction of the split-unadj price to get the correct factor which is then used to adjust the prices.

My method for calculating adjusted prices is solid. It can only help the community should any one be interested in using it.
profile picture

Eugene

#6
QUOTE:
The dividend needs to be split-adjusted, and then expressed as a fraction of the split-unadj price to get the correct factor which is then used to adjust the prices.

Then I wonder what's holding you back from applying the adjustment method above to the dividend series?
profile picture

Sammy_G

#7
You can't use the standard dividend series b/c of the way it is constructed. Like all fundamental items, the value of dividend at a bar is derived from its last occurrence; in other words, an item's value is carried forward till the next occurrence of that item. However, dividend adjustments are applied backwards - in other words, future dividends will lower past prices - and this effect is cumulative (the more there are future dividends, the greater is the past adjustment).
profile picture

Cone

#8
I don't follow your point. Are you saying that you want back adjust for dividends, but it's impossible because of the format of the series?

Keep in mind that you can create a DataSeries and fill it with any values you want. Adjust the dividends with whichever method you like and put in your custom DataSeries to perform your custom adjustment.
profile picture

Sammy_G

#9
Can you post code to show how to create a custom dividend series in reverse chronological order (bar loop is from Bars.Count-1 down to bar = 0)?
profile picture

Cone

#10
Well, I could, but it would just give you the same result as this:
CODE:
Please log in to see this code.
profile picture

Sammy_G

#11
Cone, would you like me to post my WL4 code to show how I did it? Its really good, I believe. Its just that my lack of WL5 coding experience is hampering my translation, and perhaps I am not conveying the methodology precisely too.
profile picture

Cone

#12
You can always post code. But if you already have the code, what is the problem?
profile picture

Sammy_G

#13
B/c its in WL4 format, as I mentioned in my first post.

We seem to be going around in circles. Can you please post code to show how how to create a custom cumulative dividend series in reverse chronological order (bar loop from Bars.Count-1 down to bar = 0) and one that cumulatively adds value as it encounters each new occurrence of dividend [meaning: from bars.Count-1 down to last ex-dividend bar (lets call it ExDivBar1) it may have a value of 0, then from ExDivBar1 -1 down to the previous ex-dividend bar (ExDivBar2) it will have the value of dividend as reported on ExDivBar1; and then from ExDivBar2-1 down to ExDivBar3 the series will have the total of dividends reported on ExDivBar1 and ExDivBar2, and so on down to bar 0.] I hope that clarifies. This will create a cumulative div series in reverse chronological order and is *not* the same as FundamantalDataSeries("dividend"). This will provide a template for my understanding from which I can then move forward.
profile picture

Cone

#14
It's hard for me to believe that if you have it coded in v4 (Delphi Script) that you can't translate it to C#. They are SOOO similar.

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

Sammy_G

#15
I am still very new to C# and it takes a while to get familiar. I was getting stuck while decrementing 'n' inside the bar loop, couldn't get that right.

Your script compiles fine but when run gives a 'Runtime error. Index was out of range. Must be non-negative and less than the size of the collection.' Can you double check on your PC to see if you are also getting the same?
profile picture

Cone

#16
Are you running it on a symbol with a Fidelity "dividend" series? (The code isn't bullet-proofed.)

Edit: Actually that shouldn't create the error. What symbol, scale, and data range causes it?

Edit2: Nevermind, I see it. It would happen if the dividend series were longer than the chart history. Fixed above.
profile picture

Sammy_G

#17
That fixes the error. Thanks, Cone.

On randomly checking against some symbols, noted that it plotted the series for most. But some symbols failed (series had a 0 value):
- SMH, BA, CAT, etc.
These are all Fidelity symbols and I can see the dividend dates on the chart & the tooltip shows the div value. But the series has a 0 value. Using Daily bars, 6 years data.

Lastly, values , when plotted, only start from the 2nd bar (bar: 1), bar: 0 always has no value. Nice if that could be fixed.
profile picture

Cone

#18
This was just supposed to be an example of how to fill a custom series in reverse. You didn't actually expect it to work for all cases without a little work of your own, did you?

Okay, last edit above.
profile picture

Sammy_G

#19
Ahh, I see what you did. Very clever.
And that requires a deep understanding of the data items.
And I believe the script is now bulletproof for its intended purpose.


Re: Values start from 2nd bar.
I just realized that the value for the 1st bar is there (you can bring it up by hovering the mouse in the general area where the plot would be) but for unknown reasons the plot at bar 0 is invisible (visibility starts at bar 2). Dunno why; may be a custom series plot bug or may even be by WL5 design.
==============================

This has been a great learning experience. Thanks for all your help, Cone. Now I need to work further to get my Adjusted Prices.
profile picture

Sammy_G

#20
While playing around with dividends, I was surprised - nay, shocked - to discover that Fidelity has quietly made the following change:
In WL4, the dividends were raw dividends i.e. what was actually paid out per share.
In WL5, the dividends are being split adjusted.

Examples of a couple of symbols that have had both splits and dividends:
1) FAS. Had a 3:1 split on 5/5/10, which is correctly identified in both WL4 and WL5.
In WL4, on 3/23/10, there is a dividend shown in the amount of 0.29172/share.
In WL5, on 3/23/10, the dividend is shown as 0.10/share (0.29172/3 = 0.09724 = 0.10 rounded to 2 decimals for display).

2) AIG. Had a 1/20 reverse split on 7/1/09.
In WL4, on 9/3/08, there is a dividend shown in the amount of 0.22/share.
In WL5, on 9/3/08, the dividend is shown as 4.40/share (0.22/(1/20) = 4.40) !!!

Like I said, I was shocked at this radical departure from the old format, and there is no mention of it anywhere.

Needless to say, folks using dividends in their scripts may need to revisit them to check they are working as intended.

I have not yet explored what the implications are of this change for the WL5 option under Prefs | Backtest Settings| Apply dividends to backtest results when using Portfolio Simulation mode.
profile picture

Cone

#21
I'll have to look back a few years, but not adjusting for dividends was a Version 4 "bug" that was corrected in Version 5. Generally, I try to summarize bug fixes in the New and Noteworthy section of the User Guide for the current release (this was probably corrected for 5.0 or 5.1).

The implication is that dividends are properly applied for the number of shares owned during a Portfolio Simulation mode backtest when that preference is enabled... and that can't be all that "shocking".

That said, certainly the "dividend" (per share) item should be identified in the Fundamental Data Guide, and there I don't even see it mentioned.
- I take that back, it's in the list on p.29, but doesn't define it as a per share, adjusted value.
profile picture

gbullr

#22
LVLT recently reverse split but my chart shows a "jump" what is the setting to adjust for splits?

profile picture

Eugene

#23
To perform a manual split of the current symbol's data, open a chart of the instrument, right click and select "Process a Stock Split".
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).