Skip to main content

Self-adaptive Interval Type-2 Fuzzy Set Induced Stock Index Prediction

  • Chapter
  • First Online:
Time-Series Prediction and Applications

Part of the book series: Intelligent Systems Reference Library ((ISRL,volume 127))

  • 2184 Accesses

Abstract

This chapter introduces an alternative approach to time-series prediction for stock index data using Interval Type-2 Fuzzy Sets. The work differs from the existing research on time-series prediction by the following counts. First, partitions of the time-series, obtained by fragmenting its valuation space over disjoint equal sized intervals, are represented by Interval Type-2 Fuzzy Sets (or Type-1 fuzzy sets in absence of sufficient data points in the partitions). Second, an interval type-2 (or type-1) fuzzy reasoning is performed using prediction rules, extracted from the (main factor) time-series. Third, a type-2 (or type-1) centroidal defuzzification is undertaken to determine crisp measure of inferences obtained from the fired rules, and lastly a weighted averaging of the defuzzified outcomes of the fired rules is performed to predict the time-series at the next time point from its current value. Besides the above three main prediction steps, the other issues considered in this chapter include: (i) employing a new strategy to induce the main factor time-series prediction by its secondary factors (other reference time-series), and (ii) self-adaptation of membership functions to properly tune them to capture the sudden changes in the main-factor time-series. Performance analysis undertaken reveals that the proposed prediction algorithm outperforms existing algorithms with respect to root mean-square error by a large margin (≥23%). A statistical analysis undertaken with paired t-test confirms that the proposed method is superior in performance at 95% confidence level to most of the existing techniques with root mean square error as the key metric.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 139.00
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 179.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info
Hardcover Book
USD 179.99
Price excludes VAT (USA)
  • Durable hardcover edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Abbreviations

CSV:

Composite secondary variation

CSVS:

Composite secondary variation series

FOU:

Footprint of uncertainty

IT2:

Interval type-2

IT2FS:

Interval type-2 fuzzy set

IT2MF:

Interval type-2 membership function

MFCP:

Main factor close price

MFTS:

Main factor time-series

MFVS:

Main factor variation series

RMSE:

Root mean square error

SFTS:

Secondary factor time-series

SFVS:

Secondary factor variation series

SFVTS:

Secondary factor variation time-series

T1:

Type-1

T1FS:

Type-1 fuzzy set

VTS:

Variation time-series

\( A_{i,j} \) :

Type-1 fuzzy set for partition \( P_{i} \) of MFTS

\( \tilde{A}_{i} \) :

Interval type-2 fuzzy set for partition \( P_{i} \) in MFTS

\( B_{i} \) :

Classical set for partition \( Q_{i} \) of MFVS

\( B^{\prime}_{i} \) :

Classical set for partition \( Q_{i} \) for SFVS/CSVS

\( c(t) \) :

Close Price on \( t{\text{th}} \) day

\( c_{l} \) :

Left end point centroid of IT2FS

\( c_{r} \) :

Right end point centroid of IT2FS

\( c \) :

Centroid of an IT2FS

c′:

Measured value of \( c\left( t \right) \) in centroid calculation

\( c^{x} \) :

Type-1 centroid of \( \mu_{{A_{x} }} (c(t)) \)

\( m_{A} \) :

Mean values of the distributions of RMSE obtained by algorithms A

\( P_{i} \) :

Ith partition for close price time series (of MFTS)

\( Q_{i} \) :

Ith partition for variation series (of MFVS/SFVS/CSVS)

\( s_{A} \) :

Standard deviation of the respective samples obtained by algorithms A

\( V_{M}^{d} \left( t \right) \) :

Main factor variation series with delay \( d \)

\( V_{{S^{i} }}^{d} \) :

Ith secondary factor variation series with delay \( d \)

\( V_{S}^{d} \left( t \right) \) :

Composite secondary variation series with delay \( d \)

\( W_{{S^{i} }} \) :

Weight for ith secondary factor

\( \mu_{A} (x) \) :

Type-1 membership function of linguistic variable \( x \) in fuzzy set \( A \)

\( \bar{\mu }_{{\tilde{A}}} (x) \) :

Upper membership function of IT2FS \( \tilde{A} \)

\( \underline{\mu }_{{\tilde{A}}} (x) \) :

Lower membership function of IT2FS \( \tilde{A} \)

\( \Delta_{{S^{i} }} \) :

Total difference variation for CSVS of ith secondary factor

\( \hat{\Delta }_{{S^{i} }} \) :

Normalized value of \( \Delta_{{S^{i} }} \) for CSVS of ith secondary factor

