Welcome Guest, please sign in to participate in a discussion. Search | Active Topics |

Response please Rate this Topic:
Previous Topic · Next Topic Watch this topic · Print this topic ·
Freas
Posted : Friday, July 27, 2007 9:17:35 AM
Registered User
Joined: 10/7/2004
Posts: 22
Craig/Bruce
Did you miss or drop this one or are you working on it?

Worden Discussion Forum » Blocks 2.0 » General Discussion » Regression Channels in Blocks

Freas
Bruce_L
Posted : Friday, July 27, 2007 9:57:24 AM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
You are not being ignored. I have created a version of Linear Regression Channels that adds options for adding an Extension Parameter and Width matching TC's LR Dispersion Channels. It does not have a Logarithmic Calculation Option, but I'm not sure it is possible to add this in a way that is compatible with changing a single setting in QuickEdit.

It would currently require the creation of a Custom Code Block to add Width matching TC's LR Dispersion Channels however. Getting the Block added to Blocks would allow it to be implemented by customers that do not wish to create Custom Code Blocks. I will not be posting my work until I know if the Block is up to the standards required to be added to the program.

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
Freas
Posted : Monday, July 30, 2007 2:47:54 PM
Registered User
Joined: 10/7/2004
Posts: 22
Thanks for your reply Bruce. I don’t want to let go of this, partly because your answer seems to leave it open ended for a conclusion, and partly because it is so very important to me. So I must respond as follows and hope that it is sufficiently concise although quite lengthly.

I have been trying to work through the LR problem using your BEL LR Channels Workspace. I find more problems and misunderstandings that I could sure use your help on. I will list them by number and would hope you could answer them the same way.
1. Ref. Linear Regression Trendline.2 Block diagram:

I wanted to disconnect from the Date Marker so I replaced its block with “Add Days” block using “BarChart End Date” and “Parameter: Whole Number”. Although this appeared to work at first it caused some confusion in that the chart did not reflect the correct LR start date; -19 days had to be used to get a 15 day setback. The “Add Days” block uses calendar days not the number of bars. Problems: The blocks definition should state “calendar days” to avoid confusion for most of us who think in terms of bars. Secondly there is no block for “Add Bars” to obtain a date relative to the end date/bar, i.e., date output as opposed to the “Date and Bar” series output of the “Bar Offset Block”.

I then attempted to insert a “Bar Offset” block between the “BarChart Price History 2” and “Linear Regression Trendline” blocks with a “Parameter: Whole Number” input (set at 15). Doing this results in the Trendline to change its slope and be in error but it does set the Trendline start date back 15 bars as noted when the “Optional: Regression Date” input to the “Linear Regression Trendline” block is eliminated. Can you explain what is going on here since it does seem to be a logical setup?

The block diagram was left with the “Add days” connection made and the “Bar Offset” output disconnected.

It was also noted that the LR Channel deviation varied as the date pointer was moved so attention was directed to the:

2. SD Channel Block Diagram:

I first changed the “Value For Date” block input from the date indicator to the “Add Days” block arrangement as indicated above for the “Linear Regression Trendline.2 Block diagram”. This fixed the channel deviation changes caused by the date bar. However if the Integer input to the “Add Days” block causes the output date to be a weekend day the LR Bands disappear! Either the integer would have to be adjusted whenever the LR Bands disappeared, the blocks code would have to be modified, or a Bar Count block with date output would have to be coded. In addition, weather the “Value For Date” date input comes from either the “Bar Chart End Date” block or the “Add Days” block the LR Channel line values and deviation do not line up with those in TeleCharts. This may be partly but not totally the result of the Log Scale dilemma.

Furthermore, I do not understand the definitions for either of the “Value for Date” and “Output Constant Single” blocks. Please elaborate on the definitions and terms of these two blocks.

