using MarketData.Generator; using MarketData.MarketDataModel; using MarketData.Utils; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Media; using TradeBlotter.ViewModels; using TradeBlotter.UIUtils; using System.Collections.Specialized; using MarketData; using MarketData.Generator.Momentum; namespace TradeBlotter.Model { public class MGPositionModelCollection : ObservableCollection { public void Add(ActivePositions activePositions) { List slotKeys=new List(activePositions.Keys); for(int keyIndex=0;keyIndexposition.CurrentPrice)priceChangeDirection=-1; else if(prevPrice==position.CurrentPrice)priceChangeDirection=0; else priceChangeDirection=1; prevPrice=position.CurrentPrice; base.OnPropertyChanged("CurrentPrice"); base.OnPropertyChanged("MarketValue"); base.OnPropertyChanged("ActiveMarketValue"); base.OnPropertyChanged("GainLoss"); base.OnPropertyChanged("GainLossPcnt"); base.OnPropertyChanged("CurrentPriceColor"); } } public double RSI3 { get{return rsi3;} set { if(rsi3==value)return; rsi3=value; base.OnPropertyChanged("RSI3"); base.OnPropertyChanged("RSI3Color"); } } public DateTime LastUpdated { get{return lastUpdated;} set{lastUpdated=value;base.OnPropertyChanged("LastUpdated");} } public Brush CurrentPriceColor { get { if(!IsActivePosition)return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Blue); if(priceChangeDirection>0)return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Green); else if(priceChangeDirection<0)return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Red); else return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Black); } } public Brush RSI3Color { get { if(!IsActivePosition)return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Blue); if(RSI3<10||RSI3>80)return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Red); return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Black); } } public double Exposure { get{return Shares*PurchasePrice;} } public double ActiveExposure { get{return IsActivePosition?Exposure:0.00;} } public Brush ActiveExposureColor { get { if(!IsActivePosition)return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Blue); else return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Black); } } public double MarketValue { get{return Shares*CurrentPrice;} } public double ActiveMarketValue { get{return IsActivePosition?MarketValue:0.00;} } public Brush ActiveMarketValueColor { get { if(!IsActivePosition)return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Blue); if (ActiveMarketValue > Exposure) return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Green); else if (ActiveMarketValue < Exposure) return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Red); else return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Black); } } public long Volume { get{return position.Volume;} set{position.Volume=value;base.OnPropertyChanged("Volume");} } public double Return1D { get{return position.Return1D;} set{position.Return1D=value;base.OnPropertyChanged("Return1D");} } public double GainLoss { get{return MarketValue-Exposure;} } public Brush GainLossColor { get { if(!IsActivePosition)return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Blue); if(GainLoss>0)return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Green); else if(GainLoss<0)return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Red); else return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Black); } } public double GainLossPcnt { get{return (MarketValue-Exposure)/Exposure;} } public Brush GainLossPcntColor { get { if(!IsActivePosition)return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Blue); if(GainLoss>0)return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Green); else if(GainLoss<0)return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Red); else return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Black); } } public double CumReturn252 { get{return position.CumReturn252;} set{position.CumReturn252=value;base.OnPropertyChanged("CumReturn252");} } public double IDIndicator { get{return position.IDIndicator;} set{position.IDIndicator=value;base.OnPropertyChanged("IDIndicator");} } public double Score { get { return position.Score; } set { position.Score=value; base.OnPropertyChanged("Score"); } } public double MaxDrawdown { get{return position.MaxDrawdown;} set{position.MaxDrawdown=value;base.OnPropertyChanged("MaxDrawdown");} } public double MaxUpside { get{return position.MaxUpside;} set{position.MaxUpside=value;base.OnPropertyChanged("MaxUpside");} } public double Velocity { get{return position.Velocity;} set{position.Velocity=value;base.OnPropertyChanged("Velocity");} } public double PE { get{return position.PE;} set{position.PE=value;base.OnPropertyChanged("PE");} } public String ZacksRank { get {return position.ZacksRank;} set{position.ZacksRank=value;base.OnPropertyChanged("ZacksRank");} } public double Beta { get{return position.Beta;} set{position.Beta=value;base.OnPropertyChanged("Beta");} } public double SharpeRatio { get { return position.SharpeRatio; } set { position.SharpeRatio = value; base.OnPropertyChanged("SharpeRatio"); } } public bool IsActivePosition { get{return Utility.IsEpoch(SellDate)?true:false;} } } }