Multiplies all elements of inputVector together, and puts the result into resultVariable. The input vector is left unchanged. See examples at right. If any element of inputVector is a missing value ("." or NaN), the result of the entire command will be NaN. If you want to remove NaNs from your vectors, use the CLEAN command. |
COPY (12 8 10 4 6 2) data PRODUCT data dataProduct PRINT dataProduct The above program produces the following output: dataProduct: 46080.0 You can quickly compute a factorial as this example of the factorial of 10: PRODUCT 1,10 factorial PRINT factorial Here is a more practical example: 'Given the data for the annual change in the NASDAQ index, 'analyze it to estimate the range of gains/losses 'within 1 standard deviation of the mean if you invested '$10000 in the index and held it for 10 years. 'Also, calculate the probabilities of having a gain 'and a loss after 10 years. 'For simplicity, ignore costs, dividends, and inflation. 'Data from: http://www.finfacts.com/Private/curency/nasdaqcompositeperformance.htm 'Annual fractional price change of Nasdaq 1930--2006: COPY (0.1018 0.0173 -0.1733 0.0905 0.2214 \ 0.2390 0.3313 -0.1099 0.0553 -0.0924 0.0702 \ 0.2284 0.1045 0.0138 -0.0248 0.4553 0.1534 \ 0.1135 -0.1850 0.4155 0.0693 -0.0147 0.3166 \ -0.1502 0.2044 0.2312 0.1715 -0.0455 0.2659 \ 0.2577 -0.0236 -0.0984 0.2736 0.1718 -0.3106 \ -0.3511 0.2976 0.2610 0.0733 0.1231 0.2811 \ 0.3388 -0.0321 0.1867 0.1987 -0.1122 0.3115 \ 0.0753 -0.0526 0.1541 0.1926 -0.1780 0.5684 \ 0.1545 0.1475 -0.0320 0.3992 0.2271 0.2164 \ 0.3963 0.8559 -0.3929 -0.2105 -0.3153 0.5001 \ 0.0859 0.0137 -0.0188) nasdaqData NAME 10 numberOfYears NAME 10000 initialInvestment NAME 10000 repeatCount 'Add 1 to the gains to get annual gain factors ADD 1 nasdaqData nasdaqGainFactors REPEAT repeatCount SAMPLE numberOfYears nasdaqGainFactors sampleHistory PRODUCT sampleHistory totalGainFactor MULTIPLY initialInvestment totalGainFactor totalGain SCORE totalGain gains END 'Compute median and 1 std dev below median and 1 above: PERCENTILE gains (15.87 50 84.13) oneStdevRangeOfGains COUNT gains <initialInvestment howManyLosingPeriods COUNT gains >initialInvestment howManyGainingPeriods DIVIDE howManyLosingPeriods repeatCount probabilityOfLoss DIVIDE howManyGainingPeriods repeatCount probabilityOfGain PRINT probabilityOfGain probabilityOfLoss PRINT oneStdevRangeOfGains%8.0F The above program produces the following output: probabilityOfGain: 0.9048 probabilityOfLoss: 0.0952 oneStdevRangeOfGains: (12417 24537 45803) |