Init
This commit is contained in:
65
Model/BlotterTradeModel.cs
Normal file
65
Model/BlotterTradeModel.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using MarketData.MarketDataModel;
|
||||
|
||||
namespace TradeBlotter.Model
|
||||
{
|
||||
public class BlotterTradeModel : PortfolioTrade
|
||||
{
|
||||
public static BlotterTradeModel CreateTrade()
|
||||
{
|
||||
BlotterTradeModel trade = new BlotterTradeModel();
|
||||
trade.TradeDate = DateTime.Now;
|
||||
trade.Price = 0.0;
|
||||
return trade;
|
||||
}
|
||||
protected BlotterTradeModel()
|
||||
{
|
||||
}
|
||||
public BlotterTradeModel Clone()
|
||||
{
|
||||
BlotterTradeModel blotterTradeModel = CreateTrade();
|
||||
blotterTradeModel.TradeId=TradeId;
|
||||
blotterTradeModel.Symbol = Symbol;
|
||||
blotterTradeModel.TradeDate = TradeDate;
|
||||
blotterTradeModel.Shares = Shares;
|
||||
blotterTradeModel.Price = Price;
|
||||
blotterTradeModel.Commission = Commission;
|
||||
blotterTradeModel.BuySell = BuySell;
|
||||
blotterTradeModel.Account = Account;
|
||||
blotterTradeModel.Status = Status;
|
||||
blotterTradeModel.CompanyName = CompanyName;
|
||||
blotterTradeModel.LatestPrice = LatestPrice;
|
||||
blotterTradeModel.PriceDate = PriceDate;
|
||||
blotterTradeModel.HasLatestPrice = HasLatestPrice;
|
||||
blotterTradeModel.SellDate = SellDate;
|
||||
blotterTradeModel.SellPrice = SellPrice;
|
||||
return blotterTradeModel;
|
||||
}
|
||||
public void CopyFrom(BlotterTradeModel trade)
|
||||
{
|
||||
TradeId = trade.TradeId;
|
||||
Symbol = trade.Symbol;
|
||||
TradeDate = trade.TradeDate;
|
||||
Shares = trade.Shares;
|
||||
Price = trade.Price;
|
||||
Commission = trade.Commission;
|
||||
BuySell = trade.BuySell;
|
||||
Account = trade.Account;
|
||||
Status = trade.Status;
|
||||
CompanyName = trade.CompanyName;
|
||||
LatestPrice = trade.LatestPrice;
|
||||
PriceDate = trade.PriceDate;
|
||||
HasLatestPrice = trade.HasLatestPrice;
|
||||
SellDate = trade.SellDate;
|
||||
SellPrice = trade.SellPrice;
|
||||
}
|
||||
public String CompanyName { get; set; }
|
||||
public new double Exposure { get { return Price * Shares; } }
|
||||
public double LatestPrice { get; set; }
|
||||
public DateTime PriceDate { get; set; }
|
||||
public Boolean HasLatestPrice{get;set;}
|
||||
}
|
||||
}
|
||||
156
Model/BollingerBandModel.cs
Normal file
156
Model/BollingerBandModel.cs
Normal file
@@ -0,0 +1,156 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using MarketData.MarketDataModel;
|
||||
using MarketData.Numerical;
|
||||
using Microsoft.Research.DynamicDataDisplay.DataSources;
|
||||
using MarketData.Utils;
|
||||
|
||||
namespace TradeBlotter.Model
|
||||
{
|
||||
public class BollingerBandModel
|
||||
{
|
||||
private BollingerBandModel()
|
||||
{
|
||||
}
|
||||
public static CompositeDataSource SMAN(BollingerBands bollingerBands)
|
||||
{
|
||||
if (null == bollingerBands) return null;
|
||||
CompositeDataSource compositeDataSource;
|
||||
var xData = new EnumerableDataSource<DateTime>(bollingerBands.Select(x => x.Date.Date));
|
||||
xData.SetXMapping(x => (x.Ticks / 10000000000.0));
|
||||
var yData = new EnumerableDataSource<double>(bollingerBands.Select(y => y.SMAN));
|
||||
yData.SetYMapping(y => y);
|
||||
compositeDataSource = xData.Join(yData);
|
||||
return compositeDataSource;
|
||||
}
|
||||
public static CompositeDataSource K(BollingerBands bollingerBands)
|
||||
{
|
||||
if (null == bollingerBands) return null;
|
||||
CompositeDataSource compositeDataSource;
|
||||
var xData = new EnumerableDataSource<DateTime>(bollingerBands.Select(x => x.Date.Date));
|
||||
xData.SetXMapping(x => (x.Ticks/ 10000000000.0));
|
||||
var yData = new EnumerableDataSource<double>(bollingerBands.Select(y => y.K));
|
||||
yData.SetYMapping(y => y);
|
||||
compositeDataSource = xData.Join(yData);
|
||||
return compositeDataSource;
|
||||
}
|
||||
public static CompositeDataSource KL1(BollingerBands bollingerBands)
|
||||
{
|
||||
if (null == bollingerBands) return null;
|
||||
CompositeDataSource compositeDataSource;
|
||||
var xData = new EnumerableDataSource<DateTime>(bollingerBands.Select(x => x.Date.Date));
|
||||
xData.SetXMapping(x => (x.Ticks / 10000000000.0));
|
||||
var yData = new EnumerableDataSource<double>(bollingerBands.Select(y => y.KL1));
|
||||
yData.SetYMapping(y => y);
|
||||
compositeDataSource = xData.Join(yData);
|
||||
return compositeDataSource;
|
||||
}
|
||||
public static CompositeDataSource L(BollingerBands bollingerBands)
|
||||
{
|
||||
if (null == bollingerBands) return null;
|
||||
CompositeDataSource compositeDataSource;
|
||||
var xData = new EnumerableDataSource<DateTime>(bollingerBands.Select(x => x.Date.Date));
|
||||
xData.SetXMapping(x => (x.Ticks / 10000000000.0));
|
||||
var yData = new EnumerableDataSource<double>(bollingerBands.Select(y => y.L));
|
||||
yData.SetYMapping(y => y);
|
||||
compositeDataSource = xData.Join(yData);
|
||||
return compositeDataSource;
|
||||
}
|
||||
public static CompositeDataSource LP1(BollingerBands bollingerBands)
|
||||
{
|
||||
if (null == bollingerBands) return null;
|
||||
CompositeDataSource compositeDataSource;
|
||||
var xData = new EnumerableDataSource<DateTime>(bollingerBands.Select(x => x.Date.Date));
|
||||
xData.SetXMapping(x => (x.Ticks / 10000000000.0));
|
||||
var yData = new EnumerableDataSource<double>(bollingerBands.Select(y => y.LP1));
|
||||
yData.SetYMapping(y => y);
|
||||
compositeDataSource = xData.Join(yData);
|
||||
return compositeDataSource;
|
||||
}
|
||||
public static CompositeDataSource High(BollingerBands bollingerBands)
|
||||
{
|
||||
if (null == bollingerBands) return null;
|
||||
CompositeDataSource compositeDataSource;
|
||||
var xData = new EnumerableDataSource<DateTime>(bollingerBands.Select(x => x.Date.Date));
|
||||
xData.SetXMapping(x => (x.Ticks / 10000000000.0));
|
||||
var yData = new EnumerableDataSource<double>(bollingerBands.Select(y => y.High));
|
||||
yData.SetYMapping(y => y);
|
||||
compositeDataSource = xData.Join(yData);
|
||||
return compositeDataSource;
|
||||
}
|
||||
public static CompositeDataSource Low(BollingerBands bollingerBands)
|
||||
{
|
||||
if (null == bollingerBands) return null;
|
||||
CompositeDataSource compositeDataSource;
|
||||
var xData = new EnumerableDataSource<DateTime>(bollingerBands.Select(x => x.Date.Date));
|
||||
xData.SetXMapping(x => (x.Ticks / 10000000000.0));
|
||||
var yData = new EnumerableDataSource<double>(bollingerBands.Select(y => y.Low));
|
||||
yData.SetYMapping(y => y);
|
||||
compositeDataSource = xData.Join(yData);
|
||||
return compositeDataSource;
|
||||
}
|
||||
public static CompositeDataSource Close(BollingerBands bollingerBands)
|
||||
{
|
||||
if (null == bollingerBands) return null;
|
||||
CompositeDataSource compositeDataSource;
|
||||
var xData = new EnumerableDataSource<DateTime>(bollingerBands.Select(x => x.Date.Date));
|
||||
xData.SetXMapping(x => (x.Ticks / 10000000000.0));
|
||||
var yData = new EnumerableDataSource<double>(bollingerBands.Select(y => y.Close));
|
||||
yData.SetYMapping(y => y);
|
||||
compositeDataSource = xData.Join(yData);
|
||||
return compositeDataSource;
|
||||
}
|
||||
public static CompositeDataSource LeastSquares(BollingerBands bollingerBands)
|
||||
{
|
||||
if (null == bollingerBands) return null;
|
||||
CompositeDataSource compositeDataSource;
|
||||
var xData = new EnumerableDataSource<DateTime>(bollingerBands.Select(x => x.Date.Date));
|
||||
xData.SetXMapping(x => (x.Ticks / 10000000000.0));
|
||||
LeastSquaresResult leastSquaresResult=bollingerBands.LeastSquaresFitClose();
|
||||
var yData = new EnumerableDataSource<double>(leastSquaresResult.LeastSquares);
|
||||
yData.SetYMapping(y => y);
|
||||
compositeDataSource = xData.Join(yData);
|
||||
return compositeDataSource;
|
||||
}
|
||||
public static CompositeDataSource LeastSquaresExtend(BollingerBands bollingerBands,DateTime extendToDate)
|
||||
{
|
||||
if (null == bollingerBands) return null;
|
||||
CompositeDataSource compositeDataSource;
|
||||
|
||||
LeastSquaresResult leastSquaresResult=bollingerBands.LeastSquaresFitClose();
|
||||
DateTime maxDateInBand=bollingerBands.Select(x=>x.Date).Max();
|
||||
if(maxDateInBand<extendToDate)
|
||||
{
|
||||
DateGenerator dateGenerator=new DateGenerator();
|
||||
List<DateTime> extendedDates=dateGenerator.GenerateHistoricalDates(dateGenerator.FindNextBusinessDay(maxDateInBand),extendToDate);
|
||||
var xData=new EnumerableDataSource<DateTime>(bollingerBands.Select(x => x.Date.Date).Union(extendedDates.Select(x=>x)).OrderByDescending(x=>x.Date));
|
||||
leastSquaresResult.Extend(extendedDates.Count,leastSquaresResult.Slope);
|
||||
xData.SetXMapping(x => (x.Ticks / 10000000000.0));
|
||||
var yData = new EnumerableDataSource<double>(leastSquaresResult.LeastSquares);
|
||||
yData.SetYMapping(y => y);
|
||||
compositeDataSource = xData.Join(yData);
|
||||
}
|
||||
else
|
||||
{
|
||||
var xData = new EnumerableDataSource<DateTime>(bollingerBands.Select(x => x.Date.Date));
|
||||
xData.SetXMapping(x => (x.Ticks / 10000000000.0));
|
||||
var yData = new EnumerableDataSource<double>(leastSquaresResult.LeastSquares);
|
||||
yData.SetYMapping(y => y);
|
||||
compositeDataSource = xData.Join(yData);
|
||||
}
|
||||
return compositeDataSource;
|
||||
}
|
||||
public static CompositeDataSource Volume(BollingerBands bollingerBands)
|
||||
{
|
||||
if (null == bollingerBands) return null;
|
||||
CompositeDataSource compositeDataSource;
|
||||
var xData = new EnumerableDataSource<DateTime>(bollingerBands.Select(x => x.Date.Date));
|
||||
xData.SetXMapping(x => (x.Ticks / 10000000000.0));
|
||||
var yData = new EnumerableDataSource<long>(bollingerBands.Select(y => y.Volume));
|
||||
yData.SetYMapping(y => y);
|
||||
compositeDataSource = xData.Join(yData);
|
||||
return compositeDataSource;
|
||||
}
|
||||
}
|
||||
}
|
||||
295
Model/CMPositionModel.cs
Normal file
295
Model/CMPositionModel.cs
Normal file
@@ -0,0 +1,295 @@
|
||||
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.CMMomentum;
|
||||
using Position=MarketData.Generator.CMMomentum.Position;
|
||||
|
||||
namespace TradeBlotter.Model
|
||||
{
|
||||
public class CMPositionModelCollection : ObservableCollection<CMPositionModel>
|
||||
{
|
||||
public void Add(ActivePositions activePositions)
|
||||
{
|
||||
List<int> slotKeys = new List<int>(activePositions.Keys);
|
||||
for (int keyIndex = 0; keyIndex < slotKeys.Count; keyIndex++)
|
||||
{
|
||||
Positions slotPositions = activePositions[slotKeys[keyIndex]];
|
||||
foreach (Position position in slotPositions) Add(new CMPositionModel(position, keyIndex));
|
||||
}
|
||||
}
|
||||
public void Add(Positions allPositions)
|
||||
{
|
||||
foreach (Position position in allPositions) Add(new CMPositionModel(position));
|
||||
}
|
||||
public void OnCollectionChanged()
|
||||
{
|
||||
base.OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset, null));
|
||||
}
|
||||
}
|
||||
// ************************************************************************************************************************************************************************************
|
||||
public class CMPositionModel : ModelBase
|
||||
{
|
||||
private Position position = new Position();
|
||||
private int slot;
|
||||
private int priceChangeDirection = 0;
|
||||
private double prevPrice = double.NaN;
|
||||
private DateTime lastUpdated = DateTime.Now;
|
||||
private double rsi3 = double.NaN;
|
||||
|
||||
public CMPositionModel()
|
||||
{
|
||||
}
|
||||
public CMPositionModel(Position position, int slot)
|
||||
{
|
||||
Slot = slot;
|
||||
Symbol = position.Symbol;
|
||||
PurchaseDate = position.PurchaseDate;
|
||||
SellDate = position.SellDate;
|
||||
Shares = position.Shares;
|
||||
PurchasePrice = position.PurchasePrice;
|
||||
CurrentPrice = position.CurrentPrice;
|
||||
Beta = position.Beta;
|
||||
BetaMonths = position.BetaMonths;
|
||||
SharpeRatio = position.SharpeRatio;
|
||||
CNNPrediction = position.CNNPrediction;
|
||||
}
|
||||
public CMPositionModel(Position position)
|
||||
{
|
||||
slot = -1;
|
||||
Symbol = position.Symbol;
|
||||
PurchaseDate = position.PurchaseDate;
|
||||
SellDate = position.SellDate;
|
||||
Shares = position.Shares;
|
||||
PurchasePrice = position.PurchasePrice;
|
||||
CurrentPrice = position.CurrentPrice;
|
||||
Beta = position.Beta;
|
||||
BetaMonths = position.BetaMonths;
|
||||
SharpeRatio = position.SharpeRatio;
|
||||
CNNPrediction = position.CNNPrediction;
|
||||
}
|
||||
public String Symbol
|
||||
{
|
||||
get { return position.Symbol; }
|
||||
set { position.Symbol = value; base.OnPropertyChanged("Symbol"); }
|
||||
}
|
||||
public DateTime PurchaseDate
|
||||
{
|
||||
get { return position.PurchaseDate; }
|
||||
set { position.PurchaseDate = value; base.OnPropertyChanged("PurchaseDate"); }
|
||||
}
|
||||
|
||||
public Brush PurchaseDateColor
|
||||
{
|
||||
get
|
||||
{
|
||||
DateGenerator dateGenerator=new DateGenerator();
|
||||
if(!dateGenerator.IsMarketOpen(PurchaseDate)) return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Red);
|
||||
if(!IsActivePosition) return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Blue);
|
||||
return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Black);
|
||||
}
|
||||
}
|
||||
|
||||
public DateTime SellDate
|
||||
{
|
||||
get { return position.SellDate; }
|
||||
set { position.SellDate = value; base.OnPropertyChanged("SellDate"); }
|
||||
}
|
||||
|
||||
public Brush SellDateColor
|
||||
{
|
||||
get
|
||||
{
|
||||
if(Utility.IsEpoch(SellDate)) return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Black);
|
||||
DateGenerator dateGenerator=new DateGenerator();
|
||||
if(!dateGenerator.IsMarketOpen(SellDate)) return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Red);
|
||||
if(!IsActivePosition) return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Blue);
|
||||
return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Black);
|
||||
}
|
||||
}
|
||||
|
||||
public int DaysHeld
|
||||
{
|
||||
get
|
||||
{
|
||||
DateGenerator dateGenerator = new DateGenerator();
|
||||
if (Utility.IsEpoch(SellDate)) return dateGenerator.DaysBetween(PurchaseDate, DateTime.Now.Date);
|
||||
return dateGenerator.DaysBetween(PurchaseDate, SellDate);
|
||||
}
|
||||
}
|
||||
public int Slot
|
||||
{
|
||||
get { return slot; }
|
||||
set { slot = value; base.OnPropertyChanged("Slot"); }
|
||||
}
|
||||
public String SlotAsString
|
||||
{
|
||||
get
|
||||
{
|
||||
if (-1 == Slot) return Constants.CONST_DASHES;
|
||||
return Slot.ToString();
|
||||
}
|
||||
}
|
||||
public double Shares
|
||||
{
|
||||
get { return position.Shares; }
|
||||
set { position.Shares = value; base.OnPropertyChanged("Shares"); base.OnPropertyChanged("Exposure"); base.OnPropertyChanged("ActiveExposure"); base.OnPropertyChanged("MarketValue"); base.OnPropertyChanged("ActiveMarketValue"); base.OnPropertyChanged("GainLoss"); base.OnPropertyChanged("GainLossPcnt"); }
|
||||
}
|
||||
public double PurchasePrice
|
||||
{
|
||||
get { return position.PurchasePrice; }
|
||||
set { position.PurchasePrice = value; base.OnPropertyChanged("PurchasePrice"); base.OnPropertyChanged("Exposure"); base.OnPropertyChanged("ActiveExposure"); base.OnPropertyChanged("GainLoss"); base.OnPropertyChanged("GainLossPcnt"); }
|
||||
}
|
||||
public double CurrentPrice
|
||||
{
|
||||
get { return position.CurrentPrice; }
|
||||
set
|
||||
{
|
||||
if (position.CurrentPrice == value) return;
|
||||
position.CurrentPrice = value;
|
||||
if (double.IsNaN(prevPrice)) { prevPrice = position.CurrentPrice; priceChangeDirection = 0; }
|
||||
else if (prevPrice > position.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 bool CNNPrediction
|
||||
{
|
||||
get { return position.CNNPrediction; }
|
||||
set { position.CNNPrediction = value; base.OnPropertyChanged("CNNPrediction"); }
|
||||
}
|
||||
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 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 Beta
|
||||
{
|
||||
get { return position.Beta; }
|
||||
set { position.Beta = value; base.OnPropertyChanged("Beta"); }
|
||||
}
|
||||
public int BetaMonths
|
||||
{
|
||||
get { return position.BetaMonths; }
|
||||
set { position.BetaMonths = value; base.OnPropertyChanged("BetaMonths"); }
|
||||
}
|
||||
public double SharpeRatio
|
||||
{
|
||||
get { return position.SharpeRatio; }
|
||||
set { position.SharpeRatio = value; base.OnPropertyChanged("SharpeRatio"); }
|
||||
}
|
||||
public bool IsActivePosition
|
||||
{
|
||||
get { return Utility.IsEpoch(SellDate) ? true : false; }
|
||||
}
|
||||
}
|
||||
}
|
||||
496
Model/CMTPositionModel.cs
Normal file
496
Model/CMTPositionModel.cs
Normal file
@@ -0,0 +1,496 @@
|
||||
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.Generator.CMTrend;
|
||||
using MarketData;
|
||||
|
||||
using Position=MarketData.Generator.CMTrend.Position;
|
||||
using StopLimit=MarketData.MarketDataModel.StopLimit;
|
||||
|
||||
using MarketData.DataAccess;
|
||||
|
||||
namespace TradeBlotter.Model
|
||||
{
|
||||
public class CMTPositionModelCollection:ObservableCollection<CMTPositionModel>
|
||||
{
|
||||
public void Add(ActivePositions activePositions)
|
||||
{
|
||||
foreach(Position position in activePositions)Add(new CMTPositionModel(position));
|
||||
}
|
||||
public void Add(Positions allPositions)
|
||||
{
|
||||
foreach(Position position in allPositions) Add(new CMTPositionModel(position));
|
||||
}
|
||||
public void OnCollectionChanged()
|
||||
{
|
||||
base.OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset,null));
|
||||
}
|
||||
}
|
||||
|
||||
public class CMTPositionModel:ModelBase
|
||||
{
|
||||
private Position position=new Position();
|
||||
private int priceChangeDirection=0;
|
||||
private double prevPrice=double.NaN;
|
||||
private double currentPriceLow=double.NaN;
|
||||
private DateTime lastUpdated=DateTime.Now;
|
||||
private double edgeRatio=double.NaN;
|
||||
|
||||
public CMTPositionModel()
|
||||
{
|
||||
}
|
||||
public CMTPositionModel(Position position)
|
||||
{
|
||||
Symbol=position.Symbol;
|
||||
PurchaseDate=position.PurchaseDate;
|
||||
SellDate=position.SellDate;
|
||||
Shares=position.Shares;
|
||||
PurchasePrice=position.PurchasePrice;
|
||||
CurrentPrice=position.CurrentPrice;
|
||||
PositionRiskPercentDecimal=position.PositionRiskPercentDecimal;
|
||||
InitialStopLimit=position.InitialStopLimit;
|
||||
TrailingStopLimit=position.TrailingStopLimit;
|
||||
LastStopAdjustment=position.LastStopAdjustment;
|
||||
this.position.R=position.R;
|
||||
this.position.C=position.C;
|
||||
}
|
||||
public void UpdateProperties()
|
||||
{
|
||||
base.OnPropertyChanged("CurrentPrice");
|
||||
base.OnPropertyChanged("MarketValue");
|
||||
base.OnPropertyChanged("ActiveMarketValue");
|
||||
base.OnPropertyChanged("GainLoss");
|
||||
base.OnPropertyChanged("GainLossPcnt");
|
||||
base.OnPropertyChanged("RMultipleAsString");
|
||||
base.OnPropertyChanged("EdgeRatioAsString");
|
||||
base.OnPropertyChanged("CurrentPriceColor");
|
||||
base.OnPropertyChanged("TrailingStopLimitColor");
|
||||
base.OnPropertyChanged("InitialStopLimitColor");
|
||||
base.OnPropertyChanged("TotalRiskExposureColor");
|
||||
base.OnPropertyChanged("ActiveMarketValueColor");
|
||||
base.OnPropertyChanged("GainLossColor");
|
||||
base.OnPropertyChanged("GainLossPcntColor");
|
||||
base.OnPropertyChanged("EdgeRatioAsStringColor");
|
||||
}
|
||||
public Position Position
|
||||
{
|
||||
get{return position;}
|
||||
set
|
||||
{
|
||||
Symbol=position.Symbol;
|
||||
PurchaseDate=position.PurchaseDate;
|
||||
SellDate=position.SellDate;
|
||||
Shares=position.Shares;
|
||||
PurchasePrice=position.PurchasePrice;
|
||||
CurrentPrice=position.CurrentPrice;
|
||||
PositionRiskPercentDecimal=position.PositionRiskPercentDecimal;
|
||||
InitialStopLimit=position.InitialStopLimit;
|
||||
TrailingStopLimit=position.TrailingStopLimit;
|
||||
LastStopAdjustment=position.LastStopAdjustment;
|
||||
this.position.R=position.R;
|
||||
this.position.C=position.C;
|
||||
}
|
||||
}
|
||||
public String Symbol
|
||||
{
|
||||
get { return position.Symbol; }
|
||||
set { position.Symbol=value; base.OnPropertyChanged("Symbol"); }
|
||||
}
|
||||
public Brush SymbolColor
|
||||
{
|
||||
get
|
||||
{
|
||||
if(!IsActivePosition) return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Blue);
|
||||
return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Black);
|
||||
}
|
||||
}
|
||||
// ***
|
||||
public DateTime PurchaseDate
|
||||
{
|
||||
get { return position.PurchaseDate; }
|
||||
set { position.PurchaseDate=value; base.OnPropertyChanged("PurchaseDate"); }
|
||||
}
|
||||
|
||||
public Brush PurchaseDateColor
|
||||
{
|
||||
get
|
||||
{
|
||||
DateGenerator dateGenerator=new DateGenerator();
|
||||
if(!dateGenerator.IsMarketOpen(PurchaseDate)) return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Red);
|
||||
if(!IsActivePosition) return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Blue);
|
||||
return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Black);
|
||||
}
|
||||
}
|
||||
|
||||
public DateTime SellDate
|
||||
{
|
||||
get { return position.SellDate; }
|
||||
set { position.SellDate=value; base.OnPropertyChanged("SellDate"); }
|
||||
}
|
||||
|
||||
public Brush SellDateColor
|
||||
{
|
||||
get
|
||||
{
|
||||
if(Utility.IsEpoch(SellDate)) return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Black);
|
||||
DateGenerator dateGenerator=new DateGenerator();
|
||||
if(!dateGenerator.IsMarketOpen(SellDate)) return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Red);
|
||||
if(!IsActivePosition) return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Blue);
|
||||
return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Black);
|
||||
}
|
||||
}
|
||||
// ***
|
||||
public int DaysHeld
|
||||
{
|
||||
get
|
||||
{
|
||||
DateGenerator dateGenerator=new DateGenerator();
|
||||
if(Utility.IsEpoch(SellDate)) return dateGenerator.DaysBetween(PurchaseDate,DateTime.Now.Date);
|
||||
return dateGenerator.DaysBetween(PurchaseDate,SellDate);
|
||||
}
|
||||
}
|
||||
public Brush DaysHeldColor
|
||||
{
|
||||
get
|
||||
{
|
||||
if(!IsActivePosition) return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Blue);
|
||||
return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Black);
|
||||
}
|
||||
}
|
||||
// ***
|
||||
// Here we take R as based upon our StopLimit.
|
||||
public double R
|
||||
{
|
||||
get
|
||||
{
|
||||
if(position.TrailingStopLimit>position.PurchasePrice)return 0.00; // here we are considering the current risk/share which is based on our stop limit
|
||||
return position.TrailingStopLimit>position.PurchasePrice?0.00:position.PurchasePrice-position.TrailingStopLimit;
|
||||
}
|
||||
}
|
||||
public Brush RColor
|
||||
{
|
||||
get
|
||||
{
|
||||
if(!IsActivePosition) return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Blue);
|
||||
return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Black);
|
||||
}
|
||||
}
|
||||
// ***
|
||||
public double TotalRiskExposure
|
||||
{
|
||||
get{return R*position.Shares;}
|
||||
}
|
||||
public Brush TotalRiskExposureColor
|
||||
{
|
||||
get
|
||||
{
|
||||
if(!IsActivePosition) return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Blue);
|
||||
return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Black);
|
||||
}
|
||||
}
|
||||
// ***
|
||||
public double EdgeRatio
|
||||
{
|
||||
get{return edgeRatio;}
|
||||
set
|
||||
{
|
||||
edgeRatio=value;
|
||||
base.OnPropertyChanged("EdgeRatio");
|
||||
base.OnPropertyChanged("EdgeRatioAsStringColor");
|
||||
}
|
||||
}
|
||||
public String EdgeRatioAsString
|
||||
{
|
||||
get{return Utility.FormatNumber(edgeRatio,2,false);}
|
||||
}
|
||||
public Brush EdgeRatioAsStringColor
|
||||
{
|
||||
get
|
||||
{
|
||||
if(!IsActivePosition) return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Blue);
|
||||
if(double.IsNaN(edgeRatio))return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Black);
|
||||
if(edgeRatio>=1.00)return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Green);
|
||||
return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Red);
|
||||
}
|
||||
}
|
||||
// ***
|
||||
|
||||
public String RMultipleAsString
|
||||
{
|
||||
get{return Utility.FormatNumber((position.CurrentPrice-position.PurchasePrice)/(position.PurchasePrice-position.InitialStopLimit),2,false)+"R";} // always based on original position risk
|
||||
}
|
||||
public Brush RMultipleAsStringColor
|
||||
{
|
||||
get
|
||||
{
|
||||
if(!IsActivePosition) return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Blue);
|
||||
return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Black);
|
||||
}
|
||||
}
|
||||
// ***
|
||||
public double PositionRiskPercentDecimal
|
||||
{
|
||||
get{return position.PositionRiskPercentDecimal;}
|
||||
set { position.PositionRiskPercentDecimal=value; base.OnPropertyChanged("PositionRiskPercentDecimal"); }
|
||||
}
|
||||
public double InitialStopLimit
|
||||
{
|
||||
get { return position.InitialStopLimit; }
|
||||
set
|
||||
{
|
||||
position.InitialStopLimit=value;
|
||||
base.OnPropertyChanged("InitialStopLimit");
|
||||
base.OnPropertyChanged("InitialStopLimitColor");
|
||||
}
|
||||
}
|
||||
public Brush InitialStopLimitColor
|
||||
{
|
||||
get
|
||||
{
|
||||
if(!IsActivePosition) return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Blue);
|
||||
if(!Utility.IsEpoch(position.LastStopAdjustment)) return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Black); // if we have a trailing stop then we are no longer using the initial stop
|
||||
StopLimit stopLimit=PortfolioDA.GetStopLimit(position.Symbol);
|
||||
if(null==stopLimit||!stopLimit.StopPrice.Equals(Math.Round(position.InitialStopLimit,2))) return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Purple);
|
||||
if(currentPriceLow<=position.InitialStopLimit) return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Red);
|
||||
return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Black);
|
||||
}
|
||||
}
|
||||
public double TrailingStopLimit
|
||||
{
|
||||
get { return position.TrailingStopLimit; }
|
||||
set
|
||||
{
|
||||
position.TrailingStopLimit=value;
|
||||
base.OnPropertyChanged("TrailingStopLimit");
|
||||
base.OnPropertyChanged("TrailingStopLimitColor");
|
||||
}
|
||||
}
|
||||
public Brush TrailingStopLimitColor
|
||||
{
|
||||
get
|
||||
{
|
||||
if(!IsActivePosition) return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Blue);
|
||||
StopLimit stopLimit=PortfolioDA.GetStopLimit(position.Symbol);
|
||||
if(null==stopLimit||!stopLimit.StopPrice.Equals(Math.Round(position.TrailingStopLimit,2))) return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Purple);
|
||||
if(currentPriceLow<=position.TrailingStopLimit)return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Red);
|
||||
return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Black);
|
||||
}
|
||||
}
|
||||
// ***
|
||||
public DateTime LastStopAdjustment
|
||||
{
|
||||
get { return position.LastStopAdjustment; }
|
||||
set { position.LastStopAdjustment=value; base.OnPropertyChanged("LastStopAdjustment"); }
|
||||
}
|
||||
public Brush LastStopAdjustmentColor
|
||||
{
|
||||
get
|
||||
{
|
||||
if(!IsActivePosition) return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Blue);
|
||||
return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Black);
|
||||
}
|
||||
}
|
||||
// ***
|
||||
public int DaysSinceLastStopAdjustment
|
||||
{
|
||||
get
|
||||
{
|
||||
if(!IsActivePosition)return int.MinValue;
|
||||
DateGenerator dateGenerator=new DateGenerator();
|
||||
DateTime today=DateTime.Now;
|
||||
int daysSinceLastStopAdjustment=int.MinValue;
|
||||
if(Utility.IsEpoch(position.LastStopAdjustment)) daysSinceLastStopAdjustment=dateGenerator.DaysBetweenActual(today,position.PurchaseDate);
|
||||
else daysSinceLastStopAdjustment=dateGenerator.DaysBetweenActual(today,position.LastStopAdjustment);
|
||||
return daysSinceLastStopAdjustment;
|
||||
}
|
||||
}
|
||||
public Brush DaysSinceLastStopAdjustmentColor
|
||||
{
|
||||
get
|
||||
{
|
||||
if(!IsActivePosition) return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Blue);
|
||||
int daysSinceLastStopAdjustment=DaysSinceLastStopAdjustment;
|
||||
if(int.MinValue.Equals(daysSinceLastStopAdjustment))return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Blue);
|
||||
if(daysSinceLastStopAdjustment>=90) return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Red);
|
||||
else if(daysSinceLastStopAdjustment>=60) return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Red); // I made them both red because yellow and purple looked horrible
|
||||
return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Green);
|
||||
}
|
||||
}
|
||||
|
||||
// ***
|
||||
public double Shares
|
||||
{
|
||||
get { return position.Shares; }
|
||||
set { position.Shares=value; base.OnPropertyChanged("Shares"); base.OnPropertyChanged("Exposure"); base.OnPropertyChanged("ActiveExposure"); base.OnPropertyChanged("MarketValue"); base.OnPropertyChanged("ActiveMarketValue"); base.OnPropertyChanged("GainLoss"); base.OnPropertyChanged("GainLossPcnt"); }
|
||||
}
|
||||
public Brush SharesColor
|
||||
{
|
||||
get
|
||||
{
|
||||
if(!IsActivePosition) return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Blue);
|
||||
return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Black);
|
||||
}
|
||||
}
|
||||
// ***
|
||||
public double PurchasePrice
|
||||
{
|
||||
get { return position.PurchasePrice; }
|
||||
set { position.PurchasePrice=value; base.OnPropertyChanged("PurchasePrice"); base.OnPropertyChanged("Exposure"); base.OnPropertyChanged("ActiveExposure"); base.OnPropertyChanged("GainLoss"); base.OnPropertyChanged("GainLossPcnt"); }
|
||||
}
|
||||
public Brush PurchasePriceColor
|
||||
{
|
||||
get
|
||||
{
|
||||
if(!IsActivePosition) return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Blue);
|
||||
return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Black);
|
||||
}
|
||||
}
|
||||
// ***
|
||||
public double CurrentPrice
|
||||
{
|
||||
get { return position.CurrentPrice; }
|
||||
set
|
||||
{
|
||||
if(position.CurrentPrice==value) return;
|
||||
position.CurrentPrice=value;
|
||||
if(double.IsNaN(prevPrice)) { prevPrice=position.CurrentPrice; priceChangeDirection=0; }
|
||||
else if(prevPrice>position.CurrentPrice) priceChangeDirection=-1;
|
||||
else if(prevPrice==position.CurrentPrice) priceChangeDirection=0;
|
||||
else priceChangeDirection=1;
|
||||
prevPrice=position.CurrentPrice;
|
||||
UpdateProperties();
|
||||
}
|
||||
}
|
||||
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 double CurrentPriceLow
|
||||
{
|
||||
get{return currentPriceLow;}
|
||||
set
|
||||
{
|
||||
if(currentPriceLow==value)return;
|
||||
currentPriceLow=value;
|
||||
base.OnPropertyChanged("CurrentPriceLow");
|
||||
base.OnPropertyChanged("CurrentPriceLowAsString");
|
||||
base.OnPropertyChanged("TrailingStopLimitColor");
|
||||
base.OnPropertyChanged("InitialStopLimitColor");
|
||||
}
|
||||
}
|
||||
// ***
|
||||
public String CurrentPriceLowAsString
|
||||
{
|
||||
get { return Utility.FormatCurrency(currentPriceLow); }
|
||||
}
|
||||
public Brush CurrentPriceLowAsStringColor
|
||||
{
|
||||
get
|
||||
{
|
||||
if(!IsActivePosition) return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Blue);
|
||||
return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Black);
|
||||
}
|
||||
}
|
||||
// ***
|
||||
public DateTime LastUpdated
|
||||
{
|
||||
get { return lastUpdated; }
|
||||
set { lastUpdated=value; base.OnPropertyChanged("LastUpdated"); }
|
||||
}
|
||||
public Brush LastUpdatedColor
|
||||
{
|
||||
get
|
||||
{
|
||||
if(!IsActivePosition) return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Blue);
|
||||
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 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 bool IsActivePosition
|
||||
{
|
||||
get { return Utility.IsEpoch(SellDate)?true:false; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
14
Model/Constants.cs
Normal file
14
Model/Constants.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace TradeBlotter.Model
|
||||
{
|
||||
public class Constants
|
||||
{
|
||||
public const String CONST_ALL ="{All}";
|
||||
public const String CONST_DASHES = "---";
|
||||
}
|
||||
}
|
||||
28
Model/DividendLoadModel.cs
Normal file
28
Model/DividendLoadModel.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using MarketData.MarketDataModel;
|
||||
using MarketData.Numerical;
|
||||
using Microsoft.Research.DynamicDataDisplay.DataSources;
|
||||
using MarketData;
|
||||
|
||||
namespace TradeBlotter.Model
|
||||
{
|
||||
public class DividendLoadModel
|
||||
{
|
||||
private DividendLoadModel()
|
||||
{
|
||||
}
|
||||
public static CompositeDataSource GenerateCompositeDataSource(DividendLoadCollection dividendLoadCollection)
|
||||
{
|
||||
if (null == dividendLoadCollection || 0 == dividendLoadCollection.Count) return null;
|
||||
CompositeDataSource compositeDataSource;
|
||||
var xData = new EnumerableDataSource<DateTime>(dividendLoadCollection.Select(x => new DateTime(x.Year,12,31)));
|
||||
xData.SetXMapping(x => (x.Ticks / 10000000000.0));
|
||||
var yData = new EnumerableDataSource<double>(dividendLoadCollection.Select(y => y.DividendLoadPcnt));
|
||||
yData.SetYMapping(y => y);
|
||||
compositeDataSource = xData.Join(yData);
|
||||
return compositeDataSource;
|
||||
}
|
||||
}
|
||||
}
|
||||
130
Model/DividendPaymentModel.cs
Normal file
130
Model/DividendPaymentModel.cs
Normal file
@@ -0,0 +1,130 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using MarketData.MarketDataModel;
|
||||
using MarketData.Utils;
|
||||
using System.Collections.ObjectModel;
|
||||
using Microsoft.Research.DynamicDataDisplay.DataSources;
|
||||
using MarketData;
|
||||
using MarketData.Numerical;
|
||||
|
||||
namespace TradeBlotter.Model
|
||||
{
|
||||
public class DividendPaymentModelCollection : ObservableCollection<DividendPaymentModel>
|
||||
{
|
||||
public DividendPaymentModelCollection(DividendPayments dividendPayments)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (null == dividendPayments || 0 == dividendPayments.Count) return;
|
||||
List<DividendPayment> dividendPaymentsOrdered = dividendPayments.OrderByDescending(x => x.PaymentDate).ThenBy(x => x.Account).ThenBy(x => x.Symbol).ToList();
|
||||
int currentYear = -1;
|
||||
for (int index = dividendPaymentsOrdered.Count - 1; index >= 0; index--)
|
||||
{
|
||||
DividendPaymentModel dividendPaymentModel = new DividendPaymentModel(dividendPaymentsOrdered[index]);
|
||||
if (0 == Count) dividendPaymentModel.TotalAmount = dividendPaymentModel.Amount;
|
||||
else dividendPaymentModel.TotalAmount = this[0].TotalAmount + dividendPaymentModel.Amount;
|
||||
if (currentYear != dividendPaymentModel.PaymentDate.Year) { currentYear = dividendPaymentModel.PaymentDate.Year; dividendPaymentModel.TotalAnnualAmount = dividendPaymentModel.Amount; }
|
||||
else dividendPaymentModel.TotalAnnualAmount = this[0].TotalAnnualAmount + dividendPaymentModel.Amount;
|
||||
Insert(0, dividendPaymentModel);
|
||||
}
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG, String.Format("{0}",exception));
|
||||
}
|
||||
}
|
||||
// This method just takes the total for each day and then splines the result to get a smooth curve
|
||||
public CompositeDataSource ToCompositeDataSource(bool useTotal)
|
||||
{
|
||||
if (0 == Count) return null;
|
||||
List<DividendPaymentModel> dividendPaymentsModelList = new List<DividendPaymentModel>();
|
||||
DateTime currentDate = Utility.Epoch;
|
||||
foreach (DividendPaymentModel dividendPaymentModel in this)
|
||||
{
|
||||
if (currentDate.Equals(Utility.Epoch))
|
||||
{
|
||||
currentDate = dividendPaymentModel.PaymentDate;
|
||||
dividendPaymentsModelList.Add(dividendPaymentModel);
|
||||
}
|
||||
else if(!currentDate.Date.Equals(dividendPaymentModel.PaymentDate))
|
||||
{
|
||||
currentDate = dividendPaymentModel.PaymentDate;
|
||||
dividendPaymentsModelList.Add(dividendPaymentModel);
|
||||
}
|
||||
}
|
||||
|
||||
List<Element> sourcePairs = new List<Element>();
|
||||
List<Element> destPairs = new List<Element>();
|
||||
DateGenerator dateGenerator = new DateGenerator();
|
||||
DateTime minDate = dividendPaymentsModelList.Min(x => x.PaymentDate);
|
||||
DateTime maxDate = dividendPaymentsModelList.Max(x => x.PaymentDate);
|
||||
List<DateTime> historicalDates=dateGenerator.GenerateHistoricalDates(maxDate, minDate);
|
||||
foreach (DateTime historicalDate in historicalDates) destPairs.Add(new Element(dateGenerator.DaysBetweenActual(minDate,historicalDate.Date), 0));
|
||||
foreach (DividendPaymentModel dividendPaymentModel in dividendPaymentsModelList)
|
||||
{
|
||||
sourcePairs.Add(new Element(dateGenerator.DaysBetweenActual(minDate,dividendPaymentModel.PaymentDate), dividendPaymentModel.TotalAmount));
|
||||
}
|
||||
Element[] sourcePairsArray = sourcePairs.ToArray();
|
||||
Element[] destPairsArray = destPairs.ToArray();
|
||||
CatmullRom.PerformSpline(sourcePairsArray, destPairsArray);
|
||||
|
||||
CompositeDataSource compositeDataSource;
|
||||
var xData = new EnumerableDataSource<DateTime>(destPairsArray.Select(x => dateGenerator.DaysAddActual(minDate,Math.Abs((int)x.Column))));
|
||||
xData.SetXMapping(x => x.Ticks / 10000000000.0);
|
||||
var yData = new EnumerableDataSource<double>(destPairsArray.Select(y => y.Row));
|
||||
yData.SetYMapping(y => y);
|
||||
compositeDataSource = xData.Join(yData);
|
||||
return compositeDataSource;
|
||||
}
|
||||
// This method takes the points only at the payment dates
|
||||
public CompositeDataSource CollectionToCompositeDataSource(bool useTotal)
|
||||
{
|
||||
if (0 == Count) return null;
|
||||
List<DividendPaymentModel> dividendPaymentsModelList = new List<DividendPaymentModel>();
|
||||
DateTime currentDate = Utility.Epoch;
|
||||
foreach (DividendPaymentModel dividendPaymentModel in this)
|
||||
{
|
||||
if (currentDate.Equals(Utility.Epoch))
|
||||
{
|
||||
currentDate = dividendPaymentModel.PaymentDate;
|
||||
dividendPaymentsModelList.Add(dividendPaymentModel);
|
||||
}
|
||||
else if (!currentDate.Date.Equals(dividendPaymentModel.PaymentDate))
|
||||
{
|
||||
currentDate = dividendPaymentModel.PaymentDate;
|
||||
dividendPaymentsModelList.Add(dividendPaymentModel);
|
||||
}
|
||||
}
|
||||
CompositeDataSource compositeDataSource;
|
||||
var xData = new EnumerableDataSource<DateTime>(dividendPaymentsModelList.Select(x => x.PaymentDate));
|
||||
xData.SetXMapping(x => x.Ticks / 10000000000.0);
|
||||
var yData = new EnumerableDataSource<double>(dividendPaymentsModelList.Select(y => y.TotalAmount));
|
||||
yData.SetYMapping(y => y);
|
||||
compositeDataSource = xData.Join(yData);
|
||||
return compositeDataSource;
|
||||
}
|
||||
//public ObservableCollection<DividendPaymentModel> Clone()
|
||||
//{
|
||||
// ObservableCollection<DividendPaymentModel> dividendPayments = new ObservableCollection<DividendPaymentModel>();
|
||||
// foreach (DividendPaymentModel dividendPaymentModel in this) Add(dividendPaymentModel);
|
||||
// return dividendPayments;
|
||||
//}
|
||||
}
|
||||
public class DividendPaymentModel : DividendPayment
|
||||
{
|
||||
public DividendPaymentModel()
|
||||
{
|
||||
}
|
||||
public DividendPaymentModel(DividendPayment dividendPayment)
|
||||
{
|
||||
this.PaymentDate = dividendPayment.PaymentDate;
|
||||
this.Symbol = dividendPayment.Symbol;
|
||||
this.Account = dividendPayment.Account;
|
||||
this.Amount = dividendPayment.Amount;
|
||||
}
|
||||
public double TotalAmount { get; set; }
|
||||
public double TotalAnnualAmount { get; set; }
|
||||
}
|
||||
}
|
||||
43
Model/ETFHoldingModel.cs
Normal file
43
Model/ETFHoldingModel.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using MarketData.MarketDataModel;
|
||||
|
||||
namespace TradeBlotter.Model
|
||||
{
|
||||
public class ETFHoldingModel
|
||||
{
|
||||
private ETFHolding etfHolding;
|
||||
|
||||
public ETFHoldingModel(ETFHolding etfHolding)
|
||||
{
|
||||
this.etfHolding=etfHolding;
|
||||
}
|
||||
public String ETFHoldingSymbol
|
||||
{
|
||||
get{return etfHolding.ETFSymbol;}
|
||||
}
|
||||
public String HoldingSymbol
|
||||
{
|
||||
get
|
||||
{
|
||||
String symbolNoExchange = etfHolding.HoldingSymbol;
|
||||
if (symbolNoExchange.Contains(".")) symbolNoExchange = symbolNoExchange.Split('.')[0];
|
||||
return symbolNoExchange;
|
||||
}
|
||||
}
|
||||
public String HoldingSymbolShareClass
|
||||
{
|
||||
get{return etfHolding.HoldingSymbolShareClass;}
|
||||
}
|
||||
public String HoldingCompanyName
|
||||
{
|
||||
get{return etfHolding.HoldingCompanyName;}
|
||||
}
|
||||
public double PercentOfAssets
|
||||
{
|
||||
get{return etfHolding.PercentOfAssets;}
|
||||
}
|
||||
}
|
||||
}
|
||||
50
Model/EarningsAnnouncementModel.cs
Normal file
50
Model/EarningsAnnouncementModel.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using MarketData.MarketDataModel;
|
||||
using MarketData.Utils;
|
||||
|
||||
namespace TradeBlotter.Model
|
||||
{
|
||||
public class EarningsAnnouncementModel : IComparable
|
||||
{
|
||||
public EarningsAnnouncementModel()
|
||||
{
|
||||
}
|
||||
public EarningsAnnouncementModel(String symbol,DateTime nextEarningsDate)
|
||||
{
|
||||
Symbol = symbol;
|
||||
NextEarningsDate = nextEarningsDate;
|
||||
}
|
||||
public int CompareTo(object other)
|
||||
{
|
||||
if (other.GetType() != typeof(EarningsAnnouncementModel)) throw new Exception("Expected typeof " + this.GetType().Name);
|
||||
EarningsAnnouncementModel otherModel = (EarningsAnnouncementModel)other;
|
||||
return NextEarningsDate.CompareTo(otherModel.NextEarningsDate);
|
||||
}
|
||||
public String Symbol { get; set; }
|
||||
public String CompanyName { get; set; }
|
||||
public DateTime NextEarningsDate { get; set; }
|
||||
public int DaysFromToday { get; set; }
|
||||
public double LastPrice { get; set; }
|
||||
public double Upside { get; set; }
|
||||
public double Downside { get; set; }
|
||||
public double UpsidePcnt { get; set; }
|
||||
public double DownsidePcnt { get; set; }
|
||||
public DateTime PricingDate { get; set; }
|
||||
public double PE { get; set; }
|
||||
public double PEG { get; set; }
|
||||
public double AnticipatedEarningsGrowth { get; set; }
|
||||
public String AnticipatedEarningsGrowthStr
|
||||
{
|
||||
get
|
||||
{
|
||||
if (double.IsInfinity(AnticipatedEarningsGrowth) || double.NaN.Equals(AnticipatedEarningsGrowth)) return Constants.CONST_DASHES;
|
||||
return Utility.FormatPercent(AnticipatedEarningsGrowth);
|
||||
}
|
||||
}
|
||||
public String PEGValuation { get; set; }
|
||||
public DateTime LastUpdated { get; set; }
|
||||
}
|
||||
}
|
||||
124
Model/GainLossModel.cs
Normal file
124
Model/GainLossModel.cs
Normal file
@@ -0,0 +1,124 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using TradeBlotter.Views;
|
||||
using MarketData.MarketDataModel;
|
||||
using MarketData.Generator;
|
||||
using Microsoft.Research.DynamicDataDisplay.DataSources;
|
||||
using MarketData.Numerical;
|
||||
using MarketData.MarketDataModel.GainLoss;
|
||||
|
||||
namespace TradeBlotter.Model
|
||||
{
|
||||
public class GainLossModel
|
||||
{
|
||||
private GainLossModel()
|
||||
{
|
||||
}
|
||||
public static CompositeDataSource CreateCompositeDataSource(DateTime xSource,double ySource)
|
||||
{
|
||||
CompositeDataSource compositeDataSource;
|
||||
var xData=new EnumerableDataSource<DateTime>(new DateTime[] { xSource });
|
||||
xData.SetXMapping(x => (x.Ticks/10000000000.0));
|
||||
var yData=new EnumerableDataSource<double>(new double[] { ySource });
|
||||
yData.SetYMapping(y => y);
|
||||
compositeDataSource=xData.Join(yData);
|
||||
return compositeDataSource;
|
||||
}
|
||||
public static CompositeDataSource Price(Price price)
|
||||
{
|
||||
if (null == price) return null;
|
||||
CompositeDataSource compositeDataSource;
|
||||
var xData = new EnumerableDataSource<DateTime>(new DateTime[]{price.Date});
|
||||
xData.SetXMapping(x => (x.Ticks / 10000000000.0));
|
||||
var yData = new EnumerableDataSource<double>(new double[]{price.Close});
|
||||
yData.SetYMapping(y => y);
|
||||
compositeDataSource = xData.Join(yData);
|
||||
return compositeDataSource;
|
||||
}
|
||||
// *************************************************************** A C T I V E G A I N / L O S S C O M P O N E N T S ***************************************
|
||||
// This is the active gain/loss as number or percent.
|
||||
public static CompositeDataSource GainLoss(ModelPerformanceSeries gainLossList,bool useGainLoss)
|
||||
{
|
||||
if(null==gainLossList) return null;
|
||||
CompositeDataSource compositeDataSource;
|
||||
var xData=new EnumerableDataSource<DateTime>(gainLossList.Select(x => x.Date.Date));
|
||||
xData.SetXMapping(x => (x.Ticks/10000000000.0));
|
||||
var yData=new EnumerableDataSource<double>(gainLossList.Select(y => useGainLoss?y.CumulativeGainLoss:y.CumProdMinusOne*100.00));
|
||||
yData.SetYMapping(y => y);
|
||||
compositeDataSource=xData.Join(yData);
|
||||
return compositeDataSource;
|
||||
}
|
||||
|
||||
// This is the active gain/loss as number or percent.
|
||||
public static CompositeDataSource GainLoss(GainLossCompoundModelCollection gainLossList,bool useGainLoss)
|
||||
{
|
||||
if (null == gainLossList) return null;
|
||||
CompositeDataSource compositeDataSource;
|
||||
var xData = new EnumerableDataSource<DateTime>(gainLossList.Select(x => x.Date.Date));
|
||||
xData.SetXMapping(x => (x.Ticks / 10000000000.0));
|
||||
var yData = new EnumerableDataSource<double>(gainLossList.Select(y => useGainLoss?y.ActiveGainLoss:y.ActiveGainLossPercent));
|
||||
yData.SetYMapping(y => y);
|
||||
compositeDataSource = xData.Join(yData);
|
||||
return compositeDataSource;
|
||||
}
|
||||
// This is the least squares composite data source based on the active gain/loss
|
||||
public static CompositeDataSource LeastSquares(GainLossCompoundModelCollection gainLossList,bool useGainLoss)
|
||||
{
|
||||
if (null == gainLossList) return null;
|
||||
CompositeDataSource compositeDataSource;
|
||||
var xData = new EnumerableDataSource<DateTime>(gainLossList.Select(x => x.Date.Date));
|
||||
xData.SetXMapping(x => (x.Ticks / 10000000000.0));
|
||||
LeastSquaresResult leastSquaresResult=LeastSquaresFit(gainLossList,useGainLoss);
|
||||
var yData = new EnumerableDataSource<double>(leastSquaresResult.LeastSquares);
|
||||
yData.SetYMapping(y => y);
|
||||
compositeDataSource = xData.Join(yData);
|
||||
return compositeDataSource;
|
||||
}
|
||||
// This is the LeastSquares fit based on the active gain/loss
|
||||
public static LeastSquaresResult LeastSquaresFit(GainLossCompoundModelCollection gainLossList,bool useGainLoss)
|
||||
{
|
||||
double[] values=null;
|
||||
if(useGainLoss)values=(from GainLossCompoundModel gainLoss in gainLossList select gainLoss.ActiveGainLoss).ToList().ToArray();
|
||||
else values=(from GainLossCompoundModel gainLoss in gainLossList select gainLoss.ActiveGainLossPercent).ToList().ToArray();
|
||||
LeastSquaresResult leastSquaresResult=Numerics.LeastSquares(values);
|
||||
return leastSquaresResult;
|
||||
}
|
||||
// *************************************************************** T O T A L G A I N / L O S S C O M P O N E N T S ***************************************
|
||||
// This is the total gain loss as number or percent
|
||||
public static CompositeDataSource TotalGainLoss(GainLossCompoundModelCollection gainLossList,bool useGainLoss)
|
||||
{
|
||||
if (null == gainLossList) return null;
|
||||
CompositeDataSource compositeDataSource;
|
||||
var xData = new EnumerableDataSource<DateTime>(gainLossList.Select(x => x.Date.Date));
|
||||
xData.SetXMapping(x => (x.Ticks / 10000000000.0));
|
||||
var yData = new EnumerableDataSource<double>(gainLossList.Select(y => useGainLoss?y.TotalGainLoss:y.TotalGainLossPercent));
|
||||
yData.SetYMapping(y => y);
|
||||
compositeDataSource = xData.Join(yData);
|
||||
return compositeDataSource;
|
||||
}
|
||||
// This is the least squares composite data source based on the total gain/loss
|
||||
public static CompositeDataSource TotalLeastSquares(GainLossCompoundModelCollection gainLossList,bool useGainLoss)
|
||||
{
|
||||
if (null == gainLossList) return null;
|
||||
CompositeDataSource compositeDataSource;
|
||||
var xData = new EnumerableDataSource<DateTime>(gainLossList.Select(x => x.Date.Date));
|
||||
xData.SetXMapping(x => (x.Ticks / 10000000000.0));
|
||||
LeastSquaresResult leastSquaresResult=TotalLeastSquaresFit(gainLossList,useGainLoss);
|
||||
var yData = new EnumerableDataSource<double>(leastSquaresResult.LeastSquares);
|
||||
yData.SetYMapping(y => y);
|
||||
compositeDataSource = xData.Join(yData);
|
||||
return compositeDataSource;
|
||||
}
|
||||
// This is the LeastSquares fit based on the total gain/loss
|
||||
public static LeastSquaresResult TotalLeastSquaresFit(GainLossCompoundModelCollection gainLossList,bool useGainLoss)
|
||||
{
|
||||
double[] values=null;
|
||||
if(useGainLoss)values=(from GainLossCompoundModel gainLoss in gainLossList select gainLoss.TotalGainLoss).ToList().ToArray();
|
||||
else values=(from GainLossCompoundModel gainLoss in gainLossList select gainLoss.TotalGainLossPercent).ToList().ToArray();
|
||||
LeastSquaresResult leastSquaresResult=Numerics.LeastSquares(values);
|
||||
return leastSquaresResult;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
28
Model/InsiderTransactionModel.cs
Normal file
28
Model/InsiderTransactionModel.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using TradeBlotter.Views;
|
||||
using MarketData.MarketDataModel;
|
||||
using MarketData.Generator;
|
||||
using Microsoft.Research.DynamicDataDisplay.DataSources;
|
||||
|
||||
namespace TradeBlotter.Model
|
||||
{
|
||||
public class InsiderTransactionModel
|
||||
{
|
||||
private InsiderTransactionModel()
|
||||
{
|
||||
}
|
||||
public static CompositeDataSource InsiderTransactionSummaries(InsiderTransactionSummaries insiderTransactionSummaries,double minPrice)
|
||||
{
|
||||
if (null == insiderTransactionSummaries) return null;
|
||||
CompositeDataSource compositeDataSource;
|
||||
var xData = new EnumerableDataSource<DateTime>(insiderTransactionSummaries.Select(x => x.TransactionDate.Date));
|
||||
xData.SetXMapping(x => (x.Ticks / 10000000000.0));
|
||||
var yData = new EnumerableDataSource<double>(insiderTransactionSummaries.Select(y=>minPrice));
|
||||
yData.SetYMapping(y => y);
|
||||
compositeDataSource = xData.Join(yData);
|
||||
return compositeDataSource;
|
||||
}
|
||||
}
|
||||
}
|
||||
14
Model/Item.cs
Normal file
14
Model/Item.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System.Text;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace TradeBlotter.Model
|
||||
{
|
||||
public class Items : List<Item>
|
||||
{
|
||||
}
|
||||
public class Item
|
||||
{
|
||||
public Item(string v) { Value = v; }
|
||||
public string Value { get; private set; }
|
||||
}
|
||||
}
|
||||
70
Model/MACDModel.cs
Normal file
70
Model/MACDModel.cs
Normal file
@@ -0,0 +1,70 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using MarketData.MarketDataModel;
|
||||
using Microsoft.Research.DynamicDataDisplay.DataSources;
|
||||
|
||||
namespace TradeBlotter.Model
|
||||
{
|
||||
public class MACDModel
|
||||
{
|
||||
private MACDModel()
|
||||
{
|
||||
}
|
||||
public static CompositeDataSource Signals(Signals signals,double anchor)
|
||||
{
|
||||
if (null == signals) return null;
|
||||
CompositeDataSource compositeDataSource;
|
||||
var xData = new EnumerableDataSource<DateTime>(signals.Select(x => x.SignalDate.Date));
|
||||
xData.SetXMapping(x => (x.Ticks / 10000000000.0));
|
||||
var yData = new EnumerableDataSource<double>(signals.Select(y => anchor));
|
||||
yData.SetYMapping(y => y);
|
||||
compositeDataSource = xData.Join(yData);
|
||||
return compositeDataSource;
|
||||
}
|
||||
public static CompositeDataSource SignalSlow(MACDFastSlowSignals macdFastSlowSignals)
|
||||
{
|
||||
if (null == macdFastSlowSignals) return null;
|
||||
CompositeDataSource compositeDataSource;
|
||||
var xData = new EnumerableDataSource<DateTime>(macdFastSlowSignals.Select(x => x.Date.Date));
|
||||
xData.SetXMapping(x => (x.Ticks / 10000000000.0));
|
||||
var yData = new EnumerableDataSource<double>(macdFastSlowSignals.Select(y => y.SignalSlow));
|
||||
yData.SetYMapping(y => y);
|
||||
compositeDataSource = xData.Join(yData);
|
||||
return compositeDataSource;
|
||||
}
|
||||
public static CompositeDataSource MACDSlow(MACDFastSlowSignals macdFastSlowSignals)
|
||||
{
|
||||
if (null == macdFastSlowSignals) return null;
|
||||
CompositeDataSource compositeDataSource;
|
||||
var xData = new EnumerableDataSource<DateTime>(macdFastSlowSignals.Select(x => x.Date.Date));
|
||||
xData.SetXMapping(x => (x.Ticks / 10000000000.0));
|
||||
var yData = new EnumerableDataSource<double>(macdFastSlowSignals.Select(y => y.MACDSlow));
|
||||
yData.SetYMapping(y => y);
|
||||
compositeDataSource = xData.Join(yData);
|
||||
return compositeDataSource;
|
||||
}
|
||||
public static CompositeDataSource SignalFast(MACDFastSlowSignals macdFastSlowSignals)
|
||||
{
|
||||
if (null == macdFastSlowSignals) return null;
|
||||
CompositeDataSource compositeDataSource;
|
||||
var xData = new EnumerableDataSource<DateTime>(macdFastSlowSignals.Select(x => x.Date.Date));
|
||||
xData.SetXMapping(x => (x.Ticks / 10000000000.0));
|
||||
var yData = new EnumerableDataSource<double>(macdFastSlowSignals.Select(y => y.SignalFast));
|
||||
yData.SetYMapping(y => y);
|
||||
compositeDataSource = xData.Join(yData);
|
||||
return compositeDataSource;
|
||||
}
|
||||
public static CompositeDataSource MACDFast(MACDFastSlowSignals macdFastSlowSignals)
|
||||
{
|
||||
if (null == macdFastSlowSignals) return null;
|
||||
CompositeDataSource compositeDataSource;
|
||||
var xData = new EnumerableDataSource<DateTime>(macdFastSlowSignals.Select(x => x.Date.Date));
|
||||
xData.SetXMapping(x => (x.Ticks / 10000000000.0));
|
||||
var yData = new EnumerableDataSource<double>(macdFastSlowSignals.Select(y => y.MACDFast));
|
||||
yData.SetYMapping(y => y);
|
||||
compositeDataSource = xData.Join(yData);
|
||||
return compositeDataSource;
|
||||
}
|
||||
}
|
||||
}
|
||||
347
Model/MGPositionModel.cs
Normal file
347
Model/MGPositionModel.cs
Normal file
@@ -0,0 +1,347 @@
|
||||
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<MGPositionModel>
|
||||
{
|
||||
public void Add(ActivePositions activePositions)
|
||||
{
|
||||
List<int> slotKeys=new List<int>(activePositions.Keys);
|
||||
for(int keyIndex=0;keyIndex<slotKeys.Count;keyIndex++)
|
||||
{
|
||||
Positions slotPositions=activePositions[slotKeys[keyIndex]];
|
||||
foreach (MarketData.Generator.Momentum.Position position in slotPositions) Add(new MGPositionModel(position, keyIndex));
|
||||
}
|
||||
}
|
||||
public void Add(MarketData.Generator.Momentum.Positions allPositions)
|
||||
{
|
||||
foreach (MarketData.Generator.Momentum.Position position in allPositions) Add(new MGPositionModel(position));
|
||||
}
|
||||
public void OnCollectionChanged()
|
||||
{
|
||||
base.OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset,null));
|
||||
}
|
||||
}
|
||||
public class MGPositionModel : ModelBase
|
||||
{
|
||||
private MarketData.Generator.Momentum.Position position = new MarketData.Generator.Momentum.Position();
|
||||
private int slot;
|
||||
private int priceChangeDirection=0;
|
||||
private double prevPrice=double.NaN;
|
||||
private DateTime lastUpdated=DateTime.Now;
|
||||
private double rsi3=double.NaN;
|
||||
|
||||
public MGPositionModel()
|
||||
{
|
||||
}
|
||||
public MGPositionModel(MarketData.Generator.Momentum.Position position, int slot)
|
||||
{
|
||||
Slot=slot;
|
||||
Symbol=position.Symbol;
|
||||
PurchaseDate=position.PurchaseDate;
|
||||
SellDate=position.SellDate;
|
||||
Shares=position.Shares;
|
||||
PurchasePrice=position.PurchasePrice;
|
||||
CurrentPrice=position.CurrentPrice;
|
||||
Volume=position.Volume;
|
||||
Return1D=position.Return1D;
|
||||
CumReturn252=position.CumReturn252;
|
||||
IDIndicator=position.IDIndicator;
|
||||
Score=position.Score;
|
||||
MaxDrawdown=position.MaxDrawdown;
|
||||
MaxUpside=position.MaxUpside;
|
||||
Velocity=position.Velocity;
|
||||
PE=position.PE;
|
||||
Beta=position.Beta;
|
||||
ZacksRank=position.ZacksRank;
|
||||
SharpeRatio = position.SharpeRatio;
|
||||
}
|
||||
public MGPositionModel(MarketData.Generator.Momentum.Position position)
|
||||
{
|
||||
slot=-1;
|
||||
Symbol=position.Symbol;
|
||||
PurchaseDate=position.PurchaseDate;
|
||||
SellDate=position.SellDate;
|
||||
Shares=position.Shares;
|
||||
PurchasePrice=position.PurchasePrice;
|
||||
CurrentPrice=position.CurrentPrice;
|
||||
Volume=position.Volume;
|
||||
Return1D=position.Return1D;
|
||||
CumReturn252=position.CumReturn252;
|
||||
IDIndicator=position.IDIndicator;
|
||||
Score=position.Score;
|
||||
MaxDrawdown=position.MaxDrawdown;
|
||||
MaxUpside=position.MaxUpside;
|
||||
Velocity=position.Velocity;
|
||||
PE=position.PE;
|
||||
Beta=position.Beta;
|
||||
ZacksRank=position.ZacksRank;
|
||||
SharpeRatio = position.SharpeRatio;
|
||||
}
|
||||
public String Symbol
|
||||
{
|
||||
get{return position.Symbol;}
|
||||
set{position.Symbol=value;base.OnPropertyChanged("Symbol");}
|
||||
}
|
||||
public DateTime PurchaseDate
|
||||
{
|
||||
get{return position.PurchaseDate;}
|
||||
set{position.PurchaseDate=value;base.OnPropertyChanged("PurchaseDate");}
|
||||
}
|
||||
|
||||
public Brush PurchaseDateColor
|
||||
{
|
||||
get
|
||||
{
|
||||
DateGenerator dateGenerator=new DateGenerator();
|
||||
if(!dateGenerator.IsMarketOpen(PurchaseDate)) return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Red);
|
||||
if(!IsActivePosition) return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Blue);
|
||||
return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Black);
|
||||
}
|
||||
}
|
||||
|
||||
public Brush SellDateColor
|
||||
{
|
||||
get
|
||||
{
|
||||
DateGenerator dateGenerator=new DateGenerator();
|
||||
if(!dateGenerator.IsMarketOpen(SellDate)) return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Red);
|
||||
if(!IsActivePosition) return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Blue);
|
||||
return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Black);
|
||||
}
|
||||
}
|
||||
|
||||
public DateTime SellDate
|
||||
{
|
||||
get{return position.SellDate;}
|
||||
set{position.SellDate=value;base.OnPropertyChanged("SellDate");}
|
||||
}
|
||||
public int DaysHeld
|
||||
{
|
||||
get
|
||||
{
|
||||
DateGenerator dateGenerator=new DateGenerator();
|
||||
if(Utility.IsEpoch(SellDate))return dateGenerator.DaysBetween(PurchaseDate,DateTime.Now.Date);
|
||||
return dateGenerator.DaysBetween(PurchaseDate,SellDate);
|
||||
}
|
||||
}
|
||||
public int Slot
|
||||
{
|
||||
get{return slot;}
|
||||
set{slot=value;base.OnPropertyChanged("Slot");}
|
||||
}
|
||||
public String SlotAsString
|
||||
{
|
||||
get
|
||||
{
|
||||
if(-1==Slot)return Constants.CONST_DASHES;
|
||||
return Slot.ToString();
|
||||
}
|
||||
}
|
||||
public double Shares
|
||||
{
|
||||
get{return position.Shares;}
|
||||
set{position.Shares=value;base.OnPropertyChanged("Shares");base.OnPropertyChanged("Exposure");base.OnPropertyChanged("ActiveExposure");base.OnPropertyChanged("MarketValue");base.OnPropertyChanged("ActiveMarketValue");base.OnPropertyChanged("GainLoss");base.OnPropertyChanged("GainLossPcnt");}
|
||||
}
|
||||
public double PurchasePrice
|
||||
{
|
||||
get{return position.PurchasePrice;}
|
||||
set{position.PurchasePrice=value;base.OnPropertyChanged("PurchasePrice");base.OnPropertyChanged("Exposure");base.OnPropertyChanged("ActiveExposure");base.OnPropertyChanged("GainLoss");base.OnPropertyChanged("GainLossPcnt");}
|
||||
}
|
||||
public double CurrentPrice
|
||||
{
|
||||
get{return position.CurrentPrice;}
|
||||
set
|
||||
{
|
||||
if(position.CurrentPrice==value)return;
|
||||
position.CurrentPrice=value;
|
||||
if(double.IsNaN(prevPrice)){prevPrice=position.CurrentPrice;priceChangeDirection=0;}
|
||||
else if(prevPrice>position.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;}
|
||||
}
|
||||
}
|
||||
}
|
||||
466
Model/MMPositionModel.cs
Normal file
466
Model/MMPositionModel.cs
Normal file
@@ -0,0 +1,466 @@
|
||||
//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.Generator.MMTrend;
|
||||
//using MarketData;
|
||||
|
||||
//using Position=MarketData.Generator.MMTrend.Position;
|
||||
//using StopLimit=MarketData.MarketDataModel.StopLimit;
|
||||
|
||||
//using MarketData.DataAccess;
|
||||
|
||||
//namespace TradeBlotter.Model
|
||||
//{
|
||||
// public class MMPositionModelCollection:ObservableCollection<MMPositionModel>
|
||||
// {
|
||||
// public void Add(ActivePositions activePositions)
|
||||
// {
|
||||
// foreach(Position position in activePositions)Add(new MMPositionModel(position));
|
||||
// }
|
||||
// public void Add(Positions allPositions)
|
||||
// {
|
||||
// foreach(Position position in allPositions) Add(new MMPositionModel(position));
|
||||
// }
|
||||
// public void OnCollectionChanged()
|
||||
// {
|
||||
// base.OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset,null));
|
||||
// }
|
||||
// }
|
||||
|
||||
// public class MMPositionModel:ModelBase
|
||||
// {
|
||||
// private Position position=new Position();
|
||||
// private int priceChangeDirection=0;
|
||||
// private double prevPrice=double.NaN;
|
||||
// private double currentPriceLow=double.NaN;
|
||||
// private DateTime lastUpdated=DateTime.Now;
|
||||
|
||||
// public MMPositionModel()
|
||||
// {
|
||||
// }
|
||||
// public MMPositionModel(Position position)
|
||||
// {
|
||||
// Symbol=position.Symbol;
|
||||
// PurchaseDate=position.PurchaseDate;
|
||||
// SellDate=position.SellDate;
|
||||
// Shares=position.Shares;
|
||||
// PurchasePrice=position.PurchasePrice;
|
||||
// CurrentPrice=position.CurrentPrice;
|
||||
// PositionRiskPercentDecimal=position.PositionRiskPercentDecimal;
|
||||
// InitialStopLimit=position.InitialStopLimit;
|
||||
// TrailingStopLimit=position.TrailingStopLimit;
|
||||
// LastStopAdjustment=position.LastStopAdjustment;
|
||||
// this.position.R=position.R;
|
||||
// this.position.C=position.C;
|
||||
// }
|
||||
// public void UpdateProperties()
|
||||
// {
|
||||
// base.OnPropertyChanged("CurrentPrice");
|
||||
// base.OnPropertyChanged("MarketValue");
|
||||
// base.OnPropertyChanged("ActiveMarketValue");
|
||||
// base.OnPropertyChanged("GainLoss");
|
||||
// base.OnPropertyChanged("GainLossPcnt");
|
||||
// base.OnPropertyChanged("RMultipleAsString");
|
||||
// base.OnPropertyChanged("CurrentPriceColor");
|
||||
// base.OnPropertyChanged("TrailingStopLimitColor");
|
||||
// base.OnPropertyChanged("InitialStopLimitColor");
|
||||
// base.OnPropertyChanged("TotalRiskExposureColor");
|
||||
// base.OnPropertyChanged("ActiveMarketValueColor");
|
||||
// base.OnPropertyChanged("GainLossColor");
|
||||
// base.OnPropertyChanged("GainLossPcntColor");
|
||||
// }
|
||||
// public Position Position
|
||||
// {
|
||||
// get{return position;}
|
||||
// set
|
||||
// {
|
||||
// Symbol=position.Symbol;
|
||||
// PurchaseDate=position.PurchaseDate;
|
||||
// SellDate=position.SellDate;
|
||||
// Shares=position.Shares;
|
||||
// PurchasePrice=position.PurchasePrice;
|
||||
// CurrentPrice=position.CurrentPrice;
|
||||
// PositionRiskPercentDecimal=position.PositionRiskPercentDecimal;
|
||||
// InitialStopLimit=position.InitialStopLimit;
|
||||
// TrailingStopLimit=position.TrailingStopLimit;
|
||||
// LastStopAdjustment=position.LastStopAdjustment;
|
||||
// this.position.R=position.R;
|
||||
// this.position.C=position.C;
|
||||
// }
|
||||
// }
|
||||
// public String Symbol
|
||||
// {
|
||||
// get { return position.Symbol; }
|
||||
// set { position.Symbol=value; base.OnPropertyChanged("Symbol"); }
|
||||
// }
|
||||
// public Brush SymbolColor
|
||||
// {
|
||||
// get
|
||||
// {
|
||||
// if(!IsActivePosition) return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Blue);
|
||||
// return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Black);
|
||||
// }
|
||||
// }
|
||||
//// ***
|
||||
// public DateTime PurchaseDate
|
||||
// {
|
||||
// get { return position.PurchaseDate; }
|
||||
// set { position.PurchaseDate=value; base.OnPropertyChanged("PurchaseDate"); }
|
||||
// }
|
||||
|
||||
// public Brush PurchaseDateColor
|
||||
// {
|
||||
// get
|
||||
// {
|
||||
// DateGenerator dateGenerator=new DateGenerator();
|
||||
// if(!dateGenerator.IsMarketOpen(PurchaseDate)) return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Red);
|
||||
// if(!IsActivePosition) return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Blue);
|
||||
// return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Black);
|
||||
// }
|
||||
// }
|
||||
|
||||
// public DateTime SellDate
|
||||
// {
|
||||
// get { return position.SellDate; }
|
||||
// set { position.SellDate=value; base.OnPropertyChanged("SellDate"); }
|
||||
// }
|
||||
|
||||
// public Brush SellDateColor
|
||||
// {
|
||||
// get
|
||||
// {
|
||||
// if(Utility.IsEpoch(SellDate)) return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Black);
|
||||
// DateGenerator dateGenerator=new DateGenerator();
|
||||
// if(!dateGenerator.IsMarketOpen(SellDate)) return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Red);
|
||||
// if(!IsActivePosition) return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Blue);
|
||||
// return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Black);
|
||||
// }
|
||||
// }
|
||||
//// ***
|
||||
// public int DaysHeld
|
||||
// {
|
||||
// get
|
||||
// {
|
||||
// DateGenerator dateGenerator=new DateGenerator();
|
||||
// if(Utility.IsEpoch(SellDate)) return dateGenerator.DaysBetween(PurchaseDate,DateTime.Now.Date);
|
||||
// return dateGenerator.DaysBetween(PurchaseDate,SellDate);
|
||||
// }
|
||||
// }
|
||||
// public Brush DaysHeldColor
|
||||
// {
|
||||
// get
|
||||
// {
|
||||
// if(!IsActivePosition) return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Blue);
|
||||
// return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Black);
|
||||
// }
|
||||
// }
|
||||
//// ***
|
||||
//// Here we take R as based upon our StopLimit.
|
||||
// public double R
|
||||
// {
|
||||
// get
|
||||
// {
|
||||
// if(position.TrailingStopLimit>position.PurchasePrice)return 0.00; // here we are considering the current risk/share which is based on our stop limit
|
||||
// return position.TrailingStopLimit>position.PurchasePrice?0.00:position.PurchasePrice-position.TrailingStopLimit;
|
||||
// }
|
||||
// }
|
||||
// public Brush RColor
|
||||
// {
|
||||
// get
|
||||
// {
|
||||
// if(!IsActivePosition) return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Blue);
|
||||
// return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Black);
|
||||
// }
|
||||
// }
|
||||
//// ***
|
||||
// public double TotalRiskExposure
|
||||
// {
|
||||
// get{return R*position.Shares;}
|
||||
// }
|
||||
// public Brush TotalRiskExposureColor
|
||||
// {
|
||||
// get
|
||||
// {
|
||||
// if(!IsActivePosition) return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Blue);
|
||||
// return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Black);
|
||||
// }
|
||||
// }
|
||||
//// ***
|
||||
// public String RMultipleAsString
|
||||
// {
|
||||
// get{return Utility.FormatNumber((position.CurrentPrice-position.PurchasePrice)/(position.PurchasePrice-position.InitialStopLimit),2,false)+"R";} // always based on original position risk
|
||||
// }
|
||||
// public Brush RMultipleAsStringColor
|
||||
// {
|
||||
// get
|
||||
// {
|
||||
// if(!IsActivePosition) return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Blue);
|
||||
// return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Black);
|
||||
// }
|
||||
// }
|
||||
//// ***
|
||||
// public double PositionRiskPercentDecimal
|
||||
// {
|
||||
// get{return position.PositionRiskPercentDecimal;}
|
||||
// set { position.PositionRiskPercentDecimal=value; base.OnPropertyChanged("PositionRiskPercentDecimal"); }
|
||||
// }
|
||||
// public double InitialStopLimit
|
||||
// {
|
||||
// get { return position.InitialStopLimit; }
|
||||
// set
|
||||
// {
|
||||
// position.InitialStopLimit=value;
|
||||
// base.OnPropertyChanged("InitialStopLimit");
|
||||
// base.OnPropertyChanged("InitialStopLimitColor");
|
||||
// }
|
||||
// }
|
||||
// public Brush InitialStopLimitColor
|
||||
// {
|
||||
// get
|
||||
// {
|
||||
// if(!IsActivePosition) return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Blue);
|
||||
// if(!Utility.IsEpoch(position.LastStopAdjustment)) return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Black); // if we have a trailing stop then we are no longer using the initial stop
|
||||
// StopLimit stopLimit=PortfolioDA.GetStopLimit(position.Symbol);
|
||||
// if(null==stopLimit||!stopLimit.StopPrice.Equals(Math.Round(position.InitialStopLimit,2))) return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Purple);
|
||||
// if(currentPriceLow<=position.InitialStopLimit) return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Red);
|
||||
// return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Black);
|
||||
// }
|
||||
// }
|
||||
// public double TrailingStopLimit
|
||||
// {
|
||||
// get { return position.TrailingStopLimit; }
|
||||
// set
|
||||
// {
|
||||
// position.TrailingStopLimit=value;
|
||||
// base.OnPropertyChanged("TrailingStopLimit");
|
||||
// base.OnPropertyChanged("TrailingStopLimitColor");
|
||||
// }
|
||||
// }
|
||||
// public Brush TrailingStopLimitColor
|
||||
// {
|
||||
// get
|
||||
// {
|
||||
// if(!IsActivePosition) return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Blue);
|
||||
// StopLimit stopLimit=PortfolioDA.GetStopLimit(position.Symbol);
|
||||
// if(null==stopLimit||!stopLimit.StopPrice.Equals(Math.Round(position.TrailingStopLimit,2))) return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Purple);
|
||||
// if(currentPriceLow<=position.TrailingStopLimit)return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Red);
|
||||
// return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Black);
|
||||
// }
|
||||
// }
|
||||
//// ***
|
||||
// public DateTime LastStopAdjustment
|
||||
// {
|
||||
// get { return position.LastStopAdjustment; }
|
||||
// set { position.LastStopAdjustment=value; base.OnPropertyChanged("LastStopAdjustment"); }
|
||||
// }
|
||||
// public Brush LastStopAdjustmentColor
|
||||
// {
|
||||
// get
|
||||
// {
|
||||
// if(!IsActivePosition) return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Blue);
|
||||
// return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Black);
|
||||
// }
|
||||
// }
|
||||
//// ***
|
||||
// public int DaysSinceLastStopAdjustment
|
||||
// {
|
||||
// get
|
||||
// {
|
||||
// if(!IsActivePosition)return int.MinValue;
|
||||
// DateGenerator dateGenerator=new DateGenerator();
|
||||
// DateTime today=DateTime.Now;
|
||||
// int daysSinceLastStopAdjustment=int.MinValue;
|
||||
// if(Utility.IsEpoch(position.LastStopAdjustment)) daysSinceLastStopAdjustment=dateGenerator.DaysBetweenActual(today,position.PurchaseDate);
|
||||
// else daysSinceLastStopAdjustment=dateGenerator.DaysBetweenActual(today,position.LastStopAdjustment);
|
||||
// return daysSinceLastStopAdjustment;
|
||||
// }
|
||||
// }
|
||||
// public Brush DaysSinceLastStopAdjustmentColor
|
||||
// {
|
||||
// get
|
||||
// {
|
||||
// if(!IsActivePosition) return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Blue);
|
||||
// int daysSinceLastStopAdjustment=DaysSinceLastStopAdjustment;
|
||||
// if(int.MinValue.Equals(daysSinceLastStopAdjustment))return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Blue);
|
||||
// if(daysSinceLastStopAdjustment>=90) return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Red);
|
||||
// else if(daysSinceLastStopAdjustment>=60) return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Yellow);
|
||||
// return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Green);
|
||||
// }
|
||||
// }
|
||||
|
||||
//// ***
|
||||
// public double Shares
|
||||
// {
|
||||
// get { return position.Shares; }
|
||||
// set { position.Shares=value; base.OnPropertyChanged("Shares"); base.OnPropertyChanged("Exposure"); base.OnPropertyChanged("ActiveExposure"); base.OnPropertyChanged("MarketValue"); base.OnPropertyChanged("ActiveMarketValue"); base.OnPropertyChanged("GainLoss"); base.OnPropertyChanged("GainLossPcnt"); }
|
||||
// }
|
||||
// public Brush SharesColor
|
||||
// {
|
||||
// get
|
||||
// {
|
||||
// if(!IsActivePosition) return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Blue);
|
||||
// return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Black);
|
||||
// }
|
||||
// }
|
||||
//// ***
|
||||
// public double PurchasePrice
|
||||
// {
|
||||
// get { return position.PurchasePrice; }
|
||||
// set { position.PurchasePrice=value; base.OnPropertyChanged("PurchasePrice"); base.OnPropertyChanged("Exposure"); base.OnPropertyChanged("ActiveExposure"); base.OnPropertyChanged("GainLoss"); base.OnPropertyChanged("GainLossPcnt"); }
|
||||
// }
|
||||
// public Brush PurchasePriceColor
|
||||
// {
|
||||
// get
|
||||
// {
|
||||
// if(!IsActivePosition) return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Blue);
|
||||
// return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Black);
|
||||
// }
|
||||
// }
|
||||
//// ***
|
||||
// public double CurrentPrice
|
||||
// {
|
||||
// get { return position.CurrentPrice; }
|
||||
// set
|
||||
// {
|
||||
// if(position.CurrentPrice==value) return;
|
||||
// position.CurrentPrice=value;
|
||||
// if(double.IsNaN(prevPrice)) { prevPrice=position.CurrentPrice; priceChangeDirection=0; }
|
||||
// else if(prevPrice>position.CurrentPrice) priceChangeDirection=-1;
|
||||
// else if(prevPrice==position.CurrentPrice) priceChangeDirection=0;
|
||||
// else priceChangeDirection=1;
|
||||
// prevPrice=position.CurrentPrice;
|
||||
// UpdateProperties();
|
||||
// }
|
||||
// }
|
||||
// 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 double CurrentPriceLow
|
||||
// {
|
||||
// get{return currentPriceLow;}
|
||||
// set
|
||||
// {
|
||||
// if(currentPriceLow==value)return;
|
||||
// currentPriceLow=value;
|
||||
// base.OnPropertyChanged("CurrentPriceLow");
|
||||
// base.OnPropertyChanged("CurrentPriceLowAsString");
|
||||
// base.OnPropertyChanged("TrailingStopLimitColor");
|
||||
// base.OnPropertyChanged("InitialStopLimitColor");
|
||||
// }
|
||||
// }
|
||||
//// ***
|
||||
// public String CurrentPriceLowAsString
|
||||
// {
|
||||
// get { return Utility.FormatCurrency(currentPriceLow); }
|
||||
// }
|
||||
// public Brush CurrentPriceLowAsStringColor
|
||||
// {
|
||||
// get
|
||||
// {
|
||||
// if(!IsActivePosition) return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Blue);
|
||||
// return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Black);
|
||||
// }
|
||||
// }
|
||||
//// ***
|
||||
// public DateTime LastUpdated
|
||||
// {
|
||||
// get { return lastUpdated; }
|
||||
// set { lastUpdated=value; base.OnPropertyChanged("LastUpdated"); }
|
||||
// }
|
||||
// public Brush LastUpdatedColor
|
||||
// {
|
||||
// get
|
||||
// {
|
||||
// if(!IsActivePosition) return BrushCollection.GetContextBrush(BrushCollection.BrushColor.Blue);
|
||||
// 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 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 bool IsActivePosition
|
||||
// {
|
||||
// get { return Utility.IsEpoch(SellDate)?true:false; }
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
15
Model/MenuItem.cs
Normal file
15
Model/MenuItem.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace TradeBlotter.Model
|
||||
{
|
||||
public class MenuItem
|
||||
{
|
||||
public String Text { get; set; }
|
||||
public bool StaysOpenOnClick { get; set; }
|
||||
public ICommand MenuItemClickedCommand { get; set; }
|
||||
}
|
||||
}
|
||||
474
Model/ModelPerformanceAggregator.cs
Normal file
474
Model/ModelPerformanceAggregator.cs
Normal file
@@ -0,0 +1,474 @@
|
||||
using MarketData.Cache;
|
||||
using MarketData.DataAccess;
|
||||
using MarketData.MarketDataModel;
|
||||
using MarketData.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace TradeBlotter.Model
|
||||
{
|
||||
public class ModelPerformanceAggregator
|
||||
{
|
||||
private ModelPerformanceAggregator()
|
||||
{
|
||||
}
|
||||
// ***********************************************************************************************************************************************************************************************************
|
||||
// *********************************************************************************** M A R C M I N E R V I N I M O M E N T U M *************************************************************************
|
||||
// ***********************************************************************************************************************************************************************************************************
|
||||
// 2 versions : one handles MMTrend the other handes the CMTrend.
|
||||
public static double CalculateCumulativeReturn(IEnumerable<CMTPositionModel> positions)
|
||||
{
|
||||
ModelPerformanceSeries performanceSeries=GetModelPerformance(positions);
|
||||
if(null==performanceSeries) return double.NaN;
|
||||
return performanceSeries[performanceSeries.Count-1].CumProdMinusOne;
|
||||
}
|
||||
public static ModelPerformanceSeries GetModelPerformance(IEnumerable<CMTPositionModel> positions)
|
||||
{
|
||||
ModelPerformanceSeries performanceSeries=new ModelPerformanceSeries();
|
||||
try
|
||||
{
|
||||
DateTime minDate=positions.Min(x => x.PurchaseDate);
|
||||
DateTime maxDate=PricingDA.GetLatestDate();
|
||||
DateGenerator dateGenerator=new DateGenerator();
|
||||
double cumulativeReturn=double.NaN;
|
||||
double prevGainLoss=double.NaN;
|
||||
|
||||
LocalPriceCache.GetInstance().RemoveDate(maxDate);
|
||||
List<DateTime> historicalDates=dateGenerator.GenerateHistoricalDates(minDate,maxDate);
|
||||
|
||||
foreach(CMTPositionModel position in positions)
|
||||
{
|
||||
if(dateGenerator.IsWeekend(position.PurchaseDate))
|
||||
{
|
||||
while(true)
|
||||
{
|
||||
position.PurchaseDate=dateGenerator.GetNextBusinessDay(position.PurchaseDate);
|
||||
if(!HolidayDA.IsMarketHoliday(position.PurchaseDate)) break;
|
||||
}
|
||||
}
|
||||
if(dateGenerator.IsWeekend(position.SellDate))
|
||||
{
|
||||
while(true)
|
||||
{
|
||||
position.SellDate=dateGenerator.GetNextBusinessDay(position.SellDate);
|
||||
if(!HolidayDA.IsMarketHoliday(position.SellDate)) break;
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach(DateTime currentDate in historicalDates)
|
||||
{
|
||||
IEnumerable<CMTPositionModel> openPositions=positions.Where(x => (x.PurchaseDate<=currentDate&&(!Utility.IsEpoch(x.SellDate)&&x.SellDate>currentDate))||(x.PurchaseDate<=currentDate&&Utility.IsEpoch(x.SellDate))).ToList();
|
||||
IEnumerable<CMTPositionModel> closedPositions=positions.Where(x => (!Utility.IsEpoch(x.SellDate)&&x.SellDate.Equals(currentDate))).ToList();
|
||||
if(0==openPositions.Count()&&0==closedPositions.Count()) continue;
|
||||
double gainLoss=0.00;
|
||||
double gainLossClosedPositions=0.00;
|
||||
double exposure=0.00;
|
||||
double marketValue=0.00;
|
||||
if(HolidayDA.IsMarketHoliday(currentDate)) continue;
|
||||
ModelPerformanceItem performanceItem=new ModelPerformanceItem();
|
||||
foreach(CMTPositionModel openPosition in openPositions)
|
||||
{
|
||||
exposure+=openPosition.Shares*openPosition.PurchasePrice;
|
||||
if(!LocalPriceCache.GetInstance().ContainsPrice(openPosition.Symbol,currentDate))
|
||||
{
|
||||
Prices prices=PricingDA.GetPricesForward(openPosition.Symbol,currentDate,90);
|
||||
LocalPriceCache.GetInstance().Add(prices);
|
||||
}
|
||||
Price price=LocalPriceCache.GetInstance().GetPrice(openPosition.Symbol,currentDate);
|
||||
gainLoss+=((price.Close*openPosition.Shares)-(openPosition.PurchasePrice*openPosition.Shares));
|
||||
marketValue+=(price.Close*openPosition.Shares);
|
||||
}
|
||||
foreach(CMTPositionModel closedPosition in closedPositions)
|
||||
{
|
||||
double gainLossPosition=(closedPosition.CurrentPrice*closedPosition.Shares)-(closedPosition.PurchasePrice*closedPosition.Shares);
|
||||
gainLossClosedPositions+=gainLossPosition;
|
||||
}
|
||||
double dailyReturn=0.00;
|
||||
if(double.IsNaN(prevGainLoss)) dailyReturn=(marketValue-exposure)/Math.Abs(exposure);
|
||||
else dailyReturn=((gainLoss-prevGainLoss)/Math.Abs(prevGainLoss))/100.00;
|
||||
if(double.IsNaN(cumulativeReturn)) cumulativeReturn=1.00*(1.00+dailyReturn);
|
||||
else cumulativeReturn=cumulativeReturn*(1.00+dailyReturn);
|
||||
|
||||
performanceItem.Date=currentDate;
|
||||
performanceItem.Exposure=exposure;
|
||||
performanceItem.MarketValue=marketValue;
|
||||
performanceItem.GainLossDOD=double.IsNaN(prevGainLoss)?gainLoss:(gainLoss-prevGainLoss)+gainLossClosedPositions;
|
||||
performanceItem.GainLoss=gainLoss+gainLossClosedPositions;
|
||||
performanceItem.ClosedPositions=closedPositions.Count()>0?true:false;
|
||||
performanceSeries.Add(performanceItem);
|
||||
prevGainLoss=gainLoss;
|
||||
}
|
||||
|
||||
|
||||
for(int index=0;index<performanceSeries.Count;index++)
|
||||
{
|
||||
ModelPerformanceItem currentModelPerformanceItem=performanceSeries[index];
|
||||
ModelPerformanceItem prevModelPerformanceItem=0==index?null:performanceSeries[index-1];
|
||||
if(null==prevModelPerformanceItem)
|
||||
{
|
||||
currentModelPerformanceItem.CumulativeGainLoss=currentModelPerformanceItem.GainLossDOD;
|
||||
currentModelPerformanceItem.R=(currentModelPerformanceItem.MarketValue-currentModelPerformanceItem.Exposure)/currentModelPerformanceItem.Exposure;
|
||||
currentModelPerformanceItem.OnePlusR=1.00+currentModelPerformanceItem.R;
|
||||
currentModelPerformanceItem.CumProd=currentModelPerformanceItem.OnePlusR;
|
||||
currentModelPerformanceItem.CumProdMinusOne=currentModelPerformanceItem.CumProd-1.00;
|
||||
}
|
||||
else
|
||||
{
|
||||
currentModelPerformanceItem.CumulativeGainLoss=currentModelPerformanceItem.GainLossDOD+prevModelPerformanceItem.CumulativeGainLoss;
|
||||
currentModelPerformanceItem.R=prevModelPerformanceItem.Exposure.Equals(currentModelPerformanceItem.Exposure)?(currentModelPerformanceItem.MarketValue-prevModelPerformanceItem.MarketValue)/prevModelPerformanceItem.MarketValue:0;
|
||||
currentModelPerformanceItem.OnePlusR=1.00+currentModelPerformanceItem.R;
|
||||
currentModelPerformanceItem.CumProd=currentModelPerformanceItem.OnePlusR*prevModelPerformanceItem.CumProd;
|
||||
currentModelPerformanceItem.CumProdMinusOne=currentModelPerformanceItem.CumProd-1.00;
|
||||
}
|
||||
}
|
||||
return performanceSeries;
|
||||
}
|
||||
catch(Exception)
|
||||
{
|
||||
return performanceSeries;
|
||||
}
|
||||
}
|
||||
//public static double CalculateCumulativeReturn(IEnumerable<MMPositionModel> positions)
|
||||
//{
|
||||
// ModelPerformanceSeries performanceSeries=GetModelPerformance(positions);
|
||||
// if(null==performanceSeries) return double.NaN;
|
||||
// return performanceSeries[performanceSeries.Count-1].CumProdMinusOne;
|
||||
//}
|
||||
//public static ModelPerformanceSeries GetModelPerformance(IEnumerable<MMPositionModel> positions)
|
||||
//{
|
||||
// ModelPerformanceSeries performanceSeries=new ModelPerformanceSeries();
|
||||
// try
|
||||
// {
|
||||
// DateTime minDate=positions.Min(x => x.PurchaseDate);
|
||||
// DateTime maxDate=PricingDA.GetLatestDate();
|
||||
// DateGenerator dateGenerator=new DateGenerator();
|
||||
// double cumulativeReturn=double.NaN;
|
||||
// double prevGainLoss=double.NaN;
|
||||
|
||||
// LocalPriceCache.GetInstance().RemoveDate(maxDate);
|
||||
// List<DateTime> historicalDates=dateGenerator.GenerateHistoricalDates(minDate,maxDate);
|
||||
|
||||
// foreach(MMPositionModel position in positions)
|
||||
// {
|
||||
// if(dateGenerator.IsWeekend(position.PurchaseDate))
|
||||
// {
|
||||
// while(true)
|
||||
// {
|
||||
// position.PurchaseDate=dateGenerator.GetNextBusinessDay(position.PurchaseDate);
|
||||
// if(!HolidayDA.IsMarketHoliday(position.PurchaseDate)) break;
|
||||
// }
|
||||
// }
|
||||
// if(dateGenerator.IsWeekend(position.SellDate))
|
||||
// {
|
||||
// while(true)
|
||||
// {
|
||||
// position.SellDate=dateGenerator.GetNextBusinessDay(position.SellDate);
|
||||
// if(!HolidayDA.IsMarketHoliday(position.SellDate)) break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// foreach(DateTime currentDate in historicalDates)
|
||||
// {
|
||||
// IEnumerable<MMPositionModel> openPositions=positions.Where(x => (x.PurchaseDate<=currentDate&&(!Utility.IsEpoch(x.SellDate)&&x.SellDate>currentDate))||(x.PurchaseDate<=currentDate&&Utility.IsEpoch(x.SellDate))).ToList();
|
||||
// IEnumerable<MMPositionModel> closedPositions=positions.Where(x => (!Utility.IsEpoch(x.SellDate)&&x.SellDate.Equals(currentDate))).ToList();
|
||||
// if(0==openPositions.Count()&&0==closedPositions.Count()) continue;
|
||||
// double gainLoss=0.00;
|
||||
// double gainLossClosedPositions=0.00;
|
||||
// double exposure=0.00;
|
||||
// double marketValue=0.00;
|
||||
// if(HolidayDA.IsMarketHoliday(currentDate)) continue;
|
||||
// ModelPerformanceItem performanceItem=new ModelPerformanceItem();
|
||||
// foreach(MMPositionModel openPosition in openPositions)
|
||||
// {
|
||||
// exposure+=openPosition.Shares*openPosition.PurchasePrice;
|
||||
// if(!LocalPriceCache.GetInstance().ContainsPrice(openPosition.Symbol,currentDate))
|
||||
// {
|
||||
// Prices prices=PricingDA.GetPricesForward(openPosition.Symbol,currentDate,90);
|
||||
// LocalPriceCache.GetInstance().Add(prices);
|
||||
// }
|
||||
// Price price=LocalPriceCache.GetInstance().GetPrice(openPosition.Symbol,currentDate);
|
||||
// gainLoss+=((price.Close*openPosition.Shares)-(openPosition.PurchasePrice*openPosition.Shares));
|
||||
// marketValue+=(price.Close*openPosition.Shares);
|
||||
// }
|
||||
// foreach(MMPositionModel closedPosition in closedPositions)
|
||||
// {
|
||||
// double gainLossPosition=(closedPosition.CurrentPrice*closedPosition.Shares)-(closedPosition.PurchasePrice*closedPosition.Shares);
|
||||
// gainLossClosedPositions+=gainLossPosition;
|
||||
// }
|
||||
// double dailyReturn=0.00;
|
||||
// if(double.IsNaN(prevGainLoss)) dailyReturn=(marketValue-exposure)/Math.Abs(exposure);
|
||||
// else dailyReturn=((gainLoss-prevGainLoss)/Math.Abs(prevGainLoss))/100.00;
|
||||
// if(double.IsNaN(cumulativeReturn)) cumulativeReturn=1.00*(1.00+dailyReturn);
|
||||
// else cumulativeReturn=cumulativeReturn*(1.00+dailyReturn);
|
||||
|
||||
// performanceItem.Date=currentDate;
|
||||
// performanceItem.Exposure=exposure;
|
||||
// performanceItem.MarketValue=marketValue;
|
||||
// performanceItem.GainLossDOD=double.IsNaN(prevGainLoss)?gainLoss:(gainLoss-prevGainLoss)+gainLossClosedPositions;
|
||||
// performanceItem.GainLoss=gainLoss+gainLossClosedPositions;
|
||||
// performanceItem.ClosedPositions=closedPositions.Count()>0?true:false;
|
||||
// performanceSeries.Add(performanceItem);
|
||||
// prevGainLoss=gainLoss;
|
||||
// }
|
||||
|
||||
|
||||
// for(int index=0;index<performanceSeries.Count;index++)
|
||||
// {
|
||||
// ModelPerformanceItem currentModelPerformanceItem=performanceSeries[index];
|
||||
// ModelPerformanceItem prevModelPerformanceItem=0==index?null:performanceSeries[index-1];
|
||||
// if(null==prevModelPerformanceItem)
|
||||
// {
|
||||
// currentModelPerformanceItem.CumulativeGainLoss=currentModelPerformanceItem.GainLossDOD;
|
||||
// currentModelPerformanceItem.R=(currentModelPerformanceItem.MarketValue-currentModelPerformanceItem.Exposure)/currentModelPerformanceItem.Exposure;
|
||||
// currentModelPerformanceItem.OnePlusR=1.00+currentModelPerformanceItem.R;
|
||||
// currentModelPerformanceItem.CumProd=currentModelPerformanceItem.OnePlusR;
|
||||
// currentModelPerformanceItem.CumProdMinusOne=currentModelPerformanceItem.CumProd-1.00;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// currentModelPerformanceItem.CumulativeGainLoss=currentModelPerformanceItem.GainLossDOD+prevModelPerformanceItem.CumulativeGainLoss;
|
||||
// currentModelPerformanceItem.R=prevModelPerformanceItem.Exposure.Equals(currentModelPerformanceItem.Exposure)?(currentModelPerformanceItem.MarketValue-prevModelPerformanceItem.MarketValue)/prevModelPerformanceItem.MarketValue:0;
|
||||
// currentModelPerformanceItem.OnePlusR=1.00+currentModelPerformanceItem.R;
|
||||
// currentModelPerformanceItem.CumProd=currentModelPerformanceItem.OnePlusR*prevModelPerformanceItem.CumProd;
|
||||
// currentModelPerformanceItem.CumProdMinusOne=currentModelPerformanceItem.CumProd-1.00;
|
||||
// }
|
||||
// }
|
||||
// return performanceSeries;
|
||||
// }
|
||||
// catch(Exception)
|
||||
// {
|
||||
// return performanceSeries;
|
||||
// }
|
||||
//}
|
||||
// ***********************************************************************************************************************************************************************************************************
|
||||
// *********************************************************************************** C L E N O W M O M E N T U M **************************************************************************************
|
||||
// ***********************************************************************************************************************************************************************************************************
|
||||
public static double CalculateCumulativeReturn(IEnumerable<CMPositionModel> positions)
|
||||
{
|
||||
ModelPerformanceSeries performanceSeries=GetModelPerformance(positions);
|
||||
if(null==performanceSeries)return double.NaN;
|
||||
return performanceSeries[performanceSeries.Count-1].CumProdMinusOne;
|
||||
}
|
||||
public static double CalculateCumulativeReturn(IEnumerable<MGPositionModel> positions)
|
||||
{
|
||||
ModelPerformanceSeries performanceSeries=GetModelPerformance(positions);
|
||||
if(null==performanceSeries) return double.NaN;
|
||||
return performanceSeries[performanceSeries.Count-1].CumProdMinusOne;
|
||||
}
|
||||
public static ModelPerformanceSeries GetModelPerformance(IEnumerable<CMPositionModel> positions)
|
||||
{
|
||||
ModelPerformanceSeries performanceSeries=new ModelPerformanceSeries();
|
||||
try
|
||||
{
|
||||
DateTime minDate=positions.Min(x => x.PurchaseDate);
|
||||
DateTime maxDate=PricingDA.GetLatestDate();
|
||||
DateGenerator dateGenerator=new DateGenerator();
|
||||
double cumulativeReturn=double.NaN;
|
||||
double prevGainLoss=double.NaN;
|
||||
|
||||
LocalPriceCache.GetInstance().RemoveDate(maxDate);
|
||||
List<DateTime> historicalDates=dateGenerator.GenerateHistoricalDates(minDate,maxDate);
|
||||
|
||||
foreach(CMPositionModel position in positions)
|
||||
{
|
||||
if(dateGenerator.IsWeekend(position.PurchaseDate))
|
||||
{
|
||||
while(true)
|
||||
{
|
||||
position.PurchaseDate=dateGenerator.GetNextBusinessDay(position.PurchaseDate);
|
||||
if(!HolidayDA.IsMarketHoliday(position.PurchaseDate)) break;
|
||||
}
|
||||
}
|
||||
if(dateGenerator.IsWeekend(position.SellDate))
|
||||
{
|
||||
while(true)
|
||||
{
|
||||
position.SellDate=dateGenerator.GetNextBusinessDay(position.SellDate);
|
||||
if(!HolidayDA.IsMarketHoliday(position.SellDate)) break;
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach(DateTime currentDate in historicalDates)
|
||||
{
|
||||
IEnumerable<CMPositionModel> openPositions=positions.Where(x => (x.PurchaseDate<=currentDate&&(!Utility.IsEpoch(x.SellDate)&&x.SellDate>currentDate))||(x.PurchaseDate<=currentDate&&Utility.IsEpoch(x.SellDate))).ToList();
|
||||
IEnumerable<CMPositionModel> closedPositions=positions.Where(x => (!Utility.IsEpoch(x.SellDate)&&x.SellDate.Equals(currentDate))).ToList();
|
||||
if(0==openPositions.Count()&&0==closedPositions.Count()) continue;
|
||||
double gainLoss=0.00;
|
||||
double gainLossClosedPositions=0.00;
|
||||
double exposure=0.00;
|
||||
double marketValue=0.00;
|
||||
if(HolidayDA.IsMarketHoliday(currentDate)) continue;
|
||||
ModelPerformanceItem performanceItem=new ModelPerformanceItem();
|
||||
foreach(CMPositionModel openPosition in openPositions)
|
||||
{
|
||||
exposure+=openPosition.Shares*openPosition.PurchasePrice;
|
||||
if(!LocalPriceCache.GetInstance().ContainsPrice(openPosition.Symbol,currentDate))
|
||||
{
|
||||
Prices prices=PricingDA.GetPricesForward(openPosition.Symbol,currentDate,90);
|
||||
LocalPriceCache.GetInstance().Add(prices);
|
||||
}
|
||||
Price price=LocalPriceCache.GetInstance().GetPrice(openPosition.Symbol,currentDate);
|
||||
gainLoss+=((price.Close*openPosition.Shares)-(openPosition.PurchasePrice*openPosition.Shares));
|
||||
marketValue+=(price.Close*openPosition.Shares);
|
||||
}
|
||||
foreach(CMPositionModel closedPosition in closedPositions)
|
||||
{
|
||||
double gainLossPosition=(closedPosition.CurrentPrice*closedPosition.Shares)-(closedPosition.PurchasePrice*closedPosition.Shares);
|
||||
gainLossClosedPositions+=gainLossPosition;
|
||||
}
|
||||
double dailyReturn=0.00;
|
||||
if(double.IsNaN(prevGainLoss)) dailyReturn=(marketValue-exposure)/Math.Abs(exposure);
|
||||
else dailyReturn=((gainLoss-prevGainLoss)/Math.Abs(prevGainLoss))/100.00;
|
||||
if(double.IsNaN(cumulativeReturn)) cumulativeReturn=1.00*(1.00+dailyReturn);
|
||||
else cumulativeReturn=cumulativeReturn*(1.00+dailyReturn);
|
||||
|
||||
performanceItem.Date=currentDate;
|
||||
performanceItem.Exposure=exposure;
|
||||
performanceItem.MarketValue=marketValue;
|
||||
performanceItem.GainLossDOD=double.IsNaN(prevGainLoss)?gainLoss:(gainLoss-prevGainLoss)+gainLossClosedPositions;
|
||||
performanceItem.GainLoss=gainLoss+gainLossClosedPositions;
|
||||
performanceItem.ClosedPositions=closedPositions.Count()>0?true:false;
|
||||
performanceSeries.Add(performanceItem);
|
||||
prevGainLoss=gainLoss;
|
||||
}
|
||||
|
||||
|
||||
for(int index=0;index<performanceSeries.Count;index++)
|
||||
{
|
||||
ModelPerformanceItem currentModelPerformanceItem=performanceSeries[index];
|
||||
ModelPerformanceItem prevModelPerformanceItem=0==index?null:performanceSeries[index-1];
|
||||
if(null==prevModelPerformanceItem)
|
||||
{
|
||||
currentModelPerformanceItem.CumulativeGainLoss=currentModelPerformanceItem.GainLossDOD;
|
||||
currentModelPerformanceItem.R=(currentModelPerformanceItem.MarketValue-currentModelPerformanceItem.Exposure)/currentModelPerformanceItem.Exposure;
|
||||
currentModelPerformanceItem.OnePlusR=1.00+currentModelPerformanceItem.R;
|
||||
currentModelPerformanceItem.CumProd=currentModelPerformanceItem.OnePlusR;
|
||||
currentModelPerformanceItem.CumProdMinusOne=currentModelPerformanceItem.CumProd-1.00;
|
||||
}
|
||||
else
|
||||
{
|
||||
currentModelPerformanceItem.CumulativeGainLoss=currentModelPerformanceItem.GainLossDOD+prevModelPerformanceItem.CumulativeGainLoss;
|
||||
currentModelPerformanceItem.R=prevModelPerformanceItem.Exposure.Equals(currentModelPerformanceItem.Exposure)?(currentModelPerformanceItem.MarketValue-prevModelPerformanceItem.MarketValue)/prevModelPerformanceItem.MarketValue:0;
|
||||
currentModelPerformanceItem.OnePlusR=1.00+currentModelPerformanceItem.R;
|
||||
currentModelPerformanceItem.CumProd=currentModelPerformanceItem.OnePlusR*prevModelPerformanceItem.CumProd;
|
||||
currentModelPerformanceItem.CumProdMinusOne=currentModelPerformanceItem.CumProd-1.00;
|
||||
}
|
||||
}
|
||||
return performanceSeries;
|
||||
}
|
||||
catch(Exception)
|
||||
{
|
||||
return performanceSeries;
|
||||
}
|
||||
}
|
||||
// ***********************************************************************************************************************************************************************************************************
|
||||
// *********************************************************************************** Q U A N T U M M O M E N T U M **************************************************************************************
|
||||
// ***********************************************************************************************************************************************************************************************************
|
||||
public static ModelPerformanceSeries GetModelPerformance(IEnumerable<MGPositionModel> positions)
|
||||
{
|
||||
ModelPerformanceSeries performanceSeries=new ModelPerformanceSeries();
|
||||
try
|
||||
{
|
||||
DateTime minDate=positions.Min(x => x.PurchaseDate);
|
||||
DateTime maxDate=PricingDA.GetLatestDate();
|
||||
DateGenerator dateGenerator=new DateGenerator();
|
||||
double cumulativeReturn=double.NaN;
|
||||
double prevGainLoss=double.NaN;
|
||||
|
||||
LocalPriceCache.GetInstance().RemoveDate(maxDate);
|
||||
List<DateTime> historicalDates=dateGenerator.GenerateHistoricalDates(minDate,maxDate);
|
||||
|
||||
foreach(MGPositionModel position in positions)
|
||||
{
|
||||
if(dateGenerator.IsWeekend(position.PurchaseDate))
|
||||
{
|
||||
while(true)
|
||||
{
|
||||
position.PurchaseDate=dateGenerator.GetNextBusinessDay(position.PurchaseDate);
|
||||
if(!HolidayDA.IsMarketHoliday(position.PurchaseDate)) break;
|
||||
}
|
||||
}
|
||||
if(dateGenerator.IsWeekend(position.SellDate))
|
||||
{
|
||||
while(true)
|
||||
{
|
||||
position.SellDate=dateGenerator.GetNextBusinessDay(position.SellDate);
|
||||
if(!HolidayDA.IsMarketHoliday(position.SellDate)) break;
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach(DateTime currentDate in historicalDates)
|
||||
{
|
||||
IEnumerable<MGPositionModel> openPositions=positions.Where(x => (x.PurchaseDate<=currentDate&&(!Utility.IsEpoch(x.SellDate)&&x.SellDate>currentDate))||(x.PurchaseDate<=currentDate&&Utility.IsEpoch(x.SellDate))).ToList();
|
||||
IEnumerable<MGPositionModel> closedPositions=positions.Where(x => (!Utility.IsEpoch(x.SellDate)&&x.SellDate.Equals(currentDate))).ToList();
|
||||
if(0==openPositions.Count()&&0==closedPositions.Count()) continue;
|
||||
double gainLoss=0.00;
|
||||
double gainLossClosedPositions=0.00;
|
||||
double exposure=0.00;
|
||||
double marketValue=0.00;
|
||||
if(HolidayDA.IsMarketHoliday(currentDate)) continue;
|
||||
ModelPerformanceItem performanceItem=new ModelPerformanceItem();
|
||||
foreach(MGPositionModel openPosition in openPositions)
|
||||
{
|
||||
exposure+=openPosition.Shares*openPosition.PurchasePrice;
|
||||
if(!LocalPriceCache.GetInstance().ContainsPrice(openPosition.Symbol,currentDate))
|
||||
{
|
||||
Prices prices=PricingDA.GetPricesForward(openPosition.Symbol,currentDate,90);
|
||||
LocalPriceCache.GetInstance().Add(prices);
|
||||
}
|
||||
Price price=LocalPriceCache.GetInstance().GetPrice(openPosition.Symbol,currentDate);
|
||||
gainLoss+=((price.Close*openPosition.Shares)-(openPosition.PurchasePrice*openPosition.Shares));
|
||||
marketValue+=(price.Close*openPosition.Shares);
|
||||
}
|
||||
foreach(MGPositionModel closedPosition in closedPositions)
|
||||
{
|
||||
double gainLossPosition=(closedPosition.CurrentPrice*closedPosition.Shares)-(closedPosition.PurchasePrice*closedPosition.Shares);
|
||||
gainLossClosedPositions+=gainLossPosition;
|
||||
}
|
||||
double dailyReturn=0.00;
|
||||
if(double.IsNaN(prevGainLoss)) dailyReturn=(marketValue-exposure)/Math.Abs(exposure);
|
||||
else dailyReturn=((gainLoss-prevGainLoss)/Math.Abs(prevGainLoss))/100.00;
|
||||
if(double.IsNaN(cumulativeReturn)) cumulativeReturn=1.00*(1.00+dailyReturn);
|
||||
else cumulativeReturn=cumulativeReturn*(1.00+dailyReturn);
|
||||
performanceItem.Date=currentDate;
|
||||
performanceItem.Exposure=exposure;
|
||||
performanceItem.MarketValue=marketValue;
|
||||
performanceItem.GainLossDOD=double.IsNaN(prevGainLoss)?gainLoss:(gainLoss-prevGainLoss)+gainLossClosedPositions;
|
||||
performanceItem.GainLoss=gainLoss+gainLossClosedPositions;
|
||||
performanceItem.ClosedPositions=closedPositions.Count()>0?true:false;
|
||||
performanceSeries.Add(performanceItem);
|
||||
prevGainLoss=gainLoss;
|
||||
}
|
||||
for(int index=0;index<performanceSeries.Count;index++)
|
||||
{
|
||||
ModelPerformanceItem currentModelPerformanceItem=performanceSeries[index];
|
||||
ModelPerformanceItem prevModelPerformanceItem=0==index?null:performanceSeries[index-1];
|
||||
if(null==prevModelPerformanceItem)
|
||||
{
|
||||
currentModelPerformanceItem.CumulativeGainLoss=currentModelPerformanceItem.GainLossDOD;
|
||||
currentModelPerformanceItem.R=(currentModelPerformanceItem.MarketValue-currentModelPerformanceItem.Exposure)/currentModelPerformanceItem.Exposure;
|
||||
currentModelPerformanceItem.OnePlusR=1.00+currentModelPerformanceItem.R;
|
||||
currentModelPerformanceItem.CumProd=currentModelPerformanceItem.OnePlusR;
|
||||
currentModelPerformanceItem.CumProdMinusOne=currentModelPerformanceItem.CumProd-1.00;
|
||||
}
|
||||
else
|
||||
{
|
||||
currentModelPerformanceItem.CumulativeGainLoss=currentModelPerformanceItem.GainLossDOD+prevModelPerformanceItem.CumulativeGainLoss;
|
||||
currentModelPerformanceItem.R=prevModelPerformanceItem.Exposure.Equals(currentModelPerformanceItem.Exposure)?(currentModelPerformanceItem.MarketValue-prevModelPerformanceItem.MarketValue)/prevModelPerformanceItem.MarketValue:0;
|
||||
currentModelPerformanceItem.OnePlusR=1.00+currentModelPerformanceItem.R;
|
||||
currentModelPerformanceItem.CumProd=currentModelPerformanceItem.OnePlusR*prevModelPerformanceItem.CumProd;
|
||||
currentModelPerformanceItem.CumProdMinusOne=currentModelPerformanceItem.CumProd-1.00;
|
||||
}
|
||||
}
|
||||
return performanceSeries;
|
||||
}
|
||||
catch(Exception)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
119
Model/MovingAverageModel.cs
Normal file
119
Model/MovingAverageModel.cs
Normal file
@@ -0,0 +1,119 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using MarketData.MarketDataModel;
|
||||
using Microsoft.Research.DynamicDataDisplay.DataSources;
|
||||
|
||||
namespace TradeBlotter.Model
|
||||
{
|
||||
public class MovingAverageModel
|
||||
{
|
||||
private MovingAverageModel()
|
||||
{
|
||||
}
|
||||
public static CompositeDataSource Close(MovingAverages movingAverages)
|
||||
{
|
||||
if (null == movingAverages) return null;
|
||||
CompositeDataSource compositeDataSource;
|
||||
var xData = new EnumerableDataSource<DateTime>(movingAverages.Select(x => x.Date.Date));
|
||||
xData.SetXMapping(x => (x.Ticks / 10000000000.0));
|
||||
var yData = new EnumerableDataSource<double>(movingAverages.Select(y => y.Close));
|
||||
yData.SetYMapping(y => y);
|
||||
compositeDataSource = xData.Join(yData);
|
||||
return compositeDataSource;
|
||||
}
|
||||
public static CompositeDataSource High(MovingAverages movingAverages)
|
||||
{
|
||||
if (null == movingAverages) return null;
|
||||
CompositeDataSource compositeDataSource;
|
||||
var xData = new EnumerableDataSource<DateTime>(movingAverages.Select(x => x.Date.Date));
|
||||
xData.SetXMapping(x => (x.Ticks / 10000000000.0));
|
||||
var yData = new EnumerableDataSource<double>(movingAverages.Select(y => y.High));
|
||||
yData.SetYMapping(y => y);
|
||||
compositeDataSource = xData.Join(yData);
|
||||
return compositeDataSource;
|
||||
}
|
||||
public static CompositeDataSource Low(MovingAverages movingAverages)
|
||||
{
|
||||
if (null == movingAverages) return null;
|
||||
CompositeDataSource compositeDataSource;
|
||||
var xData = new EnumerableDataSource<DateTime>(movingAverages.Select(x => x.Date.Date));
|
||||
xData.SetXMapping(x => (x.Ticks / 10000000000.0));
|
||||
var yData = new EnumerableDataSource<double>(movingAverages.Select(y => y.Low));
|
||||
yData.SetYMapping(y => y);
|
||||
compositeDataSource = xData.Join(yData);
|
||||
return compositeDataSource;
|
||||
}
|
||||
public static CompositeDataSource MA200(MovingAverages movingAverages)
|
||||
{
|
||||
if (null == movingAverages) return null;
|
||||
movingAverages=new MovingAverages((from MovingAverageElement element in movingAverages where !double.IsNaN(element.MA200) select element).ToList());
|
||||
CompositeDataSource compositeDataSource;
|
||||
var xData = new EnumerableDataSource<DateTime>(movingAverages.Select(x => x.Date.Date));
|
||||
xData.SetXMapping(x => (x.Ticks / 10000000000.0));
|
||||
var yData = new EnumerableDataSource<double>(movingAverages.Select(y => y.MA200));
|
||||
yData.SetYMapping(y => y);
|
||||
compositeDataSource = xData.Join(yData);
|
||||
return compositeDataSource;
|
||||
}
|
||||
public static CompositeDataSource MA100(MovingAverages movingAverages)
|
||||
{
|
||||
if (null == movingAverages) return null;
|
||||
movingAverages = new MovingAverages((from MovingAverageElement element in movingAverages where !double.IsNaN(element.MA100) select element).ToList());
|
||||
CompositeDataSource compositeDataSource;
|
||||
var xData = new EnumerableDataSource<DateTime>(movingAverages.Select(x => x.Date.Date));
|
||||
xData.SetXMapping(x => (x.Ticks / 10000000000.0));
|
||||
var yData = new EnumerableDataSource<double>(movingAverages.Select(y => y.MA100));
|
||||
yData.SetYMapping(y => y);
|
||||
compositeDataSource = xData.Join(yData);
|
||||
return compositeDataSource;
|
||||
}
|
||||
public static CompositeDataSource MA55(MovingAverages movingAverages)
|
||||
{
|
||||
if (null == movingAverages) return null;
|
||||
movingAverages=new MovingAverages((from MovingAverageElement element in movingAverages where !double.IsNaN(element.MA55) select element).ToList());
|
||||
CompositeDataSource compositeDataSource;
|
||||
var xData = new EnumerableDataSource<DateTime>(movingAverages.Select(x => x.Date.Date));
|
||||
xData.SetXMapping(x => (x.Ticks / 10000000000.0));
|
||||
var yData = new EnumerableDataSource<double>(movingAverages.Select(y => y.MA55));
|
||||
yData.SetYMapping(y => y);
|
||||
compositeDataSource = xData.Join(yData);
|
||||
return compositeDataSource;
|
||||
}
|
||||
public static CompositeDataSource MA21(MovingAverages movingAverages)
|
||||
{
|
||||
if (null == movingAverages) return null;
|
||||
movingAverages=new MovingAverages((from MovingAverageElement element in movingAverages where !double.IsNaN(element.MA21) select element).ToList());
|
||||
CompositeDataSource compositeDataSource;
|
||||
var xData = new EnumerableDataSource<DateTime>(movingAverages.Select(x => x.Date.Date));
|
||||
xData.SetXMapping(x => (x.Ticks / 10000000000.0));
|
||||
var yData = new EnumerableDataSource<double>(movingAverages.Select(y => y.MA21));
|
||||
yData.SetYMapping(y => y);
|
||||
compositeDataSource = xData.Join(yData);
|
||||
return compositeDataSource;
|
||||
}
|
||||
public static CompositeDataSource MA5(MovingAverages movingAverages)
|
||||
{
|
||||
if (null == movingAverages) return null;
|
||||
movingAverages=new MovingAverages((from MovingAverageElement element in movingAverages where !double.IsNaN(element.MA5) select element).ToList());
|
||||
CompositeDataSource compositeDataSource;
|
||||
var xData = new EnumerableDataSource<DateTime>(movingAverages.Select(x => x.Date.Date));
|
||||
xData.SetXMapping(x => (x.Ticks / 10000000000.0));
|
||||
var yData = new EnumerableDataSource<double>(movingAverages.Select(y => y.MA5));
|
||||
yData.SetYMapping(y => y);
|
||||
compositeDataSource = xData.Join(yData);
|
||||
return compositeDataSource;
|
||||
}
|
||||
public static CompositeDataSource CreateCompositeDataSource(DMAValues dmaValues)
|
||||
{
|
||||
if (null == dmaValues) return null;
|
||||
CompositeDataSource compositeDataSource;
|
||||
var xData = new EnumerableDataSource<DateTime>(dmaValues.Select(x => x.Date));
|
||||
xData.SetXMapping(x => (x.Ticks / 10000000000.0));
|
||||
var yData = new EnumerableDataSource<double>(dmaValues.Select(y => y.MAValue));
|
||||
yData.SetYMapping(y => y);
|
||||
compositeDataSource = xData.Join(yData);
|
||||
return compositeDataSource;
|
||||
}
|
||||
}
|
||||
}
|
||||
39
Model/OptionStrikeModel.cs
Normal file
39
Model/OptionStrikeModel.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using MarketData.MarketDataModel;
|
||||
using Microsoft.Research.DynamicDataDisplay.DataSources;
|
||||
|
||||
namespace TradeBlotter.Model
|
||||
{
|
||||
public class OptionStrike
|
||||
{
|
||||
public OptionStrike(DateTime expirationDate, double strikePrice)
|
||||
{
|
||||
ExpirationDate = expirationDate;
|
||||
StrikePrice = strikePrice;
|
||||
}
|
||||
public DateTime ExpirationDate { get; set; }
|
||||
public double StrikePrice { get; set; }
|
||||
}
|
||||
public class OptionStrikes : List<OptionStrike>
|
||||
{
|
||||
}
|
||||
public class OptionStrikeModel
|
||||
{
|
||||
private OptionStrikeModel()
|
||||
{
|
||||
}
|
||||
public static CompositeDataSource OptionStrikes(OptionStrikes optionStrikes)
|
||||
{
|
||||
if (null == optionStrikes) return null;
|
||||
CompositeDataSource compositeDataSource;
|
||||
var xData = new EnumerableDataSource<DateTime>(optionStrikes.Select(x => x.ExpirationDate.Date));
|
||||
xData.SetXMapping(x => (x.Ticks / 10000000000.0));
|
||||
var yData = new EnumerableDataSource<double>(optionStrikes.Select(y => y.StrikePrice));
|
||||
yData.SetYMapping(y => y);
|
||||
compositeDataSource = xData.Join(yData);
|
||||
return compositeDataSource;
|
||||
}
|
||||
}
|
||||
}
|
||||
26
Model/PortfolioTradeModel.cs
Normal file
26
Model/PortfolioTradeModel.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using MarketData.MarketDataModel;
|
||||
using Microsoft.Research.DynamicDataDisplay.DataSources;
|
||||
|
||||
namespace TradeBlotter.Model
|
||||
{
|
||||
public class PortfolioTradeModel
|
||||
{
|
||||
private PortfolioTradeModel()
|
||||
{
|
||||
}
|
||||
public static CompositeDataSource PortfolioTrades(PortfolioTrades portfolioTrades)
|
||||
{
|
||||
if (null == portfolioTrades || 0 == portfolioTrades.Count) return new CompositeDataSource();
|
||||
CompositeDataSource compositeDataSource;
|
||||
var xData = new EnumerableDataSource<DateTime>(portfolioTrades.Select(x => x.TradeDate.Date));
|
||||
xData.SetXMapping(x => (x.Ticks / 10000000000.0));
|
||||
var yData = new EnumerableDataSource<double>(portfolioTrades.Select(y => y.Price));
|
||||
yData.SetYMapping(y => y);
|
||||
compositeDataSource = xData.Join(yData);
|
||||
return compositeDataSource;
|
||||
}
|
||||
}
|
||||
}
|
||||
126
Model/PriceModel.cs
Normal file
126
Model/PriceModel.cs
Normal file
@@ -0,0 +1,126 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Microsoft.Research.DynamicDataDisplay.DataSources;
|
||||
using MarketData.MarketDataModel;
|
||||
|
||||
namespace TradeBlotter.Model
|
||||
{
|
||||
public class PricesModel
|
||||
{
|
||||
private PricesModel()
|
||||
{
|
||||
}
|
||||
public static CompositeDataSource Close(Prices prices)
|
||||
{
|
||||
if (null == prices) return null;
|
||||
CompositeDataSource compositeDataSource;
|
||||
var xData = new EnumerableDataSource<DateTime>(prices.Select(x => x.Date.Date));
|
||||
xData.SetXMapping(x => (x.Ticks / 10000000000.0));
|
||||
var yData = new EnumerableDataSource<double>(prices.Select(y => y.Close));
|
||||
yData.SetYMapping(y => y);
|
||||
compositeDataSource = xData.Join(yData);
|
||||
return compositeDataSource;
|
||||
}
|
||||
public static CompositeDataSource LeastSquares(Prices prices)
|
||||
{
|
||||
if (null == prices) return null;
|
||||
CompositeDataSource compositeDataSource;
|
||||
var xData = new EnumerableDataSource<DateTime>(prices.Select(x => x.Date.Date));
|
||||
xData.SetXMapping(x => (x.Ticks / 10000000000.0));
|
||||
var yData = new EnumerableDataSource<double>(prices.GetLeastSquaresFit());
|
||||
yData.SetYMapping(y => y);
|
||||
compositeDataSource = xData.Join(yData);
|
||||
return compositeDataSource;
|
||||
}
|
||||
}
|
||||
public class PriceModel
|
||||
{
|
||||
private Price price;
|
||||
private float return1d;
|
||||
private float return5d;
|
||||
private float return10d;
|
||||
private float return15d;
|
||||
private float return30d;
|
||||
private float return60d;
|
||||
private float return200d;
|
||||
private String companyName;
|
||||
public PriceModel(Price price,float return1d,float return5d,float return10d,float return15d,float return30d,float return60d,float return200d,String companyName)
|
||||
{
|
||||
this.price = price;
|
||||
this.return1d = return1d;
|
||||
this.return5d = return5d;
|
||||
this.return10d = return10d;
|
||||
this.return15d = return15d;
|
||||
this.return30d=return30d;
|
||||
this.return60d=return60d;
|
||||
this.return200d=return200d;
|
||||
this.companyName = companyName;
|
||||
}
|
||||
public String CompanyName
|
||||
{
|
||||
get { return companyName; }
|
||||
}
|
||||
public String Symbol
|
||||
{
|
||||
get { return price.Symbol; }
|
||||
}
|
||||
public DateTime Date
|
||||
{
|
||||
get { return price.Date; }
|
||||
}
|
||||
public double Open
|
||||
{
|
||||
get { return price.Open; }
|
||||
}
|
||||
public double High
|
||||
{
|
||||
get { return price.High; }
|
||||
}
|
||||
public double Low
|
||||
{
|
||||
get { return price.Low; }
|
||||
}
|
||||
public double Close
|
||||
{
|
||||
get { return price.Close; }
|
||||
}
|
||||
public long Volume
|
||||
{
|
||||
get { return price.Volume; }
|
||||
}
|
||||
public double AdjClose
|
||||
{
|
||||
get { return price.AdjClose; }
|
||||
}
|
||||
public float Return1D
|
||||
{
|
||||
get { return return1d; }
|
||||
}
|
||||
public float Return5D
|
||||
{
|
||||
get { return return5d; }
|
||||
}
|
||||
public float Return10D
|
||||
{
|
||||
get { return return10d; }
|
||||
}
|
||||
public float Return15D
|
||||
{
|
||||
get { return return15d; }
|
||||
}
|
||||
public float Return30D
|
||||
{
|
||||
get{return return30d;}
|
||||
}
|
||||
public float Return60D
|
||||
{
|
||||
get{return return60d;}
|
||||
}
|
||||
public float Return200D
|
||||
{
|
||||
get{return return200d;}
|
||||
}
|
||||
}
|
||||
}
|
||||
26
Model/RSIModel.cs
Normal file
26
Model/RSIModel.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using MarketData.MarketDataModel;
|
||||
using Microsoft.Research.DynamicDataDisplay.DataSources;
|
||||
|
||||
namespace TradeBlotter.Model
|
||||
{
|
||||
public class RSIModel
|
||||
{
|
||||
private RSIModel()
|
||||
{
|
||||
}
|
||||
public static CompositeDataSource Pcnt(RSICollection rsiCollection)
|
||||
{
|
||||
if (null == rsiCollection) return null;
|
||||
CompositeDataSource compositeDataSource;
|
||||
var xData = new EnumerableDataSource<DateTime>(rsiCollection.Select(x => x.Date.Date));
|
||||
xData.SetXMapping(x => (x.Ticks / 10000000000.0));
|
||||
var yData = new EnumerableDataSource<double>(rsiCollection.Select(y => y.RSI));
|
||||
yData.SetYMapping(y => y);
|
||||
compositeDataSource = xData.Join(yData);
|
||||
return compositeDataSource;
|
||||
}
|
||||
}
|
||||
}
|
||||
28
Model/RatingsModel.cs
Normal file
28
Model/RatingsModel.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Microsoft.Research.DynamicDataDisplay.DataSources;
|
||||
using MarketData.MarketDataModel;
|
||||
|
||||
namespace TradeBlotter.Model
|
||||
{
|
||||
public class RatingsModel
|
||||
{
|
||||
private RatingsModel()
|
||||
{
|
||||
}
|
||||
// if latestPrice is provided and PriceTarget of rating is zero then the graph is placed at current price. This improves the appearance of the graph on the screen
|
||||
public static CompositeDataSource Ratings(AnalystRatings analystRatings,Price latestPrice)
|
||||
{
|
||||
if (null == analystRatings) return null;
|
||||
CompositeDataSource compositeDataSource;
|
||||
var xData = new EnumerableDataSource<DateTime>(analystRatings.Select(x => x.Date.Date));
|
||||
xData.SetXMapping(x => (x.Ticks / 10000000000.0));
|
||||
var yData = new EnumerableDataSource<double>(analystRatings.Select(y => 0==y.PriceTarget&&null!=latestPrice?latestPrice.Close:y.PriceTarget));
|
||||
yData.SetYMapping(y => y);
|
||||
compositeDataSource = xData.Join(yData);
|
||||
return compositeDataSource;
|
||||
}
|
||||
}
|
||||
}
|
||||
93
Model/ResistanceAndSupportModel.cs
Normal file
93
Model/ResistanceAndSupportModel.cs
Normal file
@@ -0,0 +1,93 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using MarketData.MarketDataModel;
|
||||
using Microsoft.Research.DynamicDataDisplay.DataSources;
|
||||
|
||||
namespace TradeBlotter.Model
|
||||
{
|
||||
public class ResistanceAndSupportModel
|
||||
{
|
||||
private ResistanceAndSupportModel()
|
||||
{
|
||||
}
|
||||
public static CompositeDataSource R1(List<ResistanceSupport> resistanceSupportList)
|
||||
{
|
||||
if (null == resistanceSupportList || 0 == resistanceSupportList.Count) return null;
|
||||
CompositeDataSource compositeDataSource;
|
||||
var xData = new EnumerableDataSource<DateTime>(resistanceSupportList.Select(x => x.Date.Date));
|
||||
xData.SetXMapping(x => (x.Ticks / 10000000000.0));
|
||||
var yData = new EnumerableDataSource<double>(resistanceSupportList.Select(y => y.Resistance1));
|
||||
yData.SetYMapping(y => y);
|
||||
compositeDataSource = xData.Join(yData);
|
||||
return compositeDataSource;
|
||||
}
|
||||
public static CompositeDataSource S1(List<ResistanceSupport> resistanceSupportList)
|
||||
{
|
||||
if (null == resistanceSupportList || 0 == resistanceSupportList.Count) return null;
|
||||
CompositeDataSource compositeDataSource;
|
||||
var xData = new EnumerableDataSource<DateTime>(resistanceSupportList.Select(x => x.Date.Date));
|
||||
xData.SetXMapping(x => (x.Ticks / 10000000000.0));
|
||||
var yData = new EnumerableDataSource<double>(resistanceSupportList.Select(y => y.Support1));
|
||||
yData.SetYMapping(y => y);
|
||||
compositeDataSource = xData.Join(yData);
|
||||
return compositeDataSource;
|
||||
}
|
||||
public static CompositeDataSource R2(List<ResistanceSupport> resistanceSupportList)
|
||||
{
|
||||
if (null == resistanceSupportList || 0 == resistanceSupportList.Count) return null;
|
||||
CompositeDataSource compositeDataSource;
|
||||
var xData = new EnumerableDataSource<DateTime>(resistanceSupportList.Select(x => x.Date.Date));
|
||||
xData.SetXMapping(x => (x.Ticks / 10000000000.0));
|
||||
var yData = new EnumerableDataSource<double>(resistanceSupportList.Select(y => y.Resistance2));
|
||||
yData.SetYMapping(y => y);
|
||||
compositeDataSource = xData.Join(yData);
|
||||
return compositeDataSource;
|
||||
}
|
||||
public static CompositeDataSource S2(List<ResistanceSupport> resistanceSupportList)
|
||||
{
|
||||
if (null == resistanceSupportList || 0 == resistanceSupportList.Count) return null;
|
||||
CompositeDataSource compositeDataSource;
|
||||
var xData = new EnumerableDataSource<DateTime>(resistanceSupportList.Select(x => x.Date.Date));
|
||||
xData.SetXMapping(x => (x.Ticks / 10000000000.0));
|
||||
var yData = new EnumerableDataSource<double>(resistanceSupportList.Select(y => y.Support2));
|
||||
yData.SetYMapping(y => y);
|
||||
compositeDataSource = xData.Join(yData);
|
||||
return compositeDataSource;
|
||||
}
|
||||
public static CompositeDataSource High(List<ResistanceSupport> resistanceSupportList)
|
||||
{
|
||||
if (null == resistanceSupportList || 0 == resistanceSupportList.Count) return null;
|
||||
CompositeDataSource compositeDataSource;
|
||||
var xData = new EnumerableDataSource<DateTime>(resistanceSupportList.Select(x => x.Date.Date));
|
||||
xData.SetXMapping(x => (x.Ticks / 10000000000.0));
|
||||
var yData = new EnumerableDataSource<double>(resistanceSupportList.Select(y => y.High));
|
||||
yData.SetYMapping(y => y);
|
||||
compositeDataSource = xData.Join(yData);
|
||||
return compositeDataSource;
|
||||
}
|
||||
public static CompositeDataSource Low(List<ResistanceSupport> resistanceSupportList)
|
||||
{
|
||||
if (null == resistanceSupportList || 0 == resistanceSupportList.Count) return null;
|
||||
CompositeDataSource compositeDataSource;
|
||||
var xData = new EnumerableDataSource<DateTime>(resistanceSupportList.Select(x => x.Date.Date));
|
||||
xData.SetXMapping(x => (x.Ticks / 10000000000.0));
|
||||
var yData = new EnumerableDataSource<double>(resistanceSupportList.Select(y => y.Low));
|
||||
yData.SetYMapping(y => y);
|
||||
compositeDataSource = xData.Join(yData);
|
||||
return compositeDataSource;
|
||||
}
|
||||
public static CompositeDataSource Close(List<ResistanceSupport> resistanceSupportList)
|
||||
{
|
||||
if (null == resistanceSupportList || 0 == resistanceSupportList.Count) return null;
|
||||
CompositeDataSource compositeDataSource;
|
||||
var xData = new EnumerableDataSource<DateTime>(resistanceSupportList.Select(x => x.Date.Date));
|
||||
xData.SetXMapping(x => (x.Ticks / 10000000000.0));
|
||||
var yData = new EnumerableDataSource<double>(resistanceSupportList.Select(y => y.Close));
|
||||
yData.SetYMapping(y => y);
|
||||
compositeDataSource = xData.Join(yData);
|
||||
return compositeDataSource;
|
||||
}
|
||||
}
|
||||
}
|
||||
37
Model/StochasticsModel.cs
Normal file
37
Model/StochasticsModel.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using MarketData.MarketDataModel;
|
||||
using Microsoft.Research.DynamicDataDisplay.DataSources;
|
||||
|
||||
namespace TradeBlotter.Model
|
||||
{
|
||||
public class StochasticsModel
|
||||
{
|
||||
private StochasticsModel()
|
||||
{
|
||||
}
|
||||
public static CompositeDataSource PcntK(Stochastics stochastics)
|
||||
{
|
||||
if (null == stochastics) return null;
|
||||
CompositeDataSource compositeDataSource;
|
||||
var xData = new EnumerableDataSource<DateTime>(stochastics.Select(x => x.Date.Date));
|
||||
xData.SetXMapping(x => (x.Ticks / 10000000000.0));
|
||||
var yData = new EnumerableDataSource<double>(stochastics.Select(y => y.PK));
|
||||
yData.SetYMapping(y => y);
|
||||
compositeDataSource = xData.Join(yData);
|
||||
return compositeDataSource;
|
||||
}
|
||||
public static CompositeDataSource PcntD(Stochastics stochastics)
|
||||
{
|
||||
if (null == stochastics) return null;
|
||||
CompositeDataSource compositeDataSource;
|
||||
var xData = new EnumerableDataSource<DateTime>(stochastics.Select(x => x.Date.Date));
|
||||
xData.SetXMapping(x => (x.Ticks / 10000000000.0));
|
||||
var yData = new EnumerableDataSource<double>(stochastics.Select(y => y.PD));
|
||||
yData.SetYMapping(y => y);
|
||||
compositeDataSource = xData.Join(yData);
|
||||
return compositeDataSource;
|
||||
}
|
||||
}
|
||||
}
|
||||
29
Model/StopLimitCompositeModel.cs
Normal file
29
Model/StopLimitCompositeModel.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using TradeBlotter.Views;
|
||||
using MarketData.MarketDataModel;
|
||||
using MarketData.Generator;
|
||||
using Microsoft.Research.DynamicDataDisplay.DataSources;
|
||||
using MarketData.Numerical;
|
||||
|
||||
namespace TradeBlotter.Model
|
||||
{
|
||||
public class StopLimitCompositeModel
|
||||
{
|
||||
private StopLimitCompositeModel()
|
||||
{
|
||||
}
|
||||
public static CompositeDataSource CreateCompositeDataSource(StopLimits stopLimits)
|
||||
{
|
||||
if(null==stopLimits) return null;
|
||||
CompositeDataSource compositeDataSource;
|
||||
var xData=new EnumerableDataSource<DateTime>(stopLimits.Select(x => x.EffectiveDate.Date));
|
||||
xData.SetXMapping(x => (x.Ticks/10000000000.0));
|
||||
var yData=new EnumerableDataSource<double>(stopLimits.Select(y => y.StopPrice));
|
||||
yData.SetYMapping(y => y);
|
||||
compositeDataSource=xData.Join(yData);
|
||||
return compositeDataSource;
|
||||
}
|
||||
}
|
||||
}
|
||||
96
Model/TermStructureModel.cs
Normal file
96
Model/TermStructureModel.cs
Normal file
@@ -0,0 +1,96 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using MarketData.MarketDataModel;
|
||||
using Microsoft.Research.DynamicDataDisplay.DataSources;
|
||||
using MarketData.Generator.TermStructure;
|
||||
using MarketData.Utils;
|
||||
|
||||
namespace TradeBlotter.Model
|
||||
{
|
||||
public class TermStructureModel
|
||||
{
|
||||
private TermStructureModel()
|
||||
{
|
||||
}
|
||||
public static CurveData GetTenorCurve(TermStructureInterpolatorByDate termStrucureInterpolatorByDate,DateTime analysisDate)
|
||||
{
|
||||
if(null==termStrucureInterpolatorByDate)return null;
|
||||
TermStructureInterpolator termStructureInterpolator = termStrucureInterpolatorByDate[analysisDate];
|
||||
return termStructureInterpolator.CurveData;
|
||||
}
|
||||
public static CompositeDataSource GetTenorRates(TermStructureInterpolatorByDate termStrucureInterpolatorByDate,DateTime analysisDate)
|
||||
{
|
||||
if (null == termStrucureInterpolatorByDate||!termStrucureInterpolatorByDate.ContainsKey(analysisDate)) return null;
|
||||
TermStructureInterpolator termStructureInterpolator = termStrucureInterpolatorByDate[analysisDate];
|
||||
if(null==termStructureInterpolator.CurveData)return null;
|
||||
CompositeDataSource compositeDataSource;
|
||||
DateGenerator dateGenerator=new DateGenerator();
|
||||
List<DateTime> dates = new List<DateTime>();
|
||||
//DateTime today = DateTime.Now;
|
||||
dates.Add(analysisDate);
|
||||
dates.Add(dateGenerator.GenerateFutureDate(analysisDate,30));
|
||||
dates.Add(dateGenerator.GenerateFutureDate(analysisDate,30*3));
|
||||
dates.Add(dateGenerator.GenerateFutureDate(analysisDate,30*6));
|
||||
dates.Add(dateGenerator.GenerateFutureDate(analysisDate,360*1));
|
||||
dates.Add(dateGenerator.GenerateFutureDate(analysisDate,360*2));
|
||||
dates.Add(dateGenerator.GenerateFutureDate(analysisDate,360*3));
|
||||
dates.Add(dateGenerator.GenerateFutureDate(analysisDate,360*5));
|
||||
dates.Add(dateGenerator.GenerateFutureDate(analysisDate,360*7));
|
||||
dates.Add(dateGenerator.GenerateFutureDate(analysisDate,360*10));
|
||||
dates.Add(dateGenerator.GenerateFutureDate(analysisDate,360*20));
|
||||
dates.Add(dateGenerator.GenerateFutureDate(analysisDate,360*30));
|
||||
|
||||
double[] rates = new double[]
|
||||
{
|
||||
double.Parse(termStructureInterpolator.CurveData.GetTenorValue("1D")),
|
||||
double.Parse(termStructureInterpolator.CurveData.GetTenorValue("1M")),
|
||||
double.Parse(termStructureInterpolator.CurveData.GetTenorValue("3M")),
|
||||
double.Parse(termStructureInterpolator.CurveData.GetTenorValue("6M")),
|
||||
double.Parse(termStructureInterpolator.CurveData.GetTenorValue("1Y")),
|
||||
double.Parse(termStructureInterpolator.CurveData.GetTenorValue("2Y")),
|
||||
double.Parse(termStructureInterpolator.CurveData.GetTenorValue("3Y")),
|
||||
double.Parse(termStructureInterpolator.CurveData.GetTenorValue("5Y")),
|
||||
double.Parse(termStructureInterpolator.CurveData.GetTenorValue("7Y")),
|
||||
double.Parse(termStructureInterpolator.CurveData.GetTenorValue("10Y")),
|
||||
double.Parse(termStructureInterpolator.CurveData.GetTenorValue("20Y")),
|
||||
double.Parse(termStructureInterpolator.CurveData.GetTenorValue("30Y"))
|
||||
};
|
||||
var xData = new EnumerableDataSource<DateTime>(dates);
|
||||
xData.SetXMapping(x => (x.Ticks / 10000000000.0));
|
||||
var yData = new EnumerableDataSource<double>(rates);
|
||||
yData.SetYMapping(y => y);
|
||||
compositeDataSource = xData.Join(yData);
|
||||
return compositeDataSource;
|
||||
}
|
||||
public static CompositeDataSource GetInterpolatedRates(TermStructureInterpolatorByDate termStrucureInterpolatorByDate,DateTime analysisDate)
|
||||
{
|
||||
if(null==termStrucureInterpolatorByDate)return null;
|
||||
// if(null==compositeDataSource)compositeDataSource=new CompositeDataSource();
|
||||
TermStructureInterpolator termStructureInterpolator = termStrucureInterpolatorByDate[analysisDate];
|
||||
CompositeDataSource compositeDataSource=new CompositeDataSource();
|
||||
DateGenerator dateGenerator=new DateGenerator();
|
||||
List<DateTime> dates = new List<DateTime>();
|
||||
List<double> rates = new List<double>();
|
||||
|
||||
analysisDate=analysisDate.Date;
|
||||
List<int> keys = new List<int>(termStructureInterpolator.SplineRates.Keys);
|
||||
keys.Sort();
|
||||
foreach (int key in keys)
|
||||
{
|
||||
dates.Add(analysisDate);
|
||||
rates.Add(termStructureInterpolator.SplineRates[key]);
|
||||
analysisDate=dateGenerator.GetNextDay(analysisDate);
|
||||
}
|
||||
double[] ratesArray = rates.ToArray<double>();
|
||||
var xData = new EnumerableDataSource<DateTime>(dates);
|
||||
xData.SetXMapping(x => (x.Ticks / 10000000000.0));
|
||||
var yData = new EnumerableDataSource<double>(rates);
|
||||
yData.SetYMapping(y => y);
|
||||
// compositeDataSource = xData.Join(yData);
|
||||
compositeDataSource.AddDataPart(xData.Join(yData));
|
||||
return compositeDataSource;
|
||||
}
|
||||
}
|
||||
}
|
||||
35
Model/TimeSeriesModel.cs
Normal file
35
Model/TimeSeriesModel.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using MarketData.MarketDataModel;
|
||||
using Microsoft.Research.DynamicDataDisplay.DataSources;
|
||||
|
||||
namespace TradeBlotter.Model
|
||||
{
|
||||
public delegate double ValueConverter(double value);
|
||||
public class TimeSeriesModel
|
||||
{
|
||||
public static CompositeDataSource GenerateCompositeDataSource(TimeSeriesCollection timeSeriesCollection)
|
||||
{
|
||||
if (null == timeSeriesCollection || 0 == timeSeriesCollection.Count) return null;
|
||||
CompositeDataSource compositeDataSource;
|
||||
var xData = new EnumerableDataSource<DateTime>(timeSeriesCollection.Select(x => x.AsOf.Date));
|
||||
xData.SetXMapping(x => (x.Ticks / 10000000000.0));
|
||||
var yData = new EnumerableDataSource<double>(timeSeriesCollection.Select(y => y.Value));
|
||||
yData.SetYMapping(y => y);
|
||||
compositeDataSource = xData.Join(yData);
|
||||
return compositeDataSource;
|
||||
}
|
||||
public static CompositeDataSource GenerateCompositeDataSource(TimeSeriesCollection timeSeriesCollection,ValueConverter valueConverter)
|
||||
{
|
||||
if (null == timeSeriesCollection || 0 == timeSeriesCollection.Count) return null;
|
||||
CompositeDataSource compositeDataSource;
|
||||
var xData = new EnumerableDataSource<DateTime>(timeSeriesCollection.Select(x => x.AsOf.Date));
|
||||
xData.SetXMapping(x => (x.Ticks / 10000000000.0));
|
||||
var yData = new EnumerableDataSource<double>(timeSeriesCollection.Select(y => valueConverter(y.Value)));
|
||||
yData.SetYMapping(y => y);
|
||||
compositeDataSource = xData.Join(yData);
|
||||
return compositeDataSource;
|
||||
}
|
||||
}
|
||||
}
|
||||
338
Model/TradeEntryModel.cs
Normal file
338
Model/TradeEntryModel.cs
Normal file
@@ -0,0 +1,338 @@
|
||||
//using System;
|
||||
//using System.Collections.Generic;
|
||||
//using System.ComponentModel;
|
||||
//using System.Linq;
|
||||
//using System.Text;
|
||||
//using System.Windows.Input;
|
||||
//using MarketData;
|
||||
//using MarketData.MarketDataModel;
|
||||
//using MarketData.Helper;
|
||||
//using MarketData.DataAccess;
|
||||
//using MarketData.Utils;
|
||||
//using TradeBlotter.DataAccess;
|
||||
//using TradeBlotter.Command;
|
||||
//using TradeBlotter.Model;
|
||||
//using TradeBlotter.ViewModels;
|
||||
|
||||
//namespace TradeBlotter.Model
|
||||
//{
|
||||
// public class TradeEntryModel : ModelBase
|
||||
// {
|
||||
// private BlotterTradeModel trade = null;
|
||||
// private readonly TradeRepository tradeRepository;
|
||||
// private RelayCommand saveCommand;
|
||||
// private bool updatePrice = true;
|
||||
// private String statusText="";
|
||||
|
||||
// public TradeEntryModel(BlotterTradeModel trade, TradeRepository tradeRepository,bool updatePrice=true)
|
||||
// {
|
||||
// // base.DisplayName = "TradeEntry";
|
||||
// this.updatePrice = updatePrice;
|
||||
// this.trade = trade;
|
||||
// this.tradeRepository = tradeRepository;
|
||||
// PropertyChanged += OnTradeEntryViewModelPropertyChanged;
|
||||
// UpdateProperties();
|
||||
// }
|
||||
// //public override SaveParameters GetSaveParameters()
|
||||
// //{
|
||||
// // return null;
|
||||
// //}
|
||||
// //public override void SetSaveParameters(SaveParameters saveParameters)
|
||||
// //{
|
||||
// //}
|
||||
// //public override bool CanPersist()
|
||||
// //{
|
||||
// // return false;
|
||||
// //}
|
||||
// public void SetActiveTrade(BlotterTradeModel trade)
|
||||
// {
|
||||
// this.trade = trade;
|
||||
// updatePrice = false;
|
||||
// UpdateProperties();
|
||||
// }
|
||||
// private void UpdateProperties()
|
||||
// {
|
||||
// base.OnPropertyChanged("Symbol");
|
||||
// base.OnPropertyChanged("Price");
|
||||
// base.OnPropertyChanged("CompanyName");
|
||||
// base.OnPropertyChanged("TradeDate");
|
||||
// base.OnPropertyChanged("SelectedTradeType");
|
||||
// base.OnPropertyChanged("SelectedAccount");
|
||||
// base.OnPropertyChanged("SelectedStatus");
|
||||
// base.OnPropertyChanged("TradeId");
|
||||
// base.OnPropertyChanged("Shares");
|
||||
// base.OnPropertyChanged("Exposure");
|
||||
// }
|
||||
// private void OnTradeEntryViewModelPropertyChanged(object sender, PropertyChangedEventArgs eventArgs)
|
||||
// {
|
||||
// if (eventArgs.PropertyName.Equals("Symbol"))
|
||||
// {
|
||||
// if (updatePrice)
|
||||
// {
|
||||
// Price price = null;
|
||||
// if (!Utility.IsEpoch(trade.TradeDate) && !trade.TradeDate.Date.Equals(DateTime.Now.Date))
|
||||
// {
|
||||
// price = PricingDA.GetPrice(trade.Symbol, trade.TradeDate);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// price=MarketDataHelper.GetLatestPrice(trade.Symbol);
|
||||
// if (null == price) price = PricingDA.GetPrice(trade.Symbol);
|
||||
// }
|
||||
// if (null != price)trade.Price = price.Close;
|
||||
// else trade.Price=0;
|
||||
// base.OnPropertyChanged("Price");
|
||||
// }
|
||||
// String companyName = PricingDA.GetNameForSymbol(trade.Symbol);
|
||||
// if (null != companyName)
|
||||
// {
|
||||
// trade.CompanyName = companyName;
|
||||
// base.OnPropertyChanged("CompanyName");
|
||||
// }
|
||||
// }
|
||||
// else if (eventArgs.PropertyName.Equals("TradeDate"))
|
||||
// {
|
||||
// base.OnPropertyChanged("Price");
|
||||
// }
|
||||
// }
|
||||
// public String TradeId
|
||||
// {
|
||||
// get { return -1==trade.TradeId?Constants.CONST_DASHES:trade.TradeId.ToString(); }
|
||||
// set { ;}
|
||||
// }
|
||||
// public List<String> TradeTypeOptions
|
||||
// {
|
||||
// get { return new List<String>() { "Buy", "Sell" }; }
|
||||
// }
|
||||
//// Buy/Sell
|
||||
// public String SelectedTradeType
|
||||
// {
|
||||
// get
|
||||
// {
|
||||
// if (null == trade.BuySell) return null;
|
||||
// else if (trade.BuySell.Equals("S")) return "Sell";
|
||||
// else if (trade.BuySell.Equals("B")) return "Buy";
|
||||
// else return null;
|
||||
// }
|
||||
// set
|
||||
// {
|
||||
// if(String.IsNullOrEmpty(value)) return;
|
||||
// trade.BuySell = value.Equals("Buy") ? "B" : "S";
|
||||
// if (trade.BuySell.Equals("B"))
|
||||
// {
|
||||
// trade.Status = "OPEN";
|
||||
// trade.SellPrice = double.NaN;
|
||||
// trade.SellDate = Utility.Epoch;
|
||||
// base.OnPropertyChanged("SellPrice");
|
||||
// base.OnPropertyChanged("SellDate");
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// trade.Status = "CLOSED";
|
||||
// }
|
||||
// base.OnPropertyChanged("SelectedStatus");
|
||||
// base.OnPropertyChanged("SelectedTradeType");
|
||||
// }
|
||||
// }
|
||||
//// ***************************************** A C C O U N T ***************************
|
||||
// public List<String> AccountOptions
|
||||
// {
|
||||
// get { return PortfolioDA.GetAccounts(); }
|
||||
// }
|
||||
// public String SelectedAccount
|
||||
// {
|
||||
// get { return null==trade.Account||trade.Account.Equals("") ? null : trade.Account; }
|
||||
// set
|
||||
// {
|
||||
// trade.Account = value;
|
||||
// base.OnPropertyChanged("SelectedAccount");
|
||||
// }
|
||||
// }
|
||||
////************************************************************************************
|
||||
// public List<String> TradeStatusOptions
|
||||
// {
|
||||
// get {return new List<String>(){"OPEN","CLOSED"}; }
|
||||
// }
|
||||
// public String SelectedStatus
|
||||
// {
|
||||
// get
|
||||
// {
|
||||
// return null==trade.Status||trade.Status.Equals("") ? null : trade.Status;
|
||||
// }
|
||||
// }
|
||||
// public DateTime TradeDate
|
||||
// {
|
||||
// get { return trade.TradeDate; }
|
||||
// set
|
||||
// {
|
||||
// trade.TradeDate = value;
|
||||
// Price price = null;
|
||||
// if (!Utility.IsEpoch(trade.TradeDate) && !trade.TradeDate.Date.Equals(DateTime.Now.Date))
|
||||
// {
|
||||
// price = PricingDA.GetPrice(trade.Symbol, trade.TradeDate);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// price = MarketDataHelper.GetLatestPrice(trade.Symbol);
|
||||
// if (null == price) price = PricingDA.GetPrice(trade.Symbol);
|
||||
// }
|
||||
// if (null != price)
|
||||
// {
|
||||
// trade.Price = price.Close;
|
||||
// base.OnPropertyChanged("TradeDate");
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// public String Symbol
|
||||
// {
|
||||
// get { return trade.Symbol; }
|
||||
// set
|
||||
// {
|
||||
// trade.Symbol = value;
|
||||
// trade.Symbol = trade.Symbol.ToUpper();
|
||||
// base.OnPropertyChanged("Symbol");
|
||||
// }
|
||||
// }
|
||||
// public double Shares
|
||||
// {
|
||||
// get
|
||||
// {
|
||||
// return trade.Shares;
|
||||
// }
|
||||
// set
|
||||
// {
|
||||
// trade.Shares = value;
|
||||
// base.OnPropertyChanged("Shares");
|
||||
// base.OnPropertyChanged("Exposure");
|
||||
// }
|
||||
// }
|
||||
// public String CompanyName
|
||||
// {
|
||||
// get { return trade.CompanyName; }
|
||||
// set
|
||||
// {
|
||||
// trade.CompanyName = value;
|
||||
// base.OnPropertyChanged("CompanyName");
|
||||
// }
|
||||
// }
|
||||
// public String Exposure
|
||||
// {
|
||||
// get { return Utility.FormatCurrency(trade.Exposure); }
|
||||
// set { ;}
|
||||
// }
|
||||
// public String Price
|
||||
// {
|
||||
// get
|
||||
// {
|
||||
// return Utility.FormatCurrency(trade.Price,3);
|
||||
// }
|
||||
// set
|
||||
// {
|
||||
// trade.Price = Utility.ParseCurrency(value);
|
||||
// base.OnPropertyChanged("Price");
|
||||
// base.OnPropertyChanged("Exposure");
|
||||
// }
|
||||
// }
|
||||
// public String SellPrice
|
||||
// {
|
||||
// get
|
||||
// {
|
||||
// return Utility.FormatCurrency(trade.SellPrice);
|
||||
// }
|
||||
// set
|
||||
// {
|
||||
// if (!trade.Status.Equals("CLOSED")) return;
|
||||
// trade.SellPrice = Utility.ParseCurrency(value);
|
||||
// base.OnPropertyChanged("SellPrice");
|
||||
// }
|
||||
// }
|
||||
// public DateTime? SellDate
|
||||
// {
|
||||
// get
|
||||
// {
|
||||
// if (Utility.IsEpoch(trade.SellDate)) return null;
|
||||
// return trade.SellDate;
|
||||
// }
|
||||
// set
|
||||
// {
|
||||
// trade.SellDate = value.Value;
|
||||
// base.OnPropertyChanged("SellDate");
|
||||
// }
|
||||
// }
|
||||
// public String Commission
|
||||
// {
|
||||
// get
|
||||
// {
|
||||
// return Utility.FormatCurrency(trade.Commission);
|
||||
// }
|
||||
// set
|
||||
// {
|
||||
// trade.Commission = Utility.ParseCurrency(value);
|
||||
// }
|
||||
// }
|
||||
// public String Status
|
||||
// {
|
||||
// get
|
||||
// {
|
||||
// UIUtils.UIServices.ClearProperty(3, OnClearPropertyEvent);
|
||||
// return statusText;
|
||||
// }
|
||||
// set
|
||||
// {
|
||||
// statusText = value;
|
||||
// base.OnPropertyChanged("Status");
|
||||
// }
|
||||
// }
|
||||
// public void OnClearPropertyEvent(Object sender,EventArgs e)
|
||||
// {
|
||||
// statusText = "";
|
||||
// base.OnPropertyChanged("Status");
|
||||
// }
|
||||
//// *******************************************************************************************************
|
||||
//// ****************************************** S A V E C O M M A N D *************************************
|
||||
//// *******************************************************************************************************
|
||||
// public ICommand SaveCommand
|
||||
// {
|
||||
// get
|
||||
// {
|
||||
// if(saveCommand == null)
|
||||
// {
|
||||
// saveCommand = new RelayCommand(param => this.Save(),param => this.CanSave);
|
||||
// }
|
||||
// return saveCommand;
|
||||
// }
|
||||
// }
|
||||
// public void Save()
|
||||
// {
|
||||
// if (!tradeRepository.ContainsTrade(trade))
|
||||
// {
|
||||
// tradeRepository.AddTrade(trade);
|
||||
// base.OnPropertyChanged("TradeId");
|
||||
// base.OnPropertyChanged("DisplayName");
|
||||
// statusText = "Save completed.";
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// tradeRepository.UpdateTrade(trade);
|
||||
// statusText="Update completed.";
|
||||
// }
|
||||
// base.OnPropertyChanged("Status");
|
||||
// }
|
||||
// public bool CanSave
|
||||
// {
|
||||
// get
|
||||
// {
|
||||
// if (null == trade.TradeDate || Utility.IsEpoch(trade.TradeDate)) return false;
|
||||
// if (null == trade.BuySell || !(trade.BuySell.ToUpper().Equals("B") || trade.BuySell.ToUpper().Equals("S"))) return false;
|
||||
// if (null == trade.Status || (!trade.Status.Equals("OPEN") && !trade.Status.Equals("CLOSED"))) return false;
|
||||
// if((trade.Status.Equals("CLOSED")||trade.BuySell.ToUpper().Equals("S"))&&double.IsNaN(trade.SellPrice))return false;
|
||||
// if ((trade.Status.Equals("CLOSED") || trade.BuySell.ToUpper().Equals("S")) && Utility.IsEpoch(trade.SellDate)) return false;
|
||||
// if (null == trade.Symbol) return false;
|
||||
// if (0 == trade.Shares) return false;
|
||||
// if (null == trade.Account || "".Equals(trade.Account)) return false;
|
||||
// if (0 == trade.Price) return false;
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
128
Model/TradeResultModel.cs
Normal file
128
Model/TradeResultModel.cs
Normal file
@@ -0,0 +1,128 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace TradeBlotter.Model
|
||||
{
|
||||
public class TradeResultList : List<TradeResult>
|
||||
{
|
||||
public TradeResultList()
|
||||
{
|
||||
}
|
||||
}
|
||||
public class TradeResult : IComparable
|
||||
{
|
||||
private DateTime tradeDate;
|
||||
private String buySell;
|
||||
private String symbol;
|
||||
private long shares;
|
||||
private double price;
|
||||
private double gainLoss;
|
||||
private double exposure;
|
||||
private double returnOnPosition;
|
||||
private long daysHeld;
|
||||
private String comment;
|
||||
|
||||
public TradeResult(DateTime tradeDate, String buySell, String symbol, long shares, double price, double gainLoss, double returnOnPosition,double exposure,long daysHeld, String comment)
|
||||
{
|
||||
this.tradeDate = tradeDate;
|
||||
this.buySell = buySell;
|
||||
this.symbol = symbol;
|
||||
this.shares = shares;
|
||||
this.price = price;
|
||||
this.gainLoss = gainLoss;
|
||||
this.daysHeld = daysHeld;
|
||||
this.comment = comment;
|
||||
this.exposure = exposure;
|
||||
this.returnOnPosition = returnOnPosition;
|
||||
}
|
||||
public int CompareTo(Object o)
|
||||
{
|
||||
if (!o.GetType().Equals(typeof(TradeResult))) throw new Exception("Exected " + typeof(TradeResult));
|
||||
TradeResult thatResult = (TradeResult)o;
|
||||
return thatResult.TradeDate.CompareTo(tradeDate);
|
||||
}
|
||||
public DateTime TradeDate
|
||||
{
|
||||
get { return tradeDate; }
|
||||
}
|
||||
public String BuySell
|
||||
{
|
||||
get { return buySell; }
|
||||
}
|
||||
public String Symbol
|
||||
{
|
||||
get { return symbol; }
|
||||
}
|
||||
public long Shares
|
||||
{
|
||||
get { return shares; }
|
||||
}
|
||||
public double Price
|
||||
{
|
||||
get { return price; }
|
||||
}
|
||||
public double GainLoss
|
||||
{
|
||||
get { return gainLoss; }
|
||||
}
|
||||
public double Exposure
|
||||
{
|
||||
get { return exposure; }
|
||||
}
|
||||
public double Return
|
||||
{
|
||||
get { return returnOnPosition; }
|
||||
}
|
||||
public long DaysHeld
|
||||
{
|
||||
get { return daysHeld; }
|
||||
}
|
||||
public String Comment
|
||||
{
|
||||
get { return comment; }
|
||||
}
|
||||
}
|
||||
public class TradeResultSummary
|
||||
{
|
||||
private double portfolioValue;
|
||||
private double portfolioReturn;
|
||||
private double averageGainLoss;
|
||||
private double averageHoldingDays;
|
||||
private double minimumHoldingDays;
|
||||
private double maximumHoldingDays;
|
||||
|
||||
public TradeResultSummary()
|
||||
{
|
||||
}
|
||||
public double PortfolioValue
|
||||
{
|
||||
get { return portfolioValue; }
|
||||
set { portfolioValue = value; }
|
||||
}
|
||||
public double PortfolioReturn
|
||||
{
|
||||
get { return portfolioReturn; }
|
||||
set { portfolioReturn = value; }
|
||||
}
|
||||
public double AverageGainLoss
|
||||
{
|
||||
get { return averageGainLoss; }
|
||||
set { averageGainLoss = value; }
|
||||
}
|
||||
public double AverageHoldingDays
|
||||
{
|
||||
get { return averageHoldingDays; }
|
||||
set { averageHoldingDays = value; }
|
||||
}
|
||||
public double MinimumHoldingDays
|
||||
{
|
||||
get { return minimumHoldingDays; }
|
||||
set { minimumHoldingDays = value; }
|
||||
}
|
||||
public double MaximumHoldingDays
|
||||
{
|
||||
get { return maximumHoldingDays; }
|
||||
set { maximumHoldingDays = value; }
|
||||
}
|
||||
}
|
||||
}
|
||||
345
Model/ValuationModel.cs
Normal file
345
Model/ValuationModel.cs
Normal file
@@ -0,0 +1,345 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Input;
|
||||
using System.Windows;
|
||||
using System.ComponentModel;
|
||||
using MarketData;
|
||||
using MarketData.Utils;
|
||||
using MarketData.Helper;
|
||||
using MarketData.MarketDataModel;
|
||||
using MarketData.DataAccess;
|
||||
using TradeBlotter.Model;
|
||||
using TradeBlotter.DataAccess;
|
||||
using TradeBlotter.Command;
|
||||
using TradeBlotter.ViewModels;
|
||||
|
||||
namespace TradeBlotter.Model
|
||||
{
|
||||
public class ValuationModel : ModelBase
|
||||
{
|
||||
private readonly Valuation valuation;
|
||||
private readonly DateTime valuationDate;
|
||||
private bool isSelected;
|
||||
|
||||
public ValuationModel(Valuation valuation,DateTime valuationDate)
|
||||
{
|
||||
if (null == valuation) throw new ArgumentNullException("valuation");
|
||||
this.valuation = valuation;
|
||||
this.valuationDate = valuationDate;
|
||||
PropertyChanged += OnValuationViewModelPropertyChanged;
|
||||
}
|
||||
//***************************************************************************************************
|
||||
private void OnValuationViewModelPropertyChanged(object sender, PropertyChangedEventArgs eventArgs)
|
||||
{
|
||||
}
|
||||
public String ValuationDate
|
||||
{
|
||||
get { return Utility.DateTimeToStringMMSDDSYYYY(valuationDate); }
|
||||
}
|
||||
public String Symbol
|
||||
{
|
||||
get{return valuation.Symbol;}
|
||||
}
|
||||
public String Company
|
||||
{
|
||||
get{return valuation.Company;}
|
||||
}
|
||||
public double DebtToEquity
|
||||
{
|
||||
get{return valuation.DebtToEquity;}
|
||||
}
|
||||
public String Sector
|
||||
{
|
||||
get{return valuation.Sector;}
|
||||
}
|
||||
public String Industry
|
||||
{
|
||||
get{return valuation.Industry;}
|
||||
}
|
||||
public double MarketCap
|
||||
{
|
||||
get{return valuation.MarketCap;}
|
||||
}
|
||||
public double EarningsYield
|
||||
{
|
||||
get{return valuation.EarningsYield;}
|
||||
}
|
||||
public double DividendYield
|
||||
{
|
||||
get{return valuation.DividendYield;}
|
||||
}
|
||||
public double EBIT
|
||||
{
|
||||
get{return valuation.EBIT;}
|
||||
}
|
||||
public double EnterpriseValue
|
||||
{
|
||||
get{return valuation.EnterpriseValue;}
|
||||
}
|
||||
public double OperatingEarnings
|
||||
{
|
||||
get{return valuation.OperatingEarnings;}
|
||||
}
|
||||
public double AcquirersMultiple
|
||||
{
|
||||
get{return valuation.AcquirersMultiple;}
|
||||
}
|
||||
public double AMRank
|
||||
{
|
||||
get{return valuation.AMRank;}
|
||||
}
|
||||
public double TLBRankROIC
|
||||
{
|
||||
get{return valuation.TLBRankROIC;}
|
||||
}
|
||||
public double TLBRankROC
|
||||
{
|
||||
get{return valuation.TLBRankROC;}
|
||||
}
|
||||
public String SEC13
|
||||
{
|
||||
get { return Utility.BooleanToYesNoString(valuation.SEC13); }
|
||||
}
|
||||
public String SEC13FilingDate
|
||||
{
|
||||
get{return Utility.IsEpoch(valuation.SEC13FilingDate)?Constants.CONST_DASHES:Utility.DateTimeToStringMMHDDHYYYY(valuation.SEC13FilingDate);}
|
||||
}
|
||||
public String Beta90
|
||||
{
|
||||
get { return Utility.FormatNumber(valuation.Beta90,2); }
|
||||
}
|
||||
public String Beta2Y
|
||||
{
|
||||
get { return Utility.FormatNumber(valuation.Beta720,2); }
|
||||
}
|
||||
public DateTime NextEarningsDate
|
||||
{
|
||||
get{return valuation.NextEarningsDate;}
|
||||
}
|
||||
public String LongTermDebt
|
||||
{
|
||||
get { return Utility.FormatCurrency(valuation.LongTermDebt); }
|
||||
}
|
||||
public String Revenue
|
||||
{
|
||||
get { return Utility.FormatCurrency(valuation.Revenue); }
|
||||
}
|
||||
public String DebtLoad
|
||||
{
|
||||
get { return valuation.DebtLoad; }
|
||||
}
|
||||
public double AverageROIC
|
||||
{
|
||||
get { return valuation.AverageROIC; }
|
||||
}
|
||||
public double LatestROIC
|
||||
{
|
||||
get { return valuation.LatestROIC/100.00; }
|
||||
}
|
||||
public double LatestROC
|
||||
{
|
||||
get { return valuation.LatestROC; }
|
||||
}
|
||||
public double ROICSlope
|
||||
{
|
||||
get { return valuation.ROICSlope; }
|
||||
}
|
||||
public String ROICDates
|
||||
{
|
||||
get { return valuation.ROICDates; }
|
||||
}
|
||||
public String BVPSDates
|
||||
{
|
||||
get { return valuation.BVPSDates; }
|
||||
}
|
||||
public double AverageEquityGrowth
|
||||
{
|
||||
get { return valuation.AverageEquityGrowth; }
|
||||
}
|
||||
public double AverageEquityGrowth2Y
|
||||
{
|
||||
get { return valuation.AverageEquityGrowth2Y; }
|
||||
}
|
||||
public double AverageEquityGrowth4Y
|
||||
{
|
||||
get { return valuation.AverageEquityGrowth4Y; }
|
||||
}
|
||||
public String EPSDates
|
||||
{
|
||||
get { return valuation.EPSDates; }
|
||||
}
|
||||
public double AverageEPSGrowth
|
||||
{
|
||||
get { return valuation.AverageEPSGrowth; }
|
||||
}
|
||||
public double AverageEPSGrowth2Y
|
||||
{
|
||||
get { return valuation.AverageEPSGrowth2Y; }
|
||||
}
|
||||
public double AverageEPSGrowth4Y
|
||||
{
|
||||
get { return valuation.AverageEPSGrowth4Y; }
|
||||
}
|
||||
public String RevenueDates
|
||||
{
|
||||
get { return valuation.RevenueDates; }
|
||||
}
|
||||
public double AverageRevenueGrowth
|
||||
{
|
||||
get { return valuation.AverageRevenueGrowth; }
|
||||
}
|
||||
public double AverageRevenueGrowth2Y
|
||||
{
|
||||
get { return valuation.AverageRevenueGrowth2Y; }
|
||||
}
|
||||
public double AverageRevenueGrowth4Y
|
||||
{
|
||||
get { return valuation.AverageRevenueGrowth4Y; }
|
||||
}
|
||||
public double AverageFreeCashflowGrowth
|
||||
{
|
||||
get { return valuation.AverageFreeCashflowGrowth; }
|
||||
}
|
||||
public double AverageOperatingCashflow
|
||||
{
|
||||
get { return valuation.AverageOperatingCashflow; }
|
||||
}
|
||||
public double AverageWorkingCapital
|
||||
{
|
||||
get { return valuation.AverageWorkingCapital; }
|
||||
}
|
||||
public double BVPS
|
||||
{
|
||||
get { return valuation.BVPS; }
|
||||
}
|
||||
public double PBVPS
|
||||
{
|
||||
get { return valuation.PBVPS; }
|
||||
}
|
||||
public double EPS
|
||||
{
|
||||
get { return valuation.EPS; }
|
||||
}
|
||||
public double PE
|
||||
{
|
||||
get { return valuation.PE; }
|
||||
}
|
||||
public double PEG
|
||||
{
|
||||
get { return valuation.PEG; }
|
||||
}
|
||||
public double ImpliedEarningsGrowth
|
||||
{
|
||||
get { return valuation.ImpliedEarningsGrowth; }
|
||||
}
|
||||
public double LowPE
|
||||
{
|
||||
get { return valuation.LowPE; }
|
||||
}
|
||||
public double TrailingPE
|
||||
{
|
||||
get { return valuation.TrailingPE; }
|
||||
}
|
||||
public double AverageLowTrailing
|
||||
{
|
||||
get { return valuation.AverageLowTrailing; }
|
||||
}
|
||||
public double CurrentStockEstimatePrice
|
||||
{
|
||||
get { return valuation.CurrentStockEstimatePrice; }
|
||||
}
|
||||
public double PriceEstimate10Y
|
||||
{
|
||||
get { return valuation.PriceEstimate10Y; }
|
||||
}
|
||||
public double TodaysPriceForRequiredReturn
|
||||
{
|
||||
get { return valuation.TodaysPriceForRequiredReturn; }
|
||||
}
|
||||
public double MOS
|
||||
{
|
||||
get { return valuation.MOS; }
|
||||
}
|
||||
public double MOS80
|
||||
{
|
||||
get { return valuation.MOS80; }
|
||||
}
|
||||
public double IntrinsicValue
|
||||
{
|
||||
get { return valuation.IntrinsicValue; }
|
||||
}
|
||||
public double FundamentalValue
|
||||
{
|
||||
get{return valuation.FundamentalValue;}
|
||||
}
|
||||
public double NetCurrentAssetValuePerShare
|
||||
{
|
||||
get{return valuation.NetCurrentAssetValuePerShare;}
|
||||
}
|
||||
public double RGV
|
||||
{
|
||||
get { return valuation.RGV; }
|
||||
}
|
||||
public double LatestPrice
|
||||
{
|
||||
get { return valuation.LatestPrice; }
|
||||
}
|
||||
public double UpsidePcnt
|
||||
{
|
||||
get { return valuation.UpsidePcnt; }
|
||||
}
|
||||
public double DownsidePcnt
|
||||
{
|
||||
get { return valuation.DownsidePcnt; }
|
||||
}
|
||||
public double MeanTargetPrice
|
||||
{
|
||||
get { return valuation.MeanTargetPrice; }
|
||||
}
|
||||
public double LowTargetPrice
|
||||
{
|
||||
get { return valuation.LowTargetPrice; }
|
||||
}
|
||||
public double HighTargetPrice
|
||||
{
|
||||
get { return valuation.HighTargetPrice; }
|
||||
}
|
||||
public String Bargain
|
||||
{
|
||||
get { return Utility.BooleanToYesNoString(valuation.Bargain); }
|
||||
}
|
||||
public String Bargain80
|
||||
{
|
||||
get { return Utility.BooleanToYesNoString(valuation.Bargain80); }
|
||||
}
|
||||
public String SharesOutstanding
|
||||
{
|
||||
get { return Utility.FormatNumber(valuation.SharesOutstanding,0,true); }
|
||||
}
|
||||
public String OperatingCashflow
|
||||
{
|
||||
get { return Utility.FormatCurrency(valuation.OperatingCashflow,2); }
|
||||
}
|
||||
public String PCF(double price=double.NaN)
|
||||
{
|
||||
return Utility.FormatNumber(valuation.PCF(price),2,true);
|
||||
}
|
||||
public String DateGenerated
|
||||
{
|
||||
get { return Utility.DateTimeToStringMMSDDSYYYY(valuation.Modified); }
|
||||
}
|
||||
public bool IsSelected
|
||||
{
|
||||
get { return isSelected; }
|
||||
set
|
||||
{
|
||||
if (value == isSelected) return;
|
||||
isSelected = value;
|
||||
base.OnPropertyChanged("IsSelected");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
37
Model/YieldCurveModel.cs
Normal file
37
Model/YieldCurveModel.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using MarketData.MarketDataModel;
|
||||
using Microsoft.Research.DynamicDataDisplay.DataSources;
|
||||
|
||||
namespace TradeBlotter.Model
|
||||
{
|
||||
public class YieldCurveModel
|
||||
{
|
||||
private YieldCurveModel()
|
||||
{
|
||||
}
|
||||
public static CompositeDataSource Value(DMAValues values)
|
||||
{
|
||||
if (null == values) return null;
|
||||
CompositeDataSource compositeDataSource;
|
||||
var xData = new EnumerableDataSource<DateTime>(values.Select(x => x.Date));
|
||||
xData.SetXMapping(x => (x.Ticks / 10000000000.0));
|
||||
var yData = new EnumerableDataSource<double>(values.Select(y => y.Value));
|
||||
yData.SetYMapping(y => y);
|
||||
compositeDataSource = xData.Join(yData);
|
||||
return compositeDataSource;
|
||||
}
|
||||
public static CompositeDataSource MA(DMAValues values)
|
||||
{
|
||||
if (null == values) return null;
|
||||
CompositeDataSource compositeDataSource;
|
||||
var xData = new EnumerableDataSource<DateTime>(values.Select(x => x.Date));
|
||||
xData.SetXMapping(x => (x.Ticks / 10000000000.0));
|
||||
var yData = new EnumerableDataSource<double>(values.Select(y => y.MAValue));
|
||||
yData.SetYMapping(y => y);
|
||||
compositeDataSource = xData.Join(yData);
|
||||
return compositeDataSource;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user