On the left hand side of the diagram where it shows the inputs to the “Standard Deviation” block it seems to me that the standard deviation is being calculated for the last 50 days of the bar chart. I tried to insert a “Bar Offset” block (with a -15 integer input) to set the SD inputs to the agree with the 50 period and 15 bar offset of the LR line and channel. This results in no channel being shown on the chart. This is true for all negative inputs to the “Bar Offset” block, however positive (that is future as I understand it) inputs do result in the LR Channel being displayed but certainly not correct, and a “0” input results in the same LR Channel display as when the “BarChart Price History 2” is connected to the SD block instead of the “Bar Offset” block output. None of this makes sense to me so where is my thinking going wrong or is there a problem with the blocks coding or the diagram somewhere or what? Help please?

I may not understand your definition, calculation, and use of SD here as compared to that which is evident in the TeleCharts development. For example in TeleCharts a band setting of 30 just clips the top(s) or bottom(s) of the price excursions during the LR period which would indicate that the “30” setting is the 3-sigma value of the maximum excursion of price relative to the LR Trendline depending on weather that maximum excursion is above or below the LR Trendline, i.e., the absolute value of the excursion. The Blocks definition for the “SD” block is “Provides a Standard Deviation for the period provided” which leads the user to wonder whether this means 1-sigma or what, although the LR Channel depictured on the chart would seem to indicate a value near 3-sigma or simply the maximum deviation as opposed to a “standard” deviation. In the Worden Knowledge Base the best definition is given as “Standard Deviation is the root mean square of the distance of a set of points from the mean of those points” and is easy to understand but does not seem to fit the chart display without some multiplier. Please enlighten me.

I would like to know how you set up the extension and setback even without resolution for the Log scale presentation. I find that the LR Channel is still useful in all but the charts with the greatest gradient. Also to set up strategies I need to relate price to LR slope and the channel and channel extension components and values, for example the data obtainable when sorts are performed on the LR and its bands in TeleCharts. Please consider this when you are working the problems in Blocks.

Finally, a suggestion for an alternative approach to the LR Channel development; copy the LR Trendline and shift it up by an adjustable amount related to the deviation and of course the same for the lower band line. If my memory serves me correctly the original definition for the LR Trendline with Bands did not mention “standard deviation” rather it indicated some variation of the underlying over the period of the LR Trendline. The original definition is no longer available but you may be able to find it in your archives.


The products, TeleChart and Blocks, are in my opinion far above anything else of its kind to be found. It is also in my opinion that you folks are doing a spectacular job in developing the Blocks Platform at such a high rate of speed. Unfortunately, the one item I lust for, LR Trendline with bands and means to set up strategies, seems to be a big stumbling block. Thanks for your help and please make its solutions one of your highest priorities.

Thanks, Freas

Bruce_L
Posted : Monday, July 30, 2007 4:09:24 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
QUOTE (Freas)
I have been trying to work through the LR problem using your BEL LR Channels Workspace.

That's not the best place to start. The LR Channel.plot and Centerline.plot files in Regression Channels in Blocks were created for a reason.

QUOTE (Freas)
I wanted to disconnect from the Date Marker so I replaced its block with “Add Days” block using “BarChart End Date” and “Parameter: Whole Number”. Although this appeared to work at first it caused some confusion in that the chart did not reflect the correct LR start date; -19 days had to be used to get a 15 day setback. The “Add Days” block uses calendar days not the number of bars. Problems: The blocks definition should state “calendar days” to avoid confusion for most of us who think in terms of bars. Secondly there is no block for “Add Bars” to obtain a date relative to the end date/bar, i.e., date output as opposed to the “Date and Bar” series output of the “Bar Offset Block”.

Using a Market Date Adder Block uses Market Days instead of Calendar Days. That said, both would really only be useful in a 1-Day Time Frame.

QUOTE (Freas)
I then attempted to insert a “Bar Offset” block between the “BarChart Price History 2” and “Linear Regression Trendline” blocks with a “Parameter: Whole Number” input (set at 15). Doing this results in the Trendline to change its slope and be in error but it does set the Trendline start date back 15 bars as noted when the “Optional: Regression Date” input to the “Linear Regression Trendline” block is eliminated. Can you explain what is going on here since it does seem to be a logical setup?

