Friday, March 27, 2015

Calender Dating

The calender dating is a method of numbering the days of the week and the week of the month. This unique numbering is done so that specific days or specific weeks of the month can easily be called for doing additional time specific analytics. 

The following picture shows the methodology the number the trading days of the month. One method uses a consecutive numbering method and the other uses the week and day method.




Monday, March 16, 2015

UPDATES

This page will be used to list updates to the various pages and to show new pages. This is being done to help keep those coming in to check for changes to know where to look and for what changes or additions. When coming in, this will be the first page to look at. It will list the date of the change as well as the Label where it can be found

UPDATE: 3/16/2015
Program Language
The programming languages has been decided to use C++11/14 and Revolution R Open from Revolution Analytics. The reason for picking these two are for ability to multithread and parallels.

UPDATE: 3/27/2015
Priority List
Updated the priority list of needed programming sequence.

Calender Dating
Algorithm for dating the trading days and weeks of the month.

Wednesday, March 11, 2015

Priority List

The following is a priority list or a list of objectives listed in order of importance. The list is not a complete list and will be updated as needed.

  1. Creation of Zig Zag Logic in R. Sample Zig Zag Code
  2. Create charts in R using QuantMod or similar.
  3. Draw the programmed Zig Zag logic on the R charts so as to visually confirm correctness of code. The resultant output should look similar to what is found in this post
This is where the priority may split or be divided and two paths taken and programmed separately. The following studies are all independent of each other with the exception that they are based on the Zig Zag swing as the basis to find and log the needed data or conditions. When the need comes, these studies may be merged in the future to give better statistics and analytics of the said patterns. 

  1. Calculate all of the Zig Zag legs and record their values based on the conditions found in this post.
  2. Perform pattern recognition and recording of found patterns at the end of the Zig Zag legs. This link gives a brief description of pattern recognition but does the recognition in an unfiltered manner. The idea of this pattern recognition is to look at the pattern of "XX" candles prior to the ZZ turning point and "YY" candles after the ZZ turning point. These patterns will be logged and pattern recognition run on these resultants. Any type of clustering logic or other pattern identifiers should be run on these just the same as finger print or facial recognition software does. The idea here is to "identify" the pattern and market context so that a trade forecast can be made.
UPDATE: 
3/27/2015

The Zig Zag logic is complete.

The updated priority is as follows.
  1. Creation of the Calender Dating algorithm added to the Zig Zag logging.  
  2. These functions or algorithms coded within the Zig Zag logic to calculate and log the following
    1. ZZ_bars
    2. ZZ_change
    3. ZZ_percent
    4. ZZ_slope
    5. ZZ_connecting_angle.left
    6. ZZ_connecting_angle.right
  3. Any additional algorithms deemed more efficient calculated in original ZigZag logging then being calculated later in R or another process in C++.
  4. The ZigZag Mean, Standard Deviation and Median values.


Sunday, March 8, 2015

Program Language

This is a discussion to evaluate and decide the best program or various programs to use for the overall project. Items to consider for what program or programs to use depends on the following areas.
1. Pattern matching and how that will be done.
2. How to best calculate the statistics from the historical pattern matching results.
3. The best program or platform to do the forecast modeling based on the matching of current patterns and comparing to the historical statistical results.

The program that I am considering the most heavily is R. I am looking at using R from a template that has been create by either R_Studio or Revolution Analytics. I am looking for input in this manner but am favoring R Studio.

UPDATE: 3/16/2015
The programming languages has been decided to use C++11/14 and Revolution R Open from Revolution Analytics. The reason for picking these two are for ability to multithread and parallels.

Saturday, March 7, 2015

Zig Zag Statistics

Statistics indicators

After the ZigZag engine has established the location of each turning point on the chart, a number of indicators or statistical studies will be built on top of the returned resultant ZigZag legs. From these returned legs, various statistics will be applied, calculated and recorded for use in future analysis.

The measures of these legs between the peaks and valleys will be used in such studies as: horizontal distances (in bars), vertical distances (change in value), vertical distances (percent change in value), and the slope between two TPs or a TP and the current bar (expressed in degrees).

