using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; using MarketData.MarketDataModel; using MarketData.Utils; using MarketData.DataAccess; namespace MarketData.Generator { public class RSIGenerator { private RSIGenerator() { } public static RSICollection GenerateRSI(String symbol,int priceCount,int rsiDayCount=14) { if(priceCount=0;index--) { Price price=prices[index]; RSIElement rsiElement=new RSIElement(); rsiElement.Symbol=price.Symbol; rsiElement.RSIDays=rsiDayCount; rsiElement.Date=price.Date; rsiElement.Close=price.Close; if(index==prices.Count-1)continue; rsiElement.Change=price.Close-prices[index+1].Close; if(rsiElement.Change<0){rsiElement.Loss=Math.Abs(rsiElement.Change);rsiElement.Gain=0.00;} else if(rsiElement.Change>0){rsiElement.Gain=rsiElement.Change;rsiElement.Loss=0.00;} else{rsiElement.Loss=0.00;rsiElement.Gain=0.00;} rsiCollection.Add(rsiElement); } RSICollection topCollection=rsiCollection.Top(rsiDayCount,1); rsiCollection[rsiDayCount].AverageGain=topCollection.AverageGain(); rsiCollection[rsiDayCount].AverageLoss=topCollection.AverageLoss(); if(0.00==rsiCollection[rsiDayCount].AverageLoss) { rsiCollection[rsiDayCount].RS=0.00; rsiCollection[rsiDayCount].RSI=100.00; } else { rsiCollection[rsiDayCount].RS=rsiCollection[rsiDayCount].AverageGain/rsiCollection[rsiDayCount].AverageLoss; rsiCollection[rsiDayCount].RSI=100.00-(100.00/(1.00+rsiCollection[rsiDayCount].RS)); } for(int index=rsiDayCount+1;index=0;index--) { Price price=prices[index]; RSIElement rsiElement=new RSIElement(); rsiElement.Symbol=price.Symbol; rsiElement.RSIDays=rsiDayCount; rsiElement.Date=price.Date; rsiElement.Close=price.Close; if(index==prices.Count-1)continue; rsiElement.Change=price.Close-prices[index+1].Close; if(rsiElement.Change<0){rsiElement.Loss=Math.Abs(rsiElement.Change);rsiElement.Gain=0.00;} else if(rsiElement.Change>0){rsiElement.Gain=rsiElement.Change;rsiElement.Loss=0.00;} else{rsiElement.Loss=0.00;rsiElement.Gain=0.00;} rsiCollection.Add(rsiElement); } RSICollection topCollection=rsiCollection.Top(rsiDayCount,1); rsiCollection[rsiDayCount].AverageGain=topCollection.AverageGain(); rsiCollection[rsiDayCount].AverageLoss=topCollection.AverageLoss(); if(0.00==rsiCollection[rsiDayCount].AverageLoss) { rsiCollection[rsiDayCount].RS=0.00; rsiCollection[rsiDayCount].RSI=100.00; } else { rsiCollection[rsiDayCount].RS=rsiCollection[rsiDayCount].AverageGain/rsiCollection[rsiDayCount].AverageLoss; rsiCollection[rsiDayCount].RSI=100.00-(100.00/(1.00+rsiCollection[rsiDayCount].RS)); } for(int index=rsiDayCount+1;index