Bar Offset shifts the data, it does not shift the dates. So if I run Price through a Bar Offset Block set to 1, I get yesterday's value today. When you plot the Linear Regression Trendline, it using values offset by the Bar Offset Period but it is using the current date.

It would be necessary to actually trim off the most recent data for the LR Channels to behave as you were expecting. The Max Date Line Limiter does this with dates, but I'm not sure if there as a currently existing Block that would do this using Bars.

QUOTE (Freas)
It was also noted that the LR Channel deviation varied as the date pointer was moved so attention was directed to the:

It would be odd if it didn't.

QUOTE (Freas)
I first changed the “Value For Date” block input from the date indicator to the “Add Days” block arrangement as indicated above for the “Linear Regression Trendline.2 Block diagram”. This fixed the channel deviation changes caused by the date bar. However if the Integer input to the “Add Days” block causes the output date to be a weekend day the LR Bands disappear! Either the integer would have to be adjusted whenever the LR Bands disappeared, the blocks code would have to be modified, or a Bar Count block with date output would have to be coded. In addition, weather the “Value For Date” date input comes from either the “Bar Chart End Date” block or the “Add Days” block the LR Channel line values and deviation do not line up with those in TeleCharts. This may be partly but not totally the result of the Log Scale dilemma.

As noted above, using a Market Date Adder Block would resolve this to some extent, but the width would still not match. This is because the LR Channels in TeleChart do not use Standard Deviation. Standard Deviation was used in the Block Diagram both because it is available and because it is frequently used as the Channel Width for programs besides TeleChart.

QUOTE (Freas)
Furthermore, I do not understand the definitions for either of the “Value for Date” and “Output Constant Single” blocks. Please elaborate on the definitions and terms of these two blocks.

I'm hard pressed to come up with a definition for Value for Date that is better than the name itself. It is the value of the Date & Number Series at the Time of Date Input. Output Constant Single outputs the Value input for every Date in the Date & Number Series Input. If you put 10 as the Value and Prices as the Date & Number Input, you would get a Date & Number Series with 10 as the output for point where there is a Price.

QUOTE (Freas)
On the left hand side of the diagram where it shows the inputs to the “Standard Deviation” block it seems to me that the standard deviation is being calculated for the last 50 days of the bar chart. I tried to insert a “Bar Offset” block (with a -15 integer input) to set the SD inputs to the agree with the 50 period and 15 bar offset of the LR line and channel. This results in no channel being shown on the chart. This is true for all negative inputs to the “Bar Offset” block, however positive (that is future as I understand it) inputs do result in the LR Channel being displayed but certainly not correct, and a “0” input results in the same LR Channel display as when the “BarChart Price History 2” is connected to the SD block instead of the “Bar Offset” block output. None of this makes sense to me so where is my thinking going wrong or is there a problem with the blocks coding or the diagram somewhere or what? Help please?

Using a Negative Number as the Bar Offset results in retrieving a future value. In situations where the data is already at the right end of the chart, this results in not being able to retrieve a value.

Using a Positive Number as the Bar Offset results in retrieving a past value.

A Bar Offset of zero leaves the underlying Date & Number Series unchanged. So running Bar Chart Price History through a Bar Offset set to zero is the same as using Bar Chart Price History directly.

QUOTE (Freas)
I may not understand your definition, calculation, and use of SD here as compared to that which is evident in the TeleCharts development. For example in TeleCharts a band setting of 30 just clips the top(s) or bottom(s) of the price excursions during the LR period which would indicate that the “30” setting is the 3-sigma value of the maximum excursion of price relative to the LR Trendline depending on weather that maximum excursion is above or below the LR Trendline, i.e., the absolute value of the excursion. The Blocks definition for the “SD” block is “Provides a Standard Deviation for the period provided” which leads the user to wonder whether this means 1-sigma or what, although the LR Channel depictured on the chart would seem to indicate a value near 3-sigma or simply the maximum deviation as opposed to a “standard” deviation. In the Worden Knowledge Base the best definition is given as “Standard Deviation is the root mean square of the distance of a set of points from the mean of those points” and is easy to understand but does not seem to fit the chart display without some multiplier. Please enlighten me.

