LINREG_R module routines

Company Information Software Products TDF Market Reports Download Area take me Home

LINREG_R.C - LINear REGression Routines

ANSI C least-squares and best-fit linear regression and time series line regression indicator routines.

Function new_linreg_struct
Include file LINREG_R.H
Prototype LINREG *new_linreg_struct( void )
Remarks Allocate and return a virgin linear regression structure.

Function calc_linreg
Include file LINREG_R.H
Prototype void calc_linreg( LINREG *linreg , int data_max , float *data_ptr )
Remarks Calculate a least-squares linear regression on the supplied data. The parameter data_ptr is a pointer to a data series that is data_max items long. Least-squares regression uses a sequential integer count as the x-axis (or as the independent variable) to generate the projection of the dependent variable (the inputed price series). So this means least squares uses time (or bar periods if you prefer) to project prices.

Function calc_best_fit_linreg
Include file LINREG_R.H
Prototype void calc_best_fit_linreg( LINREG *linreg , int data_max , float *data_ptr_ind , float *data_ptr_dep )
Remarks Calculate a best-fit linear regression on the supplied data. The parameters data_ptr_ind & data_ptr_dep are pointers to data series that are data_max items long. A best-fit linear regression uses one data series as the x-axis (or as the independent variable) to generate the projection of the dependent variable. This means best-fit can be used to project the prices of one series given the past relationship of 2 prices series. For example given the past prices of corn & soybeans - calc the regression, then given a new price for corn you could project a new price for beans.

Function finish_regression_calcs
Include file LINREG_R.H
Prototype void finish_regression_calcs( LINREG *linreg , int data_max , float *data_ptr , double sum_x , double sum_y , double sum_xy , double sum_x_sqed , double sum_y_sqed )
Remarks This routine actually does the regression calcs after the input data has been processed (for both regression styles).

Function calc_new_price_with_linreg
Include file LINREG_R.H
Prototype float calc_new_price_with_linreg( LINREG *linreg , float cur_dep_data )
Remarks Once you have calculated a regression on a data series, use this routine to project the new data from the regression. This routine can use the regression output from either least-squares or best-fit regression. Just pass a bar number as the current dependent data value or pass an actual price for a best_fit projection.

Function detrend_data_series
Include file LINREG_R.H
Prototype void detrend_data_series( int data_cnt , float *data_ptr )
Remarks Use a least-squares regression to remove the trend from a data series.

Function restore_trend_2_data_series
Include file LINREG_R.H
Prototype void restore_trend_2_data_series( LINREG *linreg , int data_cnt , float *data_ptr )
Remarks Use a regression calc to restore the trend to a data series.

Function new_tslr_struct
Include file LINREG_R.H
Prototype TSLR *new_tslr_struct( int tslr_length )
Remarks Allocate, initialize and return a virgin Time Series Linear Regression indicator structure.

Function reset_tslr_struct
Include file LINREG_R.H
Prototype void reset_tslr_struct( TSLR *tslr_ptr )
Remarks Reset a TSLR data structure for a new data series.

Function update_tslr_struct
Include file LINREG_R.H
Prototype void update_tslr_struct( TSLR *tslr_ptr , float data )
Remarks Update the caller's TSLR with the new data. Once we have collected enough data to calc the regression, tslr_ptr->enough_data will be set to TRUE and the tslr var can be used.

Function free_tslr_struct
Include file LINREG_R.H
Prototype void free_tslr_struct( TSLR *tslr_ptr )
Remarks Return the TSLR and its sub-structure memory to the system.

Function new_tslr_ind_struct
Include file LINREG_R.H
Prototype TSLR_IND *new_tslr_ind_struct( int data_cnt )
Remarks Allocate, and return a virgin TSLR indicator display structure for data_cnt items.

Function free_tslr_ind_struct
Include file LINREG_R.H
Prototype void free_tslr_ind_struct( TSLR_IND *tslr_ptr )
Remarks Return the TSLR indicator display structure and its sub-structure memory to the system.

Function calc_tslr_ind
Include file LINREG_R.H
Prototype void calc_tslr_ind( DATA_REC *data_ptr , int data_cnt , int which_field , TSLR_IND *inds , int tslr_length )
Remarks Calculate a Time Series least-squares Linear Regression indicator for the requested field of the DATA_REC data series. The indicators will be built in the caller's TSLR_IND indicator display structure inds.

Table of Contents Function Index

generated on 08 February 1998 - 14:40:42
© 1998 Tierra del Fuego Ltd.