References

  1. Engineering Statistic and book [Online]. http://www.itl.nist.gov/div898/handbook/pmc/section4/pmc41.htm

  2. Chen, S. M., & Chen, C. D. (2011). Handling forecasting problems based on high-order fuzzy logical relationships. Expert Systems with Applications, 38(4), 3857–3864.

    Article  Google Scholar 

  3. Chen, S. M., & Tanuwijaya, K. (2011). Fuzzy forecasting based on high-order fuzzy logical relationships and automatic clustering techniques. Expert Systems with Applications, 38(12), 15425–15437.

    Article  Google Scholar 

  4. Wu, C. L., & Chau, K. W. (2013). Prediction of rainfall time series using modular soft computing methods. Elsevier, Engineering Applications of Artificial Intelligence, 26, 997–1007.

    Article  Google Scholar 

  5. Wu, C. L., Chau, K. W., & Fan, C. (2010). Prediction of rainfall time series using modular artificial neural networks coupled with data-preprocessing techniques. Elsevier, Journal of Hydrology, 389(1–2), 146–167.

    Article  Google Scholar 

  6. Barnea, O., Solow, A. R., & Stonea, L. (2006). On fitting a model to a population time series with missing values. Israel Journal Of Ecology & Evolution, 52, 1–10.

    Article  Google Scholar 

  7. Chen, S. M., & Hwang, J. R. (2000). Temperature prediction using fuzzy time series. IEEE Transactions on Systems, Man, and Cybernetics. Part B, Cybernetics, 30(2), 263–275.

    Article  Google Scholar 

  8. Song, Q., & Chissom, B. S. (1993). Fuzzy time series and its model. Fuzzy Sets and Systems, 54(3), 269–277.

    Article  MathSciNet  MATH  Google Scholar 

  9. Song, Q., & Chissom, B. S. (1993). Forecasting enrollments with fuzzy time series—Part I. Fuzzy Sets and Systems, 54(1), 1–9.

    Article  Google Scholar 

  10. Song, Q., & Chissom, B. S. (1994). Forecasting enrollments with fuzzy time series—Part II. Fuzzy Sets and Systems, 62(1), 1–8.

    Article  Google Scholar 

  11. Song, Q. (2003). A note on fuzzy time series model selection with sample autocorrelation functions. Cybernetics &Systems, 34(2), 93–107.

    Article  MATH  Google Scholar 

  12. Jalil, A., & Idrees, M. (2013). Modeling the impact of education on the economic growth: Evidence from aggregated and disaggregated time series data of Pakistan. Elsevier Economic Modelling, 31, 383–388.

    Article  Google Scholar 

  13. Edwards, R. P., Magee, J., & Bassetti, W. H. C. (2007). Technical analysis of Stock Trends, 9th Edition, p. 10. New York, USA: Amacom.

    Book  Google Scholar 

  14. Raynor, W. J., Jr. (1999) The international dictionary of artificial intelligence. IL: Glenlake Publishing.

    Google Scholar 

  15. Mallat, S. (1997). A wavelet tour of signal processing. San diego, CA, USA: Academic Press.

    MATH  Google Scholar 

  16. Bhowmik, P., Das, S., & Konar, A., Nandi, D., & Chakraborty, A. (2010) Emotion clustering from stimulated encephalographic signals using a Duffing Oscillator. International Journal of Computers in Healthcare, 1(1).

    Google Scholar 

  17. Gupta, S. C., & Kapoor, V. K. (2002). Fundamental of mathematical statistics. New Delhi, India: S. Chand & Sons.

    Google Scholar 

  18. Jansen,B. H., Bourne, J. R., Ward, J. W. (1981). Autoregressive estimation of short segment spectra for computerized EEG analysis. IEEE Transactions on Biomedical Engineering, 28(9).

    Google Scholar 

  19. Hjorth, B. (1970). EEG analysis based on time domain properties. Electroencephalography and Clinical Neurophysiology, 29, 306–310.

    Article  Google Scholar 

  20. Sanei, S. (2013) Adaptive processing of brain signals. USA: Wiley.

    Google Scholar 

  21. Chen, S. M. (1996). Forecasting enrollments based on fuzzy time series. Fuzzy Sets and Systems, 81(3), 311–319.

    Article  Google Scholar 

  22. Hwang, J. R., Chen, S. M., & Lee, C. H. (1998). Handling forecasting problems using fuzzy time series. Fuzzy Sets and Systems, 100(1–3), 217–228.

    Article  Google Scholar 

  23. Lee, L. W., Wang, L. H., & Chen, S. M. (2007). Temperature prediction and TAIFEX forecasting based on fuzzy logical relationships and genetic algorithms. Expert Systems with Applications, 33(3), 539–550.

    Article  Google Scholar 

  24. Wong, W. K., Bai, E., Chu, A. W. C. (2010). Adaptive time-variant models for fuzzy-time-series forecasting. IEEE Transaction on Systems, Man, Cybernetics-Part B: Cybernetics, 40(6).

    Google Scholar 

  25. Cheng, C. H., Chen, T. L., Teoh, H. J., & Chiang, C. H. (2008). Fuzzy time-series based on adaptive expectation model for TAIEX forecasting. Elsevier, Expert Systems with Applications, 34, 1126–1132.

    Article  Google Scholar 

  26. Chen, T. L., Cheng, C. H., & Teoh, H. J. (2007). Fuzzy time-series based on Fibonacci sequence for stock price forecasting. Elsevier, Physica A, 380, 377–390.

    Article  Google Scholar 

  27. Huarng, K., & Yu, T. H. K. (2006). The application of neural networks to forecast fuzzy time series. Physica A, 363(2), 481–491.

    Article  Google Scholar 

  28. Yu, T. H. K., & Huarng, K. H. (2010). A neural network-based fuzzy time series model to improve forecasting. Expert Systems with Applications, 37(4), 3366–3372.

    Article  Google Scholar 

  29. Kuo, I. H., Horng, S. J., Kao, T. W., Lin, T. L., Lee, C. L., & Pan, Y. (2009). An improved method for forecasting enrollments based on fuzzy time series and particle swarm optimization. Expert Systems with Applications, 36(3), 6108–6117.

    Article  Google Scholar 

  30. Lu, W., Yang, J., Liu, X., & Pedrycz, W. (2014). The modeling and prediction of time-series based on synergy of high order fuzzy cognitive map and fuzzy c-means clustering. Elsevier, Knowledge Based Systems, 70, 242–255.

    Article  Google Scholar 

  31. Yu, T. H. K., & Huarng, K. H. (2008). A bivariate fuzzy time series model to forecast the TAIEX. Expert Systems with Applications, 34(4), 2945–2952.

    Article  Google Scholar 

  32. Yu, T. H. K., & Huarng, K. H. (2010). Corrigendum to “A bivariate fuzzy time series model to forecast the TAIEX”. Expert Systems with Applications, 37(7), 5529.

    Article  Google Scholar 

  33. Chen, S. M., & Chang, Y. C. (2010). Multi-variable fuzzy forecasting based on fuzzy clustering and fuzzy rule interpolation techniques. Information Sciences, 180(24), 4772–4783.

    Article  MathSciNet  Google Scholar 

  34. Wong,H. L., Tu, Y. H., & Wang, C. C. (2009). An evaluation comparison between multivariate fuzzy time series with traditional time series model for forecasting Taiwan export. In Proceedings of World Congress on Computer Science Engineering, pp. 462–467.

    Google Scholar 

  35. Chen, S. M., & Tanuwijaya, K. (2011). Multivariate fuzzy forecasting based on fuzzy time series and automatic clustering clustering techniques. Expert Systems with Applications, 38(8), 10594–10605.

    Article  Google Scholar 

  36. Huarng, K., Yu, H. K., & Hsu, Y. W. (2007). A multivariate heuristic model for fuzzy time-series forecasting. IEEE Transactions on Systems, Man, and Cybernetics. Part B, Cybernetics, 37(4), 836–846.

    Article  Google Scholar 

  37. Sun, B. Q., Guo, H., Karimi, H. R., Ge, Y., Xiong, S. (2015). Prediction of stock index futures prices based on fuzzy sets and multivariate fuzzy time series. Neurocomputing, Elsevier, 151, 1528–1536.

    Google Scholar 

  38. Chen, T. L., Cheng, C. H., & Teoh, H. J. (2008). High-order fuzzy time-series based on multi-period adaptation model for forecasting stock markets. Elsevier, Physica A, 387, 876–888.

    Article  Google Scholar 

  39. Zadeh, L. A. (1965). Fuzzy sets. Information and Control, 8, 338–353.

    Article  MathSciNet  MATH  Google Scholar 

  40. Zhang, W. (1992). Applications engineer, Aptronics Incorporated, Copyright © by Aptronix Inc.

    Google Scholar 

  41. Virkhareg, N., & Jasutkar, R. W. (2014) Neuro-fuzzy controller based washing machine. International Journal of Engineering Science Invention, 3, 48–51.

    Google Scholar 

  42. Konstantinidis, K., Gasteratos, A., & Andreadis, I. (2005). Image retrieval based on fuzzy color histogram processing. Elsevier, Optics Communications, 248, 375–386.

    Article  Google Scholar 

  43. Halder, A., Konar, A., Mandal, R., Chakraborty, A., Bhowmik, P., Pal, N. R., et al., (2013) General and interval type-2 fuzzy face-space approach to emotion recognition. IEEE Transactions On Systems, Man, And Cybernetics: Systems, 43(3).

    Google Scholar 

  44. Karnik, N. N., & Mendel, J. M. (1999). Applications of type-2 fuzzy logic systems to forecasting of time-series. Elsevier, Information Sciences, 120, 89–111.

    Article  MATH  Google Scholar 

  45. Huarng, K., & Yu, H. K. (2005). A type 2 fuzzy time series model for stock index forecasting. Physica A, 353, 445–462.

    Article  Google Scholar 

  46. Bajestani, N. S., & Zare, A. (2011). Forecasting TAIEX using improved type 2 fuzzy time series. Expert Systems with Applications, 38(5), 5816–5821.

    Article  Google Scholar 

  47. Chen, S. M., & Chen, C. D. (2011). TAIEX forecasting based on fuzzy time series and fuzzy variation groups. IEEE Transactions on Fuzzy Systems, 19(1), 1–12.

    Article  MathSciNet  Google Scholar 

  48. Mendel, J. M., & Wu, D. (2010). Perceptual computing: Aiding people in making subjective judgements. Hoboken, NJ: IEEE-Wiley press.

    Book  Google Scholar 

  49. Chakraborty, S., Konar, A., Ralescu, A., & Pal, N. R. (2015). A fast algorithm to compute precise type-2 centroids for real time control applications. IEEE Transaction on Cybernetics, 45(2), 340–353.

    Article  Google Scholar 

  50. Chen,S. M., Chu, H. P., Sheu, T. W. (2012). TAIEX forecasting using fuzzy time series and automatically generated weights of multiple factors. IEEE Transaction on Systems, Man, and Cybernetics-Part A: Systems and Humans, 42(6), 1485–1495.

    Google Scholar 

  51. Mendel,J. M., Hagras, H., Tan, W. W., Melek, W. W., & Ying, H. (2014) Introduction to type-2 fuzzy logic control: Theory and applications. USA: IEEE-Wiley Press.

    Google Scholar 

  52. Nilsson, N. J. (1980). Principles ofartificial intelligence. CA: Morgan Kaufmann.

    Google Scholar 

  53. Web Link: http://www.computationalintelligence.net/ieee_cyb/index_prediction_appendix1.pdf

  54. Garibaldi,J. M. (2010). Alternative forms of non-standard fuzzy sets: A discussion chapter. In Proceedings of Type-2 Fuzzy Logic: State of the Art and Future Directions, London.

    Google Scholar 

  55. Wu, D. (2011). A constraint representation theorem for interval type-2 fuzzy sets using convex and normal embedded type-1 fuzzy sets, and its application to centroid computation. In Proceedings of World Conference on Soft Computing, San Francisco, CA.

    Google Scholar 

  56. Web Link for historical Data TAIEX. [Online]. Available: http://www.twse.com.tw/en/products/indices/tsec/taiex.php

  57. Storn, R., & Price, K. G. (1997). Differential Evolution- a simple and efficient heuristic for global optimization over continuous spaces. Journal of Global Optimization, 11(4), 341–359.

    Article  MathSciNet  MATH  Google Scholar 

  58. Das, S., & Suganthan, P. N. (2011) Differential evolution: A survey of the state-of-the-art. IEEE Transaction on Evolutionary Computation, 15(1), 4–31.

    Google Scholar 

  59. Chen, S. M., Kao, P.-Y. (2013). TAIEX forecasting based on time series, particle swarm optimization techniques and support vector machines. Information Science, Elsevier, 247, 62–71.

    Google Scholar 

  60. Cai, Q., Zhang, D., Zheng, W., & Leung, S. C. H. (2015). A new fuzzy time series forecasting model combined with ant colony optimization and auto-regression. Knowledge-Based Systems, 74, 61–68.

    Article  Google Scholar 

  61. Chen, Mu-Yen. (2014). A high-order fuzzy time series forecasting model for internet stock trading. Future Generation Computer Systems Elsevier, 37, 461–467.

    Article  Google Scholar 

  62. Gardner, E., & McKenzie, E. (1989). Seasonal exponential smoothing with damped trends. Management Science, 35(3), 372–376.

    Article  MATH  Google Scholar 

  63. Kuremoto, T., Kimura, S., Kobayashi, K., & Obayashi, M. (2014). Time series forecasting using a deep beliefnetwork with restricted boltzmann machines (online open access). Neurocomputing, 137(5), 47–56.

    Article  Google Scholar 

  64. Yildiz,O. T. (2013) Omnivariate rule induction using a novel pairwise statistical test. IEEE Transactions On Knowledge And Data Engineering, 25(9).

    Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Amit Konar .