TeleChart does not use Standard Deviation at all in its Linear Regression Channels. The calculations used are described in detail in Linear regression channel calculations. TeleChart's Bollinger Bands use Standard Deviation of Sample if you want to compare the Width of TeleChart's Linear Regression Channels to a Standard Deviation based Widths. The Standard Deviation Block in Blocks calculates Standard Deviation of Population (1-sigma, which is normally what is provided when there isn't additional clarification). Note that in both TeleChart's Bollinger Bands and in the Linear Regression Channels you have been playing with in Blocks, the calculated values are added to the Centerline to get the Top Band and subtracted from the Centerline to get the Bottom Band (which may be throwing off your estimate by a factor of two).

QUOTE (Freas)
I would like to know how you set up the extension and setback even without resolution for the Log scale presentation. I find that the LR Channel is still useful in all but the charts with the greatest gradient.

OK. Please start by creating the following Code Block as Line and Int to Line (please keep in mind I'm not a programmer):

TC LR Width:

Replace everything in the Code Block with (Firefox seems to work for copy and paste, IE does not):

<WBIGuid("a554d6dc-df4f-49f4-87ca-7b71ec9b7d9e"),FriendlyName("TC LR Width")> _
Public Class TC_LR_Width
inherits BaseTemplateDLStoDLSPeriod
Public Overrides Sub calculate()
If ParameterValue <= InputCount
Dim sum As Double = 0
Dim mean As Double = 0
Dim mad As Double = 0
For bar As Integer = ParameterValue - 1 To InputCount - 1
For bar1 As Integer = 1 To ParameterValue
sum = sum + InputValue(bar-ParameterValue-1+bar1)
mean = sum / bar1
mad = mad + System.Math.Abs(InputValue(bar-ParameterValue-1+bar1)-mean)
Next
AddToOutput(InputDate(bar),mad / ParameterValue / 2)
sum = 0
mad = 0
Next
End If
End Sub
End Class

You may wish to review the following for help with creating Custom Code Blocks:

VB.Net (code block) to color down Monday red
VB.net exercise to access Quickedit from your codeblock
Hello World! Writing Code Blocks in Visual Basic .Net

Once you have created the Custom Code Block, you can save the attached .bWorks file to the following folder:

\My Documents\Blocks Files\Workspaces

You can then open the Workspace via your FILE menu (Open Workspace then My Computer).

I've added pretty much everything required besides an option for logarithmic calculation (and I haven't figured out how to do that in a way that works with QuickEdit) to match the way Linear Regression Lines work in TeleChart when using arithmetic scaling (with the addition of different Width options). It will curve and adjust widths when the chart is not using arithmetic scaling if the price range is large enough (because they are arithmetic lines). TeleChart's Width setting must be divided by 10 to get the Width setting to use for this version of Linear Regression Channels in Blocks.

The current version includes both Linear Regression and Moving Linear Regression Channels. The right endpoint of the Linear Regression Channels are based on the Date Pointer, but you can adjust the Block Diagram to use the Bar Chart End Date instead.

You can see how the Linear Regression Channels and Moving Linear Regression Channels interact by using similar settings and dragging the Date Pointer across the Chart.

I'll post something in Regression Channels in Blocks when it is actually ready.

Attachments:
LR and MLR.bWorks - 77 KB, downloaded 831 time(s).



-Bruce
Personal Criteria Formulas
TC2000 Support Articles
Freas
Posted : Tuesday, July 31, 2007 9:26:44 AM
Registered User
Joined: 10/7/2004
Posts: 22
Thanks Bruce
I will be working through all this over the next few days.
it would probably be a good idea to move these comments to the original Topic. I should have kept it there.
Freas
Bruce_L
Posted : Tuesday, August 7, 2007 2:40:32 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
The TC LR Width Block has been added to the Worden Code Block Library. You should no longer need to create it as a Custom Code Block to use the attached Workspace.

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
Users browsing this topic
Guest-1

Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.