com.fisincorporated.stockanalysis
Class StockAverager

java.lang.Object
  extended bycom.fisincorporated.stockanalysis.StockAverager

public class StockAverager
extends java.lang.Object

Provides static methods for taking a Stock object or stock data and returning moving average, weekly max, mins, etc. A rather eclectic assortment created for use in learning Jess

Author:
Eric Foertsch

Constructor Summary
StockAverager()
           
 
Method Summary
static float[] calcComparativeRelativeStrength(Stock crsStock, Stock baseStock, int start, int numberPoints)
          Calculate Comparitive Relative Strength http://www.marketscreen.com/help/AtoZ/default.asp?
static float[] calcLinearRegression(float[] values, int start, int numberPoints)
          Caculate linear regression of prices (basically used to get slope) Doing the basic Y = mx + b m - slope, b - intercept http://phoenix.phys.clemson.edu/tutorials/excel/regression.html
static float[] calcLinearRegression(long[] values, int start, int numberPoints)
          Caculate linear regression of prices (basically used to get slope) Doing the basic Y = mx + b m - slope, b - intercept http://phoenix.phys.clemson.edu/tutorials/excel/regression.html
static Stock calcMovingAverage(Stock stock, int average)
           
static float[] calcOnBalanceVolume(Stock stock, int start, int numberPoints)
          Calculate a stocks On Balance Volume http://www.marketscreen.com/help/AtoZ/default.asp?
static boolean[] findWeekEndDates(java.lang.String[] dates)
          Determine the last date for each week that stock prices are available.
static Stock getMonthlyHighLowPrices(Stock oldStock, int numberPeriods)
          Return the period open, highest high, lowest low, period close, and total period volume
static float[] getPeriodValues(float[] oldValues, boolean[] datesToUse, int numberPeriods)
          Return an array with values from the passed in array
static float[] getPeriodValues(float[] oldValues, int numberPeriods)
           
static long[] getPeriodValues(long[] oldValues, boolean[] datesToUse, int numberPeriods)
          Return an array with values from the passed in array
static long[] getPeriodValues(long[] oldValues, int numberPeriods)
           
static Stock getPeriodValues(Stock oldStock, char period, int numberPeriods)
          'Summarize' the stock by taking last n periods If the stock passed in has fewer than numberPeriods data points then first (stock.length - numberPeriods) will be zero If the stock passed in has more than numberPeriods data points then only the last 'numberPeriods' data points will be used For a weekly period take the last day in each week.
static java.lang.String[] getPeriodValues(java.lang.String[] oldValues, boolean[] datesToUse, int numberPeriods)
           
static java.lang.String[] getPeriodValues(java.lang.String[] oldValues, int numberPeriods)
           
static Stock getWeeklyHighLowPrices(Stock oldStock, int numberPeriods)
          Return the period open, highest high, lowest low, period close, and total period volume Note that dates/price/volume returned only, all other stock properties unassigned.
static void main(java.lang.String[] args)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StockAverager

public StockAverager()
Method Detail

main

public static void main(java.lang.String[] args)

getPeriodValues

public static Stock getPeriodValues(Stock oldStock,
                                    char period,
                                    int numberPeriods)
                             throws java.lang.Exception
'Summarize' the stock by taking last n periods If the stock passed in has fewer than numberPeriods data points then first (stock.length - numberPeriods) will be zero If the stock passed in has more than numberPeriods data points then only the last 'numberPeriods' data points will be used For a weekly period take the last day in each week.

Parameters:
oldStock - Stock
period - 'd' - daily period, 'w' - weekly period
numberPeriods - Number of periods (daily or weekly) to return
Throws:
java.lang.Exception

getPeriodValues

public static float[] getPeriodValues(float[] oldValues,
                                      boolean[] datesToUse,
                                      int numberPeriods)
Return an array with values from the passed in array

Parameters:
oldValues - old array
datesToUse - if true take corresponding oldValue
numberPeriods - size of new array
Returns:
float[] contained correponding row from oldValues[n] where datsToUse[n] is true

getPeriodValues

public static float[] getPeriodValues(float[] oldValues,
                                      int numberPeriods)