Appendices

Appendix 2.1

See Tables 2.6, 2.7, 2.8, 2.9, 2.10, 2.11, 2.12 and 2.13.

Appendix 2.2: Source Codes of the Programs

  • % MATLAB Source Code of the Main Program and Other Functions for Time

  • % Series Prediction by IT2FS REasoning

    • % Developed by Monalisa Pal

  • % Under the guidance of Amit Konar and Diptendu Bhattacharya

% Main Program %______________________________________________________________ clear all; clc; str=input(‘Data file having Main Factor:’); load(str); closeMF=close; n=input(‘Number of secondary factors:’); n=str2double(n); SF=zeros(length(closeMF),n); for i=1:n     strSF=input([‘Data file having ’,num2str(i),’-th     Secondary Factor:’]);     load(strSF);     SF(:,i)=close; end clear close; tic; %% Training [A,B,VarMF,Au,Al]=partitioning(closeMF); plotpartitions(closeMF(s:e1),A(s:e1),Al,Au); FLRG=tableVI(B(2:e1),A(1:e1-1),A(2:e1)); VarSF=overallvar(VarMF,SF,e1,n); BSF=fuzzyvarSF(VarSF); FVG=tableIX(B(2:e1),BSF(2:e1)); WBS=tableX(FVG); %% Validation (Differential Evolution) sd=extractSD(A(s:e1),closeMF(s:e1)); [UMF,LMF,typeMF,rmse]=MFusingDE(A(s:e1),closeMF(s:e1), Al:Au-1,sd,closeMF(e1+1:e2),A(e1:e2),FLRG,WBS,BSF(e1:e2)); plotDE(rmse); plotFOU(UMF,LMF,Al:Au-1); %% Inference forecasted=predict(closeMF(e2+1:f),A(e2:f),Al,Au,UMF,LMF,typeMF, FLRG,WBS,BSF(e2:f)); [CFE,ME,MSE,RMSE,SD,MAD,MAPE]= errormetrics(forecasted,closeMF(e2+1:f)); disp(‘CFE’);disp(CFE); disp(‘ME’);disp(ME); disp(‘MSE’);disp(MSE); disp(‘RMSE’);disp(RMSE); disp(‘SD’);disp(SD); disp(‘MAD’);disp(MAD); disp(‘MAPE’);disp(MAPE); plotforecasted(forecasted,closeMF(e2+1:f),RMSE); comp_time=toc; disp(‘Execution Time’);disp(comp_time); %End of Main Program

