}//constructor #endregion Constructors, Initialization & Destructor #region Methods #region Data initialization private void initDataVariables() { // Initializes data variables - to check if recalculation is necessary m_enFrequency = cProperties.Frequency; m_drRange = new cDateRange(m_objRelevantSec.DateRange.StartDate, m_objRelevantSec.DateRange.EndDate); //if (m_dtMainRates != null) m_dtMainRates.Clear(); //m_dtMainRates = new List<Rate>(); }//initDataVariables
}//getClosestDateRowIndex private static DateTime getNextDate(DateTime dtCurr, enumDateFreq enCalcFreq) { // retrieves the next date available based on the selected frequency TimeSpan tsPeriod = new TimeSpan(4, 12, 0, 0) + new TimeSpan(2, 12, 0, 0); // one week DateTime dtFinal = dtCurr; switch (enCalcFreq) { case enumDateFreq.Daily: return(dtFinal.AddDays(-1)); case enumDateFreq.Weekly: return(dtFinal - tsPeriod); } return(dtFinal); }//getNextDate
} //calculatePriceReturns public static void calculatePriceReturns(List <Entities.dbo.Price> dtPrices, ref List <Rate> dtOut, cDateRange cDrCalc, enumDateFreq enCalcFreq, int iPosStart, int iPosEnd, String idSec, String strSymbol) { // Calculates price returns for the given table of prices DateTime dtCurrent = DateTime.Now, dtNextVal; int iNextIndex = 0; for (int iRows = iPosStart; iRows <= iPosEnd;) { // Goes through prices backwards dtCurrent = dtPrices[iRows].dDate; if ((dtCurrent < cDrCalc.StartDate) || (dtCurrent > cDrCalc.EndDate)) { iRows++; continue; } // No calculations if exceeds calculation range dtNextVal = getNextDate(dtCurrent, enCalcFreq); iNextIndex = getClosestDateRowIndex(dtPrices, iRows, dtNextVal, cDrCalc); if ((iNextIndex == -1) || (iNextIndex >= iPosEnd) || ((iPosEnd - iRows) < 7)) { return; // Finished } double dRateVal = getCalcRateVal(Convert.ToDouble(dtPrices[iRows].fClose), Convert.ToDouble(dtPrices[iNextIndex].fClose)); // calculated rate dtOut.Add(new Rate { Date = dtCurrent, RateVal = dRateVal }); if (iNextIndex > iRows) { iRows = iNextIndex; } else { iRows++; } } //main for } //calculatePriceReturns
public static void calculatePriceReturns(List <Entities.dbo.Price> dtPrices, ref List <Rate> dtOut, cDateRange cDrCalc, enumDateFreq enCalcFreq, String idSec, String strSymbol) { calculatePriceReturns(dtPrices, ref dtOut, cDrCalc, enCalcFreq, 0, dtPrices.Count - 1, idSec, strSymbol); } //calculatePriceReturns