The statistical results will be based on various time frames. This as a rule of thumb will give a better snap shot into price structure and the resultant statistics gathered from a faster time frame and fitting into a larger and slower time frame. The effectiveness of this statistical research used in a trading system will be influenced by choosing the appropriate time of day or trading window and to compare values to and how this trading window or time session fits within a larger time session such as the weekly or monthly cycles. 


The following is a list of the statistics to calculate as they are applied to these measured ZigZag or Fractal legs:

ZigZag Measure Indicators
ZZ_bars
ZZ_change
ZZ_percent
ZZ_slope

ZigZag Mean Indicators
PV: Peak to Valley
VP: Valley to Peak
ZZ_PV_mean_bars
ZZ_VP_mean_bars
ZZ_PV_mean_change
ZZ_VP_mean_change
ZZ_PV_mean_percent
ZZ_VP_mean_percent
ZZ_PV_mean_slope
ZZ_VP_mean_slope

ZigZag Standard Deviation Indicators
PV: Peak to Valley
VP: Valley to Peak
ZZ_PV_sd_bars
ZZ_VP_sd_bars
ZZ_PV_sd_change
ZZ_VP_sd_change
ZZ_PV_sd_percent
ZZ_VP_sd_percent
ZZ_PV_sd_slope
ZZ_VP_sd_slope

ZigZag Median Indicators
PV: Peak to Valley
VP: Valley to Peak
ZZ_PV_median_bars
ZZ_VP_median_bars
ZZ_PV_median_change
ZZ_VP_median_change
ZZ_PV_median_percent
ZZ_VP_median_percent
ZZ_PV_median_slope
ZZ_VP_median_slope




STATISTICAL CALCULATIONS
ZZ_PV_mean_bars:
The indicator computes the mean of the entire peak to valley horizontal distances in bars within the exploration window.

ZZ_VP_mean_bars:
The indicator computes the mean of the entire valley to peak horizontal distances in bars within the exploration window.

ZZ_PV_mean_change:
The indicator computes the mean of the entire peak to valley vertical distances in price within the exploration window.

ZZ_VP_mean_change:
The indicator computes the mean of the entire valley to peak vertical distances in price within the exploration window.

ZZ_PV_mean_percent:
The indicator computes the mean of the entire peak to valley vertical distances in terms of percent change in price within the exploration window.

ZZ_VP_mean_percent:
The indicator computes the mean of the entire valley to peak vertical distances in terms of percent change in price within the exploration window.

ZZ_PV_mean_slope:
The indicator computes the mean of the slopes of the peak to valley lines in degrees within the exploration window.


ZZ_VP_mean_slope:
The indicator computes the mean of the slopes of the valley to peak lines in degrees within the exploration window.

ZZ_PV_sd_bars:
The indicator computes the standard deviation of the entire peak to valley horizontal distances in bars within the exploration window.

ZZ_VP_sd_bars:
The indicator computes the standard deviation of the entire valley to peak horizontal distances in bars within the exploration window.

ZZ_PV_sd_change:
The indicator computes the standard deviation of the entire peak to valley vertical distances in price within the exploration window.

ZZ_VP_sd_change:
The indicator computes the standard deviation of the entire valley to peak vertical distances in price within the exploration window.

ZZ_PV_sd_percent:
The indicator computes the standard deviation of the entire peak to valley vertical distances in terms of percent change in price within the exploration window.

ZZ_VP_sd_percent:
The indicator computes the standard deviation of the entire valley to peak vertical distances in terms of percent change in price within the exploration window.

ZZ_PV_sd_slope:
The indicator computes the standard deviation of the slopes of the peak to valley lines in degrees within the exploration window.

ZZ_VP_sd_slope:
The indicator computes the standard deviation of the slopes of the valley to peak lines in degrees within the exploration window.

ZZ_PV_median_bars:
The indicator computes the median of the entire peak to valley horizontal distances in bars within the exploration window.

ZZ_VP_median_bars:
The indicator computes the median of the entire valley to peak horizontal distances in bars within the exploration window.