% Function KMmethod to compute IT2FS Centroid %____________________________________________

function centroid=KMmethod(LMF,UMF,x)

diff=ones(1,length(x))*5000; for i=1:length(x)     if UMF(i)>0         theta(i,:)=[UMF(1:i) LMF(i+1:length(LMF))];         centroid(i)=defuzz(x,theta(i,:),’centroid’);         diff(i)=abs(x(i)−centroid(i));     end end [mindiff sw_index]=min(diff); cl=x(sw_index); theta_l=[UMF(1:sw_index) LMF(sw_index+1:length(LMF))];

diff=ones(1,length(x))*5000; for i=1:length(x);     if  i<length(x)          if UMF(i+1)>0             theta(i,:)=[LMF(1:i) UMF(i+1:length(LMF))];             centroid(i)=defuzz(x,theta(i,:),’centroid’);             diff(i)=abs(x(i)−centroid(i));         end     end end; [mindiff sw_index]=min(diff); cr=x(sw_index); theta_r=[LMF(1:sw_index) UMF(sw_index+1:length(LMF))];

centroid=(cl+cr)/2; end % End of functiom KMmethod 

%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Error Metric Calculation

function [CFE,ME,MSE,RMSE,SD,MAD,MAPE]=errormetrics(predicted,TestCP) % a=isnan(predicted1); % p=size(TestCP1); % z=1; % for i=1:p %     if a(i)~=1 %         predicted(z)=predicted1(i); %         TestCP(z)=TestCP1(i);z=z+1; %     end % end     CFE=sum(TestCP−predicted); %     disp(‘CFE=‘); %     disp(CFE);     ME=mean(TestCP−predicted); %     disp(‘ME=‘); %     disp(ME);     MSE=mean((TestCP−predicted).^2); %     disp(‘MSE=‘); %     disp(MSE);     RMSE=sqrt(MSE); %     disp(‘RMSE=‘); %     disp(RMSE);     SD=std(TestCP−predicted); %     disp(‘SD=‘); %     disp(SD);     MAD=mean(abs(TestCP−predicted)); %     disp(‘MAD=‘); %     disp(MAD);     MAPE=mean(abs(TestCP−predicted)./TestCP)*100; %     disp(‘MAPE=‘); %     disp(MAPE); End

