Skip to content

Commit

Permalink
refactor: add known List size (#201)
Browse files Browse the repository at this point in the history
* add known List size
* update performance measures
  • Loading branch information
DaveSkender authored Dec 7, 2020
1 parent 2a8e968 commit d755d6b
Show file tree
Hide file tree
Showing 36 changed files with 105 additions and 105 deletions.
2 changes: 1 addition & 1 deletion indicators/Adl/Adl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static IEnumerable<AdlResult> GetAdl<TQuote>(IEnumerable<TQuote> history,
ValidateAdl(history, smaPeriod);

// initialize
List<AdlResult> results = new List<AdlResult>();
List<AdlResult> results = new List<AdlResult>(historyList.Count);
decimal prevAdl = 0;

// get money flow multiplier
Expand Down
2 changes: 1 addition & 1 deletion indicators/Adx/Adx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static IEnumerable<AdxResult> GetAdx<TQuote>(
ValidateAdx(history, lookbackPeriod);

// initialize results and working variables
List<AdxResult> results = new List<AdxResult>();
List<AdxResult> results = new List<AdxResult>(historyList.Count);
List<AtrResult> atrResults = GetAtr(history, lookbackPeriod).ToList(); // uses True Range value

decimal prevHigh = 0;
Expand Down
2 changes: 1 addition & 1 deletion indicators/Aroon/Aroon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static IEnumerable<AroonResult> GetAroon<TQuote>(
ValidateAroon(history, lookbackPeriod);

// initialize
List<AroonResult> results = new List<AroonResult>();
List<AroonResult> results = new List<AroonResult>(historyList.Count);

// roll through history
for (int i = 0; i < historyList.Count; i++)
Expand Down
2 changes: 1 addition & 1 deletion indicators/Atr/Atr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static IEnumerable<AtrResult> GetAtr<TQuote>(
ValidateAtr(history, lookbackPeriod);

// initialize results
List<AtrResult> results = new List<AtrResult>();
List<AtrResult> results = new List<AtrResult>(historyList.Count);
decimal prevAtr = 0;
decimal prevClose = 0;
decimal highMinusPrevClose = 0;
Expand Down
2 changes: 1 addition & 1 deletion indicators/Beta/Beta.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static IEnumerable<BetaResult> GetBeta<TQuote>(
ValidateBeta(historyMarket, historyEval, lookbackPeriod);

// initialize results
List<BetaResult> results = new List<BetaResult>();
List<BetaResult> results = new List<BetaResult>(historyEvalList.Count);

// get prerequisite data
List<CorrResult> correlation = GetCorrelation(historyMarket, historyEval, lookbackPeriod).ToList();
Expand Down
2 changes: 1 addition & 1 deletion indicators/BollingerBands/BollingerBands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static IEnumerable<BollingerBandsResult> GetBollingerBands<TQuote>(
ValidateBollingerBands(history, lookbackPeriod, standardDeviations);

// initialize
List<BollingerBandsResult> results = new List<BollingerBandsResult>();
List<BollingerBandsResult> results = new List<BollingerBandsResult>(historyList.Count);

// roll through history
for (int i = 0; i < historyList.Count; i++)
Expand Down
2 changes: 1 addition & 1 deletion indicators/Cci/Cci.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static IEnumerable<CciResult> GetCci<TQuote>(
ValidateCci(history, lookbackPeriod);

// initialize
List<CciResult> results = new List<CciResult>();
List<CciResult> results = new List<CciResult>(historyList.Count);


// roll through history
Expand Down
2 changes: 1 addition & 1 deletion indicators/Chandelier/Chandelier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static IEnumerable<ChandelierResult> GetChandelier<TQuote>(
ValidateChandelier(history, lookbackPeriod, multiplier);

// initialize
List<ChandelierResult> results = new List<ChandelierResult>();
List<ChandelierResult> results = new List<ChandelierResult>(historyList.Count);
List<AtrResult> atrResult = GetAtr(history, lookbackPeriod).ToList(); // uses ATR

// roll through history
Expand Down
2 changes: 1 addition & 1 deletion indicators/Cmf/Cmf.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static IEnumerable<CmfResult> GetCmf<TQuote>(
ValidateCmf(history, lookbackPeriod);

// initialize
List<CmfResult> results = new List<CmfResult>();
List<CmfResult> results = new List<CmfResult>(historyList.Count);
List<AdlResult> adlResults = GetAdl(history).ToList();

// roll through history
Expand Down
10 changes: 5 additions & 5 deletions indicators/ConnorsRsi/ConnorsRsi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,18 @@ public static IEnumerable<ConnorsRsiResult> GetConnorsRsi<TQuote>(


private static List<ConnorsRsiResult> CalcConnorsRsiBaseline(
List<BasicData> bd, int rsiPeriod, int rankPeriod)
List<BasicData> bdList, int rsiPeriod, int rankPeriod)
{
List<RsiResult> rsiResults = CalcRsi(bd, rsiPeriod).ToList();
List<ConnorsRsiResult> results = new List<ConnorsRsiResult>();
List<RsiResult> rsiResults = CalcRsi(bdList, rsiPeriod).ToList();
List<ConnorsRsiResult> results = new List<ConnorsRsiResult>(bdList.Count);

decimal? lastClose = null;
decimal streak = 0;

// compose interim results
for (int i = 0; i < bd.Count; i++)
for (int i = 0; i < bdList.Count; i++)
{
BasicData h = bd[i];
BasicData h = bdList[i];
int index = i + 1;

ConnorsRsiResult result = new ConnorsRsiResult
Expand Down
2 changes: 1 addition & 1 deletion indicators/Correlation/Correlation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static IEnumerable<CorrResult> GetCorrelation<TQuote>(
ValidateCorrelation(historyA, historyB, lookbackPeriod);

// initialize
List<CorrResult> results = new List<CorrResult>();
List<CorrResult> results = new List<CorrResult>(historyListA.Count);


// roll through history for interim data
Expand Down
2 changes: 1 addition & 1 deletion indicators/Donchian/Donchian.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static IEnumerable<DonchianResult> GetDonchian<TQuote>(
ValidateDonchian(history, lookbackPeriod);

// initialize
List<DonchianResult> results = new List<DonchianResult>();
List<DonchianResult> results = new List<DonchianResult>(historyList.Count);

// roll through history
for (int i = 0; i < historyList.Count; i++)
Expand Down
8 changes: 4 additions & 4 deletions indicators/Ema/DoubleEma.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ public static IEnumerable<EmaResult> GetDoubleEma<TQuote>(
{

// convert history to basic format
List<BasicData> bd = Cleaners.ConvertHistoryToBasic(history, "C");
List<BasicData> bdList = Cleaners.ConvertHistoryToBasic(history, "C");

// validate parameters
ValidateDema(bd, lookbackPeriod);
ValidateDema(bdList, lookbackPeriod);

// initialize
List<EmaResult> results = new List<EmaResult>();
List<EmaResult> emaN = CalcEma(bd, lookbackPeriod).ToList();
List<EmaResult> results = new List<EmaResult>(bdList.Count);
List<EmaResult> emaN = CalcEma(bdList, lookbackPeriod).ToList();

List<BasicData> bd2 = emaN
.Where(x => x.Ema != null)
Expand Down
2 changes: 1 addition & 1 deletion indicators/Ema/Ema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ private static IEnumerable<EmaResult> CalcEma(List<BasicData> bdList, int lookba
ValidateEma(bdList, lookbackPeriod);

// initialize
List<EmaResult> results = new List<EmaResult>();
List<EmaResult> results = new List<EmaResult>(bdList.Count);

// initialize EMA
decimal k = 2 / (decimal)(lookbackPeriod + 1);
Expand Down
8 changes: 4 additions & 4 deletions indicators/Ema/TripleEma.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ public static IEnumerable<EmaResult> GetTripleEma<TQuote>(
{

// convert history to basic format
List<BasicData> bd = Cleaners.ConvertHistoryToBasic(history, "C");
List<BasicData> bdList = Cleaners.ConvertHistoryToBasic(history, "C");

// validate parameters
ValidateTema(bd, lookbackPeriod);
ValidateTema(bdList, lookbackPeriod);

// initialize
List<EmaResult> results = new List<EmaResult>();
List<EmaResult> emaN1 = CalcEma(bd, lookbackPeriod).ToList();
List<EmaResult> results = new List<EmaResult>(bdList.Count);
List<EmaResult> emaN1 = CalcEma(bdList, lookbackPeriod).ToList();

List<BasicData> bd2 = emaN1
.Where(x => x.Ema != null)
Expand Down
2 changes: 1 addition & 1 deletion indicators/HeikinAshi/HeikinAshi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static IEnumerable<HeikinAshiResult> GetHeikinAshi<TQuote>(
ValidateHeikinAshi(history);

// initialize
List<HeikinAshiResult> results = new List<HeikinAshiResult>();
List<HeikinAshiResult> results = new List<HeikinAshiResult>(historyList.Count);

decimal? prevOpen = null;
decimal? prevClose = null;
Expand Down
2 changes: 1 addition & 1 deletion indicators/Ichimoku/Ichimoku.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static IEnumerable<IchimokuResult> GetIchimoku<TQuote>(
ValidateIchimoku(history, signalPeriod, shortSpanPeriod, longSpanPeriod);

// initialize
List<IchimokuResult> results = new List<IchimokuResult>();
List<IchimokuResult> results = new List<IchimokuResult>(historyList.Count);

// roll through history
for (int i = 0; i < historyList.Count; i++)
Expand Down
2 changes: 1 addition & 1 deletion indicators/Keltner/Keltner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static IEnumerable<KeltnerResult> GetKeltner<TQuote>(
ValidateKeltner(history, emaPeriod, multiplier, atrPeriod);

// initialize
List<KeltnerResult> results = new List<KeltnerResult>();
List<KeltnerResult> results = new List<KeltnerResult>(historyList.Count);
List<EmaResult> emaResults = GetEma(history, emaPeriod).ToList();
List<AtrResult> atrResults = GetAtr(history, atrPeriod).ToList();
int lookbackPeriod = Math.Max(emaPeriod, atrPeriod);
Expand Down
2 changes: 1 addition & 1 deletion indicators/Macd/Macd.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static IEnumerable<MacdResult> GetMacd<TQuote>(
List<EmaResult> emaSlow = GetEma(history, slowPeriod).ToList();

List<BasicData> emaDiff = new List<BasicData>();
List<MacdResult> results = new List<MacdResult>();
List<MacdResult> results = new List<MacdResult>(historyList.Count);

for (int i = 0; i < historyList.Count; i++)
{
Expand Down
2 changes: 1 addition & 1 deletion indicators/Mfi/Mfi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static IEnumerable<MfiResult> GetMfi<TQuote>(
ValidateMfi(history, lookbackPeriod);

// initialize
List<MfiResult> results = new List<MfiResult>();
List<MfiResult> results = new List<MfiResult>(historyList.Count);

decimal? prevTP = null;

Expand Down
2 changes: 1 addition & 1 deletion indicators/Obv/Obv.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static IEnumerable<ObvResult> GetObv<TQuote>(
ValidateObv(history, smaPeriod);

// initialize
List<ObvResult> results = new List<ObvResult>();
List<ObvResult> results = new List<ObvResult>(historyList.Count);

decimal? prevClose = null;
decimal obv = 0;
Expand Down
2 changes: 1 addition & 1 deletion indicators/ParabolicSar/ParabolicSar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static IEnumerable<ParabolicSarResult> GetParabolicSar<TQuote>(
ValidateParabolicSar(history, accelerationStep, maxAccelerationFactor);

// initialize
List<ParabolicSarResult> results = new List<ParabolicSarResult>();
List<ParabolicSarResult> results = new List<ParabolicSarResult>(historyList.Count);
TQuote first = historyList[0];

decimal accelerationFactor = accelerationStep;
Expand Down
2 changes: 1 addition & 1 deletion indicators/Prs/Prs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static IEnumerable<PrsResult> GetPrs<TQuote>(
ValidatePriceRelative(historyBase, historyEval, lookbackPeriod, smaPeriod);

// initialize
List<PrsResult> results = new List<PrsResult>();
List<PrsResult> results = new List<PrsResult>(historyEvalList.Count);


// roll through history for interim data
Expand Down
2 changes: 1 addition & 1 deletion indicators/Roc/Roc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static IEnumerable<RocResult> GetRoc<TQuote>(
ValidateRoc(history, lookbackPeriod, smaPeriod);

// initialize
List<RocResult> results = new List<RocResult>();
List<RocResult> results = new List<RocResult>(historyList.Count);

// roll through history
for (int i = 0; i < historyList.Count; i++)
Expand Down
2 changes: 1 addition & 1 deletion indicators/Rsi/Rsi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ private static IEnumerable<RsiResult> CalcRsi(List<BasicData> bdList, int lookba
decimal lastValue = bdList[0].Value;
decimal avgGain = 0m;
decimal avgLoss = 0m;
List<RsiResult> results = new List<RsiResult>();
List<RsiResult> results = new List<RsiResult>(bdList.Count);

// roll through history
for (int i = 0; i < bdList.Count; i++)
Expand Down
2 changes: 1 addition & 1 deletion indicators/Slope/Slope.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static IEnumerable<SlopeResult> GetSlope<TQuote>(
ValidateSlope(history, lookbackPeriod);

// initialize
List<SlopeResult> results = new List<SlopeResult>();
List<SlopeResult> results = new List<SlopeResult>(historyList.Count);

// roll through history for interim data
for (int i = 0; i < historyList.Count; i++)
Expand Down
2 changes: 1 addition & 1 deletion indicators/Sma/Sma.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static IEnumerable<SmaResult> GetSma<TQuote>(
ValidateSma(history, lookbackPeriod);

// initialize
List<SmaResult> results = new List<SmaResult>();
List<SmaResult> results = new List<SmaResult>(historyList.Count);

// roll through history
for (int i = 0; i < historyList.Count; i++)
Expand Down
2 changes: 1 addition & 1 deletion indicators/StdDev/StdDev.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ private static IEnumerable<StdDevResult> CalcStdDev(
ValidateStdDev(bdList, lookbackPeriod, smaPeriod);

// initialize results
List<StdDevResult> results = new List<StdDevResult>();
List<StdDevResult> results = new List<StdDevResult>(bdList.Count);

// roll through history and compute lookback standard deviation
for (int i = 0; i < bdList.Count; i++)
Expand Down
2 changes: 1 addition & 1 deletion indicators/Stoch/Stoch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static IEnumerable<StochResult> GetStoch<TQuote>(
ValidateStoch(history, lookbackPeriod, signalPeriod, smoothPeriod);

// initialize
List<StochResult> results = new List<StochResult>();
List<StochResult> results = new List<StochResult>(historyList.Count);

// oscillator
for (int i = 0; i < historyList.Count; i++)
Expand Down
4 changes: 1 addition & 3 deletions indicators/StochRsi/StochRsi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@ public static IEnumerable<StochRsiResult> GetStochRsi<TQuote>(
ValidateStochRsi(history, rsiPeriod, stochPeriod, signalPeriod, smoothPeriod);

// initialize
List<StochRsiResult> results = new List<StochRsiResult>();

// get RSI
List<RsiResult> rsiResults = GetRsi(history, rsiPeriod).ToList();
List<StochRsiResult> results = new List<StochRsiResult>(rsiResults.Count);

// convert rsi to quote format
List<Quote> rsiQuotes = rsiResults
Expand Down
8 changes: 4 additions & 4 deletions indicators/Trix/Trix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ public static IEnumerable<TrixResult> GetTrix<TQuote>(
{

// convert history to basic format
List<BasicData> bd = Cleaners.ConvertHistoryToBasic(history, "C");
List<BasicData> bdList = Cleaners.ConvertHistoryToBasic(history, "C");

// validate parameters
ValidateTrix(bd, lookbackPeriod);
ValidateTrix(bdList, lookbackPeriod);

// initialize
List<TrixResult> results = new List<TrixResult>();
List<TrixResult> results = new List<TrixResult>(bdList.Count);
decimal? lastEma = null;

List<EmaResult> emaN1 = CalcEma(bd, lookbackPeriod).ToList();
List<EmaResult> emaN1 = CalcEma(bdList, lookbackPeriod).ToList();

List<BasicData> bd2 = emaN1
.Where(x => x.Ema != null)
Expand Down
2 changes: 1 addition & 1 deletion indicators/UlcerIndex/Ulcer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static IEnumerable<UlcerIndexResult> GetUlcerIndex<TQuote>(
ValidateUlcer(history, lookbackPeriod);

// initialize
List<UlcerIndexResult> results = new List<UlcerIndexResult>();
List<UlcerIndexResult> results = new List<UlcerIndexResult>(historyList.Count);

// roll through history
for (int i = 0; i < historyList.Count; i++)
Expand Down
2 changes: 1 addition & 1 deletion indicators/Ultimate/Ultimate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static IEnumerable<UltimateResult> GetUltimate<TQuote>(
ValidateUltimate(history, shortPeriod, middlePeriod, longPeriod);

// initialize
List<UltimateResult> results = new List<UltimateResult>();
List<UltimateResult> results = new List<UltimateResult>(historyList.Count);
decimal priorClose = 0;

// roll through history
Expand Down
2 changes: 1 addition & 1 deletion indicators/Wma/Wma.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static IEnumerable<WmaResult> GetWma<TQuote>(
ValidateWma(history, lookbackPeriod);

// initialize
List<WmaResult> results = new List<WmaResult>();
List<WmaResult> results = new List<WmaResult>(historyList.Count);
decimal divisor = (lookbackPeriod * (lookbackPeriod + 1)) / 2m;

// roll through history
Expand Down
2 changes: 1 addition & 1 deletion indicators/ZigZag/ZigZag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static IEnumerable<ZigZagResult> GetZigZag<TQuote>(
ValidateZigZag(history, percentChange);

// initialize
List<ZigZagResult> results = new List<ZigZagResult>();
List<ZigZagResult> results = new List<ZigZagResult>(historyList.Count);
decimal changeThreshold = percentChange / 100m;
TQuote firstQuote = historyList[0];
ZigZagEval eval = GetZigZagEval(type, 1, firstQuote);
Expand Down
Loading

0 comments on commit d755d6b

Please sign in to comment.