Parameters:
oldValues - array of float
numberPeriods - int number of periods (values) to take starting from oldValues.length - 1 to (oldValues.length - numberPeriods)
Returns:
float[] 'numberPeriods' values from oldValues starting from end of oldValues array

getPeriodValues

public static long[] getPeriodValues(long[] oldValues,
                                     boolean[] datesToUse,
                                     int numberPeriods)
Return an array with values from the passed in array

Parameters:
oldValues - old array
datesToUse - if true take corresponding oldValue
numberPeriods - size of new array
Returns:
long[] contained correponding row from oldValues[n] where datsToUse[n] is true

getPeriodValues

public static long[] getPeriodValues(long[] oldValues,
                                     int numberPeriods)
Parameters:
oldValues - array of long
numberPeriods - int number of periods (values) to take starting from oldValues.length - 1 to (oldValues.length - numberPeriods)
Returns:
long[] 'numberPeriods' values from oldValues starting from end of oldValues array

getPeriodValues

public static java.lang.String[] getPeriodValues(java.lang.String[] oldValues,
                                                 boolean[] datesToUse,
                                                 int numberPeriods)

getPeriodValues

public static java.lang.String[] getPeriodValues(java.lang.String[] oldValues,
                                                 int numberPeriods)

findWeekEndDates

public static boolean[] findWeekEndDates(java.lang.String[] dates)
Determine the last date for each week that stock prices are available.

Parameters:
dates - Dates in ISO format 'YYYY/MM/DD'
Returns:
array of boolean same size as dates[] where boolean[n] true if corresponding date is end of week

getWeeklyHighLowPrices

public static Stock getWeeklyHighLowPrices(Stock oldStock,
                                           int numberPeriods)
Return the period open, highest high, lowest low, period close, and total period volume Note that dates/price/volume returned only, all other stock properties unassigned.

Parameters:
oldStock -
numberPeriods - to return
Returns:
Stock with 'summarized price/volume

getMonthlyHighLowPrices

public static Stock getMonthlyHighLowPrices(Stock oldStock,
                                            int numberPeriods)
Return the period open, highest high, lowest low, period close, and total period volume

Parameters:
oldStock -
numberPeriods - to return
Returns:
Stock

calcMovingAverage

public static Stock calcMovingAverage(Stock stock,
                                      int average)

calcLinearRegression

public static float[] calcLinearRegression(float[] values,
                                           int start,
                                           int numberPoints)
Caculate linear regression of prices (basically used to get slope) Doing the basic Y = mx + b m - slope, b - intercept http://phoenix.phys.clemson.edu/tutorials/excel/regression.html

Parameters:
values - (prices)
start - int Starting point in array of values
numberPoints - int Number points to use in regression
Returns:
float[] [0] - slope, [1] - correlation coefficient

calcLinearRegression

public static float[] calcLinearRegression(long[] values,
                                           int start,
                                           int numberPoints)
Caculate linear regression of prices (basically used to get slope) Doing the basic Y = mx + b m - slope, b - intercept http://phoenix.phys.clemson.edu/tutorials/excel/regression.html

Parameters:
values - (volume)
start - int Starting point in array of values
numberPoints - int Number points to use in regression
Returns:
float[] [0] - slope, [1] - correlation coefficient

calcOnBalanceVolume

public static float[] calcOnBalanceVolume(Stock stock,
                                          int start,
                                          int numberPoints)
Calculate a stocks On Balance Volume http://www.marketscreen.com/help/AtoZ/default.asp?hideHF=&Num=75

Parameters:
stock - Stock object
start - int Starting point (index) into Stock prices volumes
numberPoints - int Number points to use in OBV calc
Returns:
array of results of On Balance Volume calculations [0] is oldest [n] is most recent

calcComparativeRelativeStrength

public static float[] calcComparativeRelativeStrength(Stock crsStock,
                                                      Stock baseStock,
                                                      int start,
                                                      int numberPoints)
Calculate Comparitive Relative Strength http://www.marketscreen.com/help/AtoZ/default.asp?hideHF=&Num=92

Parameters:
crsStock - - Stock for which to calculate relative strength
baseStock - - Stock/index to use as 'base' for CRS calculation
start - - starting point (index) to start calculation
numberPoints - - number of points over which to do calculation
Returns:
- array containing comparative relative strengh calculation