%%%%%%%%%%%%%%%%% % RMSE calculation

function rmse=evalfit(x,TestCP,TestA,UMF,LMF,typeMF,FLRG,WBS,TestB)     Al=x(1);     Au=x(end)+1;       forecasted=predict(TestCP,TestA,Al,Au,UMF,LMF,typeMF,FLRG,WBS,TestB);     [~,~,~,rmse,~,~,~]=errormetrics(forecasted,TestCP); End

%%%%%%%%%%%%%%%%%%

% Find Standard Deviations(SD)

function sd=extractSD(A,close)     numFS=unique(A); % converting the close series into a matrix     FS=zeros(length(numFS),length(close));     for i=1:length(A)         FS(A(i),i)=close(i);     end     b=1;     for i=1:size(FS,1)         temp=find(FS(i,:));         %Case2: Partition has one point         if length(temp)==1             sd(b)=0.001; %             flag(b)=2;             b=b+1;         %Case3: Partition has two points         elseif length(temp)==2             sd(b)=std(close(temp)); %             flag(b)=3;             b=b+1;         %Case 1 and 4: More than 2 contiguous or discrete points         else             indx=zeros(length(temp),1);             l=1;             for j=2:length(temp)  %contiguous points have been labelled sequentially                 if (temp(j)−temp(j−1))==1                     indx(j−1)=l;                     indx(j)=l;                 elseif j>2 && (temp(j−1)−temp(j−2))==1 && (temp(j)−temp(j−1))~=1                     l=l+1;                 end             end             if max(indx)==0                 sd(b)=std(close(temp)); %                 flag(b)=4;                 b=b+1;             else                 for j=1:max(indx)                     temp1=temp(indx==j); % selecting days where the contiguous points occur                      tempsd=std(close(temp1)); %                     if tempsd>=1                         sd(b)=tempsd; %                         flag(b)=1;                         b=b+1; %                     end                 end             end         end     end end %%%%%%%%%%%%%%%%% % Forming Membership Functions(MFs)

function [UMF,LMF,typeMF]=formingMF(A,close,x,sd)     numFS=unique(A); % converting the close series into a matrix     FS=zeros(length(numFS),length(close));     for i=1:length(A)         FS(A(i),i)=close(i);     end     b=1;     UMF=zeros(length(numFS),length(x));     LMF=ones(length(numFS),length(x));     typeMF=zeros(length(numFS),1);     for i=1:size(FS,1)         temp=find(FS(i,:));         %Case2: Partition has one point         if length(temp)==1             m=round(close(temp));             typeMF(i)=1;             UMF(i,:)=max(UMF(i,:),trimf(x,[m−3*sd(b) m m+3*sd(b)]));             LMF(i,:)=min(LMF(i,:),trimf(x,[m−3*sd(b) m m+3*sd(b)]));             b=b+1;

        %Case3: Partition has two points         elseif length(temp)==2             m=round(mean(close(temp)));             typeMF(i)=1;                         UMF(i,:)=max(UMF(i,:),trimf(x,[m−3*sd(b) m m+3*sd(b)]));             LMF(i,:)=min(LMF(i,:),trimf(x,[m−3*sd(b) m m+3*sd(b)]));             b=b+1;         %Case 1 and 4: More than 2 contiguous or discrete points         else             indx=zeros(length(temp),1);             l=1;             for j=2:length(temp)  %contiguous points have been labelled sequentially                 if (temp(j)−temp(j−1))==1                     indx(j−1)=l;                     indx(j)=l;                 elseif j>2 && (temp(j−1)−temp(j−2))==1 && (temp(j)−temp(j−1))~=1                     l=l+1;                 end             end             if max(indx)==0                 m=round(mean(close(temp)));                 typeMF(i)=1;                 UMF(i,:)=max(UMF(i,:),trimf(x,[m−3*sd(b) m m+3*sd(b)]));                 LMF(i,:)=min(LMF(i,:),trimf(x,[m−3*sd(b) m m+3*sd(b)]));                 b=b+1;             else %                 c=0;                 for j=1:max(indx)                     temp1=temp(indx==j); % selecting days where the contiguous points occur                      m=round(mean(close(temp1))); %                     if sd>=1                         UMF(i,:)=max(UMF(i,:),trimf(x,[m−3*sd(b) m m+3*sd(b)]));                         LMF(i,:)=min(LMF(i,:),trimf(x,[m−3*sd(b) m m+3*sd(b)]));                         b=b+1; %                         c=c+1; %                     end                 end %                 if c==1 %                     typeMF(i)=1; %                 else                     typeMF(i)=2; %                 end             end         end     end     %Ensuring flat top     loc1=0;loc2=0;     for i=1:size(UMF,1)         for j=1:1:size(UMF,2)             if UMF(i,j)>0.999                 loc1=j;                 break;             end         end         if j~=size(UMF,2)             for j=size(UMF,2):−1:1                 if UMF(i,j)>0.999                     loc2=j;                     break;                 end             end         end         if loc1~=0             UMF(i,loc1:loc2)=1;         end     end end %%%%%%%%%%%%%%%%%%%%%%% % Gaussian MF Creation