ZZ_PV_median_change:
The indicator computes the median of the entire peak to valley vertical distances in price within the exploration window.

ZZ_VP_median_change:
The indicator computes the median of the entire valley to peak vertical distances in price within the exploration window.

ZZ_PV_median_percent:
The indicator computes the median of the entire peak to valley vertical distances in terms of percent change in price within the exploration window.

ZZ_VP_median_percent:
The indicator computes the median of the entire valley to peak vertical distances in terms of percent change in price within the exploration window.

ZZ_PV_median_slope:
The indicator computes the median of the slopes of the peak to valley lines in degrees within the exploration window.

ZZ_VP_median_slope:
The indicator computes the median of the slopes of the valley to peak lines in degrees within the exploration window.

Zig Zag Overview

The indicator that is to be created is based on the concept of recognizing local peaks and valleys where a price time series changes its direction from up to down (peak) and from down to up (valley). This indicator we will refer to as the ZigZag indicator.

A turning point (TP) peak is defined as the point where the high is higher than or equal to any other highs in the neighborhood of the point.

A turning point (TP) valley is defined as the point where the low is lower than or equal to any other lows in the neighborhood of the point.

The ZigZag Indicator used takes a look at three settings Depth, Deviation and Backstep. The ZigZag indicator draws a connecting line between each of the consecutive turning points found by the indicator. The formula for the indicator can be found in the appendix section. The Fractal points displayed are from a common indicator with unknown code. Neither of these methods or provided code are necessarily the final method used to determine and find the turning points that will be used in the statistical model.

The above definitions are illustrated by an example graph below. The peaks and valleys are labeled for the Yellow ZigZag line. Within those peaks and valleys one can find minor peaks and valleys.




The ZigZag  algorithm does not just blindly search for the first consecutive valley after a peak (or a first consecutive peak after a valley). It needs to optimize on turning points and locates such peaks and valleys that a human expert would choose by looking at the chart. The method of optimization at this time is unknown and one of the answers to be found from this research. There are three inputs that need to be variable and optimized;
1. ExtDepth
2. ExtDeviation
3. ExtBackstep
There may be other ways to find or pro-grammatically these turning points and all options need to be looked at. Programmer input is also sought and desired with all parts to help in finding the best options for all sought after results. 


There is no requirement in this research module for a peak to be higher than the previous valley, and for a valley to be lower than previous peak. Our observations have shown that if such a condition were applied, then potentially no turning points could be established on vast portions of data. These data segments would then be lost to analysis.

Zig Zag Code

for (shift = limit; shift >= 0; shift--)
            {
                        // Low
                        val = Low[iLowest(NULL, 0, MODE_LOW, ExtDepth, shift)];
                        if (val == lastlow)
                                    val = 0.0;
                        else
                        {
                                    lastlow = val;
                                    if ((Low[shift] - val) > (ExtDeviation*Point))
                                                val = 0.0;
                                    else
                                    {
                                                for (back = 1; back <= ExtBackstep; back++)
                                                {
                                                            res = LowMapBuffer[shift+back];
                                                            if ((res != 0) && (res > val))
                                                                        LowMapBuffer[shift+back] = 0.0;
                                                }
                                    }
                        }
                        if (Low[shift] == val)
                                    LowMapBuffer[shift] = val;
                        else
                                    LowMapBuffer[shift] = 0.0;
                                   
                        // High
                        val = High[iHighest(NULL,0,MODE_HIGH,ExtDepth,shift)];
                        if (val == lasthigh)
                                    val = 0.0;
                        else
                        {
                                    lasthigh = val;
                                    if ((val - High[shift]) > (ExtDeviation*Point)) val = 0.0;
                                    else
                                    {
                                                for (back = 1; back <= ExtBackstep; back++)
                                                {
                                                            res = HighMapBuffer[shift+back];
                                                            if ((res != 0) && (res < val))
                                                                        HighMapBuffer[shift+back] = 0.0;
                                                }
                                    }
                        }
                        if (High[shift] == val)
                                    HighMapBuffer[shift] = val;
                        else
                                    HighMapBuffer[shift] = 0.0;

            }