/*
 * BaseStats.java
 *
 * Created on November 21, 2007, 1:30 PM
 *
 */

package uc2;

import java.util.*;
import java.math.*;

import uc2.SingleIndexModel.*;

/**
 *
 * @author Alex_Emma
 */
public class BaseStats {
    
    /** Creates a new instance of BaseStats */
    public BaseStats() {
    }
    
    public static double computeExpectedReturn(ArrayList<StockReturn> dataList)
    {
        double total=0.0;
        StockReturn stockRet;
        for(int i = 0; i < dataList.size(); i++) 
        {
            stockRet = (StockReturn) dataList.get(i);
            total+=stockRet.roi;
        }
        return( total/dataList.size() );
    }
        
    public static double computeVariance(ArrayList<StockReturn> dataList) //variance of a single variable with equal likeliehood//
    {
        double sumd=0.0;
        double total=0.0;
        double rvariance=0.0;
        StockReturn stockRet;
        
        for(int i = 0; i < dataList.size(); i++)
        {
            stockRet = (StockReturn) dataList.get(i);
            total += stockRet.roi;
            sumd += Math.pow(stockRet.roi,2); //sum of x sqrd
        }
        total=Math.pow(total,2)/dataList.size();  //sum of [x]sqrd/n
        return ( (sumd-total)/(dataList.size()-1) ); //true value of convergence as length is large//
    }
}