function [UMF,LMF,typeMF]=formingMF(A,close,x,sd)     numFS=unique(A); % converting the close series into a matrix     FS=zeros(length(numFS),length(close));     for i=1:length(A)         FS(A(i),i)=close(i);     end     b=1;     UMF=zeros(length(numFS),length(x));     LMF=ones(length(numFS),length(x));     typeMF=zeros(length(numFS),1);     for i=1:size(FS,1)         temp=find(FS(i,:));         %Case2: Partition has one point         if length(temp)==1             m=round(close(temp));             typeMF(i)=1;             UMF(i,:)=max(UMF(i,:),gaussmf(x,[sd(b) m]));             LMF(i,:)=min(LMF(i,:),gaussmf(x,[sd(b) m]));             b=b+1;

        %Case3: Partition has two points         elseif length(temp)==2             m=round(mean(close(temp)));             typeMF(i)=1;                         UMF(i,:)=max(UMF(i,:),gaussmf(x,[sd(b) m]));             LMF(i,:)=min(LMF(i,:),gaussmf(x,[sd(b) m]));             b=b+1;         %Case 1 and 4: More than 2 contiguous or discrete points         else             indx=zeros(length(temp),1);             l=1;             for j=2:length(temp)  %contiguous points have been labelled sequentially                 if (temp(j)−temp(j−1))==1                     indx(j−1)=l;                     indx(j)=l;                 elseif j>2 && (temp(j−1)−temp(j−2))==1 && (temp(j)−temp(j−1))~=1                     l=l+1;                 end             end             if max(indx)==0                 m=round(mean(close(temp)));                 typeMF(i)=1;                 UMF(i,:)=max(UMF(i,:),gaussmf(x,[sd(b) m]));                 LMF(i,:)=min(LMF(i,:),gaussmf(x,[sd(b) m]));                 b=b+1;             else %                 c=0;                 for j=1:max(indx)                     temp1=temp(indx==j); % selecting days where the contiguous points occur                      m=round(mean(close(temp1))); %                     if sd>=1                         UMF(i,:)=max(UMF(i,:),gaussmf(x,[sd(b) m]));                         LMF(i,:)=min(LMF(i,:),gaussmf(x,[sd(b) m]));                         b=b+1; %                         c=c+1; %                     end                 end %                 if c==1 %                     typeMF(i)=1; %                 else                     typeMF(i)=2; %                 end             end         end     end     %Ensuring flat top     loc1=0;loc2=0;     for i=1:size(UMF,1)         for j=1:1:size(UMF,2)             if UMF(i,j)>0.999                 loc1=j;                 break;             end         end         if j~=size(UMF,2)             for j=size(UMF,2):−1:1                 if UMF(i,j)>0.999                     loc2=j;                     break;                 end             end         end         if loc1~=0             UMF(i,loc1:loc2)=1;         end     end end %%%%%%%%%%%%%%% % FUZZY Secondary Factor Variation

function BSF=fuzzyvarSF(VarSF) BSF=zeros(length(VarSF),1); for i=2:length(VarSF)     for j=1:14         if VarSF(i)<−6             BSF(i)=1;         elseif VarSF(i)>=6             BSF(i)=14;         elseif VarSF(i)>=(j−1)−6 && VarSF(i)<j−6             BSF(i)=j+1;         end     end end end

%%%%%%%%%%%%%%%%%%%%%%%%%%% %% MF Using DE

function [UMF,LMF,typeMF,rmse]=MFusingDE(A,close,x,sd,TestCP,TestA,FLRG,WBS,TestB)     genmax=50;     F=0.2; % Scale Factor     Cr=0.9; % Cross−over probability     NP=20; % no. of population members     gen=1;     %% Initialization     Zmin=ones(1,length(sd))*0.1;     Zmax=sd;     Z=zeros(NP,length(sd));     for i=1:NP         Z(i,:)=Zmin+rand*(Zmax−Zmin);     end     %%     rmse=zeros(genmax,NP);     while(gen<=genmax)         disp(‘Gen=‘);         disp(gen);         %% Mutation         V=zeros(NP,length(sd));         for i=1:NP             j=datasample(1:NP,1);             while j==i                 j=datasample(1:NP,1);             end             k=datasample(1:NP,1);             while k==i || k==j                 k=datasample(1:NP,1);             end             l=datasample(1:NP,1);             while l==i || l==j || l==k                 l=datasample(1:NP,1);             end             V(i,:)=Z(j,:)+F.*(Z(k,:)−Z(l,:));             for j=1:length(sd) % Ensuring V(i,j) is within Zmax and Zmin                 if V(i,j)<Zmin(j)                     V(i,j)=Zmin(j);                 elseif V(i,j)>Zmax(j)                     V(i,j)=Zmax(j);                 end             end         end         %% Crossover         U=zeros(NP,length(sd));         for i=1:NP             for j=1:length(sd)                 if rand<=Cr                     U(i,j)=V(i,j);                 else                     U(i,j)=Z(i,j);                 end             end         end         %% Selection         for i=1:NP         [UMFu,LMFu,typeMFu]=formingMF(A,close,x,U(i,:));         [UMFz,LMFz,typeMFz]=formingMF(A,close,x,Z(i,:));             if evalfit(x,TestCP,TestA,UMFu,LMFu,typeMFu,FLRG,WBS…                     ,TestB)<evalfit(x,TestCP,TestA,UMFz,LMFz,typeMFz…                     ,FLRG,WBS,TestB)                 Z(i,:)=U(i,:);             end         end         %% Storing fitness over generations         for i=1:NP             [UMFz,LMFz,typeMFz]=formingMF(A,close,x,Z(i,:));             rmse(gen,i)=evalfit(x,TestCP,TestA,UMFz,LMFz,typeMFz…                 ,FLRG,WBS,TestB);         end         %%         gen=gen+1;     end     [~,indx]=min(rmse(genmax,:));     [UMF,LMF,typeMF]=formingMF(A,close,x,Z(indx,:)); End %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% Over All Variation

function VarSF=overallvar(VarMF,SF,e,n)     %     VarSF1=zeros(size(SF,1),n);     for i=1:n         for j=2:size(SF,1)             VarSF1(j,i)=(SF(j,i)−SF(j−1,i))*100/SF(j−1,i);         end     end     %     %     tempDiffer=zeros(e,n);     for i=1:n         for j=3:e             tempDiffer(j,i)=abs(VarSF1(j−1,i)−VarMF(j));         end     end     DifferSF=sum(tempDiffer);     %     %     WVSF=zeros(1,n);     for i=1:n         WVSF(i)=sum(DifferSF)/DifferSF(i);     end     %     %     WSF=zeros(1,n);     for i=1:n         WSF(i)=WVSF(i)/sum(WVSF);     end     %     %     VarSF=zeros(1,size(SF,1));     for i=1:size(SF,1)         VarSF(i)=sum(VarSF1(i,:).*WSF);     end     % End %%%%%%%%%%%%%%%%%%%%%%%%%% %% Partitioning The Universe of Discourse(UOD)

function [A,B,Var,Au,Al]=partitioning(CP) %% A=zeros(length(CP),1); B=zeros(length(CP),1); Var=zeros(length(CP),1); %% templ=min(CP); tempu=max(CP);

if (roundn(templ,2)−templ)>0     Al=roundn(templ,2)−100; else     Al=roundn(templ,2); end

% if (roundn(tempu,2)−tempu)>0 %     Au=roundn(tempu,2); % else %     Au=roundn(tempu,2)+200; % end Au=Al; while(1)     Au=Au+200;     if Au>tempu         break;     end end

nFS=(Au–Al)/200;

for i=1:length(CP) %partioning the close series of main factor     for j=1:nFS         if CP(i)>=(j−1)*200+Al && CP(i)<j*200+Al             A(i,1)=j;             break;         end     end end %% for i=2:length(CP) % finding the var series         Var(i)=(CP(i)−CP(i−1))*100/CP(i−1); end

for i=2:length(Var) % partioning the var series     for j=1:14         if Var(i)<−6             B(i)=1;         elseif Var(i)>=6             B(i)=14;         elseif Var(i)>=(j−1)−6 && Var(i)<j−6             B(i)=j+1;         end     end end end %%%%%%%%%%%%%%%%%%%%%% %% Plot RMSE with adaptation

function plotDE(rmse)     figure,plot(1:size(rmse,1),min(rmse,[],2),’kx−’,’MarkerSize’,5);     xlabel(‘Generations −−>‘);     ylabel(‘RMSE −−>‘);     title(‘Evolving parameters to minimize RMSE’); end %%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% Plot Forecasted Price

function plotforecasted(predicted,TestCP,RMSE) figure, subplot(3,2,[1 2 3 4]); plot(TestCP,’k*:’); hold on plot(predicted,’ko−’); ylabel(‘Close Price’); axis([0 length(TestCP)+5 min(min(predicted),min(TestCP))−1000 max(max(predicted),max(TestCP))+1000]); hold off legend(‘Actual’,’Predicted’,’location’,’SouthEast’); subplot(3,2,[5 6]); stem(TestCP−predicted,’ko−’); text(27,max(TestCP−predicted)+50,{‘RMSE=‘,RMSE}); axis([0 length(TestCP) min(TestCP−predicted) max(TestCP−predicted)+150]); xlabel(‘Testing days’); ylabel(‘Error’); end %%%%%%%%%%%%%%%%%%%%%% %% Plot FOU(Foot Print of Uncertainity)

function plotFOU(UMF,LMF,x)     for i=1:size(UMF,1)         figure,shadedplot(x,LMF(i,:),UMF(i,:),[0.8 0.8 0.8]);         xlabel(‘Close’);         ylabel(‘Membership values’);         title([‘FOU for fuzzy set A’, num2str(i)]);     end end %%%%%%%%%%%%%%%%%%%%%%%%%%%% %% Plot Partitions

function plotpartitions(close,A,Al,Au)     numFS=unique(A);  % converting the close series into a matrix     FS=zeros(length(numFS),length(close));     for i=1:length(A)         FS(A(i),i)=close(i);     end

    % Plot Input Close     plot(close,’k*−’);     hold on;     for i=1:length(numFS)         part=Al+(i−1)*200;         plot([1 length(close)],[part part],’k:’);         hold on;     end     hold off;     axis([1 length(close) Al Au]);     xlabel(‘Training days’);     ylabel(‘Close’);     title(‘Fuzzifying training data’);     % End %%%%%%%%%%%%%%%%%%% %% PredictionFunction

function forecasted=predict(TestCP,A,Al,Au,UMF,LMF,typeMF,FLRG,WBS,B x=Al:Au−1; AB=horzcat(A,B); forecasted=zeros(length(TestCP),1); for i=2:size(AB,1)     a=AB(i−1,1);     b=AB(i−1,2);     consequent=find(FLRG(a,:,b));     centroid=zeros(1,size(FLRG,1));     if isempty(consequent)         if typeMF(a)==1             forecasted(i−1)=sum(x.*UMF(a,:))/sum(UMF(a,:));         elseif typeMF(a)==2             avgMF=(LMF(a,:)+UMF(a,:))/2;             forecasted(i−1)=sum(x.*avgMF)/sum(avgMF); %             forecasted(i−1)=KMmethod(LMF(a,:),UMF(a,:),x);         end     else         %SF1=0;SF2=0;SF3=0;         NF=0;         for j=1:length(consequent)             %Case1: a=T1FS, consequent(j)=T1FS             if typeMF(a)==1 && typeMF(consequent(j))==1                 predy=interp1(x,UMF(a,:),TestCP(i−1),’linear’,’extrap’);                 temp=ones(1,length(x))*predy;                 projMF=min(temp,UMF(consequent(j),:));                 centroid(consequent(j))=sum(x.*projMF)/sum(projMF);             %Case2: a=T1FS, consequent(j)=IT2FS             elseif typeMF(a)==1 && typeMF(consequent(j))==2                 predy=interp1(x,UMF(a,:),TestCP(i−1),’linear’,’extrap’);                 temp=ones(1,length(x))*predy;                 projUMF=min(temp,UMF(consequent(j),:));                 projLMF=min(temp,LMF(consequent(j),:));                 avgMF=(projLMF+projUMF)/2;                 centroid(consequent(j))=sum(x.*avgMF)/sum(avgMF); %                 centroid(consequent(j))=KMmethod(projLMF,projUMF,x);             %Case3: a=IT2FS, consequent(j)=T1FS             elseif typeMF(a)==2 && typeMF(consequent(j))==1                 predU=interp1(x,UMF(a,:),TestCP(i−1),’linear’,’extrap’); %                 predL=interp1(x,LMF(a,:),TestCP(i−1),’linear’,’extrap’);                 temp=ones(1,length(x))*predU;                 projMF=min(temp,UMF(consequent(j),:));                 centroid(consequent(j))=sum(x.*projMF)/sum(projMF);             %Case4: a=IT2FS, consequent(j)=IT2FS             elseif typeMF(a)==2 && typeMF(consequent(j))==2                 predU=interp1(x,UMF(a,:),TestCP(i−1),’linear’,’extrap’);                 predL=interp1(x,LMF(a,:),TestCP(i−1),’linear’,’extrap’);                 tempU=ones(1,length(x))*predU;                 tempL=ones(1,length(x))*predL;                 projUMF=min(tempU,UMF(consequent(j),:));                 projLMF=min(tempL,LMF(consequent(j),:));                 avgMF=(projLMF+projUMF)/2;                 centroid(consequent(j))=sum(x.*avgMF)/sum(avgMF); %                 centroid(consequent(j))=KMmethod(projLMF,projUMF,x);             end             if j<a                 forecasted(i−1)=forecasted(i−1)+centroid(consequent(j))*FLRG(a,consequent(j),b)*WBS(b,1);             elseif j==a                 forecasted(i−1)=forecasted(i−1)+centroid(consequent(j))*FLRG(a,consequent(j),b)*WBS(b,2);             else                 forecasted(i−1)=forecasted(i−1)+centroid(consequent(j))*FLRG(a,consequent(j),b)*WBS(b,3);             end         end         for j=1:length(consequent)             if j<a                 NF=NF+FLRG(a,consequent(j),b)*WBS(b,1);             elseif j==a                 NF=NF+FLRG(a,consequent(j),b)*WBS(b,2);             else                 NF=NF+FLRG(a,consequent(j),b)*WBS(b,3);             end         end         forecasted(i−1)=forecasted(i−1)/NF;     end end end %%%%%%%%%%%%%%%%%%%%%%%%%%% %% Shade Plot

function [ha hb hc] = shadedplot(x, y1, y2, varargin) y = [y1; (y2−y1)]’;  ha = area(x, y); set(ha(1), ’FaceColor’, ’none’) % this makes the bottom area invisible set(ha, ’LineStyle’, ’none’)

% plot the line edges hold on  hb = plot(x, y1, ’k’, ’LineWidth’, 2); hc = plot(x, y2, ’k’, ’LineWidth’, 2); hold off

% set the line and area colors if they are specified switch length(varargin)     case 0     case 1         set(ha(2), ’FaceColor’, varargin{1})     case 2         set(ha(2), ’FaceColor’, varargin{1})         set(hb, ’Color’, varargin{2})         set(hc, ’Color’, varargin{2})     otherwise end

% put the grid on top of the colored area set(gca, ’Layer’, ’top’) %%%%%%%%%%%%%%%%%%%%%%%%%%% %% Table IX

function FVG=tableIX(B_MF,B_SF)     FVG=zeros(14,14);     temp=zeros(14,14);     for t=2:length(B_MF)         Bx=B_MF(t);         Bz=B_SF(t−1);         temp(Bz,Bx)=1;         FVG=FVG+temp;         temp=zeros(14,14);     end end %%%%%%%%%%%%%%%%%%%%%%% %% TableVI

function FLRG=tableVI(B,fromA,toA)     endA=max([max(fromA),max(toA)]);     FLRG=zeros(endA,endA,14);

    temp=zeros(endA,endA,14);     for i=1:length(B)         temp(fromA(i),toA(i),B(i))=1;         FLRG=FLRG+temp;         temp=zeros(endA,endA,14);     end end %%%%%%%%%%%%%%%%%%%%%% %% Table X

function BS=tableX(FVG)     BS=zeros(14,3);

    for i=1:14         if sum(FVG(i,:))~=0             BS(i,1)=sum(FVG(i,1:i−1))/sum(FVG(i,:));             BS(i,2)=FVG(i,i)/sum(FVG(i,:));             BS(i,3)=sum(FVG(i,i+1:14))/sum(FVG(i,:));         end     end end %%%%%%%%%%%%%%%%%%

How to run the program with workspace construction in MATLAB is available in the url: http://computationalintelligence.net/fuzzytimeseries/howtorun.pdf.

Rights and permissions

Reprints and permissions

Copyright information

© 2017 Springer International Publishing Switzerland

About this chapter

Cite this chapter

Konar, A., Bhattacharya, D. (2017). Self-adaptive Interval Type-2 Fuzzy Set Induced Stock Index Prediction. In: Time-Series Prediction and Applications. Intelligent Systems Reference Library, vol 127. Springer, Cham. https://doi.org/10.1007/978-3-319-54597-4_2

Download citation

  • DOI: https://doi.org/10.1007/978-3-319-54597-4_2

  • Published:

  • Publisher Name: Springer, Cham

  • Print ISBN: 978-3-319-54596-7

  • Online ISBN: 978-3-319-54597-4

  • eBook Packages: EngineeringEngineering (R0)

Publish with us

Policies and ethics