Init
330
.gitignore
vendored
Normal file
@@ -0,0 +1,330 @@
|
||||
## Ignore Visual Studio temporary files, build results, and
|
||||
## files generated by popular Visual Studio add-ons.
|
||||
##
|
||||
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
|
||||
|
||||
# User-specific files
|
||||
*.suo
|
||||
*.user
|
||||
*.userosscache
|
||||
*.sln.docstates
|
||||
|
||||
# User-specific files (MonoDevelop/Xamarin Studio)
|
||||
*.userprefs
|
||||
|
||||
# Build results
|
||||
[Dd]ebug/
|
||||
[Dd]ebugPublic/
|
||||
[Rr]elease/
|
||||
[Rr]eleases/
|
||||
x64/
|
||||
x86/
|
||||
bld/
|
||||
[Bb]in/
|
||||
[Oo]bj/
|
||||
[Ll]og/
|
||||
|
||||
# Visual Studio 2015/2017 cache/options directory
|
||||
.vs/
|
||||
# Uncomment if you have tasks that create the project's static files in wwwroot
|
||||
#wwwroot/
|
||||
|
||||
# Visual Studio 2017 auto generated files
|
||||
Generated\ Files/
|
||||
|
||||
# MSTest test Results
|
||||
[Tt]est[Rr]esult*/
|
||||
[Bb]uild[Ll]og.*
|
||||
|
||||
# NUNIT
|
||||
*.VisualState.xml
|
||||
TestResult.xml
|
||||
|
||||
# Build Results of an ATL Project
|
||||
[Dd]ebugPS/
|
||||
[Rr]eleasePS/
|
||||
dlldata.c
|
||||
|
||||
# Benchmark Results
|
||||
BenchmarkDotNet.Artifacts/
|
||||
|
||||
# .NET Core
|
||||
project.lock.json
|
||||
project.fragment.lock.json
|
||||
artifacts/
|
||||
**/Properties/launchSettings.json
|
||||
|
||||
# StyleCop
|
||||
StyleCopReport.xml
|
||||
|
||||
# Files built by Visual Studio
|
||||
*_i.c
|
||||
*_p.c
|
||||
*_i.h
|
||||
*.ilk
|
||||
*.meta
|
||||
*.obj
|
||||
*.iobj
|
||||
*.pch
|
||||
*.pdb
|
||||
*.ipdb
|
||||
*.pgc
|
||||
*.pgd
|
||||
*.rsp
|
||||
*.sbr
|
||||
*.tlb
|
||||
*.tli
|
||||
*.tlh
|
||||
*.tmp
|
||||
*.tmp_proj
|
||||
*.log
|
||||
*.vspscc
|
||||
*.vssscc
|
||||
.builds
|
||||
*.pidb
|
||||
*.svclog
|
||||
*.scc
|
||||
|
||||
# Chutzpah Test files
|
||||
_Chutzpah*
|
||||
|
||||
# Visual C++ cache files
|
||||
ipch/
|
||||
*.aps
|
||||
*.ncb
|
||||
*.opendb
|
||||
*.opensdf
|
||||
*.sdf
|
||||
*.cachefile
|
||||
*.VC.db
|
||||
*.VC.VC.opendb
|
||||
|
||||
# Visual Studio profiler
|
||||
*.psess
|
||||
*.vsp
|
||||
*.vspx
|
||||
*.sap
|
||||
|
||||
# Visual Studio Trace Files
|
||||
*.e2e
|
||||
|
||||
# TFS 2012 Local Workspace
|
||||
$tf/
|
||||
|
||||
# Guidance Automation Toolkit
|
||||
*.gpState
|
||||
|
||||
# ReSharper is a .NET coding add-in
|
||||
_ReSharper*/
|
||||
*.[Rr]e[Ss]harper
|
||||
*.DotSettings.user
|
||||
|
||||
# JustCode is a .NET coding add-in
|
||||
.JustCode
|
||||
|
||||
# TeamCity is a build add-in
|
||||
_TeamCity*
|
||||
|
||||
# DotCover is a Code Coverage Tool
|
||||
*.dotCover
|
||||
|
||||
# AxoCover is a Code Coverage Tool
|
||||
.axoCover/*
|
||||
!.axoCover/settings.json
|
||||
|
||||
# Visual Studio code coverage results
|
||||
*.coverage
|
||||
*.coveragexml
|
||||
|
||||
# NCrunch
|
||||
_NCrunch_*
|
||||
.*crunch*.local.xml
|
||||
nCrunchTemp_*
|
||||
|
||||
# MightyMoose
|
||||
*.mm.*
|
||||
AutoTest.Net/
|
||||
|
||||
# Web workbench (sass)
|
||||
.sass-cache/
|
||||
|
||||
# Installshield output folder
|
||||
[Ee]xpress/
|
||||
|
||||
# DocProject is a documentation generator add-in
|
||||
DocProject/buildhelp/
|
||||
DocProject/Help/*.HxT
|
||||
DocProject/Help/*.HxC
|
||||
DocProject/Help/*.hhc
|
||||
DocProject/Help/*.hhk
|
||||
DocProject/Help/*.hhp
|
||||
DocProject/Help/Html2
|
||||
DocProject/Help/html
|
||||
|
||||
# Click-Once directory
|
||||
publish/
|
||||
|
||||
# Publish Web Output
|
||||
*.[Pp]ublish.xml
|
||||
*.azurePubxml
|
||||
# Note: Comment the next line if you want to checkin your web deploy settings,
|
||||
# but database connection strings (with potential passwords) will be unencrypted
|
||||
*.pubxml
|
||||
*.publishproj
|
||||
|
||||
# Microsoft Azure Web App publish settings. Comment the next line if you want to
|
||||
# checkin your Azure Web App publish settings, but sensitive information contained
|
||||
# in these scripts will be unencrypted
|
||||
PublishScripts/
|
||||
|
||||
# NuGet Packages
|
||||
*.nupkg
|
||||
# The packages folder can be ignored because of Package Restore
|
||||
**/[Pp]ackages/*
|
||||
# except build/, which is used as an MSBuild target.
|
||||
!**/[Pp]ackages/build/
|
||||
# Uncomment if necessary however generally it will be regenerated when needed
|
||||
#!**/[Pp]ackages/repositories.config
|
||||
# NuGet v3's project.json files produces more ignorable files
|
||||
*.nuget.props
|
||||
*.nuget.targets
|
||||
|
||||
# Microsoft Azure Build Output
|
||||
csx/
|
||||
*.build.csdef
|
||||
|
||||
# Microsoft Azure Emulator
|
||||
ecf/
|
||||
rcf/
|
||||
|
||||
# Windows Store app package directories and files
|
||||
AppPackages/
|
||||
BundleArtifacts/
|
||||
Package.StoreAssociation.xml
|
||||
_pkginfo.txt
|
||||
*.appx
|
||||
|
||||
# Visual Studio cache files
|
||||
# files ending in .cache can be ignored
|
||||
*.[Cc]ache
|
||||
# but keep track of directories ending in .cache
|
||||
!*.[Cc]ache/
|
||||
|
||||
# Others
|
||||
ClientBin/
|
||||
~$*
|
||||
*~
|
||||
*.dbmdl
|
||||
*.dbproj.schemaview
|
||||
*.jfm
|
||||
*.pfx
|
||||
*.publishsettings
|
||||
orleans.codegen.cs
|
||||
|
||||
# Including strong name files can present a security risk
|
||||
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
|
||||
#*.snk
|
||||
|
||||
# Since there are multiple workflows, uncomment next line to ignore bower_components
|
||||
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
|
||||
#bower_components/
|
||||
|
||||
# RIA/Silverlight projects
|
||||
Generated_Code/
|
||||
|
||||
# Backup & report files from converting an old project file
|
||||
# to a newer Visual Studio version. Backup files are not needed,
|
||||
# because we have git ;-)
|
||||
_UpgradeReport_Files/
|
||||
Backup*/
|
||||
UpgradeLog*.XML
|
||||
UpgradeLog*.htm
|
||||
ServiceFabricBackup/
|
||||
*.rptproj.bak
|
||||
|
||||
# SQL Server files
|
||||
*.mdf
|
||||
*.ldf
|
||||
*.ndf
|
||||
|
||||
# Business Intelligence projects
|
||||
*.rdl.data
|
||||
*.bim.layout
|
||||
*.bim_*.settings
|
||||
*.rptproj.rsuser
|
||||
|
||||
# Microsoft Fakes
|
||||
FakesAssemblies/
|
||||
|
||||
# GhostDoc plugin setting file
|
||||
*.GhostDoc.xml
|
||||
|
||||
# Node.js Tools for Visual Studio
|
||||
.ntvs_analysis.dat
|
||||
node_modules/
|
||||
|
||||
# Visual Studio 6 build log
|
||||
*.plg
|
||||
|
||||
# Visual Studio 6 workspace options file
|
||||
*.opt
|
||||
|
||||
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
|
||||
*.vbw
|
||||
|
||||
# Visual Studio LightSwitch build output
|
||||
**/*.HTMLClient/GeneratedArtifacts
|
||||
**/*.DesktopClient/GeneratedArtifacts
|
||||
**/*.DesktopClient/ModelManifest.xml
|
||||
**/*.Server/GeneratedArtifacts
|
||||
**/*.Server/ModelManifest.xml
|
||||
_Pvt_Extensions
|
||||
|
||||
# Paket dependency manager
|
||||
.paket/paket.exe
|
||||
paket-files/
|
||||
|
||||
# FAKE - F# Make
|
||||
.fake/
|
||||
|
||||
# JetBrains Rider
|
||||
.idea/
|
||||
*.sln.iml
|
||||
|
||||
# CodeRush
|
||||
.cr/
|
||||
|
||||
# Python Tools for Visual Studio (PTVS)
|
||||
__pycache__/
|
||||
*.pyc
|
||||
|
||||
# Cake - Uncomment if you are using it
|
||||
# tools/**
|
||||
# !tools/packages.config
|
||||
|
||||
# Tabs Studio
|
||||
*.tss
|
||||
|
||||
# Telerik's JustMock configuration file
|
||||
*.jmconfig
|
||||
|
||||
# BizTalk build output
|
||||
*.btp.cs
|
||||
*.btm.cs
|
||||
*.odx.cs
|
||||
*.xsd.cs
|
||||
|
||||
# OpenCover UI analysis results
|
||||
OpenCover/
|
||||
|
||||
# Azure Stream Analytics local run output
|
||||
ASALocalRun/
|
||||
|
||||
# MSBuild Binary and Structured Log
|
||||
*.binlog
|
||||
|
||||
# NVidia Nsight GPU debugger configuration file
|
||||
*.nvuser
|
||||
|
||||
# MFractors (Xamarin productivity tool) working folder
|
||||
.mfractor/
|
||||
33
App.config
Normal file
@@ -0,0 +1,33 @@
|
||||
<?xml version="1.0"?>
|
||||
<configuration>
|
||||
<appSettings>
|
||||
<add key="market_data" value="Database=market_data;Datasource=localhost;Username=root;Password=dbas"/>
|
||||
<add key="portfolio_data" value="Database=portfolio_data;Datasource=localhost;Username=root;Password=dbas"/>
|
||||
<add key="ClientSettingsProvider.ServiceUri" value=""/>
|
||||
<add key="LaunchTickerView" value="true"/>
|
||||
<add key="TickerEarningsAnnouncementMaxDays" value="5"/>
|
||||
<add key="TickerPremarketFeedIdleAfter" value="23:59:59"/> <!--military time -->
|
||||
<add key="proxy_address" value="http://127.0.0.1:8182"/>
|
||||
<add key="proxy_GetLatestPriceYahoo" value="true"/>
|
||||
<add key="proxy_GetLatestPriceBigCharts" value="true"/>
|
||||
<add key="proxy_GetETFHoldings" value="true"/>
|
||||
<add key="proxy_GetAnalystPriceTargetYahoo" value="true"/>
|
||||
<add key="proxy_GetDailyPrices" value="true"/>
|
||||
<add key="proxy_GetCompanyHeadlines" value="true"/>
|
||||
</appSettings>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2"/>
|
||||
</startup>
|
||||
<system.web>
|
||||
<membership defaultProvider="ClientAuthenticationMembershipProvider">
|
||||
<providers>
|
||||
<add name="ClientAuthenticationMembershipProvider" type="System.Web.ClientServices.Providers.ClientFormsAuthenticationMembershipProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri=""/>
|
||||
</providers>
|
||||
</membership>
|
||||
<roleManager defaultProvider="ClientRoleProvider" enabled="true">
|
||||
<providers>
|
||||
<add name="ClientRoleProvider" type="System.Web.ClientServices.Providers.ClientRoleProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" cacheTimeout="86400"/>
|
||||
</providers>
|
||||
</roleManager>
|
||||
</system.web>
|
||||
</configuration>
|
||||
11
App.xaml
Normal file
@@ -0,0 +1,11 @@
|
||||
<Application x:Class="TradeBlotter.App"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
>
|
||||
<Application.Resources>
|
||||
<LinearGradientBrush x:Key="Brush_HeaderBackground" StartPoint="0.5,0" EndPoint="0.5,1">
|
||||
<GradientStop Color="#303030" Offset="0" />
|
||||
<GradientStop Color="#666666" Offset="1" />
|
||||
</LinearGradientBrush>
|
||||
</Application.Resources>
|
||||
</Application>
|
||||
10
App.xaml.bak
Normal file
@@ -0,0 +1,10 @@
|
||||
<Application x:Class="TradeBlotter.App"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
>
|
||||
<LinearGradientBrush x:Key="Brush_HeaderBackground" StartPoint="0.5,0" EndPoint="0.5,1">
|
||||
<GradientStop Color="#303030" Offset="0" />
|
||||
<GradientStop Color="#666666" Offset="1" />
|
||||
</LinearGradientBrush>
|
||||
</Application.Resources>
|
||||
</Application>
|
||||
128
App.xaml.cs
Normal file
@@ -0,0 +1,128 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Globalization;
|
||||
using System.Windows.Markup;
|
||||
using System.ComponentModel;
|
||||
using System.Configuration;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using Forms=System.Windows.Forms;
|
||||
using TradeBlotter.ViewModels;
|
||||
using MarketData;
|
||||
using TradeBlotter.UIUtils;
|
||||
using MarketData.Cache;
|
||||
using TradeBlotter.Cache;
|
||||
|
||||
namespace TradeBlotter
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for App.xaml
|
||||
/// </summary>
|
||||
public partial class App : Application
|
||||
{
|
||||
static App()
|
||||
{
|
||||
FrameworkElement.LanguageProperty.OverrideMetadata(typeof(FrameworkElement),new FrameworkPropertyMetadata(XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));
|
||||
}
|
||||
protected override void OnStartup(StartupEventArgs e)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
MDTrace.LogLevel = LogLevel.VERBOSE;
|
||||
String strLogFile = "enavigator.log";
|
||||
Trace.Listeners.Add(new TextWriterTraceListener(strLogFile));
|
||||
MDTrace.WriteLine(LogLevel.DEBUG, "[STARTING]");
|
||||
|
||||
AppDomain currentDomain = AppDomain.CurrentDomain;
|
||||
currentDomain.UnhandledException += new UnhandledExceptionEventHandler(UnhandledExceptionHandler);
|
||||
|
||||
|
||||
WebBrowserHelper.SetWebBrowserCompatibility(); // This is to prevent the webbrowser control from popping up compatibility messagebox while browsing the SEC filings.
|
||||
base.OnStartup(e);
|
||||
MainWindow mainWindow = new MainWindow();
|
||||
MainWindowViewModel mainWindowViewModel = new MainWindowViewModel();
|
||||
EventHandler handler = null;
|
||||
handler = delegate
|
||||
{
|
||||
if(null!=mainWindowViewModel)
|
||||
{
|
||||
mainWindowViewModel.RequestClose -= handler;
|
||||
mainWindowViewModel.Dispose();
|
||||
mainWindowViewModel = null;
|
||||
}
|
||||
if(null!=mainWindow)
|
||||
{
|
||||
mainWindow.Close();
|
||||
mainWindow = null;
|
||||
}
|
||||
};
|
||||
mainWindowViewModel.RequestClose+=handler;
|
||||
mainWindow.DataContext=mainWindowViewModel;
|
||||
CancelEventHandler closingEventHandler = null;
|
||||
closingEventHandler = delegate
|
||||
{
|
||||
if (null != mainWindowViewModel)
|
||||
{
|
||||
mainWindowViewModel.RequestClose -= handler;
|
||||
mainWindowViewModel.Dispose();
|
||||
mainWindowViewModel = null;
|
||||
}
|
||||
};
|
||||
mainWindow.Closing += closingEventHandler;
|
||||
mainWindow.Show();
|
||||
mainWindow.WindowState=WindowState.Maximized;
|
||||
CreateFloatingWindow(mainWindow);
|
||||
mainWindow.Focus();
|
||||
}
|
||||
catch(Exception exception)
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Exception:{0}",exception.ToString()));
|
||||
MessageBox.Show(String.Format("An exception was encountered. Please check the log file. The application will now exit. {0}",exception.ToString()));
|
||||
}
|
||||
}
|
||||
// The caches are disposed in the MainWindowViewModel::OnDispose()
|
||||
protected override void OnExit(ExitEventArgs e)
|
||||
{
|
||||
//try{LocalPriceCache.GetInstance().Dispose();}catch(Exception){;}
|
||||
//try{GBPriceCache.GetInstance().Dispose();}catch(Exception){;}
|
||||
//try{PriceCache.GetInstance().Dispose();}catch(Exception){;}
|
||||
// DividendHistoryCache.GetInstance().Dispose();
|
||||
}
|
||||
void UnhandledExceptionHandler(object sender, UnhandledExceptionEventArgs eventArgs)
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG, String.Format("App.Xaml.cs->UnhandledExceptionHandler()"));
|
||||
string errorMessage = string.Format("An unhandled exception occurred: {0}", eventArgs.ExceptionObject);
|
||||
MDTrace.WriteLine(LogLevel.DEBUG, String.Format("Exception:{0}", errorMessage));
|
||||
}
|
||||
//void OnDispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs eventArgs)
|
||||
//{
|
||||
// string errorMessage = string.Format("An unhandled exception occurred: {0}", eventArgs.Exception.Message);
|
||||
// MDTrace.WriteLine(LogLevel.DEBUG, String.Format("Exception:{0}", errorMessage));
|
||||
// eventArgs.Handled = true;
|
||||
//}
|
||||
private static void CreateFloatingWindow(Window parentWindow)
|
||||
{
|
||||
String launchTicker=ConfigurationManager.AppSettings["LaunchTickerView"];
|
||||
if(null==launchTicker)return;
|
||||
launchTicker=launchTicker.ToLower();
|
||||
if(launchTicker.Equals("false"))return;
|
||||
FloatingWindow floatingWindow=new FloatingWindow();
|
||||
floatingWindow.Width=SystemParameters.VirtualScreenWidth;
|
||||
floatingWindow.Top=(SystemParameters.VirtualScreenTop+SystemParameters.VirtualScreenHeight)-floatingWindow.Height;
|
||||
floatingWindow.Left=0;
|
||||
floatingWindow.Topmost=true;
|
||||
FloatingWindowViewModel floatingWindowViewModel=new FloatingWindowViewModel(floatingWindow.LayoutRoot);
|
||||
floatingWindow.DataContext=floatingWindowViewModel;
|
||||
parentWindow.Closing+=delegate
|
||||
{
|
||||
floatingWindowViewModel.Dispose();
|
||||
floatingWindow.Close();
|
||||
};
|
||||
floatingWindow.Show();
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
Application.ico
Normal file
|
After Width: | Height: | Size: 8.2 KiB |
105
Cache/PriceCache.cs
Normal file
@@ -0,0 +1,105 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using MarketData.MarketDataModel;
|
||||
using MarketData.Helper;
|
||||
using MarketData;
|
||||
using MarketData.Utils;
|
||||
|
||||
namespace TradeBlotter.Cache
|
||||
{
|
||||
public class PriceCache:IDisposable
|
||||
{
|
||||
private Dictionary<String,Price> priceCache=new Dictionary<String,Price>();
|
||||
private Object thisLock=new Object();
|
||||
private Thread cacheMonitorThread=null;
|
||||
private volatile bool threadRun=true;
|
||||
private int cacheRefreshAfter=60000;
|
||||
private static PriceCache priceCacheInstance=null;
|
||||
|
||||
private PriceCache()
|
||||
{
|
||||
cacheMonitorThread=new Thread(new ThreadStart(ThreadProc));
|
||||
cacheMonitorThread.Start();
|
||||
}
|
||||
public static PriceCache GetInstance()
|
||||
{
|
||||
lock(typeof(PriceCache))
|
||||
{
|
||||
if(null==priceCacheInstance) priceCacheInstance=new PriceCache();
|
||||
return priceCacheInstance;
|
||||
}
|
||||
}
|
||||
public void Clear()
|
||||
{
|
||||
lock(thisLock)
|
||||
{
|
||||
priceCache=new Dictionary<String,Price>();
|
||||
}
|
||||
}
|
||||
public void Dispose()
|
||||
{
|
||||
lock(thisLock)
|
||||
{
|
||||
if(null==priceCacheInstance || false==threadRun)return;
|
||||
threadRun=false;
|
||||
if(null!=cacheMonitorThread)
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[PriceCache:Dispose]Thread state is {0}. Joining main thread...",Utility.ThreadStateToString(cacheMonitorThread)));
|
||||
cacheMonitorThread.Join(5000);
|
||||
cacheMonitorThread=null;
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,"[PriceCache:Dispose] End.");
|
||||
}
|
||||
priceCacheInstance=null;
|
||||
}
|
||||
}
|
||||
public Price GetLatestPrice(String symbol)
|
||||
{
|
||||
lock(thisLock)
|
||||
{
|
||||
if(priceCache.ContainsKey(symbol))
|
||||
{
|
||||
return priceCache[symbol];
|
||||
}
|
||||
Price price=MarketDataHelper.GetLatestPrice(symbol);
|
||||
if(null!=price) Add(price);
|
||||
return price;
|
||||
}
|
||||
}
|
||||
public bool Contains(String symbol)
|
||||
{
|
||||
lock(thisLock)
|
||||
{
|
||||
return priceCache.ContainsKey(symbol);
|
||||
}
|
||||
}
|
||||
private void Add(Price price)
|
||||
{
|
||||
lock(thisLock)
|
||||
{
|
||||
if(priceCache.ContainsKey(price.Symbol)) return;
|
||||
priceCache.Add(price.Symbol,price);
|
||||
}
|
||||
}
|
||||
private void ThreadProc()
|
||||
{
|
||||
int quantums=0;
|
||||
int quantumInterval=1000;
|
||||
while(threadRun)
|
||||
{
|
||||
Thread.Sleep(quantumInterval);
|
||||
quantums+=quantumInterval;
|
||||
if(quantums>cacheRefreshAfter)
|
||||
{
|
||||
quantums=0;
|
||||
lock(thisLock)
|
||||
{
|
||||
priceCache.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
33
Command/CommandViewModel.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Windows.Input;
|
||||
using System.Text;
|
||||
using TradeBlotter.ViewModels;
|
||||
|
||||
namespace TradeBlotter.Command
|
||||
{
|
||||
public class CommandViewModel : ViewModelBase
|
||||
{
|
||||
public CommandViewModel(string displayName, ICommand command)
|
||||
{
|
||||
if (command == null) throw new ArgumentNullException("command");
|
||||
base.DisplayName = displayName;
|
||||
this.Command = command;
|
||||
}
|
||||
public ICommand Command
|
||||
{
|
||||
get; private set;
|
||||
}
|
||||
public override SaveParameters GetSaveParameters()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
public override void SetSaveParameters(SaveParameters saveParameters)
|
||||
{
|
||||
}
|
||||
public override bool CanPersist()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
44
Command/RelayCommand.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Windows.Input;
|
||||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
|
||||
namespace TradeBlotter.Command
|
||||
{
|
||||
public class RelayCommand : ICommand
|
||||
{
|
||||
readonly Action<object> execute;
|
||||
readonly Predicate<object> canExecute;
|
||||
public RelayCommand(Action<object> execute)
|
||||
: this(execute, null)
|
||||
{
|
||||
}
|
||||
public RelayCommand(Action<object> execute, Predicate<object> canExecute)
|
||||
{
|
||||
if (execute == null) throw new ArgumentNullException("execute");
|
||||
this.execute = execute;
|
||||
this.canExecute = canExecute;
|
||||
}
|
||||
[DebuggerStepThrough]
|
||||
public bool CanExecute(object parameter)
|
||||
{
|
||||
return canExecute == null ? true : canExecute(parameter);
|
||||
}
|
||||
public event EventHandler CanExecuteChanged
|
||||
{
|
||||
add
|
||||
{
|
||||
CommandManager.RequerySuggested += value;
|
||||
}
|
||||
remove
|
||||
{
|
||||
CommandManager.RequerySuggested -= value;
|
||||
}
|
||||
}
|
||||
public void Execute(object parameter)
|
||||
{
|
||||
execute(parameter);
|
||||
}
|
||||
}
|
||||
}
|
||||
18
DataAccess/TradeAddedEvenArgs.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using TradeBlotter.Model;
|
||||
using MarketData.MarketDataModel;
|
||||
|
||||
namespace TradeBlotter.DataAccess
|
||||
{
|
||||
public class TradeAddedEventArgs : EventArgs
|
||||
{
|
||||
public TradeAddedEventArgs(BlotterTradeModel trade)
|
||||
{
|
||||
this.NewTrade = trade;
|
||||
}
|
||||
public BlotterTradeModel NewTrade { get; private set; }
|
||||
}
|
||||
}
|
||||
139
DataAccess/TradeRepository.cs
Normal file
@@ -0,0 +1,139 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using TradeBlotter.Model;
|
||||
using MarketData.MarketDataModel;
|
||||
using MarketData.DataAccess;
|
||||
|
||||
namespace TradeBlotter.DataAccess
|
||||
{
|
||||
public class TradeRepository
|
||||
{
|
||||
private readonly List<BlotterTradeModel> trades;
|
||||
private static TradeRepository instance=null;
|
||||
|
||||
private TradeRepository()
|
||||
{
|
||||
Dictionary<String,String> companyNameCache=new Dictionary<String,String>();
|
||||
trades = new List<BlotterTradeModel>();
|
||||
PortfolioTrades portfolioTrades = PortfolioDA.GetTrades();
|
||||
if (null == portfolioTrades || 0 == portfolioTrades.Count) return;
|
||||
foreach (PortfolioTrade portfolioTrade in portfolioTrades)
|
||||
{
|
||||
BlotterTradeModel blotterTrade = BlotterTradeModel.CreateTrade();
|
||||
blotterTrade.TradeId = portfolioTrade.TradeId;
|
||||
blotterTrade.Symbol=portfolioTrade.Symbol;
|
||||
blotterTrade.TradeDate=portfolioTrade.TradeDate;
|
||||
blotterTrade.Shares=portfolioTrade.Shares;
|
||||
blotterTrade.BuySell=portfolioTrade.BuySell;
|
||||
blotterTrade.Price=portfolioTrade.Price;
|
||||
blotterTrade.Commission = portfolioTrade.Commission;
|
||||
blotterTrade.Account = portfolioTrade.Account;
|
||||
blotterTrade.Status = portfolioTrade.Status;
|
||||
if(companyNameCache.ContainsKey(portfolioTrade.Symbol))blotterTrade.CompanyName=companyNameCache[portfolioTrade.Symbol];
|
||||
else
|
||||
{
|
||||
String companyName=PricingDA.GetNameForSymbol(portfolioTrade.Symbol);
|
||||
if(null!=companyName)
|
||||
{
|
||||
companyNameCache.Add(portfolioTrade.Symbol,companyName);
|
||||
blotterTrade.CompanyName=companyNameCache[portfolioTrade.Symbol];
|
||||
}
|
||||
}
|
||||
// blotterTrade.CompanyName = PricingDA.GetNameForSymbol(portfolioTrade.Symbol);
|
||||
blotterTrade.SellPrice = portfolioTrade.SellPrice;
|
||||
blotterTrade.SellDate = portfolioTrade.SellDate;
|
||||
trades.Add(blotterTrade);
|
||||
}
|
||||
}
|
||||
public static TradeRepository GetInstance()
|
||||
{
|
||||
lock(typeof(TradeRepository))
|
||||
{
|
||||
if(null==instance)instance=new TradeRepository();
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
public event EventHandler<TradeAddedEventArgs> TradeAdded;
|
||||
public bool AddTrade(BlotterTradeModel trade)
|
||||
{
|
||||
if (null == trade) throw new ArgumentNullException("trade");
|
||||
if (ContainsTrade(trade)) return false;
|
||||
int tradeId = PortfolioDA.AddTrade(trade);
|
||||
if (-1 == tradeId) return false;
|
||||
trade.TradeId = tradeId;
|
||||
trades.Add(trade);
|
||||
AdjustCash(trade);
|
||||
if (null != this.TradeAdded) this.TradeAdded(this, new TradeAddedEventArgs(trade));
|
||||
return true;
|
||||
}
|
||||
public bool UpdateTrade(BlotterTradeModel trade)
|
||||
{
|
||||
bool result = false;
|
||||
BlotterTradeModel blotterTradeModel = GetTrade(trade.TradeId);
|
||||
if (null == blotterTradeModel) return false;
|
||||
blotterTradeModel.CopyFrom(trade);
|
||||
result=PortfolioDA.UpdateTrade(trade);
|
||||
if (true == result) AdjustCash(trade);
|
||||
return result;
|
||||
}
|
||||
public bool ContainsTrade(BlotterTradeModel searchTrade)
|
||||
{
|
||||
var existingTrades=from trade in trades where trade.TradeId==searchTrade.TradeId select trade;
|
||||
return 0 == existingTrades.Count() ? false : true;
|
||||
}
|
||||
public BlotterTradeModel GetTrade(int tradeId)
|
||||
{
|
||||
var existingTrades = from trade in trades where trade.TradeId == tradeId select trade;
|
||||
if (0 == existingTrades.Count()) return null;
|
||||
return existingTrades.FirstOrDefault();
|
||||
}
|
||||
public void Remove(int tradeId)
|
||||
{
|
||||
var theTrades=from trade in trades where trade.TradeId==tradeId select trade;
|
||||
PortfolioDA.DeleteTrade(theTrades.ElementAt(0).TradeId);
|
||||
trades.Remove(theTrades.ElementAt(0));
|
||||
}
|
||||
public List<BlotterTradeModel> GetTrades()
|
||||
{
|
||||
return new List<BlotterTradeModel>(trades);
|
||||
}
|
||||
// Accounting
|
||||
private void AdjustCash(BlotterTradeModel trade)
|
||||
{
|
||||
CashTransaction cashTransaction = new CashTransaction();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
cashTransaction.Account = trade.Account;
|
||||
if(trade.BuySell.Equals("B"))
|
||||
{
|
||||
cashTransaction.TransactionDate = trade.TradeDate;
|
||||
cashTransaction.Debit = trade.Shares * trade.Price;
|
||||
sb.Append("Buy").Append(" ").Append(trade.Shares.ToString());
|
||||
sb.Append(" of ").Append(trade.Symbol).Append(" @").Append(String.Format("{0:C}", trade.Price));
|
||||
}
|
||||
else
|
||||
{
|
||||
cashTransaction.TransactionDate = trade.SellDate;
|
||||
cashTransaction.Credit = trade.Shares * trade.SellPrice;
|
||||
sb.Append("Sell").Append(" ").Append(trade.Shares.ToString());
|
||||
sb.Append(" of ").Append(trade.Symbol).Append(" @").Append(String.Format("{0:C}", trade.SellPrice));
|
||||
}
|
||||
cashTransaction.Description = sb.ToString();
|
||||
CashDA.AddTransaction(cashTransaction);
|
||||
if (trade.Commission > 0)
|
||||
{
|
||||
cashTransaction = new CashTransaction();
|
||||
cashTransaction.Account = trade.Account;
|
||||
if(trade.BuySell.Equals("B"))cashTransaction.TransactionDate = trade.TradeDate;
|
||||
else cashTransaction.TransactionDate = trade.SellDate;
|
||||
cashTransaction.Debit = trade.Commission;
|
||||
sb=new StringBuilder();
|
||||
sb.Append("Commission: ").Append(trade.Symbol).Append(" ").Append(String.Format("{0:C}", trade.Commission));
|
||||
cashTransaction.Description = sb.ToString();
|
||||
CashDA.AddTransaction(cashTransaction);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
43
FloatingWindow.xaml
Normal file
@@ -0,0 +1,43 @@
|
||||
<Window x:Class="TradeBlotter.FloatingWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
mc:Ignorable="d" d:DesignHeight="60" d:DesignWidth="681" Foreground="#FFFFFFFF"
|
||||
Title="FloatingWindow" WindowStyle="None" Width="800" Height="40" MinHeight="40" MaxHeight="40" AllowsTransparency="true" ResizeMode="CanResizeWithGrip" MouseLeftButtonDown="wndMouseLeftButtonDown" MouseDoubleClick="wndMouseDoubleClick">
|
||||
<Window.Resources>
|
||||
<Style TargetType="{x:Type Hyperlink}">
|
||||
<Style.Triggers>
|
||||
<Trigger Property="IsMouseOver" Value="True">
|
||||
<Setter Property="TextBlock.TextDecorations" Value="Underline" />
|
||||
</Trigger>
|
||||
</Style.Triggers>
|
||||
<Setter Property="Foreground" Value="White" />
|
||||
<Setter Property="TextBlock.TextDecorations" Value="{x:Null}" />
|
||||
</Style>
|
||||
</Window.Resources>
|
||||
<Border BorderBrush="WhiteSmoke" BorderThickness="2" CornerRadius="6">
|
||||
<Canvas x:Name="LayoutRoot" Background="#303030" >
|
||||
<TextBlock HorizontalAlignment="Left" Width="55" Text="{Binding Mode=TwoWay,Path=ItemCount}" TextWrapping="Wrap" FontSize="18" x:Name="ItemCount" Canvas.Top="5" Canvas.Left="30" Panel.ZIndex="51">
|
||||
<TextBlock.Foreground>
|
||||
<SolidColorBrush Color="WhiteSmoke" Opacity="0.5"/>
|
||||
</TextBlock.Foreground>
|
||||
</TextBlock>
|
||||
<Button Opacity="0.5" Width="16" Height="16" Canvas.Top="9" Panel.ZIndex="52" Canvas.Left="10" Name="TogglePause" Command="{Binding Path=TogglePlayPauseCommand}" Cursor="Hand">
|
||||
<Button.Template>
|
||||
<ControlTemplate>
|
||||
<Image Source="/Resources/pause.png" Stretch="Fill" Name="PART_IMAGE" />
|
||||
<ControlTemplate.Triggers>
|
||||
<DataTrigger Binding="{Binding Path=IsPaused}" Value="true">
|
||||
<Setter Property="Source" Value="/Resources/play.png" TargetName="PART_IMAGE"></Setter>
|
||||
</DataTrigger>
|
||||
<DataTrigger Binding="{Binding Path=IsPaused}" Value="false">
|
||||
<Setter Property="Source" Value="/Resources/pause.png" TargetName="PART_IMAGE"></Setter>
|
||||
</DataTrigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
</Button.Template>
|
||||
</Button>
|
||||
</Canvas>
|
||||
</Border>
|
||||
</Window>
|
||||
39
FloatingWindow.xaml.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace TradeBlotter
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for FloatingWindow.xaml
|
||||
/// </summary>
|
||||
public partial class FloatingWindow : Window
|
||||
{
|
||||
public FloatingWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void wndMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
DragMove();
|
||||
}
|
||||
private void wndMouseDoubleClick(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
Top=(SystemParameters.VirtualScreenTop+SystemParameters.VirtualScreenHeight)-Height;
|
||||
Left=0;
|
||||
Width=SystemParameters.VirtualScreenWidth;
|
||||
Topmost=true;
|
||||
}
|
||||
}
|
||||
}
|
||||
117
Helper/FilterEvaluator.cs
Normal file
@@ -0,0 +1,117 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
//using System.Linq;
|
||||
using System.Text;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace TradeBlotter.Helper
|
||||
{
|
||||
public class FilterEvaluator<T> where T : IConvertible, IComparable
|
||||
{
|
||||
public enum Expression { Equal, LessThan, LessThanOrEqual, GreaterThan, GreaterThanOrEqual, Invalid };
|
||||
private T value;
|
||||
private bool isValid = false;
|
||||
private Expression expression = Expression.Invalid;
|
||||
private String defaultExpression;
|
||||
private bool isEnabled = false;
|
||||
private bool debugMode = false;
|
||||
private String filterName;
|
||||
|
||||
public FilterEvaluator(String filterName,String filterExpression)
|
||||
{
|
||||
this.filterName = filterName;
|
||||
defaultExpression = filterExpression;
|
||||
SetExpression(filterExpression);
|
||||
}
|
||||
public bool IsEnabled
|
||||
{
|
||||
get { return isEnabled; }
|
||||
set { isEnabled = value; }
|
||||
}
|
||||
public bool DebugMode
|
||||
{
|
||||
get { return debugMode; }
|
||||
set { debugMode = value; }
|
||||
}
|
||||
public void UseDefault()
|
||||
{
|
||||
SetExpression(defaultExpression);
|
||||
}
|
||||
public bool SetExpression(String filterExpression)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (filterExpression == null)
|
||||
{
|
||||
isValid = false;
|
||||
return false;
|
||||
}
|
||||
if (filterExpression.StartsWith("<="))
|
||||
{
|
||||
expression = Expression.LessThanOrEqual;
|
||||
value = (T)Convert.ChangeType(filterExpression.Substring(2), typeof(T));
|
||||
}
|
||||
else if (filterExpression.StartsWith(">="))
|
||||
{
|
||||
expression = Expression.GreaterThanOrEqual;
|
||||
value = (T)Convert.ChangeType(filterExpression.Substring(2), typeof(T));
|
||||
}
|
||||
else if (filterExpression.StartsWith("="))
|
||||
{
|
||||
expression = Expression.Equal;
|
||||
value = (T)Convert.ChangeType(filterExpression.Substring(1), typeof(T));
|
||||
}
|
||||
else if (filterExpression.StartsWith("<"))
|
||||
{
|
||||
expression = Expression.LessThan;
|
||||
value = (T)Convert.ChangeType(filterExpression.Substring(1), typeof(T));
|
||||
}
|
||||
else if (filterExpression.StartsWith(">"))
|
||||
{
|
||||
expression = Expression.GreaterThan;
|
||||
value = (T)Convert.ChangeType(filterExpression.Substring(1), typeof(T));
|
||||
}
|
||||
else
|
||||
{
|
||||
expression = Expression.Equal;
|
||||
value = (T)Convert.ChangeType(filterExpression, typeof(T));
|
||||
}
|
||||
isValid = true;
|
||||
return true;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
isValid = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public bool IsValid
|
||||
{
|
||||
get { return isValid; }
|
||||
}
|
||||
public bool Evaluate(T value)
|
||||
{
|
||||
if (!IsValid ||!IsEnabled) return true;
|
||||
switch (expression)
|
||||
{
|
||||
case Expression.Equal:
|
||||
if (debugMode) Debug.WriteLine(value.ToString() + "==" + this.value + ":" + value.Equals(this.value).ToString());
|
||||
return value.Equals(this.value);
|
||||
case Expression.LessThan:
|
||||
if (debugMode) Debug.WriteLine(value.ToString() + "<" + this.value + ":" + (value.CompareTo(this.value)<0).ToString());
|
||||
return value.CompareTo(this.value) < 0 ? true : false;
|
||||
case Expression.GreaterThan:
|
||||
if (debugMode) Debug.WriteLine(value.ToString() + ">" + this.value + ":" + (value.CompareTo(this.value)>0).ToString());
|
||||
return value.CompareTo(this.value) > 0 ? true : false;
|
||||
case Expression.LessThanOrEqual:
|
||||
if (debugMode) Debug.WriteLine(value.ToString() + "<=" + this.value + ":" + (value.CompareTo(this.value)<=0).ToString());
|
||||
return value.CompareTo(this.value) <= 0 ? true : false;
|
||||
case Expression.GreaterThanOrEqual:
|
||||
if (debugMode) Debug.WriteLine(value.ToString() + ">=" + this.value + ":" + (value.CompareTo(this.value)>=0).ToString());
|
||||
return value.CompareTo(this.value) >= 0 ? true : false;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
HighSeas.jpg
Normal file
|
After Width: | Height: | Size: 89 KiB |
BIN
HighSeas2.jpg
Normal file
|
After Width: | Height: | Size: 936 KiB |
63
MainWindow.xaml
Normal file
@@ -0,0 +1,63 @@
|
||||
|
||||
<Window x:Class="TradeBlotter.MainWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:vm="clr-namespace:TradeBlotter.ViewModels"
|
||||
xmlns:vw="clr-namespace:TradeBlotter.Views"
|
||||
xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
|
||||
Title="{Binding Path=DisplayName}"
|
||||
Icon="Application.ico"
|
||||
FontSize="13"
|
||||
FontFamily="Verdana"
|
||||
Height="600"
|
||||
Width="920"
|
||||
WindowStartupLocation="CenterScreen">
|
||||
<Window.Resources>
|
||||
<ResourceDictionary Source="MainWindowResources.xaml" />
|
||||
</Window.Resources>
|
||||
<Grid >
|
||||
<DockPanel>
|
||||
<DockPanel DockPanel.Dock="Top" KeyboardNavigation.TabNavigation="None">
|
||||
<Menu KeyboardNavigation.TabNavigation="Cycle" Name="mainMenu">
|
||||
<MenuItem Header="_File" >
|
||||
<MenuItem Header="E_xit" Command="{Binding Path=CloseCommand}" />
|
||||
</MenuItem>
|
||||
<MenuItem Header="_Edit"/>
|
||||
<MenuItem Header="_Options"/>
|
||||
<MenuItem Header="_Windows" ItemsSource="{Binding MenuItems,Mode=OneWay}"/>
|
||||
<MenuItem Header="_Help"/>
|
||||
</Menu>
|
||||
</DockPanel>
|
||||
<Grid Margin="4">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="4" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Border
|
||||
Grid.Column="0"
|
||||
Style="{StaticResource MainBorderStyle}"
|
||||
Width="185"
|
||||
>
|
||||
<HeaderedContentControl
|
||||
Content="{Binding Path=Commands}"
|
||||
ContentTemplate="{StaticResource CommandsTemplate}"
|
||||
Header="View Panel"
|
||||
Style="{StaticResource MainHCCStyle}"
|
||||
/>
|
||||
</Border>
|
||||
<Border
|
||||
Grid.Column="2"
|
||||
Style="{StaticResource MainBorderStyle}"
|
||||
>
|
||||
<HeaderedContentControl
|
||||
Content="{Binding Path=Workspaces}"
|
||||
ContentTemplate="{StaticResource WorkspacesTemplate}"
|
||||
Header="Views"
|
||||
Style="{StaticResource MainHCCStyle}"
|
||||
/>
|
||||
</Border>
|
||||
</Grid>
|
||||
</DockPanel>
|
||||
</Grid>
|
||||
</Window>
|
||||
37
MainWindow.xaml.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using MarketData;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
using Telerik.Windows.Controls;
|
||||
|
||||
namespace TradeBlotter
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for MainWindow.xaml
|
||||
/// </summary>
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
public MainWindow()
|
||||
{
|
||||
try
|
||||
{
|
||||
ToolTipService.ShowDurationProperty.OverrideMetadata(typeof(DependencyObject), new FrameworkPropertyMetadata(Int32.MaxValue));
|
||||
InitializeComponent();
|
||||
}
|
||||
catch(Exception exception)
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Exception {0}",exception.ToString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
286
MainWindowResources.xaml
Normal file
@@ -0,0 +1,286 @@
|
||||
<!--
|
||||
This resource dictionary is used by the MainWindow.
|
||||
-->
|
||||
<ResourceDictionary
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:vm="clr-namespace:TradeBlotter.ViewModels"
|
||||
xmlns:vw="clr-namespace:TradeBlotter.Views"
|
||||
xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
|
||||
xmlns:dock="http://schemas.xceed.com/wpf/xaml/avalondock"
|
||||
xmlns:dockctrl="clr-namespace:Xceed.Wpf.AvalonDock.Controls;assembly=Xceed.Wpf.AvalonDock"
|
||||
xmlns:dockdht="clr-namespace:Xceed.Wpf.AvalonDock.DocumentHeaderTemplate;assembly=Xceed.Wpf.AvalonDock"
|
||||
>
|
||||
|
||||
<DataTemplate DataType="{x:Type vm:DividendRiskParityViewModel}">
|
||||
<vw:DividendRiskParityView />
|
||||
</DataTemplate>
|
||||
|
||||
<DataTemplate DataType="{x:Type vm:FeedStatisticsViewModel}">
|
||||
<vw:FeedStatisticsView />
|
||||
</DataTemplate>
|
||||
|
||||
<DataTemplate DataType="{x:Type vm:DividendPaymentViewModel}">
|
||||
<vw:DividendPaymentView />
|
||||
</DataTemplate>
|
||||
|
||||
<DataTemplate DataType="{x:Type vm:WatchListViewModel}">
|
||||
<vw:WatchListView />
|
||||
</DataTemplate>
|
||||
|
||||
<!--<DataTemplate DataType="{x:Type vm:MMTrendViewModel}">
|
||||
<vw:MMTrendView />
|
||||
</DataTemplate>-->
|
||||
|
||||
<DataTemplate DataType="{x:Type vm:CMTTrendViewModel}">
|
||||
<vw:CMTTrendView />
|
||||
</DataTemplate>
|
||||
|
||||
<DataTemplate DataType="{x:Type vm:MomentumViewModel}">
|
||||
<vw:MomentumView />
|
||||
</DataTemplate>
|
||||
|
||||
<DataTemplate DataType="{x:Type vm:CMMomentumViewModel}">
|
||||
<vw:CMMomentumView />
|
||||
</DataTemplate>
|
||||
|
||||
<DataTemplate DataType="{x:Type vm:HeadlinesViewModel}">
|
||||
<vw:HeadlinesView />
|
||||
</DataTemplate>
|
||||
|
||||
<DataTemplate DataType="{x:Type vm:OptionsWorksheetViewModel}">
|
||||
<vw:OptionsWorksheetView />
|
||||
</DataTemplate>
|
||||
|
||||
<DataTemplate DataType="{x:Type vm:DividendHistoryViewModel}">
|
||||
<vw:DividendView />
|
||||
</DataTemplate>
|
||||
|
||||
<DataTemplate DataType="{x:Type vm:EarningsAnnouncementViewModel}">
|
||||
<vw:EarningsAnnouncementView />
|
||||
</DataTemplate>
|
||||
|
||||
<DataTemplate DataType="{x:Type vm:PricingViewModel}">
|
||||
<vw:PricingView />
|
||||
</DataTemplate>
|
||||
|
||||
<DataTemplate DataType="{x:Type vm:BlotterViewModel}">
|
||||
<vw:BlotterView />
|
||||
</DataTemplate>
|
||||
|
||||
<DataTemplate DataType="{x:Type vm:SectorViewModel}">
|
||||
<vw:SectorView />
|
||||
</DataTemplate>
|
||||
|
||||
<DataTemplate DataType="{x:Type vm:RiskProfileViewModel}">
|
||||
<vw:RiskProfileView />
|
||||
</DataTemplate>
|
||||
|
||||
<DataTemplate DataType="{x:Type vm:TradeEntryViewModel}">
|
||||
<vw:TradeEntryView />
|
||||
</DataTemplate>
|
||||
|
||||
<DataTemplate DataType="{x:Type vm:BollingerBandViewModel}">
|
||||
<vw:BollingerBandView />
|
||||
</DataTemplate>
|
||||
|
||||
<DataTemplate DataType="{x:Type vm:YieldCurveViewModel}">
|
||||
<vw:YieldCurveView />
|
||||
</DataTemplate>
|
||||
|
||||
<DataTemplate DataType="{x:Type vm:StochasticsViewModel}">
|
||||
<vw:StochasticsView />
|
||||
</DataTemplate>
|
||||
|
||||
<DataTemplate DataType="{x:Type vm:RSIViewModel}">
|
||||
<vw:RSIView />
|
||||
</DataTemplate>
|
||||
|
||||
<DataTemplate DataType="{x:Type vm:MovingAverageViewModel}">
|
||||
<vw:MovingAverageView />
|
||||
</DataTemplate>
|
||||
|
||||
<DataTemplate DataType="{x:Type vm:MACDViewModel}">
|
||||
<vw:MACDView />
|
||||
</DataTemplate>
|
||||
|
||||
<DataTemplate DataType="{x:Type vm:HistoricalViewModel}">
|
||||
<vw:HistoricalView />
|
||||
</DataTemplate>
|
||||
|
||||
<DataTemplate DataType="{x:Type vm:ValuationsViewModel}">
|
||||
<vw:ValuationsView />
|
||||
</DataTemplate>
|
||||
|
||||
<DataTemplate DataType="{x:Type vm:SECFilingViewModel}">
|
||||
<vw:SECFilingView />
|
||||
</DataTemplate>
|
||||
|
||||
<DataTemplate DataType="{x:Type vm:ResistanceAndSupportViewModel}">
|
||||
<vw:ResistanceAndSupportView />
|
||||
</DataTemplate>
|
||||
|
||||
<DataTemplate DataType="{x:Type vm:GainLossViewModel}">
|
||||
<vw:GainLossView />
|
||||
</DataTemplate>
|
||||
|
||||
<DataTemplate DataType="{x:Type vm:TradeModelViewModel}">
|
||||
<vw:TradeModelView />
|
||||
</DataTemplate>
|
||||
|
||||
<DataTemplate DataType="{x:Type vm:ETFHoldingViewModel}">
|
||||
<vw:ETFHoldingView />
|
||||
</DataTemplate>
|
||||
|
||||
<DataTemplate DataType="{x:Type vm:OptionsViewModel}">
|
||||
<vw:OptionsView />
|
||||
</DataTemplate>
|
||||
|
||||
<DataTemplate DataType="{x:Type vm:AnalystRatingsViewModel}">
|
||||
<vw:AnalystRatingsView />
|
||||
</DataTemplate>
|
||||
|
||||
<DataTemplate DataType="{x:Type vm:ValueAtRiskViewModel}">
|
||||
<vw:ValueAtRiskView />
|
||||
</DataTemplate>
|
||||
|
||||
<DataTemplate DataType="{x:Type vm:StickerPriceViewModel}">
|
||||
<vw:StickerPriceView />
|
||||
</DataTemplate>
|
||||
|
||||
<DataTemplate DataType="{x:Type vm:DCFValuationViewModel}">
|
||||
<vw:DCFValuationView />
|
||||
</DataTemplate>
|
||||
|
||||
<!--
|
||||
This style configures both of the main content areas in the main window.
|
||||
-->
|
||||
<!--<ContextMenu x:Key="MyMenu">
|
||||
<MenuItem Header="A" />
|
||||
<MenuItem Header="B" />
|
||||
<MenuItem Header="C" />
|
||||
</ContextMenu>-->
|
||||
|
||||
<Style x:Key="MainHCCStyle" TargetType="{x:Type HeaderedContentControl}">
|
||||
<Setter Property="HeaderTemplate">
|
||||
<Setter.Value>
|
||||
<DataTemplate>
|
||||
<Border
|
||||
Background="{StaticResource Brush_HeaderBackground}"
|
||||
BorderBrush="Black"
|
||||
BorderThickness="1"
|
||||
CornerRadius="5"
|
||||
Margin="4"
|
||||
Padding="4"
|
||||
SnapsToDevicePixels="True"
|
||||
>
|
||||
<TextBlock
|
||||
FontSize="10"
|
||||
FontWeight="Bold"
|
||||
Foreground="WhiteSmoke"
|
||||
HorizontalAlignment="Center"
|
||||
Text="{TemplateBinding Content}">
|
||||
</TextBlock>
|
||||
</Border>
|
||||
</DataTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
<Setter Property="IsTabStop" Value="False" />
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<!--
|
||||
This template ensures that content of a HeaderedContentControl
|
||||
fills the available vertical space.
|
||||
-->
|
||||
<ControlTemplate TargetType="{x:Type HeaderedContentControl}">
|
||||
<DockPanel>
|
||||
<ContentPresenter
|
||||
DockPanel.Dock="Top"
|
||||
ContentSource="Header"
|
||||
ContentTemplate="{TemplateBinding HeaderTemplate}"
|
||||
/>
|
||||
<ContentPresenter
|
||||
ContentSource="Content"
|
||||
ContentTemplate="{TemplateBinding ContentTemplate}"
|
||||
/>
|
||||
</DockPanel>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
|
||||
<!--
|
||||
This style ensures that the borders in the main window are consistent.
|
||||
-->
|
||||
<Style x:Key="MainBorderStyle" TargetType="{x:Type Border}">
|
||||
<Setter Property="Background" Value="#303030" />
|
||||
<Setter Property="BorderBrush" Value="LightGray" />
|
||||
<Setter Property="BorderThickness" Value="1" />
|
||||
<Setter Property="CornerRadius" Value="5" />
|
||||
<Setter Property="SnapsToDevicePixels" Value="True" />
|
||||
</Style>
|
||||
|
||||
<!--
|
||||
This template explains how to render the list of commands on the left
|
||||
side in the main window (the 'Control Panel' area).
|
||||
-->
|
||||
<DataTemplate x:Key="CommandsTemplate">
|
||||
<ItemsControl IsTabStop="False" ItemsSource="{Binding}" Margin="6,2">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Margin="2,6">
|
||||
<Hyperlink Focusable="false" Command="{Binding Path=Command, Mode=OneWay}" FontFamily="Verdana" FontSize="10" Foreground="White">
|
||||
<TextBlock Text="{Binding Path=DisplayName}" Foreground="WhiteSmoke" />
|
||||
</Hyperlink>
|
||||
</TextBlock>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
</DataTemplate>
|
||||
|
||||
<!--
|
||||
This template explains how to render
|
||||
a tab item with a close button.
|
||||
-->
|
||||
<DataTemplate x:Key="ClosableTabItemTemplate">
|
||||
<DockPanel Width="120">
|
||||
<Button
|
||||
Command="{Binding Path=CloseCommand}"
|
||||
Content="X"
|
||||
Cursor="Hand"
|
||||
DockPanel.Dock="Right"
|
||||
Focusable="False"
|
||||
FontFamily="Courier"
|
||||
FontSize="9"
|
||||
FontWeight="Bold"
|
||||
Margin="0,1,0,0"
|
||||
Padding="0"
|
||||
VerticalContentAlignment="Bottom"
|
||||
Width="16" Height="16"
|
||||
/>
|
||||
<ContentPresenter
|
||||
Content="{Binding Path=DisplayName}"
|
||||
VerticalAlignment="Center"
|
||||
/>
|
||||
</DockPanel>
|
||||
</DataTemplate>
|
||||
|
||||
<!--
|
||||
This template explains how to render the 'Workspace' content area in the main window.
|
||||
-->
|
||||
|
||||
<DataTemplate x:Key="WorkspacesTemplate">
|
||||
<telerik:RadTabControl
|
||||
AllowDragOverTab="True"
|
||||
AllowDragReorder="True"
|
||||
IsContentPreserved="true"
|
||||
IsSynchronizedWithCurrentItem="True"
|
||||
FontFamily="Verdana"
|
||||
FontSize="10"
|
||||
ItemsSource="{Binding}"
|
||||
ItemTemplate="{StaticResource ClosableTabItemTemplate}"
|
||||
Margin="4">
|
||||
</telerik:RadTabControl>
|
||||
</DataTemplate>
|
||||
|
||||
</ResourceDictionary>
|
||||
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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
55
Properties/AssemblyInfo.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
using System.Reflection;
|
||||
using System.Resources;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Windows;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("eNavigator")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("Diversified Software Solutions")]
|
||||
[assembly: AssemblyProduct("Equity Navigation System")]
|
||||
[assembly: AssemblyCopyright("Copyright © Diversified Software Solutions")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
//In order to begin building localizable applications, set
|
||||
//<UICulture>CultureYouAreCodingWith</UICulture> in your .csproj file
|
||||
//inside a <PropertyGroup>. For example, if you are using US english
|
||||
//in your source files, set the <UICulture> to en-US. Then uncomment
|
||||
//the NeutralResourceLanguage attribute below. Update the "en-US" in
|
||||
//the line below to match the UICulture setting in the project file.
|
||||
|
||||
//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
|
||||
|
||||
|
||||
[assembly: ThemeInfo(
|
||||
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
|
||||
//(used if a resource is not found in the page,
|
||||
// or application resource dictionaries)
|
||||
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
|
||||
//(used if a resource is not found in the page,
|
||||
// app, or any theme specific resource dictionaries)
|
||||
)]
|
||||
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
63
Properties/Resources.Designer.cs
generated
Normal file
@@ -0,0 +1,63 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Runtime Version:4.0.30319.42000
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace TradeBlotter.Properties {
|
||||
using System;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// A strongly-typed resource class, for looking up localized strings, etc.
|
||||
/// </summary>
|
||||
// This class was auto-generated by the StronglyTypedResourceBuilder
|
||||
// class via a tool like ResGen or Visual Studio.
|
||||
// To add or remove a member, edit your .ResX file then rerun ResGen
|
||||
// with the /str option, or rebuild your VS project.
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
internal class Resources {
|
||||
|
||||
private static global::System.Resources.ResourceManager resourceMan;
|
||||
|
||||
private static global::System.Globalization.CultureInfo resourceCulture;
|
||||
|
||||
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
||||
internal Resources() {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the cached ResourceManager instance used by this class.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Resources.ResourceManager ResourceManager {
|
||||
get {
|
||||
if (object.ReferenceEquals(resourceMan, null)) {
|
||||
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("TradeBlotter.Properties.Resources", typeof(Resources).Assembly);
|
||||
resourceMan = temp;
|
||||
}
|
||||
return resourceMan;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Overrides the current thread's CurrentUICulture property for all
|
||||
/// resource lookups using this strongly typed resource class.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Globalization.CultureInfo Culture {
|
||||
get {
|
||||
return resourceCulture;
|
||||
}
|
||||
set {
|
||||
resourceCulture = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
121
Properties/Resources.resx
Normal file
@@ -0,0 +1,121 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
|
||||
</root>
|
||||
26
Properties/Settings.Designer.cs
generated
Normal file
@@ -0,0 +1,26 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Runtime Version:4.0.30319.42000
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace TradeBlotter.Properties {
|
||||
|
||||
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
|
||||
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
|
||||
|
||||
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
|
||||
|
||||
public static Settings Default {
|
||||
get {
|
||||
return defaultInstance;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
7
Properties/Settings.settings
Normal file
@@ -0,0 +1,7 @@
|
||||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<SettingsFile xmlns="uri:settings" CurrentProfile="(Default)">
|
||||
<Profiles>
|
||||
<Profile Name="(Default)" />
|
||||
</Profiles>
|
||||
<Settings />
|
||||
</SettingsFile>
|
||||
BIN
Resources/HighSeas.bmp
Normal file
|
After Width: | Height: | Size: 1.6 MiB |
BIN
Resources/HighSeas.jpg
Normal file
|
After Width: | Height: | Size: 302 KiB |
BIN
Resources/HighSeas2.jpg
Normal file
|
After Width: | Height: | Size: 269 KiB |
BIN
Resources/HighSeas_safe.jpg
Normal file
|
After Width: | Height: | Size: 243 KiB |
BIN
Resources/pause.png
Normal file
|
After Width: | Height: | Size: 3.0 KiB |
BIN
Resources/play.png
Normal file
|
After Width: | Height: | Size: 3.2 KiB |
157
Safe/PriceCache.cs
Normal file
@@ -0,0 +1,157 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using MarketData.MarketDataModel;
|
||||
using MarketData.Helper;
|
||||
using MarketData.DataAccess;
|
||||
using MarketData.Utils;
|
||||
|
||||
namespace TradeBlotter.Cache
|
||||
{
|
||||
//public class CacheInfo
|
||||
//{
|
||||
// public CacheInfo()
|
||||
// {
|
||||
// }
|
||||
// public Prices Prices { get; set; }
|
||||
//}
|
||||
|
||||
public class PriceCache : IDisposable
|
||||
{
|
||||
private Dictionary<String, Prices> priceCache = new Dictionary<String, Prices>();
|
||||
private Object thisLock = new Object();
|
||||
private Thread cacheMonitorThread = null;
|
||||
private bool threadRun = true;
|
||||
private int cacheRefreshAfter = 30000;
|
||||
private static PriceCache priceCacheInstance = null;
|
||||
|
||||
private PriceCache()
|
||||
{
|
||||
cacheMonitorThread = new Thread(new ThreadStart(ThreadProc));
|
||||
cacheMonitorThread.Start();
|
||||
}
|
||||
public static PriceCache GetInstance()
|
||||
{
|
||||
lock (typeof(PriceCache))
|
||||
{
|
||||
if (null == priceCacheInstance) priceCacheInstance = new PriceCache();
|
||||
return priceCacheInstance;
|
||||
}
|
||||
}
|
||||
public void Dispose()
|
||||
{
|
||||
lock (thisLock)
|
||||
{
|
||||
threadRun = false;
|
||||
if (null != cacheMonitorThread)
|
||||
{
|
||||
cacheMonitorThread.Join();
|
||||
}
|
||||
priceCache.Clear();
|
||||
priceCacheInstance = null;
|
||||
}
|
||||
}
|
||||
public Prices GetPrices(String symbol, int days)
|
||||
{
|
||||
lock (thisLock)
|
||||
{
|
||||
DateTime now = DateTime.Now;
|
||||
Prices prices = null;
|
||||
Price price = null;
|
||||
if (priceCache.ContainsKey(symbol)) prices = priceCache[symbol];
|
||||
if (null != prices)
|
||||
{
|
||||
if (prices.Count >= days)
|
||||
{
|
||||
Prices priceRange = null;
|
||||
if (prices.Count == days) priceRange = prices;
|
||||
else priceRange = new Prices(prices.GetRange(0, days).ToArray());
|
||||
return priceRange;
|
||||
}
|
||||
if(prices.Count>0)price = prices[0];
|
||||
prices = PricingDA.GetPrices(symbol, days);
|
||||
if (null!=prices&&price.Date.Date.Equals(DateTime.Now.Date.Date)&&(prices.Count>0&&prices[0].Date.Date!=price.Date.Date)) prices.Insert(0,price);
|
||||
return prices;
|
||||
}
|
||||
prices = PricingDA.GetPrices(symbol, days);
|
||||
if (null != prices && 0 != prices.Count) priceCache.Add(symbol, prices);
|
||||
return prices;
|
||||
}
|
||||
}
|
||||
public Price GetLatestPrice(String symbol)
|
||||
{
|
||||
lock (thisLock)
|
||||
{
|
||||
DateTime now = DateTime.Now;
|
||||
Price price = null;
|
||||
Prices prices = null;
|
||||
if (priceCache.ContainsKey(symbol)) prices = priceCache[symbol];
|
||||
if (null!=prices)
|
||||
{
|
||||
if (0 == prices.Count)
|
||||
{
|
||||
price = MarketDataHelper.GetLatestPrice(symbol);
|
||||
if (null != price) prices.Add(price);
|
||||
}
|
||||
else
|
||||
{
|
||||
price = prices[0];
|
||||
if (price.Date.Date.Equals(now.Date.Date)) return price;
|
||||
price = MarketDataHelper.GetLatestPrice(symbol);
|
||||
if (null != price) prices.Insert(0,price);
|
||||
}
|
||||
return price;
|
||||
}
|
||||
price = MarketDataHelper.GetLatestPrice(symbol);
|
||||
if (null != price)
|
||||
{
|
||||
prices = new Prices();
|
||||
prices.Add(price);
|
||||
priceCache.Add(symbol, prices);
|
||||
}
|
||||
return price;
|
||||
}
|
||||
}
|
||||
public bool Contains(String symbol)
|
||||
{
|
||||
lock (thisLock)
|
||||
{
|
||||
return priceCache.ContainsKey(symbol);
|
||||
}
|
||||
}
|
||||
private void ThreadProc()
|
||||
{
|
||||
int quantums = 0;
|
||||
int quantumInterval = 500;
|
||||
while (threadRun)
|
||||
{
|
||||
Thread.Sleep(quantumInterval);
|
||||
quantums += quantumInterval;
|
||||
if (quantums > cacheRefreshAfter)
|
||||
{
|
||||
quantums = 0;
|
||||
lock (thisLock)
|
||||
{
|
||||
DateTime now = DateTime.Now;
|
||||
List<String> symbols = new List<String>(priceCache.Keys);
|
||||
foreach (String symbol in symbols)
|
||||
{
|
||||
Prices prices=priceCache[symbol];
|
||||
if (null ==prices || 0 == prices.Count) continue;
|
||||
Price price = prices[0];
|
||||
if (price.Date.Date.Equals(now.Date.Date))
|
||||
{
|
||||
prices.Remove(price);
|
||||
price=MarketDataHelper.GetLatestPrice(symbol);
|
||||
if(null==price)prices.Insert(0,price);
|
||||
}
|
||||
//if (price.Date.Date.Equals(now.Date.Date)) prices.Remove(price);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
32
SaveParams/saveparams.config
Normal file
@@ -0,0 +1,32 @@
|
||||
Type,TradeBlotter.ViewModels.BollingerBandViewModel,SelectedSymbol,JFNNX,SelectedWatchList,{All},SelectedDayCount,180,SyncTradeToBand,False,ShowTradeLabels,True,ShowRiskFree,False,IsLegendVisible,True,UseLeastSquaresFit,True,ShowInsiderTransactions,True
|
||||
Type,TradeBlotter.ViewModels.MomentumViewModel,PathFileName,C:\boneyard\marketdata\bin\Debug\saferun\MG20180131.txt
|
||||
Type,TradeBlotter.ViewModels.CMMomentumViewModel,PathFileName,C:\boneyard\marketdata\bin\Debug\saferun\CM20191031.txt
|
||||
Type,TradeBlotter.ViewModels.MMTrendViewModel,PathFileName,C:\boneyard\marketdata\bin\Debug\saferun\MM20200817.txt
|
||||
Type,TradeBlotter.ViewModels.BollingerBandViewModel,SelectedSymbol,XLP,SelectedWatchList,Valuations,SelectedDayCount,180,SyncTradeToBand,True,ShowTradeLabels,True,ShowRiskFree,False,IsLegendVisible,True,UseLeastSquaresFit,True,ShowInsiderTransactions,True
|
||||
Type,TradeBlotter.ViewModels.BollingerBandViewModel,SelectedSymbol,KTB,SelectedWatchList,{All},SelectedDayCount,360,SyncTradeToBand,True,ShowTradeLabels,True,ShowRiskFree,False,IsLegendVisible,True,UseLeastSquaresFit,True,ShowInsiderTransactions,True
|
||||
Type,TradeBlotter.ViewModels.BollingerBandViewModel,SelectedSymbol,FXL,SelectedWatchList,{All},SelectedDayCount,90,SyncTradeToBand,True,ShowTradeLabels,True,ShowRiskFree,False,IsLegendVisible,True,UseLeastSquaresFit,True,ShowInsiderTransactions,True
|
||||
Type,TradeBlotter.ViewModels.BollingerBandViewModel,SelectedSymbol,KOD,SelectedWatchList,{All},SelectedDayCount,180,SyncTradeToBand,False,ShowTradeLabels,True,ShowRiskFree,False,IsLegendVisible,True,UseLeastSquaresFit,True,ShowInsiderTransactions,True
|
||||
Type,TradeBlotter.ViewModels.BollingerBandViewModel,SelectedSymbol,QQQE,SelectedWatchList,{All},SelectedDayCount,180,SyncTradeToBand,True,ShowTradeLabels,True,ShowRiskFree,False,IsLegendVisible,True,UseLeastSquaresFit,True,ShowInsiderTransactions,True
|
||||
Type,TradeBlotter.ViewModels.BollingerBandViewModel,SelectedSymbol,LH,SelectedWatchList,{All},SelectedDayCount,90,SyncTradeToBand,True,ShowTradeLabels,True,ShowRiskFree,False,IsLegendVisible,True,UseLeastSquaresFit,True,ShowInsiderTransactions,True
|
||||
Type,TradeBlotter.ViewModels.BollingerBandViewModel,SelectedSymbol,FTCH,SelectedWatchList,{All},SelectedDayCount,180,SyncTradeToBand,True,ShowTradeLabels,True,ShowRiskFree,False,IsLegendVisible,True,UseLeastSquaresFit,True,ShowInsiderTransactions,True
|
||||
Type,TradeBlotter.ViewModels.BollingerBandViewModel,SelectedSymbol,NTLA,SelectedWatchList,{All},SelectedDayCount,180,SyncTradeToBand,True,ShowTradeLabels,True,ShowRiskFree,False,IsLegendVisible,True,UseLeastSquaresFit,True,ShowInsiderTransactions,True
|
||||
Type,TradeBlotter.ViewModels.BollingerBandViewModel,SelectedSymbol,DECK,SelectedWatchList,{All},SelectedDayCount,180,SyncTradeToBand,True,ShowTradeLabels,True,ShowRiskFree,False,IsLegendVisible,True,UseLeastSquaresFit,True,ShowInsiderTransactions,True
|
||||
Type,TradeBlotter.ViewModels.BollingerBandViewModel,SelectedSymbol,DNLI,SelectedWatchList,{All},SelectedDayCount,180,SyncTradeToBand,False,ShowTradeLabels,True,ShowRiskFree,False,IsLegendVisible,True,UseLeastSquaresFit,True,ShowInsiderTransactions,True
|
||||
Type,TradeBlotter.ViewModels.BollingerBandViewModel,SelectedSymbol,VDE,SelectedWatchList,{All},SelectedDayCount,1440,SyncTradeToBand,False,ShowTradeLabels,True,ShowRiskFree,False,IsLegendVisible,True,UseLeastSquaresFit,True,ShowInsiderTransactions,True
|
||||
Type,TradeBlotter.ViewModels.BollingerBandViewModel,SelectedSymbol,NEAR,SelectedWatchList,{All},SelectedDayCount,90,SyncTradeToBand,True,ShowTradeLabels,True,ShowRiskFree,False,IsLegendVisible,True,UseLeastSquaresFit,True,ShowInsiderTransactions,True
|
||||
Type,TradeBlotter.ViewModels.BollingerBandViewModel,SelectedSymbol,JHG,SelectedWatchList,Valuations,SelectedDayCount,180,SyncTradeToBand,True,ShowTradeLabels,True,ShowRiskFree,False,IsLegendVisible,True,UseLeastSquaresFit,True,ShowInsiderTransactions,True
|
||||
Type,TradeBlotter.ViewModels.BollingerBandViewModel,SelectedSymbol,SPY,SelectedWatchList,Valuations,SelectedDayCount,180,SyncTradeToBand,False,ShowTradeLabels,True,ShowRiskFree,False,IsLegendVisible,True,UseLeastSquaresFit,True,ShowInsiderTransactions,True
|
||||
Type,TradeBlotter.ViewModels.BollingerBandViewModel,SelectedSymbol,AAPL,SelectedWatchList,Valuations,SelectedDayCount,180,SyncTradeToBand,True,ShowTradeLabels,True,ShowRiskFree,False,IsLegendVisible,True,UseLeastSquaresFit,True,ShowInsiderTransactions,True
|
||||
Type,TradeBlotter.ViewModels.BollingerBandViewModel,SelectedSymbol,MTUM,SelectedWatchList,{All},SelectedDayCount,90,SyncTradeToBand,True,ShowTradeLabels,True,ShowRiskFree,False,IsLegendVisible,True,UseLeastSquaresFit,True,ShowInsiderTransactions,True,StopHistoryCount,1,StopHistory_0,Symbol=MTUM|StopPrice=154.616|Shares=0|StopType=Stop Quote|Active=0|EffectiveDate=2/10/2021
|
||||
Type,TradeBlotter.ViewModels.BollingerBandViewModel,SelectedSymbol,TAC,SelectedWatchList,{All},SelectedDayCount,180,SyncTradeToBand,False,ShowTradeLabels,True,ShowRiskFree,False,IsLegendVisible,True,UseLeastSquaresFit,True,ShowInsiderTransactions,True
|
||||
Type,TradeBlotter.ViewModels.BollingerBandViewModel,SelectedSymbol,JNJ,SelectedWatchList,{All},SelectedDayCount,360,SyncTradeToBand,True,ShowTradeLabels,True,ShowRiskFree,False,IsLegendVisible,False,UseLeastSquaresFit,True,ShowInsiderTransactions,True
|
||||
Type,TradeBlotter.ViewModels.BollingerBandViewModel,SelectedSymbol,KURA,SelectedWatchList,{All},SelectedDayCount,180,SyncTradeToBand,True,ShowTradeLabels,True,ShowRiskFree,False,IsLegendVisible,True,UseLeastSquaresFit,True,ShowInsiderTransactions,True
|
||||
Type,TradeBlotter.ViewModels.BollingerBandViewModel,SelectedSymbol,HZNP,SelectedWatchList,{All},SelectedDayCount,180,SyncTradeToBand,False,ShowTradeLabels,True,ShowRiskFree,False,IsLegendVisible,True,UseLeastSquaresFit,True,ShowInsiderTransactions,True
|
||||
Type,TradeBlotter.ViewModels.BollingerBandViewModel,SelectedSymbol,SMG,SelectedWatchList,{All},SelectedDayCount,90,SyncTradeToBand,True,ShowTradeLabels,True,ShowRiskFree,False,IsLegendVisible,False,UseLeastSquaresFit,True,ShowInsiderTransactions,True,StopHistoryCount,5,StopHistory_0,Symbol=SMG|StopPrice=136.5672|Shares=0|StopType=Stop Quote|Active=0|EffectiveDate=10/28/2020,StopHistory_1,Symbol=SMG|StopPrice=143.147428398132|Shares=0|StopType=Stop Quote|Active=0|EffectiveDate=11/12/2020,StopHistory_2,Symbol=SMG|StopPrice=178.030000743866|Shares=0|StopType=Stop Quote|Active=0|EffectiveDate=12/14/2020,StopHistory_3,Symbol=SMG|StopPrice=205.08799955368|Shares=0|StopType=Stop Quote|Active=0|EffectiveDate=1/13/2021,StopHistory_4,Symbol=SMG|StopPrice=218.696714553833|Shares=0|StopType=Stop Quote|Active=0|EffectiveDate=2/12/2021
|
||||
Type,TradeBlotter.ViewModels.BollingerBandViewModel,SelectedSymbol,POOL,SelectedWatchList,{All},SelectedDayCount,90,SyncTradeToBand,True,ShowTradeLabels,True,ShowRiskFree,False,IsLegendVisible,False,UseLeastSquaresFit,True,ShowInsiderTransactions,True,StopHistoryCount,1,StopHistory_0,Symbol=POOL|StopPrice=290.3296|Shares=0|StopType=Stop Quote|Active=0|EffectiveDate=9/2/2020
|
||||
Type,TradeBlotter.ViewModels.BollingerBandViewModel,SelectedSymbol,UUP,SelectedWatchList,{All},SelectedDayCount,1440,SyncTradeToBand,True,ShowTradeLabels,True,ShowRiskFree,False,IsLegendVisible,True,UseLeastSquaresFit,True,ShowInsiderTransactions,True
|
||||
Type,TradeBlotter.ViewModels.BollingerBandViewModel,SelectedSymbol,GLD,SelectedWatchList,{All},SelectedDayCount,180,SyncTradeToBand,True,ShowTradeLabels,True,ShowRiskFree,False,IsLegendVisible,True,UseLeastSquaresFit,True,ShowInsiderTransactions,True
|
||||
Type,TradeBlotter.ViewModels.BollingerBandViewModel,SelectedSymbol,WOW,SelectedWatchList,{All},SelectedDayCount,180,SyncTradeToBand,True,ShowTradeLabels,True,ShowRiskFree,False,IsLegendVisible,True,UseLeastSquaresFit,True,ShowInsiderTransactions,True
|
||||
Type,TradeBlotter.ViewModels.BollingerBandViewModel,SelectedSymbol,VCEL,SelectedWatchList,{All},SelectedDayCount,180,SyncTradeToBand,True,ShowTradeLabels,True,ShowRiskFree,False,IsLegendVisible,True,UseLeastSquaresFit,True,ShowInsiderTransactions,True
|
||||
Type,TradeBlotter.ViewModels.BollingerBandViewModel,SelectedSymbol,QQQE,SelectedWatchList,{All},SelectedDayCount,90,SyncTradeToBand,True,ShowTradeLabels,True,ShowRiskFree,False,IsLegendVisible,True,UseLeastSquaresFit,True,ShowInsiderTransactions,True,StopHistoryCount,4,StopHistory_0,Symbol=QQQE|StopPrice=65.4104|Shares=0|StopType=Stop Quote|Active=0|EffectiveDate=12/24/2020,StopHistory_1,Symbol=QQQE|StopPrice=71.7852856779099|Shares=0|StopType=Stop Quote|Active=0|EffectiveDate=12/28/2020,StopHistory_2,Symbol=QQQE|StopPrice=72.0925713157654|Shares=0|StopType=Stop Quote|Active=0|EffectiveDate=1/27/2021,StopHistory_3,Symbol=QQQE|StopPrice=72.5744287014008|Shares=0|StopType=Stop Quote|Active=0|EffectiveDate=2/26/2021
|
||||
Type,TradeBlotter.ViewModels.BollingerBandViewModel,SelectedSymbol,GSY,SelectedWatchList,Valuations,SelectedDayCount,720,SyncTradeToBand,True,ShowTradeLabels,True,ShowRiskFree,False,IsLegendVisible,True,UseLeastSquaresFit,True,ShowInsiderTransactions,True
|
||||
58
Scraps/BuyOptionsWindow.xaml
Normal file
@@ -0,0 +1,58 @@
|
||||
<Window x:Class="TradeBlotter.ViewModelHelper.BuyOptionsDialog"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
Title="Buy Options Window" Height="320" Width="300"
|
||||
MinHeight="10"
|
||||
MinWidth="300"
|
||||
ResizeMode="CanResizeWithGrip"
|
||||
ShowInTaskbar="False"
|
||||
WindowStartupLocation="CenterOwner"
|
||||
>
|
||||
<Grid >
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<Label Grid.Column="0" Grid.Row="0">Shares Held:</Label>
|
||||
<Label Grid.Column="0" Grid.Row="1">Price:</Label>
|
||||
<Label Grid.Column="0" Grid.Row="2">Expiration Date:</Label>
|
||||
<Label Grid.Column="0" Grid.Row="3">Contracts:</Label>
|
||||
<Label Grid.Column="0" Grid.Row="4">Strike Price:</Label>
|
||||
<Label Grid.Column="0" Grid.Row="5">Price On Expiration:</Label>
|
||||
<Label Grid.Column="0" Grid.Row="6">Bid:</Label>
|
||||
<Label Grid.Column="0" Grid.Row="7">Premium:</Label>
|
||||
<Label Grid.Column="0" Grid.Row="8">Gain/Loss:</Label>
|
||||
<Button Grid.Row="9" Content="Calculate" HorizontalAlignment="Stretch" Command="{Binding Path=CalculateCommand}" ></Button>
|
||||
<Button Grid.Column="0" Grid.Row="10" IsCancel="True" Content="Cancel" HorizontalAlignment="Stretch" ></Button>
|
||||
|
||||
<TextBox Name="SharesHeld" Grid.Column="1" Grid.Row="0" Text="{Binding Path=SharesHeldValue, ValidatesOnDataErrors=True, UpdateSourceTrigger=LostFocus}">
|
||||
<!--<TextBox.Text>
|
||||
<Binding Path="SharesHeld" UpdateSourceTrigger="LostFocus"/>
|
||||
</TextBox.Text>-->
|
||||
</TextBox>
|
||||
|
||||
<TextBox Name="Price" Grid.Column="1" Grid.Row="1" />
|
||||
<TextBox Name="ExpirationDate" Grid.Column="1" Grid.Row="2" />
|
||||
<TextBox Name="Contracts" Grid.Column="1" Grid.Row="3"/>
|
||||
<TextBox Name="StrikePrice" Grid.Column="1" Grid.Row="4" />
|
||||
<TextBox Name="PriceOnExpiration" Grid.Column="1" Grid.Row="5" />
|
||||
<TextBox Name="Bid" Grid.Column="1" Grid.Row="6" />
|
||||
<TextBox Name="Premium" Grid.Column="1" Grid.Row="7" />
|
||||
<TextBox Name="GainLoss" Grid.Column="1" Grid.Row="8" />
|
||||
</Grid>
|
||||
</Window>
|
||||
5
Scraps/ContextMenu.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
<telerik:RadContextMenu.ContextMenu>
|
||||
<telerik:RadContextMenu x:Name="GridContextMenu" >
|
||||
<MenuItem Header="Buy Covered Call" Command="{Binding BuyCoveredCallCommand}" CommandParameter="{Binding ClickedItem}" />
|
||||
</telerik:RadContextMenu>
|
||||
</telerik:RadContextMenu.ContextMenu>
|
||||
585
TradeBlotter.csproj
Normal file
@@ -0,0 +1,585 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
|
||||
<ProductVersion>8.0.30703</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{656F496C-0406-47A1-BDC3-15A5CE403381}</ProjectGuid>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>TradeBlotter</RootNamespace>
|
||||
<AssemblyName>TradeBlotter</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
|
||||
<TargetFrameworkProfile>
|
||||
</TargetFrameworkProfile>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<PublishUrl>publish\</PublishUrl>
|
||||
<Install>true</Install>
|
||||
<InstallFrom>Disk</InstallFrom>
|
||||
<UpdateEnabled>false</UpdateEnabled>
|
||||
<UpdateMode>Foreground</UpdateMode>
|
||||
<UpdateInterval>7</UpdateInterval>
|
||||
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
|
||||
<UpdatePeriodically>false</UpdatePeriodically>
|
||||
<UpdateRequired>false</UpdateRequired>
|
||||
<MapFileExtensions>true</MapFileExtensions>
|
||||
<ApplicationRevision>0</ApplicationRevision>
|
||||
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
|
||||
<IsWebBootstrapper>false</IsWebBootstrapper>
|
||||
<UseApplicationTrust>false</UseApplicationTrust>
|
||||
<BootstrapperEnabled>true</BootstrapperEnabled>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>0</WarningLevel>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<ApplicationIcon>Application.ico</ApplicationIcon>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="ReachFramework" />
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.configuration" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Web.Extensions" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="System.Xaml">
|
||||
<RequiredTargetFramework>4.0</RequiredTargetFramework>
|
||||
</Reference>
|
||||
<Reference Include="Telerik.Windows.Controls">
|
||||
<HintPath>references\Telerik.Windows.Controls.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Telerik.Windows.Controls.Chart">
|
||||
<HintPath>references\Telerik.Windows.Controls.Chart.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Telerik.Windows.Controls.Charting">
|
||||
<HintPath>references\Telerik.Windows.Controls.Charting.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Telerik.Windows.Controls.GridView">
|
||||
<HintPath>references\Telerik.Windows.Controls.GridView.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Telerik.Windows.Controls.Input">
|
||||
<HintPath>references\Telerik.Windows.Controls.Input.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Telerik.Windows.Controls.Navigation">
|
||||
<HintPath>references\Telerik.Windows.Controls.Navigation.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Telerik.Windows.Controls.RichTextBoxUI">
|
||||
<HintPath>references\Telerik.Windows.Controls.RichTextBoxUI.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Telerik.Windows.Data">
|
||||
<HintPath>references\Telerik.Windows.Data.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="WindowsBase" />
|
||||
<Reference Include="PresentationCore" />
|
||||
<Reference Include="PresentationFramework" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ApplicationDefinition Include="App.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</ApplicationDefinition>
|
||||
<Compile Include="Cache\PriceCache.cs" />
|
||||
<Compile Include="DataAccess\TradeAddedEvenArgs.cs" />
|
||||
<Compile Include="DataAccess\TradeRepository.cs" />
|
||||
<Compile Include="FloatingWindow.xaml.cs">
|
||||
<DependentUpon>FloatingWindow.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Helper\FilterEvaluator.cs" />
|
||||
<Compile Include="Model\BlotterTradeModel.cs" />
|
||||
<Compile Include="Model\BollingerBandModel.cs" />
|
||||
<Compile Include="Model\CMPositionModel.cs" />
|
||||
<Compile Include="Model\CMTPositionModel.cs" />
|
||||
<Compile Include="Model\DividendLoadModel.cs" />
|
||||
<Compile Include="Model\DividendPaymentModel.cs" />
|
||||
<Compile Include="Model\ETFHoldingModel.cs" />
|
||||
<Compile Include="Model\GainLossModel.cs" />
|
||||
<Compile Include="Model\InsiderTransactionModel.cs" />
|
||||
<Compile Include="Model\MACDModel.cs" />
|
||||
<Compile Include="Model\MenuItem.cs" />
|
||||
<Compile Include="Model\MGPositionModel.cs" />
|
||||
<Compile Include="Model\MMPositionModel.cs" />
|
||||
<Compile Include="Model\ModelPerformanceAggregator.cs" />
|
||||
<Compile Include="Model\MovingAverageModel.cs" />
|
||||
<Compile Include="Model\OptionStrikeModel.cs" />
|
||||
<Compile Include="Model\RSIModel.cs" />
|
||||
<Compile Include="Model\StopLimitCompositeModel.cs" />
|
||||
<Compile Include="Model\TermStructureModel.cs" />
|
||||
<Compile Include="Model\TradeEntryModel.cs" />
|
||||
<Compile Include="Model\ValuationModel.cs" />
|
||||
<Compile Include="Properties\Resources.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DesignTime>True</DesignTime>
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="UIUtils\CMTTrendModelClosePositionDialog.xaml.cs">
|
||||
<DependentUpon>CMTTrendModelClosePositionDialog.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="UIUtils\CMTTrendModelEditPositionDialog.xaml.cs">
|
||||
<DependentUpon>CMTTrendModelEditPositionDialog.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="UIUtils\ProformaAddPositionDialog.xaml.cs">
|
||||
<DependentUpon>ProformaAddPositionDialog.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="UIUtils\ProformaAddRiskDividendParityPositionDialog.xaml.cs">
|
||||
<DependentUpon>ProformaAddRiskDividendParityPositionDialog.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Utility\BrushCollection.cs" />
|
||||
<Compile Include="Utility\CellStyles.cs" />
|
||||
<Compile Include="Utility\WebBrowserUtils.cs" />
|
||||
<Compile Include="ViewModels\CMMomentumViewModel.cs" />
|
||||
<Compile Include="ViewModels\CMTTrendViewModel.cs" />
|
||||
<Compile Include="ViewModels\DividendRiskParityViewModel.cs" />
|
||||
<Compile Include="ViewModels\FeedStatisticsViewModel.cs" />
|
||||
<Compile Include="ViewModels\RiskProfileViewModel.cs" />
|
||||
<Compile Include="ViewModels\DCFValuationViewModel.cs" />
|
||||
<Compile Include="ViewModels\DividendHistoryViewModel.cs" />
|
||||
<Compile Include="ViewModels\DividendPaymentViewModel.cs" />
|
||||
<Compile Include="ViewModels\FloatingWindowViewModel.cs" />
|
||||
<Compile Include="ViewModels\HeadlinesViewModel.cs" />
|
||||
<Compile Include="ViewModels\MomentumViewModel.cs" />
|
||||
<Compile Include="ViewModels\OptionsWorksheetViewModel.cs" />
|
||||
<Compile Include="ViewModels\PortfolioHoldingViewModel.cs" />
|
||||
<Compile Include="Model\PortfolioTradeModel.cs" />
|
||||
<Compile Include="Model\PriceModel.cs" />
|
||||
<Compile Include="Model\RatingsModel.cs" />
|
||||
<Compile Include="Model\ResistanceAndSupportModel.cs" />
|
||||
<Compile Include="Model\StochasticsModel.cs" />
|
||||
<Compile Include="Model\TimeSeriesModel.cs" />
|
||||
<Compile Include="Model\TradeResultModel.cs" />
|
||||
<Compile Include="Model\YieldCurveModel.cs" />
|
||||
<Compile Include="Utility\AttachedBehavior.cs" />
|
||||
<Compile Include="Utility\CustomAggregator.cs" />
|
||||
<Compile Include="Model\Item.cs" />
|
||||
<Compile Include="Utility\UIUtils.cs" />
|
||||
<Compile Include="ViewModels\AnalystRatingsViewModel.cs" />
|
||||
<Compile Include="ViewModels\BollingerBandViewModel.cs" />
|
||||
<Compile Include="ViewModels\CommandViewModel.cs" />
|
||||
<Compile Include="ViewModels\EarningsAnnouncementViewModel.cs" />
|
||||
<Compile Include="ViewModels\ETFHoldingViewModel.cs" />
|
||||
<Compile Include="ViewModels\GainLossViewModel.cs" />
|
||||
<Compile Include="ViewModels\HistoricalViewModel.cs" />
|
||||
<Compile Include="ViewModels\MACDViewModel.cs" />
|
||||
<Compile Include="ViewModels\MainWindowViewModel.cs" />
|
||||
<Compile Include="ViewModels\MovingAverageViewModel.cs" />
|
||||
<Compile Include="ViewModels\OptionsViewModel.cs" />
|
||||
<Compile Include="ViewModels\PricingViewModel.cs" />
|
||||
<Compile Include="ViewModels\ResistanceAndSupportViewModel.cs" />
|
||||
<Compile Include="ViewModels\RSIViewModel.cs" />
|
||||
<Compile Include="ViewModels\SECFilingViewModel.cs" />
|
||||
<Compile Include="ViewModels\SectorViewModel.cs" />
|
||||
<Compile Include="ViewModels\StickerPriceViewModel.cs" />
|
||||
<Compile Include="ViewModels\StochasticsViewModel.cs" />
|
||||
<Compile Include="ViewModels\TradeEntryViewModel..cs" />
|
||||
<Compile Include="ViewModels\TradeModelViewModel.cs" />
|
||||
<Compile Include="ViewModels\TradeViewModel.cs" />
|
||||
<Compile Include="ViewModels\ValuationsViewModel.cs" />
|
||||
<Compile Include="ViewModels\ValueAtRiskViewModel.cs" />
|
||||
<Compile Include="ViewModels\WatchListViewModel.cs" />
|
||||
<Compile Include="ViewModels\WorkspaceViewModel.cs" />
|
||||
<Compile Include="ViewModels\WorkspaceViewModelPersistenceHelper.cs" />
|
||||
<Compile Include="ViewModels\YieldCurveViewModel.cs" />
|
||||
<Compile Include="Views\AnalystRatingsView.xaml.cs">
|
||||
<DependentUpon>AnalystRatingsView.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Views\BlotterView.xaml.cs">
|
||||
<DependentUpon>BlotterView.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Views\BollingerBandView.xaml.cs">
|
||||
<DependentUpon>BollingerBandView.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Views\CMMomentumView.xaml.cs">
|
||||
<DependentUpon>CMMomentumView.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Views\CMTTrendView.xaml.cs">
|
||||
<DependentUpon>CMTTrendView.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Views\DCFValuationView.xaml.cs">
|
||||
<DependentUpon>DCFValuationView.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Views\DividendPaymentView.xaml.cs">
|
||||
<DependentUpon>DividendPaymentView.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Views\DividendRiskParityView.xaml.cs">
|
||||
<DependentUpon>DividendRiskParityView.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Views\DividendView.xaml.cs">
|
||||
<DependentUpon>DividendView.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Views\EarningsAnnouncementView.xaml.cs">
|
||||
<DependentUpon>EarningsAnnouncementView.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Views\ETFHoldingView.xaml.cs">
|
||||
<DependentUpon>ETFHoldingView.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Views\FeedStatisticsView.xaml.cs">
|
||||
<DependentUpon>FeedStatisticsView.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Views\GainLossView.xaml.cs">
|
||||
<DependentUpon>GainLossView.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Views\HeadlinesView.xaml.cs">
|
||||
<DependentUpon>HeadlinesView.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Views\HistoricalView.xaml.cs">
|
||||
<DependentUpon>HistoricalView.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Views\MACDView.xaml.cs">
|
||||
<DependentUpon>MACDView.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Views\MomentumView.xaml.cs">
|
||||
<DependentUpon>MomentumView.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Views\MovingAverageView.xaml.cs">
|
||||
<DependentUpon>MovingAverageView.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Views\OptionsView.xaml.cs">
|
||||
<DependentUpon>OptionsView.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Views\OptionsWorksheetView.xaml.cs">
|
||||
<DependentUpon>OptionsWorksheetView.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Views\PricingView.xaml.cs">
|
||||
<DependentUpon>PricingView.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Views\ResistanceAndSupportView.xaml.cs">
|
||||
<DependentUpon>ResistanceAndSupportView.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Views\RiskProfileView.xaml.cs">
|
||||
<DependentUpon>RiskProfileView.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Views\RSIView.xaml.cs">
|
||||
<DependentUpon>RSIView.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Views\SECFilingView.xaml.cs">
|
||||
<DependentUpon>SECFilingView.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Views\SectorView.xaml.cs">
|
||||
<DependentUpon>SectorView.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Views\StickerPriceView.xaml.cs">
|
||||
<DependentUpon>StickerPriceView.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Views\StochasticsView.xaml.cs">
|
||||
<DependentUpon>StochasticsView.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Views\TradeEntryView.xaml.cs">
|
||||
<DependentUpon>TradeEntryView.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Views\TradeModelView.xaml.cs">
|
||||
<DependentUpon>TradeModelView.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Views\ValuationsView.xaml.cs">
|
||||
<DependentUpon>ValuationsView.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Views\ValueAtRiskView.xaml.cs">
|
||||
<DependentUpon>ValueAtRiskView.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Views\WatchListView.xaml.cs">
|
||||
<DependentUpon>WatchListView.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Views\YieldCurveView.xaml.cs">
|
||||
<DependentUpon>YieldCurveView.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Page Include="FloatingWindow.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="MainWindow.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
<Compile Include="App.xaml.cs">
|
||||
<DependentUpon>App.xaml</DependentUpon>
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Command\CommandViewModel.cs" />
|
||||
<Compile Include="Command\RelayCommand.cs" />
|
||||
<Compile Include="ViewModels\BlotterViewModel.cs" />
|
||||
<Compile Include="ViewModels\ViewModelBase.cs" />
|
||||
<Compile Include="MainWindow.xaml.cs">
|
||||
<DependentUpon>MainWindow.xaml</DependentUpon>
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Page Include="MainWindowResources.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
<Page Include="UIUtils\CMTTrendModelClosePositionDialog.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="UIUtils\CMTTrendModelEditPositionDialog.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="UIUtils\ProformaAddPositionDialog.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="UIUtils\ProformaAddRiskDividendParityPositionDialog.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="Views\AnalystRatingsView.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="Views\BlotterView.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="Views\BollingerBandView.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="Views\CMMomentumView.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="Views\CMTTrendView.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="Views\DCFValuationView.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="Views\DividendPaymentView.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="Views\DividendRiskParityView.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="Views\DividendView.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="Views\EarningsAnnouncementView.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="Views\ETFHoldingView.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="Views\FeedStatisticsView.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="Views\GainLossView.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="Views\HeadlinesView.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="Views\HistoricalView.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="Views\MACDView.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="Views\MomentumView.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="Views\MovingAverageView.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="Views\OptionsView.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="Views\OptionsWorksheetView.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="Views\PricingView.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="Views\ResistanceAndSupportView.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="Views\RiskProfileView.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="Views\RSIView.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="Views\SECFilingView.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="Views\SectorView.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="Views\StickerPriceView.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="Views\StochasticsView.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="Views\TradeEntryView.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="Views\TradeModelView.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="Views\ValuationsView.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="Views\ValueAtRiskView.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="Views\WatchListView.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="Views\YieldCurveView.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Properties\AssemblyInfo.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Properties\Settings.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Settings.settings</DependentUpon>
|
||||
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
||||
</Compile>
|
||||
<EmbeddedResource Include="Properties\Resources.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||
</EmbeddedResource>
|
||||
<None Include="App.config">
|
||||
<SubType>Designer</SubType>
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="Properties\Settings.settings">
|
||||
<Generator>SettingsSingleFileGenerator</Generator>
|
||||
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
|
||||
</None>
|
||||
<AppDesigner Include="Properties\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Axiom\Axiom.Core\Axiom.Core.csproj">
|
||||
<Project>{f0f0f2b4-bb86-49b5-ba93-2642637033d6}</Project>
|
||||
<Name>Axiom.Core</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\DynamicDataDisplay\DynamicDataDisplay.csproj">
|
||||
<Project>{ecd37682-df7e-409f-912d-0965634556b5}</Project>
|
||||
<Name>DynamicDataDisplay</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\marketdata\MarketDataLib\MarketDataLib.csproj">
|
||||
<Project>{E807F1CA-9D9C-484A-8E83-269D57707B4B}</Project>
|
||||
<Name>MarketDataLib</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\TickerLib\TickerLib.csproj">
|
||||
<Project>{c2682400-eeb6-41ad-ae25-1d60a307d99c}</Project>
|
||||
<Name>TickerLib</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\WPFToolkit\Src\Xceed.Wpf.Toolkit\Xceed.Wpf.Toolkit.csproj">
|
||||
<Project>{72e591d6-8f83-4d8c-8f67-9c325e623234}</Project>
|
||||
<Name>Xceed.Wpf.Toolkit</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<BootstrapperPackage Include=".NETFramework,Version=v4.0,Profile=Client">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>Microsoft .NET Framework 4 Client Profile %28x86 and x64%29</ProductName>
|
||||
<Install>true</Install>
|
||||
</BootstrapperPackage>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
|
||||
<Install>false</Install>
|
||||
</BootstrapperPackage>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 3.5 SP1</ProductName>
|
||||
<Install>false</Install>
|
||||
</BootstrapperPackage>
|
||||
<BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>Windows Installer 3.1</ProductName>
|
||||
<Install>true</Install>
|
||||
</BootstrapperPackage>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Resource Include="Application.ico">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Resource>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Resource Include="Resources\HighSeas.jpg">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Resource>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Resource Include="Resources\pause.png" />
|
||||
<Resource Include="Resources\play.png" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Resource Include="Resources\HighSeas2.jpg">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Resource>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<PropertyGroup>
|
||||
<PostBuildEvent>editbin /largeaddressaware $(targetpath)</PostBuildEvent>
|
||||
</PropertyGroup>
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
130
TradeBlotter.sln
Normal file
@@ -0,0 +1,130 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 2013
|
||||
VisualStudioVersion = 12.0.21005.1
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TradeBlotter", "TradeBlotter.csproj", "{656F496C-0406-47A1-BDC3-15A5CE403381}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{72E591D6-8F83-4D8C-8F67-9C325E623234} = {72E591D6-8F83-4D8C-8F67-9C325E623234}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MarketDataLib", "..\marketdata\MarketDataLib\MarketDataLib.csproj", "{E807F1CA-9D9C-484A-8E83-269D57707B4B}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DynamicDataDisplay", "..\DynamicDataDisplay\DynamicDataDisplay.csproj", "{ECD37682-DF7E-409F-912D-0965634556B5}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Xceed.Wpf.Toolkit", "..\WPFToolkit\Src\Xceed.Wpf.Toolkit\Xceed.Wpf.Toolkit.csproj", "{72E591D6-8F83-4D8C-8F67-9C325E623234}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TickerLib", "..\TickerLib\TickerLib.csproj", "{C2682400-EEB6-41AD-AE25-1D60A307D99C}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Axiom.Core", "..\Axiom\Axiom.Core\Axiom.Core.csproj", "{F0F0F2B4-BB86-49B5-BA93-2642637033D6}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Debug|Mixed Platforms = Debug|Mixed Platforms
|
||||
Debug|x86 = Debug|x86
|
||||
Release|Any CPU = Release|Any CPU
|
||||
Release|Mixed Platforms = Release|Mixed Platforms
|
||||
Release|x86 = Release|x86
|
||||
ReleaseXBAP|Any CPU = ReleaseXBAP|Any CPU
|
||||
ReleaseXBAP|Mixed Platforms = ReleaseXBAP|Mixed Platforms
|
||||
ReleaseXBAP|x86 = ReleaseXBAP|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{656F496C-0406-47A1-BDC3-15A5CE403381}.Debug|Any CPU.ActiveCfg = Debug|x86
|
||||
{656F496C-0406-47A1-BDC3-15A5CE403381}.Debug|Any CPU.Build.0 = Debug|x86
|
||||
{656F496C-0406-47A1-BDC3-15A5CE403381}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
|
||||
{656F496C-0406-47A1-BDC3-15A5CE403381}.Debug|Mixed Platforms.Build.0 = Debug|x86
|
||||
{656F496C-0406-47A1-BDC3-15A5CE403381}.Debug|x86.ActiveCfg = Debug|x86
|
||||
{656F496C-0406-47A1-BDC3-15A5CE403381}.Debug|x86.Build.0 = Debug|x86
|
||||
{656F496C-0406-47A1-BDC3-15A5CE403381}.Release|Any CPU.ActiveCfg = Release|x86
|
||||
{656F496C-0406-47A1-BDC3-15A5CE403381}.Release|Any CPU.Build.0 = Release|x86
|
||||
{656F496C-0406-47A1-BDC3-15A5CE403381}.Release|Mixed Platforms.ActiveCfg = Release|x86
|
||||
{656F496C-0406-47A1-BDC3-15A5CE403381}.Release|Mixed Platforms.Build.0 = Release|x86
|
||||
{656F496C-0406-47A1-BDC3-15A5CE403381}.Release|x86.ActiveCfg = Release|x86
|
||||
{656F496C-0406-47A1-BDC3-15A5CE403381}.Release|x86.Build.0 = Release|x86
|
||||
{656F496C-0406-47A1-BDC3-15A5CE403381}.ReleaseXBAP|Any CPU.ActiveCfg = Release|x86
|
||||
{656F496C-0406-47A1-BDC3-15A5CE403381}.ReleaseXBAP|Mixed Platforms.ActiveCfg = Release|x86
|
||||
{656F496C-0406-47A1-BDC3-15A5CE403381}.ReleaseXBAP|Mixed Platforms.Build.0 = Release|x86
|
||||
{656F496C-0406-47A1-BDC3-15A5CE403381}.ReleaseXBAP|x86.ActiveCfg = Release|x86
|
||||
{656F496C-0406-47A1-BDC3-15A5CE403381}.ReleaseXBAP|x86.Build.0 = Release|x86
|
||||
{E807F1CA-9D9C-484A-8E83-269D57707B4B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{E807F1CA-9D9C-484A-8E83-269D57707B4B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{E807F1CA-9D9C-484A-8E83-269D57707B4B}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
||||
{E807F1CA-9D9C-484A-8E83-269D57707B4B}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
|
||||
{E807F1CA-9D9C-484A-8E83-269D57707B4B}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{E807F1CA-9D9C-484A-8E83-269D57707B4B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{E807F1CA-9D9C-484A-8E83-269D57707B4B}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{E807F1CA-9D9C-484A-8E83-269D57707B4B}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||
{E807F1CA-9D9C-484A-8E83-269D57707B4B}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||
{E807F1CA-9D9C-484A-8E83-269D57707B4B}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{E807F1CA-9D9C-484A-8E83-269D57707B4B}.ReleaseXBAP|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{E807F1CA-9D9C-484A-8E83-269D57707B4B}.ReleaseXBAP|Any CPU.Build.0 = Release|Any CPU
|
||||
{E807F1CA-9D9C-484A-8E83-269D57707B4B}.ReleaseXBAP|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||
{E807F1CA-9D9C-484A-8E83-269D57707B4B}.ReleaseXBAP|Mixed Platforms.Build.0 = Release|Any CPU
|
||||
{E807F1CA-9D9C-484A-8E83-269D57707B4B}.ReleaseXBAP|x86.ActiveCfg = Release|Any CPU
|
||||
{ECD37682-DF7E-409F-912D-0965634556B5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{ECD37682-DF7E-409F-912D-0965634556B5}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{ECD37682-DF7E-409F-912D-0965634556B5}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
||||
{ECD37682-DF7E-409F-912D-0965634556B5}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
|
||||
{ECD37682-DF7E-409F-912D-0965634556B5}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{ECD37682-DF7E-409F-912D-0965634556B5}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{ECD37682-DF7E-409F-912D-0965634556B5}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{ECD37682-DF7E-409F-912D-0965634556B5}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||
{ECD37682-DF7E-409F-912D-0965634556B5}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||
{ECD37682-DF7E-409F-912D-0965634556B5}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{ECD37682-DF7E-409F-912D-0965634556B5}.ReleaseXBAP|Any CPU.ActiveCfg = ReleaseXBAP|Any CPU
|
||||
{ECD37682-DF7E-409F-912D-0965634556B5}.ReleaseXBAP|Any CPU.Build.0 = ReleaseXBAP|Any CPU
|
||||
{ECD37682-DF7E-409F-912D-0965634556B5}.ReleaseXBAP|Mixed Platforms.ActiveCfg = ReleaseXBAP|Any CPU
|
||||
{ECD37682-DF7E-409F-912D-0965634556B5}.ReleaseXBAP|Mixed Platforms.Build.0 = ReleaseXBAP|Any CPU
|
||||
{ECD37682-DF7E-409F-912D-0965634556B5}.ReleaseXBAP|x86.ActiveCfg = ReleaseXBAP|Any CPU
|
||||
{72E591D6-8F83-4D8C-8F67-9C325E623234}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{72E591D6-8F83-4D8C-8F67-9C325E623234}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{72E591D6-8F83-4D8C-8F67-9C325E623234}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
||||
{72E591D6-8F83-4D8C-8F67-9C325E623234}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
|
||||
{72E591D6-8F83-4D8C-8F67-9C325E623234}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{72E591D6-8F83-4D8C-8F67-9C325E623234}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{72E591D6-8F83-4D8C-8F67-9C325E623234}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{72E591D6-8F83-4D8C-8F67-9C325E623234}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||
{72E591D6-8F83-4D8C-8F67-9C325E623234}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||
{72E591D6-8F83-4D8C-8F67-9C325E623234}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{72E591D6-8F83-4D8C-8F67-9C325E623234}.ReleaseXBAP|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{72E591D6-8F83-4D8C-8F67-9C325E623234}.ReleaseXBAP|Any CPU.Build.0 = Release|Any CPU
|
||||
{72E591D6-8F83-4D8C-8F67-9C325E623234}.ReleaseXBAP|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||
{72E591D6-8F83-4D8C-8F67-9C325E623234}.ReleaseXBAP|Mixed Platforms.Build.0 = Release|Any CPU
|
||||
{72E591D6-8F83-4D8C-8F67-9C325E623234}.ReleaseXBAP|x86.ActiveCfg = Release|Any CPU
|
||||
{C2682400-EEB6-41AD-AE25-1D60A307D99C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{C2682400-EEB6-41AD-AE25-1D60A307D99C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{C2682400-EEB6-41AD-AE25-1D60A307D99C}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
||||
{C2682400-EEB6-41AD-AE25-1D60A307D99C}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
|
||||
{C2682400-EEB6-41AD-AE25-1D60A307D99C}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{C2682400-EEB6-41AD-AE25-1D60A307D99C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{C2682400-EEB6-41AD-AE25-1D60A307D99C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{C2682400-EEB6-41AD-AE25-1D60A307D99C}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||
{C2682400-EEB6-41AD-AE25-1D60A307D99C}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||
{C2682400-EEB6-41AD-AE25-1D60A307D99C}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{C2682400-EEB6-41AD-AE25-1D60A307D99C}.ReleaseXBAP|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{C2682400-EEB6-41AD-AE25-1D60A307D99C}.ReleaseXBAP|Any CPU.Build.0 = Release|Any CPU
|
||||
{C2682400-EEB6-41AD-AE25-1D60A307D99C}.ReleaseXBAP|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||
{C2682400-EEB6-41AD-AE25-1D60A307D99C}.ReleaseXBAP|Mixed Platforms.Build.0 = Release|Any CPU
|
||||
{C2682400-EEB6-41AD-AE25-1D60A307D99C}.ReleaseXBAP|x86.ActiveCfg = Release|Any CPU
|
||||
{F0F0F2B4-BB86-49B5-BA93-2642637033D6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{F0F0F2B4-BB86-49B5-BA93-2642637033D6}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{F0F0F2B4-BB86-49B5-BA93-2642637033D6}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
||||
{F0F0F2B4-BB86-49B5-BA93-2642637033D6}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
|
||||
{F0F0F2B4-BB86-49B5-BA93-2642637033D6}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{F0F0F2B4-BB86-49B5-BA93-2642637033D6}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{F0F0F2B4-BB86-49B5-BA93-2642637033D6}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{F0F0F2B4-BB86-49B5-BA93-2642637033D6}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||
{F0F0F2B4-BB86-49B5-BA93-2642637033D6}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||
{F0F0F2B4-BB86-49B5-BA93-2642637033D6}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{F0F0F2B4-BB86-49B5-BA93-2642637033D6}.ReleaseXBAP|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{F0F0F2B4-BB86-49B5-BA93-2642637033D6}.ReleaseXBAP|Any CPU.Build.0 = Release|Any CPU
|
||||
{F0F0F2B4-BB86-49B5-BA93-2642637033D6}.ReleaseXBAP|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||
{F0F0F2B4-BB86-49B5-BA93-2642637033D6}.ReleaseXBAP|Mixed Platforms.Build.0 = Release|Any CPU
|
||||
{F0F0F2B4-BB86-49B5-BA93-2642637033D6}.ReleaseXBAP|x86.ActiveCfg = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
56
UIUtils/CMTTrendModelClosePositionDialog.xaml
Normal file
@@ -0,0 +1,56 @@
|
||||
<Window x:Class="TradeBlotter.UIUtils.CMTTrendModelClosePositionDialog"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
Title="Close Position" Height="240" Width="200"
|
||||
xmlns:wpfx="http://schemas.xceed.com/wpf/xaml/toolkit"
|
||||
WindowStartupLocation="CenterScreen"
|
||||
SizeToContent="WidthAndHeight"
|
||||
MinWidth="200"
|
||||
MinHeight="200"
|
||||
WindowStyle="SingleBorderWindow"
|
||||
ResizeMode="CanMinimize">
|
||||
<wpfx:BusyIndicator Name="BusyBar" IsBusy="{Binding Path=BusyIndicator}" BusyContent="{Binding Path=BusyContent}">
|
||||
<StackPanel Margin="5" Orientation="Vertical">
|
||||
<Grid DockPanel.Dock="Left" Margin="0,2,4,2">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="6" />
|
||||
<ColumnDefinition Width="75*" />
|
||||
<ColumnDefinition Width="6" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="20*" />
|
||||
<RowDefinition Height="25" />
|
||||
<RowDefinition Height="25" />
|
||||
<RowDefinition Height="25" />
|
||||
<RowDefinition Height="25" />
|
||||
<RowDefinition Height="25" />
|
||||
<RowDefinition Height="25" />
|
||||
<RowDefinition Height="25" />
|
||||
<RowDefinition Height="25" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<Label Name="lblCompanyName" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="3"></Label>
|
||||
|
||||
<Label Name="lblSymbol" Grid.Row="2" Grid.Column="0">Symbol</Label>
|
||||
<TextBox Name="txtSymbol" IsEnabled="False" Grid.Row="2" IsReadOnly="True" Grid.Column="2" MinWidth="75" AcceptsReturn="true">Symbol</TextBox>
|
||||
|
||||
<Label Name="lblPurchaseDate" Grid.Row="3" Grid.Column="0" MinWidth="75">Purchase Date</Label>
|
||||
<DatePicker Name="dpPurchaseDate" IsEnabled="False" Grid.Row="3" Grid.Column="2"></DatePicker>
|
||||
|
||||
<Label Name="lblSellDate" Grid.Row="4" Grid.Column="0" MinWidth="75">Sell Date</Label>
|
||||
<DatePicker Name="dpSellDate" Grid.Row="4" Grid.Column="2"></DatePicker>
|
||||
|
||||
<Label Name="lblSellPrice" Grid.Row="5" Grid.Column="0">Sell Price</Label>
|
||||
<TextBox Name="txtSellPrice" Grid.Row="5" Grid.Column="2" MinWidth="75" LostFocus="txtSellPrice_OnLostFocusHandler" KeyDown="txtSellPrice_OnKeyDownHandler">100.00</TextBox>
|
||||
<Label FontWeight="Bold" FontSize="10" Name="lblSellPriceInstructions" Grid.Row="6" Grid.Column="0" Grid.ColumnSpan="3">(enter sell price then hit enter key)</Label>
|
||||
|
||||
<CheckBox Name="cbDeleteStop" Grid.Row="7" Grid.Column="0">Delete Stop</CheckBox>
|
||||
|
||||
<Button Content="_Ok" MinWidth="75" IsDefault="False" Margin="2" Name="btnOk" Click="btnOk_Click" Grid.Row="9" Grid.Column="0"/>
|
||||
<Button Content="_Cancel" MinWidth="75" IsCancel="True" Margin="2" Name="btnCancel" Click="btnCancel_Click" Grid.Row="9" Grid.Column="2"/>
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
</wpfx:BusyIndicator>
|
||||
</Window>
|
||||
159
UIUtils/CMTTrendModelClosePositionDialog.xaml.cs
Normal file
@@ -0,0 +1,159 @@
|
||||
using MarketData.DataAccess;
|
||||
using MarketData.MarketDataModel;
|
||||
using MarketData.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Media;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Shapes;
|
||||
using System.Windows.Threading;
|
||||
using Position=MarketData.Generator.CMTrend.Position;
|
||||
|
||||
namespace TradeBlotter.UIUtils
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for CMTTrendModelClosePositionDialog.xaml
|
||||
/// </summary>
|
||||
public partial class CMTTrendModelClosePositionDialog:Window
|
||||
{
|
||||
private ManualResetEvent manualResetEvent=new ManualResetEvent(false);
|
||||
private String Symbol{get;set;}
|
||||
private DateTime PurchaseDate { get; set; }
|
||||
private DateTime SellDate{get;set;}
|
||||
private double SellPrice { get; set; }
|
||||
private bool DeleteStop{get;set;}
|
||||
private bool Result { get; set; }
|
||||
|
||||
private CMTTrendModelClosePositionDialog(String title,Position position,bool hasStopLimit)
|
||||
{
|
||||
this.Background=new SolidColorBrush(Colors.AliceBlue);
|
||||
this.Owner=Application.Current.MainWindow;
|
||||
InitializeComponent();
|
||||
this.Loaded+=new RoutedEventHandler(CMTTrendModelClosePositionDialog_Loaded);
|
||||
this.Closing+=Window_Closing;
|
||||
|
||||
dpPurchaseDate.SelectedDateChanged+=dpPurchaseDate_SelectionChanged;
|
||||
dpSellDate.SelectedDateChanged+=dpPurchaseDate_SelectionChanged;
|
||||
cbDeleteStop.Click+=cbDeleteStop_SelectionChanged;
|
||||
|
||||
Title=title;
|
||||
Symbol=position.Symbol;
|
||||
PurchaseDate=position.PurchaseDate;
|
||||
SellDate=DateTime.Now.Date;
|
||||
SellPrice=position.TrailingStopLimit;
|
||||
DeleteStop=hasStopLimit;
|
||||
|
||||
txtSymbol.Text=Symbol;
|
||||
dpPurchaseDate.SelectedDate=PurchaseDate;
|
||||
dpSellDate.SelectedDate=SellDate;
|
||||
cbDeleteStop.IsChecked=DeleteStop;
|
||||
|
||||
UpdateSellPrice();
|
||||
UpdateCompanyName();
|
||||
}
|
||||
public ManualResetEvent Event { get { return manualResetEvent; } }
|
||||
public static Position Prompt(string title,Position position,bool hasStopLimit,ref bool deleteStop)
|
||||
{
|
||||
CMTTrendModelClosePositionDialog cmtTrendModelClosePositionDialog=new CMTTrendModelClosePositionDialog(title,position,hasStopLimit);
|
||||
try { cmtTrendModelClosePositionDialog.ShowDialog(); }
|
||||
catch(Exception) { return null; }
|
||||
cmtTrendModelClosePositionDialog.Event.WaitOne();
|
||||
if( cmtTrendModelClosePositionDialog.Result)
|
||||
{
|
||||
position.SellDate=cmtTrendModelClosePositionDialog.SellDate;
|
||||
position.CurrentPrice=cmtTrendModelClosePositionDialog.SellPrice;
|
||||
deleteStop=cmtTrendModelClosePositionDialog.DeleteStop;
|
||||
return position;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
void CMTTrendModelClosePositionDialog_Loaded(object sender,RoutedEventArgs e)
|
||||
{
|
||||
txtSellPrice.Focus();
|
||||
}
|
||||
private void btnOk_Click(object sender,RoutedEventArgs e)
|
||||
{
|
||||
Result=Validate();
|
||||
if(!Result)
|
||||
{
|
||||
SystemSounds.Beep.Play();
|
||||
return;
|
||||
}
|
||||
Close();
|
||||
Event.Set();
|
||||
return;
|
||||
}
|
||||
private void cbDeleteStop_SelectionChanged(object sender,RoutedEventArgs e)
|
||||
{
|
||||
DeleteStop=cbDeleteStop.IsChecked.Value;
|
||||
}
|
||||
private void txtSellPrice_OnLostFocusHandler(Object sender,RoutedEventArgs routedEventArgs)
|
||||
{
|
||||
HandleSellPriceEvents();
|
||||
}
|
||||
private void txtSellPrice_OnKeyDownHandler(object sender,KeyEventArgs e)
|
||||
{
|
||||
if(e.Key==Key.Return)
|
||||
{
|
||||
HandleSellPriceEvents();
|
||||
}
|
||||
}
|
||||
private void HandleSellPriceEvents()
|
||||
{
|
||||
double value=0.00;
|
||||
value=Utility.ParseCurrency(txtSellPrice.Text);
|
||||
if(SellPrice.Equals(value)) return;
|
||||
SellPrice=value;
|
||||
UpdateSellPrice();
|
||||
}
|
||||
private void dpPurchaseDate_SelectionChanged(object sender,RoutedEventArgs e)
|
||||
{
|
||||
if(null==dpPurchaseDate.SelectedDate) return;
|
||||
PurchaseDate=dpPurchaseDate.SelectedDate.Value;
|
||||
}
|
||||
private void dpSellDate_SelectionChanged(object sender,RoutedEventArgs e)
|
||||
{
|
||||
if(null==dpSellDate.SelectedDate) return;
|
||||
SellDate=dpSellDate.SelectedDate.Value;
|
||||
}
|
||||
private void Window_Closing(object sender,System.ComponentModel.CancelEventArgs e)
|
||||
{
|
||||
Event.Set();
|
||||
}
|
||||
private void btnCancel_Click(object sender,RoutedEventArgs e)
|
||||
{
|
||||
Result=false;
|
||||
Close();
|
||||
Event.Set();
|
||||
}
|
||||
private bool Validate()
|
||||
{
|
||||
DateGenerator dateGenerator=new DateGenerator();
|
||||
if(null==Symbol) return false;
|
||||
if(Utility.IsEpoch(PurchaseDate)) return false;
|
||||
if(Utility.IsEpoch(SellDate))return false;
|
||||
if(!dateGenerator.IsMarketOpen(SellDate)) return false;
|
||||
if(double.IsNaN(SellPrice)) return false;
|
||||
return true;
|
||||
}
|
||||
private void UpdateSellPrice()
|
||||
{
|
||||
txtSellPrice.Text=Utility.FormatCurrency(SellPrice);
|
||||
}
|
||||
private void UpdateCompanyName()
|
||||
{
|
||||
CompanyProfile companyProfile=CompanyProfileDA.GetCompanyProfile(Symbol);
|
||||
if(null==companyProfile||null==companyProfile.CompanyName) return;
|
||||
lblCompanyName.Content=companyProfile.CompanyName.ToUpper();
|
||||
}
|
||||
}
|
||||
}
|
||||
66
UIUtils/CMTTrendModelEditPositionDialog.xaml
Normal file
@@ -0,0 +1,66 @@
|
||||
<Window x:Class="TradeBlotter.UIUtils.CMTTrendModelEditPositionDialog"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
Title="Edit Position" Height="319.586" Width="196.793"
|
||||
xmlns:wpfx="http://schemas.xceed.com/wpf/xaml/toolkit"
|
||||
WindowStartupLocation="CenterScreen"
|
||||
SizeToContent="WidthAndHeight"
|
||||
MinWidth="200"
|
||||
MinHeight="340"
|
||||
WindowStyle="SingleBorderWindow"
|
||||
ResizeMode="CanMinimize">
|
||||
<wpfx:BusyIndicator Name="BusyBar" IsBusy="{Binding Path=BusyIndicator}" BusyContent="{Binding Path=BusyContent}">
|
||||
<StackPanel Margin="5" Orientation="Vertical">
|
||||
<Grid DockPanel.Dock="Left" Margin="0,2,4,2">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="6" />
|
||||
<ColumnDefinition Width="75*" />
|
||||
<ColumnDefinition Width="6" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="20*" />
|
||||
<RowDefinition Height="25" />
|
||||
<RowDefinition Height="25" />
|
||||
<RowDefinition Height="25" />
|
||||
<RowDefinition Height="25" />
|
||||
<RowDefinition Height="25" />
|
||||
<RowDefinition Height="25" />
|
||||
<RowDefinition Height="25" />
|
||||
<RowDefinition Height="25" />
|
||||
<RowDefinition Height="25" />
|
||||
<RowDefinition Height="25" />
|
||||
<RowDefinition Height="25" />
|
||||
<RowDefinition Height="25" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<Label Name="lblCompanyName" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="3"></Label>
|
||||
|
||||
<Label Name="lblSymbol" Grid.Row="2" Grid.Column="0">Symbol</Label>
|
||||
<TextBox Name="txtSymbol" IsEnabled="False" Grid.Row="2" IsReadOnly="True" Grid.Column="2" MinWidth="75" AcceptsReturn="true">Symbol</TextBox>
|
||||
|
||||
<Label Name="lblPurchaseDate" Grid.Row="3" Grid.Column="0" MinWidth="75">Purchase Date</Label>
|
||||
<DatePicker Name="dpPurchaseDate" IsEnabled="False" Grid.Row="3" Grid.Column="2"></DatePicker>
|
||||
|
||||
<Label Name="lblPurchasePrice" Grid.Row="4" Grid.Column="0" MinWidth="75">Purchase Price</Label>
|
||||
<TextBox Name="txtPurchasePrice" Grid.Row="4" Grid.Column="2" LostFocus="txtPurchasePrice__OnLostFocusHandler" KeyDown="txtPurchasePrice_OnKeyDownHandler"></TextBox>
|
||||
<Label FontWeight="Bold" FontSize="10" Name="lblPurchasePriceInstructions" Grid.Row="5" Grid.Column="0" Grid.ColumnSpan="3">(enter purchase price then hit enter key)</Label>
|
||||
|
||||
<Label Name="lblInitialStop" Grid.Row="6" Grid.Column="0">Initial Stop</Label>
|
||||
<TextBox Name="txtInitialStop" Grid.Row="6" Grid.Column="2" MinWidth="75" LostFocus="txtInitialStop__OnLostFocusHandler" KeyDown="txtInitialStop_OnKeyDownHandler">100.00</TextBox>
|
||||
<CheckBox Name="cbSyncTrailingStop" Grid.Row="7" Grid.Column="0">Sync Trailing Stop</CheckBox>
|
||||
<Label FontWeight="Bold" FontSize="10" Name="lblInitialStopInstructions" Grid.Row="8" Grid.Column="0" Grid.ColumnSpan="3">(enter initial stop then hit enter key)</Label>
|
||||
<Label FontWeight="Bold" FontSize="10" Name="lblInitialStopRecommendation" Grid.Row="9" Grid.Column="0" Grid.ColumnSpan="3"></Label>
|
||||
|
||||
<Label Name="lblTrailingStop" Grid.Row="10" Grid.Column="0">Trailing Stop</Label>
|
||||
<TextBox Name="txtTrailingStop" Grid.Row="10" Grid.Column="2" MinWidth="75" LostFocus="txtTrailingStop__OnLostFocusHandler" KeyDown="txtTrailingStop_OnKeyDownHandler">100.00</TextBox>
|
||||
<Label FontWeight="Bold" FontSize="10" Name="lblTrailingStopInstructions" Grid.Row="11" Grid.Column="0" Grid.ColumnSpan="3">(enter trailing stop then hit enter key)</Label>
|
||||
|
||||
<Button Content="_Ok" MinWidth="75" IsDefault="False" Margin="2" Name="btnOk" Click="btnOk_Click" Grid.Row="12" Grid.Column="0"/>
|
||||
<Button Content="_Cancel" MinWidth="75" IsCancel="True" Margin="2" Name="btnCancel" Click="btnCancel_Click" Grid.Row="12" Grid.Column="2"/>
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
</wpfx:BusyIndicator>
|
||||
</Window>
|
||||
|
||||
228
UIUtils/CMTTrendModelEditPositionDialog.xaml.cs
Normal file
@@ -0,0 +1,228 @@
|
||||
using MarketData.DataAccess;
|
||||
using MarketData.MarketDataModel;
|
||||
using MarketData.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Shapes;
|
||||
using System.Windows.Threading;
|
||||
using System.Media;
|
||||
using Position=MarketData.Generator.CMTrend.Position;
|
||||
|
||||
|
||||
namespace TradeBlotter.UIUtils
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for CMTTrendModelEditPositionDialog.xaml
|
||||
/// </summary>
|
||||
public partial class CMTTrendModelEditPositionDialog:Window
|
||||
{
|
||||
private ManualResetEvent manualResetEvent=new ManualResetEvent(false);
|
||||
private String Symbol { get; set; }
|
||||
private DateTime PurchaseDate { get; set; }
|
||||
private double PurchasePrice{get;set;}
|
||||
private double TrailingStop{get;set;}
|
||||
private double InitialStop{get;set;}
|
||||
private double PositionRiskPercentDecimal{get;set;}
|
||||
private bool Result { get; set; }
|
||||
|
||||
private CMTTrendModelEditPositionDialog(String title,Position position)
|
||||
{
|
||||
this.Background=new SolidColorBrush(Colors.AliceBlue);
|
||||
this.Owner=Application.Current.MainWindow;
|
||||
InitializeComponent();
|
||||
this.Loaded+=new RoutedEventHandler(CMTTrendModelEditPositionDialog_Loaded);
|
||||
this.Closing+=Window_Closing;
|
||||
|
||||
dpPurchaseDate.SelectedDateChanged+=dpPurchaseDate_SelectionChanged;
|
||||
|
||||
Title=title;
|
||||
Symbol=position.Symbol;
|
||||
PurchaseDate=position.PurchaseDate;
|
||||
PurchasePrice=position.PurchasePrice;
|
||||
TrailingStop=position.TrailingStopLimit;
|
||||
InitialStop=position.InitialStopLimit;
|
||||
PositionRiskPercentDecimal=position.PositionRiskPercentDecimal;
|
||||
|
||||
txtSymbol.Text=Symbol;
|
||||
dpPurchaseDate.SelectedDate=PurchaseDate;
|
||||
|
||||
lblInitialStopRecommendation.FontSize=12;
|
||||
|
||||
cbSyncTrailingStop.IsChecked=true;
|
||||
|
||||
UpdatePurchasePrice();
|
||||
UpdateInitialStop();
|
||||
UpdateTrailingStop();
|
||||
UpdateCompanyName();
|
||||
UpdateInitialStopRecommendation();
|
||||
}
|
||||
public ManualResetEvent Event { get { return manualResetEvent; } }
|
||||
public static Position Prompt(string title,Position position)
|
||||
{
|
||||
CMTTrendModelEditPositionDialog mmTrendModelEditPositionDialog=new CMTTrendModelEditPositionDialog(title,position);
|
||||
try { mmTrendModelEditPositionDialog.ShowDialog(); }
|
||||
catch(Exception) { return null; }
|
||||
mmTrendModelEditPositionDialog.Event.WaitOne();
|
||||
if(mmTrendModelEditPositionDialog.Result)
|
||||
{
|
||||
position.PurchaseDate=mmTrendModelEditPositionDialog.PurchaseDate;
|
||||
position.PurchasePrice=mmTrendModelEditPositionDialog.PurchasePrice;
|
||||
position.TrailingStopLimit=mmTrendModelEditPositionDialog.TrailingStop;
|
||||
position.InitialStopLimit=mmTrendModelEditPositionDialog.InitialStop;
|
||||
return position;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
void CMTTrendModelEditPositionDialog_Loaded(object sender,RoutedEventArgs e)
|
||||
{
|
||||
txtPurchasePrice.Focus();
|
||||
}
|
||||
private void btnOk_Click(object sender,RoutedEventArgs e)
|
||||
{
|
||||
Result=Validate();
|
||||
if(!Result)
|
||||
{
|
||||
SystemSounds.Beep.Play();
|
||||
return;
|
||||
}
|
||||
Close();
|
||||
Event.Set();
|
||||
return;
|
||||
}
|
||||
// *******************************************************************************************************************************************************************************
|
||||
// ********************************************************************************** P U R C H A S E P R I C E ***************************************************************
|
||||
// *******************************************************************************************************************************************************************************
|
||||
private void txtPurchasePrice__OnLostFocusHandler(Object sender,RoutedEventArgs routedEventArgs)
|
||||
{
|
||||
HandlePurchasePriceEvents();
|
||||
}
|
||||
private void txtPurchasePrice_OnKeyDownHandler(object sender,KeyEventArgs e)
|
||||
{
|
||||
if(e.Key==Key.Return)
|
||||
{
|
||||
HandlePurchasePriceEvents();
|
||||
}
|
||||
}
|
||||
private void HandlePurchasePriceEvents()
|
||||
{
|
||||
double value=0.00;
|
||||
value=Utility.ParseCurrency(txtPurchasePrice.Text);
|
||||
if(PurchasePrice.Equals(value)) return;
|
||||
PurchasePrice=value;
|
||||
UpdatePurchasePrice();
|
||||
UpdateInitialStopRecommendation();
|
||||
}
|
||||
private void UpdatePurchasePrice()
|
||||
{
|
||||
txtPurchasePrice.Text=Utility.FormatCurrency(PurchasePrice);
|
||||
}
|
||||
// *******************************************************************************************************************************************************************************
|
||||
// ********************************************************************************** I N I T I A L S T O P R E C O M M E N D A T I O N **************************************
|
||||
// *******************************************************************************************************************************************************************************
|
||||
private void UpdateInitialStopRecommendation()
|
||||
{
|
||||
lblInitialStopRecommendation.Content="Recommended Initial Stop: "+Utility.FormatCurrency(PurchasePrice*(1.00-PositionRiskPercentDecimal),2);
|
||||
}
|
||||
// *******************************************************************************************************************************************************************************
|
||||
// ********************************************************************************** I N I T I A L S T O P *****************************************************************
|
||||
// *******************************************************************************************************************************************************************************
|
||||
private void txtInitialStop__OnLostFocusHandler(Object sender,RoutedEventArgs routedEventArgs)
|
||||
{
|
||||
HandleInitialStopEvents();
|
||||
}
|
||||
private void txtInitialStop_OnKeyDownHandler(object sender,KeyEventArgs e)
|
||||
{
|
||||
if(e.Key==Key.Return)
|
||||
{
|
||||
HandleInitialStopEvents();
|
||||
}
|
||||
}
|
||||
private void HandleInitialStopEvents()
|
||||
{
|
||||
double value=0.00;
|
||||
value=Utility.ParseCurrency(txtInitialStop.Text);
|
||||
if(InitialStop.Equals(value)) return;
|
||||
InitialStop=value;
|
||||
UpdateInitialStop();
|
||||
if(null!= cbSyncTrailingStop.IsChecked && cbSyncTrailingStop.IsChecked.Value)
|
||||
{
|
||||
TrailingStop=value;
|
||||
UpdateTrailingStop();
|
||||
}
|
||||
}
|
||||
private void UpdateInitialStop()
|
||||
{
|
||||
txtInitialStop.Text=Utility.FormatCurrency(InitialStop);
|
||||
}
|
||||
// *******************************************************************************************************************************************************************************
|
||||
// ********************************************************************************** T R A I L I N G S T O P *****************************************************************
|
||||
// *******************************************************************************************************************************************************************************
|
||||
private void txtTrailingStop__OnLostFocusHandler(Object sender,RoutedEventArgs routedEventArgs)
|
||||
{
|
||||
HandleTrailingStopEvents();
|
||||
}
|
||||
private void txtTrailingStop_OnKeyDownHandler(object sender,KeyEventArgs e)
|
||||
{
|
||||
if(e.Key==Key.Return)
|
||||
{
|
||||
HandleTrailingStopEvents();
|
||||
}
|
||||
}
|
||||
private void HandleTrailingStopEvents()
|
||||
{
|
||||
double value=0.00;
|
||||
value=Utility.ParseCurrency(txtTrailingStop.Text);
|
||||
if(TrailingStop.Equals(value)) return;
|
||||
TrailingStop=value;
|
||||
UpdateTrailingStop();
|
||||
}
|
||||
private void UpdateTrailingStop()
|
||||
{
|
||||
txtTrailingStop.Text=Utility.FormatCurrency(TrailingStop);
|
||||
}
|
||||
// *********************************************************************************************************************************************************************************
|
||||
private void dpPurchaseDate_SelectionChanged(object sender,RoutedEventArgs e)
|
||||
{
|
||||
if(null==dpPurchaseDate.SelectedDate) return;
|
||||
PurchaseDate=dpPurchaseDate.SelectedDate.Value;
|
||||
}
|
||||
// ***********************************************************************************************************************************************************************************
|
||||
private void Window_Closing(object sender,System.ComponentModel.CancelEventArgs e)
|
||||
{
|
||||
Event.Set();
|
||||
}
|
||||
private void btnCancel_Click(object sender,RoutedEventArgs e)
|
||||
{
|
||||
Result=false;
|
||||
Close();
|
||||
Event.Set();
|
||||
}
|
||||
private bool Validate()
|
||||
{
|
||||
DateGenerator dateGenerator=new DateGenerator();
|
||||
if(null==Symbol) return false;
|
||||
if(Utility.IsEpoch(PurchaseDate)) return false;
|
||||
if(!dateGenerator.IsMarketOpen(PurchaseDate))return false;
|
||||
if(double.IsNaN(PurchasePrice)) return false;
|
||||
if(double.IsNaN(TrailingStop)) return false;
|
||||
if(double.IsNaN(InitialStop)) return false;
|
||||
return true;
|
||||
}
|
||||
private void UpdateCompanyName()
|
||||
{
|
||||
CompanyProfile companyProfile=CompanyProfileDA.GetCompanyProfile(Symbol);
|
||||
if(null==companyProfile||null==companyProfile.CompanyName) return;
|
||||
lblCompanyName.Content=companyProfile.CompanyName.ToUpper();
|
||||
}
|
||||
}
|
||||
}
|
||||
76
UIUtils/ProformaAddPositionDialog.xaml
Normal file
@@ -0,0 +1,76 @@
|
||||
<Window x:Class="TradeBlotter.UIUtils.ProformaAddPositionDialog"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
Title="ProformaAddPosition" Height="300" Width="300"
|
||||
xmlns:wpfx="http://schemas.xceed.com/wpf/xaml/toolkit"
|
||||
WindowStartupLocation="CenterScreen"
|
||||
SizeToContent="WidthAndHeight"
|
||||
MinWidth="460"
|
||||
MinHeight="100"
|
||||
WindowStyle="SingleBorderWindow"
|
||||
ResizeMode="CanMinimize">
|
||||
<wpfx:BusyIndicator Name="BusyBar" IsBusy="{Binding Path=BusyIndicator}" BusyContent="{Binding Path=BusyContent}">
|
||||
<StackPanel Margin="5" Orientation="Vertical">
|
||||
<Grid DockPanel.Dock="Left" Margin="0,2,4,2">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="6" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="6" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="6" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="6" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="6" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="20*" />
|
||||
<RowDefinition Height="25" />
|
||||
<RowDefinition Height="25" />
|
||||
<RowDefinition Height="25" />
|
||||
<RowDefinition Height="25" />
|
||||
<RowDefinition Height="25" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<Label Name="lblAccount" Grid.Row="2" Grid.Column="0">Account</Label>
|
||||
<ComboBox Name="cbAccounts" Grid.Row="3" Grid.Column="0" MinWidth="75" UseLayoutRounding="False" >
|
||||
<ComboBox.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<VirtualizingStackPanel/>
|
||||
</ItemsPanelTemplate>
|
||||
</ComboBox.ItemsPanel>
|
||||
</ComboBox>
|
||||
|
||||
<Label Name="lblSymbol" Grid.Row="2" Grid.Column="2">Symbol</Label>
|
||||
<ComboBox Name="cbSymbols" Grid.Row="3" Grid.Column="2" MinWidth="75" UseLayoutRounding="False" >
|
||||
<ComboBox.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<VirtualizingStackPanel/>
|
||||
</ItemsPanelTemplate>
|
||||
</ComboBox.ItemsPanel>
|
||||
</ComboBox>
|
||||
|
||||
<Label Name="lblExposure" Grid.Row="2" Grid.Column="4">Exposure</Label>
|
||||
<TextBox Name="txtExposure" Grid.Row="3" Grid.Column="4" MinWidth="75" AcceptsReturn="true"/>
|
||||
|
||||
<Label Name="lblPurchaseDate" Grid.Row="2" Grid.Column="6" MinWidth="75">Purchase Date</Label>
|
||||
<DatePicker Name="dpPurchaseDate" Grid.Row="3" Grid.Column="6"></DatePicker>
|
||||
|
||||
<Label Name="lblPurchasePrice" Grid.Row="2" Grid.Column="8">Purchase Price</Label>
|
||||
<TextBox Name="txtPurchasePrice" Grid.Row="3" Grid.Column="8" MinWidth="75" AcceptsReturn="true"/>
|
||||
|
||||
<Label Name="lblShares" Grid.Row="4" Grid.Column="8">Shares</Label>
|
||||
<TextBox Name="txtShares" Grid.Row="5" Grid.Column="8" MinWidth="75" AcceptsReturn="true"/>
|
||||
|
||||
<Label Name="lblCompanyName" Grid.Row="4" Grid.Column="0" Grid.ColumnSpan="7"></Label>
|
||||
|
||||
<Button Content="_Ok" MinWidth="75" IsDefault="True" Margin="2" Name="btnOk" Click="btnOk_Click" Grid.Row="5" Grid.Column="0"/>
|
||||
<Button Content="_Cancel" MinWidth="75" IsCancel="True" Margin="2" Name="btnCancel" Click="btnCancel_Click" Grid.Row="6" Grid.Column="2"/>
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
</wpfx:BusyIndicator>
|
||||
</Window>
|
||||
|
||||
217
UIUtils/ProformaAddPositionDialog.xaml.cs
Normal file
@@ -0,0 +1,217 @@
|
||||
using MarketData.DataAccess;
|
||||
using MarketData.MarketDataModel;
|
||||
using MarketData.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Shapes;
|
||||
using System.Windows.Threading;
|
||||
|
||||
namespace TradeBlotter.UIUtils
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for ProformaAddPosition.xaml
|
||||
/// </summary>
|
||||
public partial class ProformaAddPositionDialog : Window
|
||||
{
|
||||
private List<String> symbols;
|
||||
private List<String> accounts;
|
||||
private ManualResetEvent manualResetEvent = new ManualResetEvent(false);
|
||||
|
||||
private String Account { get; set; }
|
||||
private DateTime PurchaseDate { get; set; }
|
||||
private double PurchasePrice { get; set; }
|
||||
private String SelectedSymbol { get; set; }
|
||||
private double Exposure { get; set; }
|
||||
private double Shares { get; set; }
|
||||
private bool Result { get; set; }
|
||||
|
||||
private ProformaAddPositionDialog(String title,String account, DateTime purchaseDate, PortfolioTrades portfolioTrades)
|
||||
{
|
||||
this.Background = new SolidColorBrush(Colors.AliceBlue);
|
||||
this.Owner = Application.Current.MainWindow;
|
||||
InitializeComponent();
|
||||
this.Loaded += new RoutedEventHandler(AddPositionDialog_Loaded);
|
||||
this.Closing += Window_Closing;
|
||||
cbSymbols.SelectionChanged += cbSymbols_SelectionChanged;
|
||||
txtPurchasePrice.SelectionChanged += txtPurchasePrice_SelectionChanged;
|
||||
txtShares.SelectionChanged += txtShares_SelectionChanged;
|
||||
txtExposure.TextChanged += txtExposure_SelectionChanged;
|
||||
dpPurchaseDate.SelectedDateChanged += dpPurchaseDate_SelectionChanged;
|
||||
|
||||
symbols=PricingDA.GetSymbols();
|
||||
Title = title;
|
||||
Shares = 0.00;
|
||||
Exposure = 0.00;
|
||||
Account = account;
|
||||
accounts=PortfolioDA.GetAccounts();
|
||||
if(null==Account||!accounts.Any(x=>x.Equals(account)))Account=accounts[0];
|
||||
cbAccounts.ItemsSource = accounts;
|
||||
cbAccounts.SelectedItem = Account;
|
||||
cbSymbols.ItemsSource = symbols;
|
||||
cbSymbols.SelectedItem = symbols[0];
|
||||
if (Utility.IsEpoch(purchaseDate)) PurchaseDate = PricingDA.GetLatestDate();
|
||||
else PurchaseDate = purchaseDate;
|
||||
dpPurchaseDate.SelectedDate = PurchaseDate;
|
||||
UpdatePrice();
|
||||
txtShares.Text = Utility.FormatNumber(Shares, 3);
|
||||
}
|
||||
public ManualResetEvent Event { get {return manualResetEvent;}}
|
||||
public static PortfolioTrades Prompt(string title,String account,DateTime effectiveDate,PortfolioTrades portfolioTrades)
|
||||
{
|
||||
ProformaAddPositionDialog proformaAddPositionDialog = new ProformaAddPositionDialog(title,account, effectiveDate, portfolioTrades);
|
||||
proformaAddPositionDialog.SelectedSymbol = null;
|
||||
try { proformaAddPositionDialog.ShowDialog(); }
|
||||
catch (Exception) { return portfolioTrades; }
|
||||
proformaAddPositionDialog.Event.WaitOne();
|
||||
if (proformaAddPositionDialog.Result == true)
|
||||
{
|
||||
PortfolioTrade portfolioTrade = proformaAddPositionDialog.CreatePortfolioTrade();
|
||||
portfolioTrades.Add(portfolioTrade);
|
||||
}
|
||||
return portfolioTrades;
|
||||
}
|
||||
void AddPositionDialog_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
cbSymbols.Focus();
|
||||
}
|
||||
public PortfolioTrade CreatePortfolioTrade()
|
||||
{
|
||||
try
|
||||
{
|
||||
PortfolioTrade portfolioTrade=new PortfolioTrade();
|
||||
portfolioTrade.Account = Account;
|
||||
portfolioTrade.BuySell = "B";
|
||||
portfolioTrade.Status = "OPEN";
|
||||
portfolioTrade.Price = PurchasePrice;
|
||||
portfolioTrade.Symbol = SelectedSymbol;
|
||||
portfolioTrade.Shares = Shares;
|
||||
portfolioTrade.TradeDate = PurchaseDate;
|
||||
return portfolioTrade;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
private void btnOk_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Result = Validate();
|
||||
Close();
|
||||
Event.Set();
|
||||
return;
|
||||
}
|
||||
private void cbSymbols_SelectionChanged(object sender, RoutedEventArgs e)
|
||||
{
|
||||
SelectedSymbol = cbSymbols.SelectedValue.ToString();
|
||||
UpdatePrice();
|
||||
UpdateExposure();
|
||||
UpdateCompanyName();
|
||||
}
|
||||
private void txtPurchasePrice_SelectionChanged(object sender, RoutedEventArgs e)
|
||||
{
|
||||
double value=0.00;
|
||||
value = Utility.ParseCurrency(txtPurchasePrice.Text);
|
||||
if (PurchasePrice.Equals(value)) return;
|
||||
PurchasePrice = value;
|
||||
if (!txtPurchasePrice.IsFocused)
|
||||
{
|
||||
UpdatePrice();
|
||||
UpdateExposure();
|
||||
}
|
||||
else UpdateExposure();
|
||||
}
|
||||
private void txtShares_SelectionChanged(object sender, RoutedEventArgs e)
|
||||
{
|
||||
double value = 0.00;
|
||||
double.TryParse(txtShares.Text, out value);
|
||||
if (Shares.Equals(value)) return;
|
||||
Shares = Math.Round(value,3);
|
||||
if (txtShares.IsFocused)
|
||||
{
|
||||
UpdatePrice();
|
||||
UpdateExposure();
|
||||
}
|
||||
}
|
||||
private void dpPurchaseDate_SelectionChanged(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (null == dpPurchaseDate.SelectedDate) return;
|
||||
PurchaseDate = dpPurchaseDate.SelectedDate.Value;
|
||||
UpdatePrice();
|
||||
UpdateExposure();
|
||||
}
|
||||
private void txtExposure_SelectionChanged(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (null == txtExposure.Text || "".Equals(txtExposure.Text)) return;
|
||||
double value=Utility.ParseCurrency(txtExposure.Text);
|
||||
if (0.00 == value || value==Exposure) return;
|
||||
txtExposure.Text = Utility.FormatCurrency(value);
|
||||
txtExposure.CaretIndex = txtExposure.Text.IndexOf('.');
|
||||
if (0.00 == PurchasePrice) return;
|
||||
Shares = Math.Round(value / PurchasePrice,3);
|
||||
if (txtExposure.IsFocused)
|
||||
{
|
||||
UpdateShares();
|
||||
}
|
||||
}
|
||||
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
|
||||
{
|
||||
Event.Set();
|
||||
}
|
||||
private void btnCancel_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Result = false;
|
||||
Close();
|
||||
Event.Set();
|
||||
}
|
||||
private bool Validate()
|
||||
{
|
||||
if (null == SelectedSymbol) return false;
|
||||
if(null==Account)return false;
|
||||
if(Utility.IsEpoch(PurchaseDate))return false;
|
||||
if (double.IsNaN(PurchasePrice)) return false;
|
||||
if (0 == Shares) return false;
|
||||
return true;
|
||||
}
|
||||
private void UpdatePrice()
|
||||
{
|
||||
if (Utility.IsEpoch(PurchaseDate)) return;
|
||||
Price price = PricingDA.GetPrice(SelectedSymbol, PurchaseDate);
|
||||
if (null == price)
|
||||
{
|
||||
DateGenerator dateGenerator = new DateGenerator();
|
||||
DateTime prevBusinessDate=dateGenerator.FindPrevBusinessDay(PurchaseDate);
|
||||
price = PricingDA.GetPrice(SelectedSymbol, prevBusinessDate);
|
||||
if (null != price) { PurchasePrice = price.Close; PurchaseDate = prevBusinessDate; dpPurchaseDate.SelectedDate = PurchaseDate; }
|
||||
else PurchasePrice = 0.00;
|
||||
}
|
||||
else PurchasePrice = price.Close;
|
||||
txtPurchasePrice.Text = Utility.FormatCurrency(PurchasePrice);
|
||||
}
|
||||
private void UpdateExposure()
|
||||
{
|
||||
Exposure = PurchasePrice * Shares;
|
||||
txtExposure.Text = Utility.FormatCurrency(Exposure);
|
||||
}
|
||||
private void UpdateShares()
|
||||
{
|
||||
txtShares.Text = Utility.FormatNumber(Shares,3);
|
||||
}
|
||||
private void UpdateCompanyName()
|
||||
{
|
||||
CompanyProfile companyProfile = CompanyProfileDA.GetCompanyProfile(SelectedSymbol);
|
||||
if (null == companyProfile||null==companyProfile.CompanyName) return;
|
||||
lblCompanyName.Content = companyProfile.CompanyName.ToUpper();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
76
UIUtils/ProformaAddRiskDividendParityPositionDialog.xaml
Normal file
@@ -0,0 +1,76 @@
|
||||
<Window x:Class="TradeBlotter.UIUtils.ProformaAddRiskDividendParityPositionDialog"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:wpfx="http://schemas.xceed.com/wpf/xaml/toolkit"
|
||||
WindowStartupLocation="CenterScreen"
|
||||
SizeToContent="WidthAndHeight"
|
||||
WindowStyle="SingleBorderWindow"
|
||||
ResizeMode="CanMinimize"
|
||||
Title="ProformaAddRiskDividendParityPositionDialog" Height="300" Width="500">
|
||||
<wpfx:BusyIndicator Name="BusyBar" IsBusy="{Binding Path=BusyIndicator}" BusyContent="{Binding Path=BusyContent}">
|
||||
<StackPanel Margin="5" Orientation="Vertical">
|
||||
<Grid DockPanel.Dock="Left" Margin="0,2,4,2">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="6" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="6" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="6" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="6" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="6" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="20*" />
|
||||
<RowDefinition Height="25" />
|
||||
<RowDefinition Height="25" />
|
||||
<RowDefinition Height="25" />
|
||||
<RowDefinition Height="25" />
|
||||
<RowDefinition Height="25" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!--<Label Name="lblAccount" Grid.Row="2" Grid.Column="0">Account</Label>
|
||||
<ComboBox Name="cbAccounts" Grid.Row="3" Grid.Column="0" MinWidth="75" UseLayoutRounding="False" >
|
||||
<ComboBox.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<VirtualizingStackPanel/>
|
||||
</ItemsPanelTemplate>
|
||||
</ComboBox.ItemsPanel>
|
||||
</ComboBox>-->
|
||||
|
||||
<Label Name="lblSymbol" Grid.Row="2" Grid.Column="0">Symbol</Label>
|
||||
<TextBox Name="txtSymbol" Grid.Row="3" Grid.Column="0" MinWidth="75" AcceptsReturn="true"/>
|
||||
<!--<ComboBox Name="cbSymbols" Grid.Row="3" Grid.Column="2" MinWidth="75" UseLayoutRounding="False" >
|
||||
<ComboBox.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<VirtualizingStackPanel/>
|
||||
</ItemsPanelTemplate>
|
||||
</ComboBox.ItemsPanel>
|
||||
</ComboBox>-->
|
||||
|
||||
<Label Name="lblExposure" Grid.Row="2" Grid.Column="2">Exposure</Label>
|
||||
<TextBox Name="txtExposure" Grid.Row="3" Grid.Column="2" MinWidth="75" AcceptsReturn="true"/>
|
||||
|
||||
<Label Name="lblPurchaseDate" Grid.Row="2" Grid.Column="6" MinWidth="75">Purchase Date</Label>
|
||||
<TextBox Name="txtPurchaseDate" Grid.Row="3" Grid.Column="6" MinWidth="75" AcceptsReturn="true" IsReadOnly="true"/>
|
||||
<!--<DatePicker Name="dpPurchaseDate" Grid.Row="3" Grid.Column="6"></DatePicker>-->
|
||||
|
||||
<Label Name="lblPurchasePrice" Grid.Row="2" Grid.Column="8">Purchase Price</Label>
|
||||
<TextBox Name="txtPurchasePrice" Grid.Row="3" Grid.Column="8" MinWidth="75" AcceptsReturn="true"/>
|
||||
|
||||
<Label Name="lblShares" Grid.Row="2" Grid.Column="10">Shares</Label>
|
||||
<TextBox Name="txtShares" Grid.Row="3" Grid.Column="10" MinWidth="75" AcceptsReturn="true"/>
|
||||
|
||||
<Label Name="lblCompanyName" Grid.Row="4" Grid.Column="0" Grid.ColumnSpan="7"></Label>
|
||||
|
||||
<Button Content="_Ok" MinWidth="75" IsDefault="True" Margin="2" Name="btnOk" Click="btnOk_Click" Grid.Row="5" Grid.Column="0"/>
|
||||
<Button Content="_Cancel" MinWidth="75" IsCancel="True" Margin="2" Name="btnCancel" Click="btnCancel_Click" Grid.Row="6" Grid.Column="2"/>
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
</wpfx:BusyIndicator>
|
||||
</Window>
|
||||
|
||||
223
UIUtils/ProformaAddRiskDividendParityPositionDialog.xaml.cs
Normal file
@@ -0,0 +1,223 @@
|
||||
using MarketData.DataAccess;
|
||||
using MarketData.DividendRiskParity;
|
||||
using MarketData.MarketDataModel;
|
||||
using MarketData.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Shapes;
|
||||
using System.Windows.Threading;
|
||||
|
||||
namespace TradeBlotter.UIUtils
|
||||
{
|
||||
public class ProformaAddRiskDividendParityPositionDialogResult
|
||||
{
|
||||
public DividendRiskParityPositionCollection DividendRiskParityPositionCollection { get; set; }
|
||||
public DividendRiskParityPosition DividendRiskParityPositionProforma { get; set; }
|
||||
public bool Success { get; set; }
|
||||
}
|
||||
public partial class ProformaAddRiskDividendParityPositionDialog : Window
|
||||
{
|
||||
private List<String> symbols;
|
||||
private ManualResetEvent manualResetEvent = new ManualResetEvent(false);
|
||||
private DateTime PurchaseDate { get; set; }
|
||||
private double PurchasePrice { get; set; }
|
||||
private String SelectedSymbol { get; set; }
|
||||
private double Exposure { get; set; }
|
||||
private double Shares { get; set; }
|
||||
private bool Result { get; set; }
|
||||
private DividendRiskParityPosition dividendRiskParityPositionProforma = null;
|
||||
|
||||
private ProformaAddRiskDividendParityPositionDialog(String title,String symbol, DateTime purchaseDate, DividendRiskParityPositionCollection dividendRiskParityPositionCollection)
|
||||
{
|
||||
this.Background = new SolidColorBrush(Colors.AliceBlue);
|
||||
this.Owner = Application.Current.MainWindow;
|
||||
InitializeComponent();
|
||||
this.Loaded += new RoutedEventHandler(AddPositionDialog_Loaded);
|
||||
this.Closing += Window_Closing;
|
||||
txtPurchasePrice.SelectionChanged += txtPurchasePrice_SelectionChanged;
|
||||
txtShares.SelectionChanged += txtShares_SelectionChanged;
|
||||
txtExposure.TextChanged += txtExposure_SelectionChanged;
|
||||
txtSymbol.SelectionChanged+=txtSymbol_SelectionChanged;
|
||||
txtSymbol.Text = symbol;
|
||||
SelectedSymbol = symbol;
|
||||
Title = title;
|
||||
Shares = 0.00;
|
||||
Exposure = 0.00;
|
||||
if (Utility.IsEpoch(purchaseDate)) PurchaseDate = PricingDA.GetLatestDate();
|
||||
else PurchaseDate = purchaseDate;
|
||||
Price price = PricingDA.GetPrice(symbol, purchaseDate);
|
||||
if (null != price) PurchasePrice = price.Close;
|
||||
txtPurchaseDate.Text = purchaseDate.ToShortDateString();
|
||||
UpdatePrice();
|
||||
txtShares.Text = Utility.FormatNumber(Shares, 3);
|
||||
txtPurchaseDate.IsReadOnly = true;
|
||||
txtSymbol.IsReadOnly = true;
|
||||
}
|
||||
public ManualResetEvent Event { get {return manualResetEvent;}}
|
||||
public static ProformaAddRiskDividendParityPositionDialogResult Prompt(string title, String account, DateTime effectiveDate, DividendRiskParityPositionCollection dividendRiskParityPositionCollection)
|
||||
{
|
||||
ProformaAddRiskDividendParityPositionDialogResult proformaAddRiskDividendParityPositionDialogResult = new ProformaAddRiskDividendParityPositionDialogResult();
|
||||
proformaAddRiskDividendParityPositionDialogResult.Success = false;
|
||||
ProformaAddRiskDividendParityPositionDialog proformaAddRiskDividendParityPositionDialog = new ProformaAddRiskDividendParityPositionDialog(title, account, effectiveDate, dividendRiskParityPositionCollection);
|
||||
try { proformaAddRiskDividendParityPositionDialog.ShowDialog(); }
|
||||
catch (Exception) { return proformaAddRiskDividendParityPositionDialogResult; }
|
||||
proformaAddRiskDividendParityPositionDialog.Event.WaitOne();
|
||||
if (proformaAddRiskDividendParityPositionDialog.Result == true)
|
||||
{
|
||||
DividendRiskParityPosition dividendRiskParityPosition = proformaAddRiskDividendParityPositionDialog.CreatePosition();
|
||||
dividendRiskParityPositionCollection.Add(dividendRiskParityPosition);
|
||||
proformaAddRiskDividendParityPositionDialogResult.Success = true;
|
||||
proformaAddRiskDividendParityPositionDialogResult.DividendRiskParityPositionProforma = proformaAddRiskDividendParityPositionDialog.dividendRiskParityPositionProforma;
|
||||
}
|
||||
proformaAddRiskDividendParityPositionDialogResult.DividendRiskParityPositionCollection = dividendRiskParityPositionCollection;
|
||||
return proformaAddRiskDividendParityPositionDialogResult;
|
||||
}
|
||||
|
||||
|
||||
void AddPositionDialog_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
//cbSymbols.Focus();
|
||||
}
|
||||
public DividendRiskParityPosition CreatePosition()
|
||||
{
|
||||
try
|
||||
{
|
||||
dividendRiskParityPositionProforma = new DividendRiskParityPosition();
|
||||
dividendRiskParityPositionProforma.Symbol = SelectedSymbol;
|
||||
dividendRiskParityPositionProforma.PurchasePrice = PurchasePrice;
|
||||
dividendRiskParityPositionProforma.Shares = Shares;
|
||||
dividendRiskParityPositionProforma.TradeDate = PurchaseDate;
|
||||
dividendRiskParityPositionProforma.TypeOfPosition = DividendRiskParityPosition.PositionType.Proforma;
|
||||
return dividendRiskParityPositionProforma;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
private void btnOk_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Result = Validate();
|
||||
Close();
|
||||
Event.Set();
|
||||
return;
|
||||
}
|
||||
private void txtPurchasePrice_SelectionChanged(object sender, RoutedEventArgs e)
|
||||
{
|
||||
double value=0.00;
|
||||
value = Utility.ParseCurrency(txtPurchasePrice.Text);
|
||||
if (PurchasePrice.Equals(value)) return;
|
||||
PurchasePrice = value;
|
||||
if (!txtPurchasePrice.IsFocused)
|
||||
{
|
||||
UpdatePrice();
|
||||
UpdateExposure();
|
||||
}
|
||||
else UpdateExposure();
|
||||
}
|
||||
private void txtShares_SelectionChanged(object sender, RoutedEventArgs e)
|
||||
{
|
||||
double value = 0.00;
|
||||
double.TryParse(txtShares.Text, out value);
|
||||
if (Shares.Equals(value)) return;
|
||||
Shares = Math.Round(value,3);
|
||||
if (txtShares.IsFocused)
|
||||
{
|
||||
UpdatePrice();
|
||||
UpdateExposure();
|
||||
}
|
||||
}
|
||||
private void txtSymbol_SelectionChanged(object sender, RoutedEventArgs e)
|
||||
{
|
||||
//double value = 0.00;
|
||||
//double.TryParse(txtShares.Text, out value);
|
||||
//if (Shares.Equals(value)) return;
|
||||
//Shares = Math.Round(value, 3);
|
||||
//if (txtShares.IsFocused)
|
||||
//{
|
||||
// UpdatePrice();
|
||||
// UpdateExposure();
|
||||
//}
|
||||
}
|
||||
private void txtExposure_SelectionChanged(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (null == txtExposure.Text || "".Equals(txtExposure.Text)) return;
|
||||
double value=Utility.ParseCurrency(txtExposure.Text);
|
||||
if (0.00 == value || value==Exposure) return;
|
||||
txtExposure.Text = Utility.FormatCurrency(value);
|
||||
txtExposure.CaretIndex = txtExposure.Text.IndexOf('.');
|
||||
if (0.00 == PurchasePrice) return;
|
||||
Shares = Math.Round(value / PurchasePrice,3);
|
||||
if (txtExposure.IsFocused)
|
||||
{
|
||||
UpdateShares();
|
||||
}
|
||||
}
|
||||
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
|
||||
{
|
||||
Event.Set();
|
||||
}
|
||||
private void btnCancel_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Result = false;
|
||||
Close();
|
||||
Event.Set();
|
||||
}
|
||||
private bool Validate()
|
||||
{
|
||||
if (null == SelectedSymbol) return false;
|
||||
//if(null==Account)return false;
|
||||
if(Utility.IsEpoch(PurchaseDate))return false;
|
||||
if (double.IsNaN(PurchasePrice)) return false;
|
||||
if (0 == Shares) return false;
|
||||
return true;
|
||||
}
|
||||
private void UpdatePrice()
|
||||
{
|
||||
if (Utility.IsEpoch(PurchaseDate)) return;
|
||||
Price price = PricingDA.GetPrice(SelectedSymbol, PurchaseDate);
|
||||
if (null == price)
|
||||
{
|
||||
DateGenerator dateGenerator = new DateGenerator();
|
||||
DateTime prevBusinessDate=dateGenerator.FindPrevBusinessDay(PurchaseDate);
|
||||
price = PricingDA.GetPrice(SelectedSymbol, prevBusinessDate);
|
||||
if (null != price)
|
||||
{
|
||||
PurchasePrice = price.Close;
|
||||
PurchaseDate = prevBusinessDate;
|
||||
//dpPurchaseDate.SelectedDate = PurchaseDate;
|
||||
txtPurchaseDate.Text=PurchaseDate.ToShortDateString();
|
||||
}
|
||||
else PurchasePrice = 0.00;
|
||||
}
|
||||
else PurchasePrice = price.Close;
|
||||
txtPurchasePrice.Text = Utility.FormatCurrency(PurchasePrice);
|
||||
}
|
||||
private void UpdateExposure()
|
||||
{
|
||||
Exposure = PurchasePrice * Shares;
|
||||
txtExposure.Text = Utility.FormatCurrency(Exposure);
|
||||
}
|
||||
private void UpdateShares()
|
||||
{
|
||||
txtShares.Text = Utility.FormatNumber(Shares,3);
|
||||
}
|
||||
private void UpdateCompanyName()
|
||||
{
|
||||
CompanyProfile companyProfile = CompanyProfileDA.GetCompanyProfile(SelectedSymbol);
|
||||
if (null == companyProfile||null==companyProfile.CompanyName) return;
|
||||
lblCompanyName.Content = companyProfile.CompanyName.ToUpper();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
233
Utility/AttachedBehavior.cs
Normal file
@@ -0,0 +1,233 @@
|
||||
using System;
|
||||
using System.Windows;
|
||||
using System.Text;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Threading;
|
||||
using System.IO;
|
||||
using Microsoft.Win32;
|
||||
using Microsoft.Research.DynamicDataDisplay.Charts.Navigation;
|
||||
using Telerik.Windows.Controls;
|
||||
using Microsoft.Research.DynamicDataDisplay;
|
||||
using System.Collections.ObjectModel;
|
||||
using TradeBlotter.ViewModels;
|
||||
using System.Windows.Data;
|
||||
using System.Reflection;
|
||||
using System.Collections.Generic;
|
||||
using MarketData.MarketDataModel;
|
||||
|
||||
namespace TradeBlotter.UIUtils
|
||||
{
|
||||
public class NameMultiValueConverter : IMultiValueConverter
|
||||
{
|
||||
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
return String.Format("{0}:{1}", values[0], values[1]);
|
||||
}
|
||||
public object[] ConvertBack(object value,Type[] targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
// ******************************************************************************************************************************
|
||||
// ********************************************** G R I D B E H A V I O R S ***********************************
|
||||
// ******************************************************************************************************************************
|
||||
// This attached behavior is used to initiate the re-calculation of all aggregates which radgridview does not do by default
|
||||
public class GridDataChangeBehavior
|
||||
{
|
||||
public static readonly DependencyProperty GridDataChangeProperty = DependencyProperty.RegisterAttached("GridDataChangeProperty", typeof(bool), typeof(GridDataChangeBehavior), new FrameworkPropertyMetadata(OnGridDataChangePropertyChanged));
|
||||
[AttachedPropertyBrowsableForType(typeof(RadGridView))]
|
||||
public static bool GetGridDataChangeProperty(RadGridView radGridView)
|
||||
{
|
||||
return (bool)radGridView.GetValue(GridDataChangeProperty);
|
||||
}
|
||||
public static void SetGridDataChangeProperty(RadGridView radGridView, bool value)
|
||||
{
|
||||
radGridView.SetValue(GridDataChangeProperty, value);
|
||||
}
|
||||
static void OnGridDataChangePropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
RadGridView radGridView = dependencyObject as RadGridView;
|
||||
radGridView.CalculateAggregates();
|
||||
}
|
||||
}
|
||||
public class GridExportGraphBehavior
|
||||
{
|
||||
public static readonly DependencyProperty ExportExcelProperty = DependencyProperty.RegisterAttached("ExportExcelProperty", typeof(String), typeof(GridExportGraphBehavior), new FrameworkPropertyMetadata(OnExportExcelPropertyChanged));
|
||||
[AttachedPropertyBrowsableForType(typeof(RadGridView))]
|
||||
public static string GetExportExcelProperty(RadGridView radGridView)
|
||||
{
|
||||
return (string)radGridView.GetValue(ExportExcelProperty);
|
||||
}
|
||||
public static void SetExportExcelProperty(RadGridView radGridView, string value)
|
||||
{
|
||||
radGridView.SetValue(ExportExcelProperty, value);
|
||||
}
|
||||
static void OnExportExcelPropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
RadGridView radGridView = dependencyObject as RadGridView;
|
||||
String pathFileName = e.NewValue as String;
|
||||
if (null == pathFileName) return;
|
||||
Action action = () =>
|
||||
{
|
||||
SaveFileDialog saveFileDialog = new SaveFileDialog()
|
||||
{
|
||||
InitialDirectory = Directory.GetCurrentDirectory(),
|
||||
Filter = "Excel files (.xls)|*.xls",
|
||||
FileName = pathFileName,
|
||||
};
|
||||
if (false == saveFileDialog.ShowDialog()) return;
|
||||
using (Stream stream = saveFileDialog.OpenFile())
|
||||
{
|
||||
radGridView.Export(stream, new GridViewExportOptions() { Format = ExportFormat.ExcelML, ShowColumnHeaders = true, ShowColumnFooters = true, ShowGroupFooters = true, });
|
||||
}
|
||||
};
|
||||
Dispatcher.CurrentDispatcher.BeginInvoke(action);
|
||||
}
|
||||
}
|
||||
// ******************************************************************************************************************************
|
||||
// *********************************** C H A R T P L O T T E R B E H A V I O R***********************************
|
||||
// ******************************************************************************************************************************
|
||||
public class ChartPlotterLegendBehavior
|
||||
{
|
||||
public static readonly DependencyProperty LegendVisibleProperty = DependencyProperty.RegisterAttached("LegendVisibleProperty", typeof(string), typeof(ChartPlotterLegendBehavior), new FrameworkPropertyMetadata(OnLegendVisiblePropertyChanged));
|
||||
[AttachedPropertyBrowsableForType(typeof(ChartPlotter))]
|
||||
public static string GetLegendVisibleProperty(ChartPlotter d)
|
||||
{
|
||||
return (string)d.GetValue(LegendVisibleProperty);
|
||||
}
|
||||
[AttachedPropertyBrowsableForType(typeof(ChartPlotter))]
|
||||
public static void SetLegendVisibleProperty(ChartPlotter d, string value)
|
||||
{
|
||||
d.SetValue(LegendVisibleProperty, value);
|
||||
}
|
||||
static void OnLegendVisiblePropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
ChartPlotter chartPlotter = dependencyObject as ChartPlotter;
|
||||
if (chartPlotter != null)
|
||||
{
|
||||
chartPlotter.NewLegendVisible = Boolean.Parse((e.NewValue as String));
|
||||
}
|
||||
}
|
||||
}
|
||||
// ******************************************************************************************************************************
|
||||
// *********************************** C O O R D I N A T E G R A P H X T E X T B E H A V I O R***********************************
|
||||
// ******************************************************************************************************************************
|
||||
public class CoordinateGraphBehavior
|
||||
{
|
||||
public static readonly DependencyProperty XTextMappingProperty = DependencyProperty.RegisterAttached("XTextMappingProperty", typeof(string), typeof(CoordinateGraphBehavior), new FrameworkPropertyMetadata(OnXTextMappingPropertyChanged));
|
||||
public static readonly DependencyProperty YTextMappingProperty = DependencyProperty.RegisterAttached("YTextMappingProperty", typeof(string), typeof(CoordinateGraphBehavior), new FrameworkPropertyMetadata(OnYTextMappingPropertyChanged));
|
||||
private static String dateFormat;
|
||||
private static String numericFormat;
|
||||
[AttachedPropertyBrowsableForType(typeof(CursorCoordinateGraph))]
|
||||
public static string GetXTextMappingProperty(CursorCoordinateGraph d)
|
||||
{
|
||||
return (string)d.GetValue(XTextMappingProperty);
|
||||
}
|
||||
public static void SetXTextMappingProperty(CursorCoordinateGraph d, string value)
|
||||
{
|
||||
d.SetValue(XTextMappingProperty, value);
|
||||
}
|
||||
static void OnXTextMappingPropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
CursorCoordinateGraph cursorCoordinateGraph = dependencyObject as CursorCoordinateGraph;
|
||||
dateFormat = e.NewValue as String;
|
||||
if (cursorCoordinateGraph != null)
|
||||
{
|
||||
cursorCoordinateGraph.XTextMapping = XConverter;
|
||||
}
|
||||
}
|
||||
public static String XConverter(double value)
|
||||
{
|
||||
DateTime dateAxis = new DateTime((long)(value * 10000000000.0));
|
||||
return dateAxis.ToString(dateFormat);
|
||||
}
|
||||
[AttachedPropertyBrowsableForType(typeof(CursorCoordinateGraph))]
|
||||
public static string GetYTextMappingProperty(CursorCoordinateGraph d)
|
||||
{
|
||||
return (string)d.GetValue(YTextMappingProperty);
|
||||
}
|
||||
public static void SetYTextMappingProperty(CursorCoordinateGraph d, string value)
|
||||
{
|
||||
d.SetValue(YTextMappingProperty, value);
|
||||
}
|
||||
static void OnYTextMappingPropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
CursorCoordinateGraph cursorCoordinateGraph = dependencyObject as CursorCoordinateGraph;
|
||||
numericFormat = e.NewValue as String;
|
||||
if (cursorCoordinateGraph != null)
|
||||
{
|
||||
cursorCoordinateGraph.YTextMapping = YConverter;
|
||||
}
|
||||
}
|
||||
public static String YConverter(double value)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.Append("{0:").Append(numericFormat).Append("}");
|
||||
return String.Format(sb.ToString(), value);
|
||||
}
|
||||
}
|
||||
// ******************************************************************************************************************************
|
||||
// *************************************************** B R O W S E R B E H A V I O R********************************************
|
||||
// ******************************************************************************************************************************
|
||||
public class BrowserBehavior
|
||||
{
|
||||
public static readonly DependencyProperty HtmlProperty = DependencyProperty.RegisterAttached("Html",typeof(string),typeof(BrowserBehavior),new FrameworkPropertyMetadata(OnHtmlChanged));
|
||||
[AttachedPropertyBrowsableForType(typeof(WebBrowser))]
|
||||
public static string GetHtml(WebBrowser d)
|
||||
{
|
||||
return (string)d.GetValue(HtmlProperty);
|
||||
}
|
||||
public static void SetHtml(WebBrowser d, string value)
|
||||
{
|
||||
d.SetValue(HtmlProperty, value);
|
||||
}
|
||||
static void OnHtmlChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
WebBrowser webBrowser = dependencyObject as WebBrowser;
|
||||
if (webBrowser != null)
|
||||
{
|
||||
FieldInfo field = typeof(WebBrowser).GetField("_axIWebBrowser2", BindingFlags.Instance | BindingFlags.NonPublic);
|
||||
if (null != field)
|
||||
{
|
||||
object axIWebBrowser2 = field.GetValue(dependencyObject);
|
||||
axIWebBrowser2.GetType().InvokeMember("Silent", BindingFlags.SetProperty, null, axIWebBrowser2, new object[] { true });
|
||||
}
|
||||
webBrowser.NavigateToString(e.NewValue as string);
|
||||
webBrowser.AllowDrop = false;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
// ******************************************************************************************************************************
|
||||
// *************************************************** C A L E N D A R B E H A V I O R ********************************************
|
||||
// ******************************************************************************************************************************
|
||||
public class CalendarBehavior
|
||||
{
|
||||
public static readonly DependencyProperty RegisterBlackoutDatesProperty = DependencyProperty.RegisterAttached("RegisterBlackoutDates", typeof(System.Collections.Generic.List<System.Windows.Controls.CalendarDateRange>), typeof(CalendarBehavior), new FrameworkPropertyMetadata(OnRegisterCommandBindingChanged));
|
||||
[AttachedPropertyBrowsableForType(typeof(Calendar))]
|
||||
public static void SetRegisterBlackoutDates(UIElement element, System.Windows.Controls.CalendarBlackoutDatesCollection value)
|
||||
{
|
||||
if (element != null)element.SetValue(RegisterBlackoutDatesProperty, value);
|
||||
}
|
||||
public static System.Windows.Controls.CalendarBlackoutDatesCollection GetRegisterBlackoutDates(UIElement element)
|
||||
{
|
||||
return (element != null ? (System.Windows.Controls.CalendarBlackoutDatesCollection)element.GetValue(RegisterBlackoutDatesProperty) : null);
|
||||
}
|
||||
private static void OnRegisterCommandBindingChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
System.Windows.Controls.Calendar element = sender as System.Windows.Controls.Calendar;
|
||||
if (element != null)
|
||||
{
|
||||
List<CalendarDateRange> blackoutDates = e.NewValue as List<CalendarDateRange>;
|
||||
if (null!=blackoutDates)
|
||||
{
|
||||
element.BlackoutDates.Clear();
|
||||
foreach (CalendarDateRange dateRange in blackoutDates)
|
||||
{
|
||||
element.BlackoutDates.Add(dateRange);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
33
Utility/BrushCollection.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace TradeBlotter.UIUtils
|
||||
{
|
||||
public class BrushCollection
|
||||
{
|
||||
public enum BrushColor{Black=0,Red=1,Green=2,Blue=3,Yellow=4,LightGreen=5,Purple=6,Indigo=7,White=8,Cyan=9};
|
||||
public static Brush[] ContextBrushes={
|
||||
new SolidColorBrush((Color)ColorConverter.ConvertFromString("#000000")),
|
||||
new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FF0000")),
|
||||
new SolidColorBrush((Color)ColorConverter.ConvertFromString("#008000")),
|
||||
new SolidColorBrush((Color)ColorConverter.ConvertFromString("#0080FF")),
|
||||
new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FFFF00")),
|
||||
new SolidColorBrush((Color)ColorConverter.ConvertFromString("#90EE90")),
|
||||
new SolidColorBrush((Color)ColorConverter.ConvertFromString("#422057FF")),
|
||||
new SolidColorBrush((Color)ColorConverter.ConvertFromString("#4B0082")),
|
||||
new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FFFFFF")),
|
||||
new SolidColorBrush((Color)ColorConverter.ConvertFromString("#00FFFF")),
|
||||
};
|
||||
private BrushCollection()
|
||||
{
|
||||
}
|
||||
public static Brush GetContextBrush(BrushColor brushColor)
|
||||
{
|
||||
return ContextBrushes[(int)brushColor];
|
||||
}
|
||||
}
|
||||
}
|
||||
52
Utility/CellStyles.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using Telerik.Windows.Controls;
|
||||
using MarketData.MarketDataModel;
|
||||
|
||||
namespace TradeBlotter.UIUtils
|
||||
{
|
||||
public class EquityPriceShockTransactionGLStyle : StyleSelector
|
||||
{
|
||||
public override Style SelectStyle(object item, DependencyObject container)
|
||||
{
|
||||
if (item is EquityPriceShock)
|
||||
{
|
||||
EquityPriceShock equityPriceShock = item as EquityPriceShock;
|
||||
if (equityPriceShock.TransactionGL<0)
|
||||
{
|
||||
return NegativeStyle;
|
||||
}
|
||||
else
|
||||
{
|
||||
return PositiveStyle;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public Style NegativeStyle { get; set; }
|
||||
public Style PositiveStyle { get; set; }
|
||||
}
|
||||
public class EquityPriceShockPositionGLStyle : StyleSelector
|
||||
{
|
||||
public override Style SelectStyle(object item, DependencyObject container)
|
||||
{
|
||||
if (item is EquityPriceShock)
|
||||
{
|
||||
EquityPriceShock equityPriceShock = item as EquityPriceShock;
|
||||
if (equityPriceShock.PositionGL < 0)
|
||||
{
|
||||
return NegativeStyle;
|
||||
}
|
||||
else
|
||||
{
|
||||
return PositiveStyle;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public Style NegativeStyle { get; set; }
|
||||
public Style PositiveStyle { get; set; }
|
||||
}
|
||||
}
|
||||
681
Utility/CustomAggregator.cs
Normal file
@@ -0,0 +1,681 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Telerik.Windows.Data;
|
||||
using MarketData.Utils;
|
||||
using MarketData.MarketDataModel;
|
||||
using TradeBlotter.Model;
|
||||
using TradeBlotter.ViewModels;
|
||||
using System.Text;
|
||||
using MarketData.DividendRiskParity;
|
||||
using MarketData.MarketDataModel.GainLoss;
|
||||
|
||||
namespace TradeBlotter.UIUtils
|
||||
{
|
||||
// **********************************************************************************************************************************
|
||||
// ********************************************************* G A I N L O S S V I E W *****************************************
|
||||
// **********************************************************************************************************************************
|
||||
public class GainLossViewSumFunctionSymbol : AggregateFunction<GainLossSummaryItem, String>
|
||||
{
|
||||
public GainLossViewSumFunctionSymbol()
|
||||
{
|
||||
this.AggregationExpression = items => Sum(items);
|
||||
}
|
||||
private String Sum(IEnumerable<GainLossSummaryItem> source)
|
||||
{
|
||||
int itemCount=0;
|
||||
if(null!=source)itemCount=source.Count();
|
||||
return String.Format("{0} rows",itemCount);
|
||||
}
|
||||
}
|
||||
|
||||
// **********************************************************************************************************************************
|
||||
// ********************************************************* D I V I D E N D P A R I T Y *****************************************
|
||||
// **********************************************************************************************************************************
|
||||
public class DividendRiskParitySumFunctionGainLossPercent : AggregateFunction<DividendRiskParityPosition, String>
|
||||
{
|
||||
public DividendRiskParitySumFunctionGainLossPercent()
|
||||
{
|
||||
this.AggregationExpression = items => Sum(items);
|
||||
}
|
||||
private String Sum(IEnumerable<DividendRiskParityPosition> source)
|
||||
{
|
||||
double totalMV=source.Sum(x=>x.CurrentPrice*x.Shares);
|
||||
double totalExposure = source.Sum(x => x.Exposure);
|
||||
return Utility.FormatPercent((totalMV-totalExposure)/totalExposure);
|
||||
}
|
||||
}
|
||||
public class DividendRiskParitySumFunctionPrice : AggregateFunction<DividendRiskParityPosition, String>
|
||||
{
|
||||
public DividendRiskParitySumFunctionPrice()
|
||||
{
|
||||
this.AggregationExpression = items => Sum(items);
|
||||
}
|
||||
private String Sum(IEnumerable<DividendRiskParityPosition> source)
|
||||
{
|
||||
double totalExposure = source.Sum(x => x.Exposure);
|
||||
double totalShares = source.Sum(x => x.Shares);
|
||||
return Utility.FormatCurrency(totalExposure/totalShares, 2);
|
||||
}
|
||||
}
|
||||
public class DividendRiskParitySumFunctionShares : AggregateFunction<DividendRiskParityPosition, String>
|
||||
{
|
||||
public DividendRiskParitySumFunctionShares()
|
||||
{
|
||||
this.AggregationExpression = items => Sum(items);
|
||||
}
|
||||
private String Sum(IEnumerable<DividendRiskParityPosition> source)
|
||||
{
|
||||
double totalShares = source.Sum(x => x.Shares);
|
||||
return Utility.FormatNumber(totalShares, 3,true);
|
||||
}
|
||||
}
|
||||
public class DividendRiskParitySumFunctionExposure : AggregateFunction<DividendRiskParityPosition, String>
|
||||
{
|
||||
public DividendRiskParitySumFunctionExposure()
|
||||
{
|
||||
this.AggregationExpression = items => Sum(items);
|
||||
}
|
||||
private String Sum(IEnumerable<DividendRiskParityPosition> source)
|
||||
{
|
||||
double totalExposure = source.Sum(x => x.Exposure);
|
||||
return Utility.FormatCurrency(totalExposure, 2);
|
||||
}
|
||||
}
|
||||
public class DividendRiskParitySumFunctionWeightedDividend : AggregateFunction<DividendRiskParityPosition, String>
|
||||
{
|
||||
public DividendRiskParitySumFunctionWeightedDividend()
|
||||
{
|
||||
this.AggregationExpression = items => Sum(items);
|
||||
}
|
||||
private String Sum(IEnumerable<DividendRiskParityPosition> source)
|
||||
{
|
||||
double totalWeightedDividendPercent = source.Sum(x => x.WeightedDividendPercent);
|
||||
return Utility.FormatNumber(totalWeightedDividendPercent,2,true);
|
||||
}
|
||||
}
|
||||
public class DividendRiskParitySumFunctionDividendPayment : AggregateFunction<DividendRiskParityPosition, String>
|
||||
{
|
||||
public DividendRiskParitySumFunctionDividendPayment()
|
||||
{
|
||||
this.AggregationExpression = items => Sum(items);
|
||||
}
|
||||
private String Sum(IEnumerable<DividendRiskParityPosition> source)
|
||||
{
|
||||
double totalDividendPayment = source.Sum(x => x.DividendPayment);
|
||||
return Utility.FormatCurrency(totalDividendPayment,2);
|
||||
}
|
||||
}
|
||||
public class DividendRiskParitySumFunctionWeight : AggregateFunction<DividendRiskParityPosition, String>
|
||||
{
|
||||
public DividendRiskParitySumFunctionWeight()
|
||||
{
|
||||
this.AggregationExpression = items => Sum(items);
|
||||
}
|
||||
private String Sum(IEnumerable<DividendRiskParityPosition> source)
|
||||
{
|
||||
double totalWeight = source.Sum(x => x.Weight);
|
||||
return Utility.FormatPercent(totalWeight);
|
||||
}
|
||||
}
|
||||
public class DividendRiskParitySumFunctionGainLoss : AggregateFunction<DividendRiskParityPosition, String>
|
||||
{
|
||||
public DividendRiskParitySumFunctionGainLoss()
|
||||
{
|
||||
this.AggregationExpression = items => Sum(items);
|
||||
}
|
||||
private String Sum(IEnumerable<DividendRiskParityPosition> source)
|
||||
{
|
||||
double totalGainLoss = source.Sum(x => x.GainLoss);
|
||||
return Utility.FormatCurrency(totalGainLoss, 2);
|
||||
}
|
||||
}
|
||||
|
||||
// **********************************************************************************************************************************
|
||||
// ********************************************************* Q U A N T U M M O M E N T U M ******************************************************
|
||||
// **********************************************************************************************************************************
|
||||
public class MomentumPositionSumFunctionShares : AggregateFunction<MGPositionModel,String>
|
||||
{
|
||||
public MomentumPositionSumFunctionShares()
|
||||
{
|
||||
this.AggregationExpression = items => Sum(items);
|
||||
}
|
||||
private String Sum(IEnumerable<MGPositionModel> source)
|
||||
{
|
||||
double sum=(from MGPositionModel positionModel in source where Utility.IsEpoch(positionModel.SellDate) select positionModel.Shares).Sum();
|
||||
return Utility.FormatNumber(sum,3,false);
|
||||
}
|
||||
}
|
||||
public class MomentumPositionSumFunctionExposure : AggregateFunction<MGPositionModel,String>
|
||||
{
|
||||
public MomentumPositionSumFunctionExposure()
|
||||
{
|
||||
this.AggregationExpression = items => Sum(items);
|
||||
}
|
||||
private String Sum(IEnumerable<MGPositionModel> source)
|
||||
{
|
||||
double exposure=(from MGPositionModel positionModel in source where Utility.IsEpoch(positionModel.SellDate) select positionModel.Exposure).Sum();
|
||||
return Utility.FormatCurrency(exposure);
|
||||
}
|
||||
}
|
||||
public class MomentumPositionSumFunctionMarketValue : AggregateFunction<MGPositionModel,String>
|
||||
{
|
||||
public MomentumPositionSumFunctionMarketValue()
|
||||
{
|
||||
this.AggregationExpression = items => Sum(items);
|
||||
}
|
||||
private String Sum(IEnumerable<MGPositionModel> source)
|
||||
{
|
||||
double marketValue=(from MGPositionModel positionModel in source where Utility.IsEpoch(positionModel.SellDate) select positionModel.MarketValue).Sum();
|
||||
return Utility.FormatCurrency(marketValue);
|
||||
}
|
||||
}
|
||||
public class MomentumPositionSumFunctionGainLoss : AggregateFunction<MGPositionModel,String>
|
||||
{
|
||||
public MomentumPositionSumFunctionGainLoss()
|
||||
{
|
||||
this.AggregationExpression = items => Sum(items);
|
||||
}
|
||||
private String Sum(IEnumerable<MGPositionModel> source)
|
||||
{
|
||||
StringBuilder sb=new StringBuilder();
|
||||
double sum=(from MGPositionModel positionModel in source select positionModel.GainLoss).Sum();
|
||||
sb.Append("Total:").Append(Utility.FormatCurrency(sum)).Append("\n");
|
||||
sum=(from MGPositionModel positionModel in source where Utility.IsEpoch(positionModel.SellDate) select positionModel.GainLoss).Sum();
|
||||
sb.Append("Active:").Append(Utility.FormatCurrency(sum));
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
public class MomentumPositionSumFunctionGainLossPcnt : AggregateFunction<MGPositionModel,String>
|
||||
{
|
||||
public MomentumPositionSumFunctionGainLossPcnt()
|
||||
{
|
||||
this.AggregationExpression = items => Sum(items);
|
||||
}
|
||||
private String Sum(IEnumerable<MGPositionModel> source)
|
||||
{
|
||||
StringBuilder sb=new StringBuilder();
|
||||
double marketValue=0.00;
|
||||
double exposure=0.00;
|
||||
double gainLossPcnt=0.00;
|
||||
|
||||
double cumulativeReturn=ModelPerformanceAggregator.CalculateCumulativeReturn(source);
|
||||
sb.Append("Total:").Append(Utility.FormatPercent(cumulativeReturn,2)).Append("\n");
|
||||
|
||||
marketValue=(from MGPositionModel positionModel in source where Utility.IsEpoch(positionModel.SellDate) select positionModel.MarketValue).Sum();
|
||||
exposure=(from MGPositionModel positionModel in source where Utility.IsEpoch(positionModel.SellDate) select positionModel.Exposure).Sum();
|
||||
if(0.00!=exposure)gainLossPcnt=(marketValue-exposure)/exposure;
|
||||
sb.Append("Active:").Append(Utility.FormatPercent(gainLossPcnt,2));
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
// **********************************************************************************************************************************
|
||||
// ********************************************************* C M M O M E N T U M ******************************************************
|
||||
// **********************************************************************************************************************************
|
||||
public class CMMomentumPositionSumFunctionShares : AggregateFunction<CMPositionModel, String>
|
||||
{
|
||||
public CMMomentumPositionSumFunctionShares()
|
||||
{
|
||||
this.AggregationExpression = items => Sum(items);
|
||||
}
|
||||
private String Sum(IEnumerable<CMPositionModel> source)
|
||||
{
|
||||
double sum = (from CMPositionModel positionModel in source where Utility.IsEpoch(positionModel.SellDate) select positionModel.Shares).Sum();
|
||||
return Utility.FormatNumber(sum, 3, false);
|
||||
}
|
||||
}
|
||||
public class CMMomentumPositionSumFunctionExposure : AggregateFunction<CMPositionModel, String>
|
||||
{
|
||||
public CMMomentumPositionSumFunctionExposure()
|
||||
{
|
||||
this.AggregationExpression = items => Sum(items);
|
||||
}
|
||||
private String Sum(IEnumerable<CMPositionModel> source)
|
||||
{
|
||||
double exposure = (from CMPositionModel positionModel in source where Utility.IsEpoch(positionModel.SellDate) select positionModel.Exposure).Sum();
|
||||
return Utility.FormatCurrency(exposure);
|
||||
}
|
||||
}
|
||||
public class CMMomentumPositionSumFunctionMarketValue : AggregateFunction<CMPositionModel, String>
|
||||
{
|
||||
public CMMomentumPositionSumFunctionMarketValue()
|
||||
{
|
||||
this.AggregationExpression = items => Sum(items);
|
||||
}
|
||||
private String Sum(IEnumerable<CMPositionModel> source)
|
||||
{
|
||||
double marketValue = (from CMPositionModel positionModel in source where Utility.IsEpoch(positionModel.SellDate) select positionModel.MarketValue).Sum();
|
||||
return Utility.FormatCurrency(marketValue);
|
||||
}
|
||||
}
|
||||
public class CMMomentumPositionSumFunctionGainLoss : AggregateFunction<CMPositionModel, String>
|
||||
{
|
||||
public CMMomentumPositionSumFunctionGainLoss()
|
||||
{
|
||||
this.AggregationExpression = items => Sum(items);
|
||||
}
|
||||
private String Sum(IEnumerable<CMPositionModel> source)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
double sum = (from CMPositionModel positionModel in source select positionModel.GainLoss).Sum();
|
||||
sb.Append("Total:").Append(Utility.FormatCurrency(sum)).Append("\n");
|
||||
sum = (from CMPositionModel positionModel in source where Utility.IsEpoch(positionModel.SellDate) select positionModel.GainLoss).Sum();
|
||||
sb.Append("Active:").Append(Utility.FormatCurrency(sum));
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
public class CMMomentumPositionSumFunctionGainLossPcnt : AggregateFunction<CMPositionModel, String>
|
||||
{
|
||||
public CMMomentumPositionSumFunctionGainLossPcnt()
|
||||
{
|
||||
this.AggregationExpression = items => Sum(items);
|
||||
}
|
||||
private String Sum(IEnumerable<CMPositionModel> source)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
double marketValue=0.00;
|
||||
double exposure=0.00;
|
||||
double gainLossPcnt=0.00;
|
||||
|
||||
double cumulativeReturn=ModelPerformanceAggregator.CalculateCumulativeReturn(source);
|
||||
sb.Append("Total:").Append(Utility.FormatPercent(cumulativeReturn,2)).Append("\n");
|
||||
|
||||
marketValue = (from CMPositionModel positionModel in source where Utility.IsEpoch(positionModel.SellDate) select positionModel.MarketValue).Sum();
|
||||
exposure = (from CMPositionModel positionModel in source where Utility.IsEpoch(positionModel.SellDate) select positionModel.Exposure).Sum();
|
||||
if (0.00 != exposure) gainLossPcnt = (marketValue - exposure) / exposure;
|
||||
sb.Append("Active:").Append(Utility.FormatPercent(gainLossPcnt,2));
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
public class CMMomentumPositionSumFunctionSharpeRatio : AggregateFunction<CMPositionModel, String>
|
||||
{
|
||||
public CMMomentumPositionSumFunctionSharpeRatio()
|
||||
{
|
||||
this.AggregationExpression = items => Sum(items);
|
||||
}
|
||||
private String Sum(IEnumerable<CMPositionModel> source)
|
||||
{
|
||||
try
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
List<double> weights = new List<double>();
|
||||
List<CMPositionModel> items = new List<CMPositionModel>(source.ToList());
|
||||
int itemCount = items.Count();
|
||||
|
||||
double totalExposure = (from CMPositionModel positionModel in items select positionModel.Exposure).Sum();
|
||||
double totalSharpeRatio = 0.00;
|
||||
foreach (CMPositionModel cmPositionModel in items) weights.Add(cmPositionModel.Exposure / totalExposure);
|
||||
|
||||
for (int index = 0; index < itemCount; index++)
|
||||
{
|
||||
CMPositionModel cmPositionModel = items[index];
|
||||
double weight = weights[index];
|
||||
totalSharpeRatio += cmPositionModel.SharpeRatio * weight;
|
||||
}
|
||||
return Utility.FormatNumber(totalSharpeRatio, 4);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return Constants.CONST_DASHES;
|
||||
}
|
||||
}
|
||||
}
|
||||
public class CMMomentumPositionSumFunctionBeta : AggregateFunction<CMPositionModel, String>
|
||||
{
|
||||
public CMMomentumPositionSumFunctionBeta()
|
||||
{
|
||||
this.AggregationExpression = items => Sum(items);
|
||||
}
|
||||
private String Sum(IEnumerable<CMPositionModel> source)
|
||||
{
|
||||
try
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
List<double> weights = new List<double>();
|
||||
List<CMPositionModel> items = new List<CMPositionModel>(source.ToList());
|
||||
int itemCount = items.Count();
|
||||
|
||||
double totalExposure = (from CMPositionModel positionModel in items select positionModel.Exposure).Sum();
|
||||
double totalBeta = 0.00;
|
||||
foreach (CMPositionModel cmPositionModel in items) weights.Add(cmPositionModel.Exposure / totalExposure);
|
||||
|
||||
for (int index = 0; index < itemCount; index++)
|
||||
{
|
||||
CMPositionModel cmPositionModel = items[index];
|
||||
double weight = weights[index];
|
||||
totalBeta += cmPositionModel.Beta * weight;
|
||||
}
|
||||
return Utility.FormatNumber(totalBeta, 4);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return Constants.CONST_DASHES;
|
||||
}
|
||||
}
|
||||
}
|
||||
// **********************************************************************************************************************************
|
||||
// ********************************* C M T T R E N D (M A R C M I N E R V I N I / V A N T H A R P E *******************************
|
||||
// **********************************************************************************************************************************
|
||||
public class CMTTrendPositionSumFunctionShares:AggregateFunction<CMTPositionModel,String>
|
||||
{
|
||||
public CMTTrendPositionSumFunctionShares()
|
||||
{
|
||||
this.AggregationExpression=items => Sum(items);
|
||||
}
|
||||
private String Sum(IEnumerable<CMTPositionModel> source)
|
||||
{
|
||||
double sum=(from CMTPositionModel positionModel in source where Utility.IsEpoch(positionModel.SellDate) select positionModel.Shares).Sum();
|
||||
return Utility.FormatNumber(sum,3,false);
|
||||
}
|
||||
}
|
||||
public class CMTTrendPositionSumFunctionExposure:AggregateFunction<CMTPositionModel,String>
|
||||
{
|
||||
public CMTTrendPositionSumFunctionExposure()
|
||||
{
|
||||
this.AggregationExpression=items => Sum(items);
|
||||
}
|
||||
private String Sum(IEnumerable<CMTPositionModel> source)
|
||||
{
|
||||
double exposure=(from CMTPositionModel positionModel in source where Utility.IsEpoch(positionModel.SellDate) select positionModel.Exposure).Sum();
|
||||
return Utility.FormatCurrency(exposure);
|
||||
}
|
||||
}
|
||||
|
||||
public class CMTTrendPositionSumFunctionEdgeRatio:AggregateFunction<CMTPositionModel,String>
|
||||
{
|
||||
public CMTTrendPositionSumFunctionEdgeRatio()
|
||||
{
|
||||
this.AggregationExpression=items => Sum(items);
|
||||
}
|
||||
private String Sum(IEnumerable<CMTPositionModel> source)
|
||||
{
|
||||
double sumERatio=0.00;
|
||||
|
||||
List<CMTPositionModel> openItems=(from CMTPositionModel positionModel in source where Utility.IsEpoch(positionModel.SellDate) select positionModel).ToList();
|
||||
if(null==openItems || 0==openItems.Count)return Utility.FormatNumber(sumERatio,2);
|
||||
double totalExposure=(from CMTPositionModel positionModel in source where Utility.IsEpoch(positionModel.SellDate) select positionModel.Exposure).Sum();
|
||||
double[] weightedRatios=new double[openItems.Count];
|
||||
for(int index=0;index<weightedRatios.Length;index++)
|
||||
{
|
||||
CMTPositionModel positionModel=openItems[index];
|
||||
weightedRatios[index]=positionModel.EdgeRatio*(positionModel.Exposure/totalExposure);
|
||||
}
|
||||
sumERatio=weightedRatios.Sum();
|
||||
return Utility.FormatNumber(sumERatio,2);
|
||||
}
|
||||
}
|
||||
|
||||
public class CMTTrendPositionSumFunctionMarketValue:AggregateFunction<CMTPositionModel,String>
|
||||
{
|
||||
public CMTTrendPositionSumFunctionMarketValue()
|
||||
{
|
||||
this.AggregationExpression=items => Sum(items);
|
||||
}
|
||||
private String Sum(IEnumerable<CMTPositionModel> source)
|
||||
{
|
||||
double marketValue=(from CMTPositionModel positionModel in source where Utility.IsEpoch(positionModel.SellDate) select positionModel.MarketValue).Sum();
|
||||
return Utility.FormatCurrency(marketValue);
|
||||
}
|
||||
}
|
||||
public class CMTTrendPositionSumFunctionGainLoss:AggregateFunction<CMTPositionModel,String>
|
||||
{
|
||||
public CMTTrendPositionSumFunctionGainLoss()
|
||||
{
|
||||
this.AggregationExpression=items => Sum(items);
|
||||
}
|
||||
private String Sum(IEnumerable<CMTPositionModel> source)
|
||||
{
|
||||
StringBuilder sb=new StringBuilder();
|
||||
double sum=(from CMTPositionModel positionModel in source select positionModel.GainLoss).Sum();
|
||||
sb.Append("Total:").Append(Utility.FormatCurrency(sum)).Append("\n");
|
||||
|
||||
sum=(from CMTPositionModel positionModel in source where Utility.IsEpoch(positionModel.SellDate) select positionModel.GainLoss).Sum();
|
||||
sb.Append("Active:").Append(Utility.FormatCurrency(sum));
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
public class CMTTrendPositionSumFunctionGainLossPcnt:AggregateFunction<CMTPositionModel,String>
|
||||
{
|
||||
public CMTTrendPositionSumFunctionGainLossPcnt()
|
||||
{
|
||||
this.AggregationExpression=items => Sum(items);
|
||||
}
|
||||
private String Sum(IEnumerable<CMTPositionModel> source)
|
||||
{
|
||||
StringBuilder sb=new StringBuilder();
|
||||
double marketValue=0.00;
|
||||
double exposure=0.00;
|
||||
double gainLossPcnt=0.00;
|
||||
|
||||
double cumulativeReturn=ModelPerformanceAggregator.CalculateCumulativeReturn(source);
|
||||
sb.Append("Total:").Append(Utility.FormatPercent(cumulativeReturn,2)).Append("\n");
|
||||
|
||||
|
||||
marketValue=(from CMTPositionModel positionModel in source where Utility.IsEpoch(positionModel.SellDate) select positionModel.MarketValue).Sum();
|
||||
exposure=(from CMTPositionModel positionModel in source where Utility.IsEpoch(positionModel.SellDate) select positionModel.Exposure).Sum();
|
||||
if(0.00!=exposure) gainLossPcnt=(marketValue-exposure)/exposure;
|
||||
sb.Append("Active:").Append(Utility.FormatPercent(gainLossPcnt));
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
public class CMTTrendPositionSumFunctionRisk:AggregateFunction<CMTPositionModel,String>
|
||||
{
|
||||
public CMTTrendPositionSumFunctionRisk()
|
||||
{
|
||||
this.AggregationExpression=items => Sum(items);
|
||||
}
|
||||
private String Sum(IEnumerable<CMTPositionModel> source)
|
||||
{
|
||||
StringBuilder sb=new StringBuilder();
|
||||
List<CMTPositionModel> activePositions=source.Where(x => x.IsActivePosition).ToList();
|
||||
double sum=activePositions.Sum(x => x.TotalRiskExposure);
|
||||
return Utility.FormatCurrency(sum);
|
||||
}
|
||||
}
|
||||
// **********************************************************************************************************************************
|
||||
// ******************************************************** V A L U E A T R I S K ************************************************
|
||||
// **********************************************************************************************************************************
|
||||
public class ValueAtRiskModelMarketValueFunction : AggregateFunction<PortfolioHoldingViewModel,String>
|
||||
{
|
||||
public ValueAtRiskModelMarketValueFunction()
|
||||
{
|
||||
this.AggregationExpression = items => Sum(items);
|
||||
}
|
||||
private String Sum(IEnumerable<PortfolioHoldingViewModel> source)
|
||||
{
|
||||
return Utility.FormatCurrency((from portfolioHoldingViewModel in source select portfolioHoldingViewModel.MarketValue).Sum());
|
||||
}
|
||||
}
|
||||
public class ValueAtRiskModelWeightFunction : AggregateFunction<PortfolioHoldingViewModel, String>
|
||||
{
|
||||
public ValueAtRiskModelWeightFunction()
|
||||
{
|
||||
this.AggregationExpression = items => Sum(items);
|
||||
}
|
||||
private String Sum(IEnumerable<PortfolioHoldingViewModel> source)
|
||||
{
|
||||
return Utility.FormatPercent((from portfolioHoldingViewModel in source select portfolioHoldingViewModel.Weight).Sum());
|
||||
}
|
||||
}
|
||||
public class ValueAtRiskModelWeightExpFunction : AggregateFunction<PortfolioHoldingViewModel, String>
|
||||
{
|
||||
public ValueAtRiskModelWeightExpFunction()
|
||||
{
|
||||
this.AggregationExpression = items => Sum(items);
|
||||
}
|
||||
private String Sum(IEnumerable<PortfolioHoldingViewModel> source)
|
||||
{
|
||||
return Utility.FormatPercent((from portfolioHoldingViewModel in source select portfolioHoldingViewModel.WeightExp).Sum());
|
||||
}
|
||||
}
|
||||
public class ValueAtRiskModelVaRContributionFunction : AggregateFunction<PortfolioHoldingViewModel, String>
|
||||
{
|
||||
public ValueAtRiskModelVaRContributionFunction()
|
||||
{
|
||||
this.AggregationExpression = items => Sum(items);
|
||||
}
|
||||
private String Sum(IEnumerable<PortfolioHoldingViewModel> source)
|
||||
{
|
||||
return Utility.FormatPercent((from portfolioHoldingViewModel in source select portfolioHoldingViewModel.Contribution).Sum());
|
||||
}
|
||||
}
|
||||
public class ValueAtRiskModelExposureFunction : AggregateFunction<PortfolioHoldingViewModel, String>
|
||||
{
|
||||
public ValueAtRiskModelExposureFunction()
|
||||
{
|
||||
this.AggregationExpression = items => Sum(items);
|
||||
}
|
||||
private String Sum(IEnumerable<PortfolioHoldingViewModel> source)
|
||||
{
|
||||
return Utility.FormatCurrency((from portfolioHoldingViewModel in source select portfolioHoldingViewModel.Exposure).Sum());
|
||||
}
|
||||
}
|
||||
// ****************************************************************
|
||||
public class SumFunctionWeight : AggregateFunction<TradeViewModel, String>
|
||||
{
|
||||
public SumFunctionWeight()
|
||||
{
|
||||
this.AggregationExpression = items => Sum(items);
|
||||
}
|
||||
private String Sum(IEnumerable<TradeViewModel> source)
|
||||
{
|
||||
double totalWeight = 0.00;
|
||||
foreach (TradeViewModel model in source)
|
||||
{
|
||||
if (!model.IsOpen) continue;
|
||||
totalWeight += Utility.ParsePercent(model.Weight);
|
||||
}
|
||||
return Utility.FormatPercent(totalWeight);
|
||||
}
|
||||
}
|
||||
// ******************************
|
||||
public class SumFunctionTodaysChange : AggregateFunction<TradeViewModel, String>
|
||||
{
|
||||
public SumFunctionTodaysChange()
|
||||
{
|
||||
this.AggregationExpression = items => Sum(items);
|
||||
}
|
||||
private String Sum(IEnumerable<TradeViewModel> source)
|
||||
{
|
||||
double totalTodaysChange = 0.00;
|
||||
foreach (TradeViewModel model in source)
|
||||
{
|
||||
if (!model.IsOpen || model.TodaysChange.Equals(Constants.CONST_DASHES)) continue;
|
||||
totalTodaysChange += Utility.ParseCurrency(model.TodaysChange);
|
||||
}
|
||||
return Utility.FormatCurrency(totalTodaysChange);
|
||||
}
|
||||
}
|
||||
// ******************************
|
||||
|
||||
public class SumFunctionShares : AggregateFunction<TradeViewModel, String>
|
||||
{
|
||||
public SumFunctionShares()
|
||||
{
|
||||
this.AggregationExpression = items => Sum(items);
|
||||
}
|
||||
private String Sum(IEnumerable<TradeViewModel> source)
|
||||
{
|
||||
double totalShares = 0.00;
|
||||
foreach (TradeViewModel model in source)
|
||||
{
|
||||
if (!model.IsOpen) continue;
|
||||
totalShares += model.Shares;
|
||||
}
|
||||
return Utility.FormatNumber(totalShares);
|
||||
}
|
||||
}
|
||||
// ******************************
|
||||
public class SumFunctionMarketValue : AggregateFunction<TradeViewModel, String>
|
||||
{
|
||||
public SumFunctionMarketValue()
|
||||
{
|
||||
this.AggregationExpression = items => Sum(items);
|
||||
}
|
||||
private String Sum(IEnumerable<TradeViewModel> source)
|
||||
{
|
||||
double totalMarketValue = 0.00;
|
||||
foreach (TradeViewModel model in source)
|
||||
{
|
||||
if (model.MarketValue.Equals(Constants.CONST_DASHES) || model.MarketValue.Equals("N.A.")) continue;
|
||||
totalMarketValue += Utility.ParseCurrency(model.MarketValue);
|
||||
}
|
||||
return Utility.FormatCurrency(totalMarketValue);
|
||||
}
|
||||
}
|
||||
// ******************************
|
||||
public class SumFunctionExposure : AggregateFunction<TradeViewModel, String>
|
||||
{
|
||||
public SumFunctionExposure()
|
||||
{
|
||||
this.AggregationExpression = items => Sum(items);
|
||||
}
|
||||
private String Sum(IEnumerable<TradeViewModel> source)
|
||||
{
|
||||
double totalExposure = 0.00;
|
||||
foreach (TradeViewModel model in source)
|
||||
{
|
||||
if (!model.IsOpen) continue;
|
||||
totalExposure += Utility.ParseCurrency(model.Exposure);
|
||||
}
|
||||
return Utility.FormatCurrency(totalExposure);
|
||||
}
|
||||
}
|
||||
// ******************************
|
||||
public class SumFunctionGainLoss : AggregateFunction<TradeViewModel, String>
|
||||
{
|
||||
public SumFunctionGainLoss()
|
||||
{
|
||||
this.AggregationExpression = items => Sum(items);
|
||||
}
|
||||
private String Sum(IEnumerable<TradeViewModel> source)
|
||||
{
|
||||
double totalGainLoss = 0.00;
|
||||
foreach (TradeViewModel model in source)
|
||||
{
|
||||
if(model.IsOpen)totalGainLoss += Utility.ParseCurrency(model.GainLoss);
|
||||
}
|
||||
return Utility.FormatCurrency(totalGainLoss);
|
||||
}
|
||||
}
|
||||
// ******************************
|
||||
public class TotalReturnFunction : AggregateFunction<TradeViewModel, String>
|
||||
{
|
||||
public TotalReturnFunction()
|
||||
{
|
||||
this.AggregationExpression = items => Sum(items);
|
||||
}
|
||||
private String Sum(IEnumerable<TradeViewModel> source)
|
||||
{
|
||||
double totalExposure = 0.00;
|
||||
double totalMarketValue = 0.00;
|
||||
foreach (TradeViewModel model in source)
|
||||
{
|
||||
if (model.IsOpen)
|
||||
{
|
||||
totalExposure += Utility.ParseCurrency(model.Exposure);
|
||||
totalMarketValue += Utility.ParseCurrency(model.MarketValue);
|
||||
}
|
||||
}
|
||||
String totalReturn = Utility.FormatPercent(((totalMarketValue - totalExposure) / totalExposure));
|
||||
return totalReturn;
|
||||
}
|
||||
}
|
||||
// ****************************************************************
|
||||
public class ETFHoldingsSumFunctionPercentOfAssets : AggregateFunction<ETFHoldingModel, String>
|
||||
{
|
||||
public ETFHoldingsSumFunctionPercentOfAssets()
|
||||
{
|
||||
this.AggregationExpression = items => Sum(items);
|
||||
}
|
||||
private String Sum(IEnumerable<ETFHoldingModel> source)
|
||||
{
|
||||
double totalWeight = 0.00;
|
||||
foreach (ETFHoldingModel model in source)
|
||||
{
|
||||
totalWeight += model.PercentOfAssets;
|
||||
}
|
||||
return Utility.FormatNumber(totalWeight,2);
|
||||
}
|
||||
}
|
||||
}
|
||||
190
Utility/UIUtils.cs
Normal file
@@ -0,0 +1,190 @@
|
||||
using System;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Threading;
|
||||
using System.Windows;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using MarketData.MarketDataModel;
|
||||
using System.Windows.Data;
|
||||
using MarketData.Utils;
|
||||
|
||||
namespace TradeBlotter.UIUtils
|
||||
{
|
||||
public class DoubleValueConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
double doubleValue = (double)value;
|
||||
if (double.IsNaN(doubleValue)) return Constants.CONST_DASHES;
|
||||
if (null != parameter) return Utility.FormatNumber(doubleValue, int.Parse(parameter.ToString()));
|
||||
return Utility.FormatNumber(doubleValue, 4);
|
||||
}
|
||||
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public class IntValueConverter:IValueConverter
|
||||
{
|
||||
public object Convert(object value,Type targetType,object parameter,System.Globalization.CultureInfo culture)
|
||||
{
|
||||
int intValue=(int)value;
|
||||
if(int.MinValue.Equals(intValue))return Constants.CONST_DASHES;
|
||||
if(null!=parameter) return Utility.FormatNumber(intValue,int.Parse(parameter.ToString()),true);
|
||||
return Utility.FormatNumber(intValue,2,true);
|
||||
}
|
||||
public object ConvertBack(object value,Type targetType,object parameter,System.Globalization.CultureInfo culture)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public class BoolValueConverter:IValueConverter
|
||||
{
|
||||
public object Convert(object value,Type targetType,object parameter,System.Globalization.CultureInfo culture)
|
||||
{
|
||||
bool boolValue=(bool)value;
|
||||
if(null!=parameter)
|
||||
{
|
||||
if("0".Equals(parameter.ToString())) return boolValue?"T":"F";
|
||||
if("1".Equals(parameter.ToString())) return boolValue?"Y":"N";
|
||||
if("2".Equals(parameter.ToString())) return boolValue?"Yes":"No";
|
||||
if("3".Equals(parameter.ToString())) return boolValue?"True":"False";
|
||||
}
|
||||
return boolValue.ToString();
|
||||
}
|
||||
public object ConvertBack(object value,Type targetType,object parameter,System.Globalization.CultureInfo culture)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public class DateValueConverter:IValueConverter
|
||||
{
|
||||
public object Convert(object value,Type targetType,object parameter,System.Globalization.CultureInfo culture)
|
||||
{
|
||||
DateTime dateValue=(DateTime)value;
|
||||
if(Utility.IsEpoch(dateValue))return Constants.CONST_DASHES;
|
||||
return Utility.DateTimeToStringMMSDDSYYYY(dateValue);
|
||||
}
|
||||
public object ConvertBack(object value,Type targetType,object parameter,System.Globalization.CultureInfo culture)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
// ********************************************************************
|
||||
public class SubStringConverter : IValueConverter
|
||||
{
|
||||
/// <summary> the zero-based starting character position </summary>
|
||||
public int StartIndex { get; set; }
|
||||
|
||||
/// <summary> The number of characters in the substring </summary>
|
||||
public int Length { get; set; }
|
||||
|
||||
/// <summary> shows "..." if value was truncated after StartIndex</summary>
|
||||
public bool ShowEllipse { get; set; }
|
||||
|
||||
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
string valueString = value as string;
|
||||
if (string.IsNullOrWhiteSpace(valueString) == false)
|
||||
{
|
||||
if (Length > 0 && Length < (valueString.Length + StartIndex))
|
||||
{
|
||||
if (ShowEllipse)
|
||||
return valueString.Substring(StartIndex, Length - 3) + "...";
|
||||
else
|
||||
return valueString.Substring(StartIndex, Length);
|
||||
}
|
||||
else if (StartIndex < valueString.Length)
|
||||
return valueString.Substring(StartIndex);
|
||||
else
|
||||
return ""; //because startIndex must be past the length of the string
|
||||
}
|
||||
else
|
||||
{
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
public class TextMarkerOffsets
|
||||
{
|
||||
private static int MAX_HITS=12;
|
||||
private Dictionary<String,double> tradesBySymbolAndDate=new Dictionary<String,double>();
|
||||
private double defaultOffset=0.00;
|
||||
private double increment=-18;
|
||||
private int hits;
|
||||
|
||||
public TextMarkerOffsets()
|
||||
{
|
||||
hits=0;
|
||||
}
|
||||
public TextMarkerOffsets(double defaultOffset)
|
||||
{
|
||||
this.defaultOffset=defaultOffset;
|
||||
hits=0;
|
||||
}
|
||||
public TextMarkerOffsets(double defaultOffset,double increment)
|
||||
{
|
||||
this.defaultOffset=defaultOffset;
|
||||
this.increment=increment;
|
||||
this.hits=0;
|
||||
}
|
||||
public double GetOffset(PortfolioTrade portfolioTrade)
|
||||
{
|
||||
String key;
|
||||
double offset=defaultOffset;
|
||||
if(portfolioTrade.IsOpen)key=portfolioTrade.Symbol+portfolioTrade.TradeDate.ToShortDateString();
|
||||
else key=portfolioTrade.Symbol+portfolioTrade.SellDate.ToShortDateString();
|
||||
if(tradesBySymbolAndDate.ContainsKey(key))
|
||||
{
|
||||
if(hits>MAX_HITS)increment=5;
|
||||
offset=tradesBySymbolAndDate[key]+increment;
|
||||
tradesBySymbolAndDate[key]=offset;
|
||||
hits++;
|
||||
}
|
||||
else
|
||||
{
|
||||
offset=defaultOffset;
|
||||
tradesBySymbolAndDate.Add(key,defaultOffset);
|
||||
}
|
||||
return offset;
|
||||
}
|
||||
}
|
||||
public class MenuItemSorter : IComparer<System.Windows.Controls.MenuItem>
|
||||
{
|
||||
public int Compare(System.Windows.Controls.MenuItem v1,System.Windows.Controls.MenuItem v2)
|
||||
{
|
||||
return v1.Header.ToString().CompareTo(v2.Header.ToString());
|
||||
}
|
||||
}
|
||||
public static class UIServices
|
||||
{
|
||||
/// <summary>
|
||||
/// A value indicating whether the UI is currently busy
|
||||
/// </summary>
|
||||
//private static bool isBusy;
|
||||
|
||||
/// <summary>
|
||||
/// Sets the busystate as busy.
|
||||
/// </summary>
|
||||
public static void ClearProperty(int fromSeconds, EventHandler dispatchEventHandler)
|
||||
{
|
||||
new DispatcherTimer(TimeSpan.FromSeconds(fromSeconds), DispatcherPriority.ApplicationIdle, dispatchEventHandler, Application.Current.Dispatcher);
|
||||
}
|
||||
public static void SortMenuItems(ObservableCollection<System.Windows.Controls.MenuItem> menuCollection)
|
||||
{
|
||||
List<System.Windows.Controls.MenuItem> items=new List<System.Windows.Controls.MenuItem>();
|
||||
foreach(System.Windows.Controls.MenuItem item in menuCollection)items.Add(item);
|
||||
items.Sort(new MenuItemSorter());
|
||||
menuCollection.Clear();
|
||||
foreach(System.Windows.Controls.MenuItem item in items)menuCollection.Add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
71
Utility/WebBrowserUtils.cs
Normal file
@@ -0,0 +1,71 @@
|
||||
using MarketData;
|
||||
using Microsoft.Win32;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace TradeBlotter.UIUtils
|
||||
{
|
||||
public class WebBrowserHelper
|
||||
{
|
||||
private WebBrowserHelper()
|
||||
{
|
||||
}
|
||||
public static bool SetWebBrowserCompatibility()
|
||||
{
|
||||
RegistryKey regkey = null;
|
||||
|
||||
try
|
||||
{
|
||||
int browserVersion;
|
||||
int regVal;
|
||||
browserVersion = BrowserVersion();
|
||||
|
||||
// set the appropriate IE verbrowsersion
|
||||
if (browserVersion >= 11)regVal = 11001;
|
||||
else if (browserVersion == 10)regVal = 10001;
|
||||
else if (browserVersion == 9)regVal = 9999;
|
||||
else if (browserVersion == 8)regVal = 8888;
|
||||
else regVal = 7000;
|
||||
|
||||
regkey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"SOFTWARE\\Microsoft\\Internet Explorer\\Main\\FeatureControl\\FEATURE_BROWSER_EMULATION", true);
|
||||
if (null == regkey)
|
||||
{
|
||||
regkey = Registry.CurrentUser.CreateSubKey(@"SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION", RegistryKeyPermissionCheck.ReadWriteSubTree);
|
||||
if (null == regkey) return false;
|
||||
}
|
||||
if (regkey.GetValue(System.Diagnostics.Process.GetCurrentProcess().ProcessName + ".exe") == null)regkey.SetValue(System.Diagnostics.Process.GetCurrentProcess().ProcessName + ".exe", regVal, RegistryValueKind.DWord);
|
||||
return true;
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[SetWebBrowserCompatibility]{0}",exception.ToString()));
|
||||
return false;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (regkey != null) {regkey.Close(); regkey.Dispose();}
|
||||
}
|
||||
}
|
||||
private static int BrowserVersion()
|
||||
{
|
||||
string strKeyPath = @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer";
|
||||
string[] versionTargets = new string[] { "svcVersion", "svcUpdateVersion", "Version", "W2kVersion" };
|
||||
int maxVer = 0;
|
||||
for (int index = 0; index < versionTargets.Length; index++)
|
||||
{
|
||||
object objVal = Microsoft.Win32.Registry.GetValue(strKeyPath, versionTargets[index], "0");
|
||||
string strVal = System.Convert.ToString(objVal);
|
||||
if (null == strVal) continue;
|
||||
int iPos = strVal.IndexOf('.');
|
||||
if (iPos > 0)strVal = strVal.Substring(0, iPos);
|
||||
int res = 0;
|
||||
if (int.TryParse(strVal, out res))maxVer = Math.Max(maxVer, res);
|
||||
}
|
||||
return maxVer;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
514
ViewModels/AnalystRatingsViewModel.cs
Normal file
@@ -0,0 +1,514 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Collections.Specialized;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Input;
|
||||
using System.Threading.Tasks;
|
||||
using MarketData;
|
||||
using MarketData.Utils;
|
||||
using MarketData.MarketDataModel;
|
||||
using MarketData.Generator;
|
||||
using MarketData.DataAccess;
|
||||
using TradeBlotter.DataAccess;
|
||||
using TradeBlotter.Command;
|
||||
using TradeBlotter.Model;
|
||||
using Microsoft.Research.DynamicDataDisplay.DataSources;
|
||||
using System.Threading;
|
||||
|
||||
namespace TradeBlotter.ViewModels
|
||||
{
|
||||
public class AnalystRatingsViewModel : WorkspaceViewModel
|
||||
{
|
||||
private enum Tasks{SelectedDate,SelectedSymbol,SelectedWatchList};
|
||||
private Dictionary<Tasks,Semaphore> semaphorePool=new Dictionary<Tasks,Semaphore>();
|
||||
private const String DISPLAY_NAME = "Analyst Ratings";
|
||||
private List<String> symbols;
|
||||
private List<String> watchLists;
|
||||
private List<String> dates;
|
||||
private String selectedWatchList;
|
||||
private String selectedSymbol;
|
||||
private String selectedCompany;
|
||||
private String selectedDate = null;
|
||||
private ObservableCollection<AnalystRating> analystRatingsCollection = null;
|
||||
private bool busyIndicator = false;
|
||||
private RelayCommand resetCommand;
|
||||
private RelayCommand stochasticsCommand;
|
||||
private RelayCommand macdCommand;
|
||||
private RelayCommand bollingerBandCommand;
|
||||
private RelayCommand priceHistoryCommand;
|
||||
private RelayCommand stickerValuationCommand;
|
||||
private RelayCommand dcfValuationCommand;
|
||||
private RelayCommand dividendHistoryCommand;
|
||||
private RelayCommand displayHeadlinesCommand;
|
||||
private RelayCommand displayHistoricalCommand;
|
||||
private AnalystRating selectedItem;
|
||||
|
||||
public AnalystRatingsViewModel(bool loadedFromParams=false)
|
||||
{
|
||||
semaphorePool.Add(Tasks.SelectedDate,new Semaphore(1,1));
|
||||
semaphorePool.Add(Tasks.SelectedSymbol,new Semaphore(1,1));
|
||||
semaphorePool.Add(Tasks.SelectedWatchList,new Semaphore(1,1));
|
||||
base.DisplayName = DISPLAY_NAME;
|
||||
watchLists = WatchListDA.GetWatchLists();
|
||||
watchLists.Insert(0, Constants.CONST_ALL);
|
||||
selectedWatchList = watchLists.Find(x => x.Equals("Valuations"));
|
||||
symbols = WatchListDA.GetWatchList(selectedWatchList);
|
||||
symbols.Insert(0, Constants.CONST_ALL);
|
||||
selectedSymbol = symbols[0];
|
||||
dates = AnalystRatingsDA.GetAnalystRatingsDates();
|
||||
dates.Insert(0, Constants.CONST_ALL);
|
||||
if (dates.Count > 1) selectedDate = dates[1];
|
||||
else selectedDate = dates[0];
|
||||
PropertyChanged += OnAnalystRatingsViewModelPropertyChanged;
|
||||
if(!loadedFromParams)
|
||||
{
|
||||
base.OnPropertyChanged("SelectedDate");
|
||||
base.OnPropertyChanged("SelectedSymbol");
|
||||
}
|
||||
}
|
||||
// ******************************************************************************************** P E R S I S T E N C E ********************************************************************************************
|
||||
public override bool CanPersist()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public override SaveParameters GetSaveParameters()
|
||||
{
|
||||
SaveParameters saveParams = new SaveParameters();
|
||||
if (null == selectedSymbol) return null;
|
||||
saveParams.Add(new KeyValuePair<String, String>("Type", GetType().Namespace + "." + GetType().Name));
|
||||
saveParams.Add(new KeyValuePair<String, String>("SelectedSymbol", selectedSymbol));
|
||||
saveParams.Add(new KeyValuePair<String, String>("SelectedCompany", selectedCompany));
|
||||
saveParams.Add(new KeyValuePair<String, String>("SelectedWatchList", selectedWatchList));
|
||||
saveParams.Add(new KeyValuePair<String, String>("SelectedDate", selectedDate));
|
||||
return saveParams;
|
||||
}
|
||||
public override void SetSaveParameters(SaveParameters saveParameters)
|
||||
{
|
||||
try
|
||||
{
|
||||
selectedSymbol = (from KeyValuePair<String, String> item in saveParameters where item.Key.Equals("SelectedSymbol") select item).FirstOrDefault().Value;
|
||||
selectedWatchList = (from KeyValuePair<String, String> item in saveParameters where item.Key.Equals("SelectedWatchList") select item).FirstOrDefault().Value;
|
||||
selectedCompany = (from KeyValuePair<String, String> item in saveParameters where item.Key.Equals("SelectedCompany") select item).FirstOrDefault().Value;
|
||||
selectedDate = (from KeyValuePair<String, String> item in saveParameters where item.Key.Equals("SelectedDate") select item).FirstOrDefault().Value;
|
||||
if (null == selectedDate) selectedDate = Constants.CONST_ALL;
|
||||
Referer=saveParameters.Referer;
|
||||
base.OnPropertyChanged("SelectedWatchList");
|
||||
base.OnPropertyChanged("SelectedSymbol");
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
}
|
||||
// ******************************************************************************************************************************************************
|
||||
public bool BusyIndicator
|
||||
{
|
||||
get { return busyIndicator; }
|
||||
set
|
||||
{
|
||||
busyIndicator = value;
|
||||
base.OnPropertyChanged("BusyIndicator");
|
||||
}
|
||||
}
|
||||
public ObservableCollection<MenuItem> MenuItems
|
||||
{
|
||||
get
|
||||
{
|
||||
ObservableCollection<MenuItem> collection = new ObservableCollection<MenuItem>();
|
||||
collection.Add(new MenuItem() { Text = "Display Bollinger Band", MenuItemClickedCommand = DisplayBollingerBand, StaysOpenOnClick = false });
|
||||
collection.Add(new MenuItem() { Text = "Display Headlines", MenuItemClickedCommand = DisplayHeadlines, StaysOpenOnClick = false });
|
||||
collection.Add(new MenuItem() { Text = "Display Sticker Valuation", MenuItemClickedCommand = DisplayStickerValuation, StaysOpenOnClick = false });
|
||||
collection.Add(new MenuItem() { Text = "Display Historical", MenuItemClickedCommand = DisplayHistorical, StaysOpenOnClick = false });
|
||||
collection.Add(new MenuItem() { Text = "Display Stochastics", MenuItemClickedCommand = DisplayStochastics, StaysOpenOnClick = false });
|
||||
collection.Add(new MenuItem() { Text = "Display MACD", MenuItemClickedCommand = DisplayMACD, StaysOpenOnClick = false });
|
||||
collection.Add(new MenuItem() { Text = "Display Price History", MenuItemClickedCommand = DisplayPriceHistory, StaysOpenOnClick = false });
|
||||
collection.Add(new MenuItem() { Text = "Display DCF Valuation", MenuItemClickedCommand = DisplayDCFValuation, StaysOpenOnClick = false });
|
||||
collection.Add(new MenuItem() { Text = "Display Dividend History", MenuItemClickedCommand = DisplayDividendHistory, StaysOpenOnClick = false });
|
||||
return collection;
|
||||
}
|
||||
}
|
||||
private void OnAnalystRatingsViewModelPropertyChanged(object sender, PropertyChangedEventArgs eventArgs)
|
||||
{
|
||||
if (eventArgs.PropertyName.Equals("SelectedDate"))
|
||||
{
|
||||
try{semaphorePool[Tasks.SelectedDate].WaitOne();HandleSelectedDate();}finally{semaphorePool[Tasks.SelectedDate].Release();}
|
||||
}
|
||||
else if (eventArgs.PropertyName.Equals("SelectedSymbol"))
|
||||
{
|
||||
try{semaphorePool[Tasks.SelectedSymbol].WaitOne();HandleSelectedSymbol();}finally{semaphorePool[Tasks.SelectedSymbol].Release();}
|
||||
}
|
||||
else if (eventArgs.PropertyName.Equals("SelectedWatchList"))
|
||||
{
|
||||
try{semaphorePool[Tasks.SelectedWatchList].WaitOne();HandleSelectedWatchList();}finally{semaphorePool[Tasks.SelectedWatchList].Release();}
|
||||
}
|
||||
}
|
||||
private void HandleSelectedDate()
|
||||
{
|
||||
BusyIndicator = true;
|
||||
Task workerTask = Task.Factory.StartNew(() =>
|
||||
{
|
||||
if (Constants.CONST_ALL.Equals(selectedDate))
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG, "AnalystRatingsViewModel::HandleSelectedDate->C1");
|
||||
AnalystRatings analystRatings = AnalystRatingsDA.GetAnalystRatings(selectedSymbol);
|
||||
selectedCompany = PricingDA.GetNameForSymbol(selectedSymbol);
|
||||
if (null != analystRatings && 0 != analystRatings.Count) analystRatingsCollection = new ObservableCollection<AnalystRating>(analystRatings);
|
||||
else analystRatingsCollection = null;
|
||||
}
|
||||
else if (null != selectedSymbol && !Constants.CONST_ALL.Equals(selectedSymbol))
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG, "AnalystRatingsViewModel::HandleSelectedDate->C2");
|
||||
AnalystRatings analystRatings = AnalystRatingsDA.GetAnalystRatings(selectedSymbol, DateTime.Parse(selectedDate));
|
||||
selectedCompany = PricingDA.GetNameForSymbol(selectedSymbol);
|
||||
if (null != analystRatings && 0 != analystRatings.Count) analystRatingsCollection = new ObservableCollection<AnalystRating>(analystRatings);
|
||||
else analystRatingsCollection = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG, "AnalystRatingsViewModel::HandleSelectedDate->C3");
|
||||
AnalystRatings analystRatings = AnalystRatingsDA.GetAnalystRatings(DateTime.Parse(selectedDate));
|
||||
if (null != analystRatings && 0 != analystRatings.Count) analystRatingsCollection = new ObservableCollection<AnalystRating>(analystRatings);
|
||||
else analystRatingsCollection = null;
|
||||
}
|
||||
});
|
||||
workerTask.ContinueWith((continuation)=>
|
||||
{
|
||||
BusyIndicator = false;
|
||||
base.OnPropertyChanged("AllItems");
|
||||
base.OnPropertyChanged("Title");
|
||||
});
|
||||
}
|
||||
private void HandleSelectedSymbol()
|
||||
{
|
||||
BusyIndicator = true;
|
||||
Task workerTask = Task.Factory.StartNew(() =>
|
||||
{
|
||||
if (null != selectedSymbol && !Constants.CONST_ALL.Equals(selectedSymbol)) base.DisplayName = DISPLAY_NAME + "(" + selectedSymbol + ")";
|
||||
if (null != selectedSymbol && Constants.CONST_ALL.Equals(selectedSymbol) && null != selectedDate && Constants.CONST_ALL.Equals(selectedDate))
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG, "AnalystRatingsViewModel::HandleSelectedSymbol->C1");
|
||||
analystRatingsCollection.Clear();
|
||||
SelectedDate = dates[1];
|
||||
}
|
||||
else if (null == selectedSymbol || Constants.CONST_ALL.Equals(selectedSymbol))
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG, "AnalystRatingsViewModel::HandleSelectedSymbol->C2");
|
||||
AnalystRatings analystRatings = null;
|
||||
if (null == selectedDate || Constants.CONST_ALL.Equals(selectedDate)) analystRatings = AnalystRatingsDA.GetAnalystRatings();
|
||||
else analystRatings = AnalystRatingsDA.GetAnalystRatings(DateTime.Parse(selectedDate));
|
||||
if (null != analystRatings && 0 != analystRatings.Count) analystRatingsCollection = new ObservableCollection<AnalystRating>(analystRatings);
|
||||
else analystRatingsCollection = null;
|
||||
}
|
||||
else if (Constants.CONST_ALL.Equals(selectedDate))
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG, "AnalystRatingsViewModel::HandleSelectedSymbol->C3");
|
||||
AnalystRatings analystRatings = AnalystRatingsDA.GetAnalystRatings(selectedSymbol);
|
||||
selectedCompany = PricingDA.GetNameForSymbol(selectedSymbol);
|
||||
if (null != analystRatings && 0 != analystRatings.Count) analystRatingsCollection = new ObservableCollection<AnalystRating>(analystRatings);
|
||||
else analystRatingsCollection = null;
|
||||
}
|
||||
else if (null != selectedSymbol)
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG, "AnalystRatingsViewModel::HandleSelectedSymbol->C4");
|
||||
analystRatingsCollection.Clear();
|
||||
SelectedDate = Constants.CONST_ALL;
|
||||
}
|
||||
else
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG, "AnalystRatingsViewModel::HandleSelectedSymbol->C5");
|
||||
AnalystRatings analystRatings = AnalystRatingsDA.GetAnalystRatings(DateTime.Parse(selectedDate));
|
||||
if (null != analystRatings && 0 != analystRatings.Count) analystRatingsCollection = new ObservableCollection<AnalystRating>(analystRatings);
|
||||
else analystRatingsCollection = null;
|
||||
}
|
||||
});
|
||||
workerTask.ContinueWith((continuation) =>
|
||||
{
|
||||
BusyIndicator = false;
|
||||
base.OnPropertyChanged("AllItems");
|
||||
base.OnPropertyChanged("Title");
|
||||
base.OnPropertyChanged("DisplayName");
|
||||
});
|
||||
}
|
||||
private void HandleSelectedWatchList()
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG, "AnalystRatingsViewModel::HandleSelectedDate");
|
||||
if (selectedWatchList.Equals(Constants.CONST_ALL)) symbols = PricingDA.GetSymbols();
|
||||
else
|
||||
{
|
||||
symbols = WatchListDA.GetWatchList(selectedWatchList);
|
||||
symbols.Insert(0, Constants.CONST_ALL);
|
||||
}
|
||||
base.OnPropertyChanged("Symbols");
|
||||
}
|
||||
public ObservableCollection<AnalystRating> AllItems
|
||||
{
|
||||
get { return analystRatingsCollection; }
|
||||
}
|
||||
public String Description
|
||||
{
|
||||
get
|
||||
{
|
||||
if(null== selectedItem || null==selectedItem.Symbol)return "No row selected.";
|
||||
CompanyProfile companyProfile=CompanyProfileDA.GetCompanyProfile(selectedItem.Symbol);
|
||||
if(null==companyProfile || null==companyProfile.Description)return "No description found.";
|
||||
return companyProfile.Description;
|
||||
}
|
||||
}
|
||||
public String ZacksRank
|
||||
{
|
||||
get
|
||||
{
|
||||
if(null== selectedItem || null==selectedItem.Symbol)return "No row selected.";
|
||||
ZacksRank zacksRank=ZacksRankDA.GetZacksRank(selectedItem.Symbol);
|
||||
if(null==zacksRank)return "No Zacks rank";
|
||||
return zacksRank.Symbol+": latest Zacks Rank:"+zacksRank.Rank+" "+(null==zacksRank.Type?"":zacksRank.Type)+" "+zacksRank.Date.ToShortDateString();
|
||||
}
|
||||
}
|
||||
public override String Title
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null != selectedSymbol && !Constants.CONST_ALL.Equals(selectedSymbol)) return "Analyst Ratings - " + selectedCompany + " (" + selectedSymbol + ")";
|
||||
return "Analyst Ratings";
|
||||
}
|
||||
}
|
||||
private void Reset()
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG, "AnalystRatingsViewModel::Reset");
|
||||
selectedSymbol = symbols[0];
|
||||
selectedDate = dates[0];
|
||||
base.OnPropertyChanged("SelectedSymbol");
|
||||
}
|
||||
private bool CanReset
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
public ICommand ResetCommand
|
||||
{
|
||||
get
|
||||
{
|
||||
if (resetCommand == null)
|
||||
{
|
||||
resetCommand = new RelayCommand(param => this.Reset(), param => this.CanReset);
|
||||
}
|
||||
return resetCommand;
|
||||
}
|
||||
}
|
||||
public List<String> Dates
|
||||
{
|
||||
get
|
||||
{
|
||||
return dates;
|
||||
}
|
||||
}
|
||||
public List<String> Symbols
|
||||
{
|
||||
get
|
||||
{
|
||||
return symbols;
|
||||
}
|
||||
}
|
||||
public String SelectedSymbol
|
||||
{
|
||||
get
|
||||
{
|
||||
return selectedSymbol;
|
||||
}
|
||||
set
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG, "AnalystRatingsViewModel::SelectedSymbol");
|
||||
if (value == selectedSymbol || String.IsNullOrEmpty(value)) return;
|
||||
selectedSymbol = value;
|
||||
if (selectedSymbol.Equals(Constants.CONST_ALL))
|
||||
{
|
||||
selectedDate = dates[0];
|
||||
}
|
||||
base.OnPropertyChanged("SelectedSymbol");
|
||||
}
|
||||
}
|
||||
public String SelectedDate
|
||||
{
|
||||
get { return selectedDate; }
|
||||
set
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG, "AnalystRatingsViewModel::SelectedDate");
|
||||
selectedDate = value;
|
||||
base.OnPropertyChanged("SelectedDate");
|
||||
}
|
||||
}
|
||||
public List<String> WatchListNames
|
||||
{
|
||||
get
|
||||
{
|
||||
return watchLists;
|
||||
}
|
||||
set { ;}
|
||||
}
|
||||
public String SelectedWatchList
|
||||
{
|
||||
get { return selectedWatchList; }
|
||||
set { selectedWatchList = value; base.OnPropertyChanged("SelectedWatchList"); }
|
||||
}
|
||||
public ICommand DisplayHistorical
|
||||
{
|
||||
get
|
||||
{
|
||||
if (displayHistoricalCommand == null)
|
||||
{
|
||||
displayHistoricalCommand = new RelayCommand(param =>
|
||||
{
|
||||
SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.HistoricalViewModel,SelectedSymbol," + selectedItem.Symbol + ",SelectedWatchList,{All}");
|
||||
saveParams.Referer=this;
|
||||
WorkspaceInstantiator.Invoke(saveParams);
|
||||
}, param => { return null != selectedItem && null != selectedItem.Symbol; });
|
||||
}
|
||||
return displayHistoricalCommand;
|
||||
}
|
||||
}
|
||||
public ICommand DisplayHeadlines
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == displayHeadlinesCommand)
|
||||
{
|
||||
displayHeadlinesCommand = new RelayCommand(param =>
|
||||
{
|
||||
SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.HeadlinesViewModel,SelectedSymbol," + selectedItem.Symbol + ",SelectedWatchList,Valuations");
|
||||
saveParams.Referer=this;
|
||||
WorkspaceInstantiator.Invoke(saveParams);
|
||||
}, param => { return null != selectedItem && null!=selectedItem.Symbol; });
|
||||
}
|
||||
return displayHeadlinesCommand;
|
||||
}
|
||||
}
|
||||
public ICommand DisplayMACD
|
||||
{
|
||||
get
|
||||
{
|
||||
if (macdCommand == null)
|
||||
{
|
||||
macdCommand = new RelayCommand(param => this.DisplayMACDCommand(), param => { return null != selectedItem && null != selectedItem.Symbol; });
|
||||
}
|
||||
return macdCommand;
|
||||
}
|
||||
}
|
||||
public ICommand DisplayStochastics
|
||||
{
|
||||
get
|
||||
{
|
||||
if (stochasticsCommand == null)
|
||||
{
|
||||
stochasticsCommand = new RelayCommand(param => this.DisplayStochasticsCommand(), param => { return null != selectedItem && null != selectedItem.Symbol; });
|
||||
}
|
||||
return stochasticsCommand;
|
||||
}
|
||||
}
|
||||
public void DisplayStochasticsCommand()
|
||||
{
|
||||
SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.StochasticsViewModel,SelectedSymbol," + selectedItem.Symbol + ",SelectedWatchList,{All},SelectedDayCount,180");
|
||||
saveParams.Referer=this;
|
||||
WorkspaceInstantiator.Invoke(saveParams);
|
||||
}
|
||||
public void DisplayMACDCommand()
|
||||
{
|
||||
SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.MACDViewModel,SelectedSymbol," + selectedItem.Symbol + ",SelectedWatchList,{All},SelectedDayCount,180");
|
||||
saveParams.Referer=this;
|
||||
WorkspaceInstantiator.Invoke(saveParams);
|
||||
}
|
||||
public ICommand DisplayStickerValuation
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == stickerValuationCommand)
|
||||
{
|
||||
stickerValuationCommand = new RelayCommand(param =>
|
||||
{
|
||||
SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.StickerPriceViewModel,SelectedSymbol," + selectedItem.Symbol + ",SelectedWatchList,{All}");
|
||||
saveParams.Referer=this;
|
||||
WorkspaceInstantiator.Invoke(saveParams);
|
||||
}, param => { return null != selectedItem && null!=selectedItem.Symbol; });
|
||||
}
|
||||
return stickerValuationCommand;
|
||||
}
|
||||
}
|
||||
public ICommand DisplayDCFValuation
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == dcfValuationCommand)
|
||||
{
|
||||
dcfValuationCommand = new RelayCommand(param =>
|
||||
{
|
||||
SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.DCFValuationViewModel,SelectedSymbol," + selectedItem.Symbol + ",SelectedWatchList,{All}");
|
||||
saveParams.Referer=this;
|
||||
WorkspaceInstantiator.Invoke(saveParams);
|
||||
}, param => { return null != selectedItem && null!=selectedItem.Symbol; });
|
||||
}
|
||||
return dcfValuationCommand;
|
||||
}
|
||||
}
|
||||
public ICommand DisplayPriceHistory
|
||||
{
|
||||
get
|
||||
{
|
||||
if (priceHistoryCommand == null)
|
||||
{
|
||||
priceHistoryCommand = new RelayCommand(param => this.DisplayPriceHistoryCommand(), param => { return null != selectedItem && null != selectedItem.Symbol; });
|
||||
}
|
||||
return priceHistoryCommand;
|
||||
}
|
||||
}
|
||||
public ICommand DisplayDividendHistory
|
||||
{
|
||||
get
|
||||
{
|
||||
if (dividendHistoryCommand == null)
|
||||
{
|
||||
dividendHistoryCommand = new RelayCommand(param =>
|
||||
{
|
||||
SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.DividendHistoryViewModel,SelectedSymbol," + selectedItem.Symbol + ",SelectedWatchList,{All}");
|
||||
saveParams.Referer=this;
|
||||
WorkspaceInstantiator.Invoke(saveParams);
|
||||
}, param => { return null != selectedItem && null != selectedItem.Symbol; });
|
||||
}
|
||||
return dividendHistoryCommand;
|
||||
}
|
||||
}
|
||||
public void DisplayPriceHistoryCommand()
|
||||
{
|
||||
SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.PricingViewModel,SelectedSymbol," + selectedItem.Symbol + ",SelectedWatchList,{All},SelectedDayCount,180");
|
||||
saveParams.Referer=this;
|
||||
WorkspaceInstantiator.Invoke(saveParams);
|
||||
}
|
||||
public ICommand DisplayBollingerBand
|
||||
{
|
||||
get
|
||||
{
|
||||
if (bollingerBandCommand == null)
|
||||
{
|
||||
bollingerBandCommand = new RelayCommand(param => this.DisplayBollingerBandCommand(), param => { return null != selectedItem && null != selectedItem.Symbol; });
|
||||
}
|
||||
return bollingerBandCommand;
|
||||
}
|
||||
}
|
||||
public void DisplayBollingerBandCommand()
|
||||
{
|
||||
SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.BollingerBandViewModel,SelectedSymbol," + selectedItem.Symbol + ",SelectedWatchList,{All},SelectedDayCount,180");
|
||||
saveParams.Referer=this;
|
||||
WorkspaceInstantiator.Invoke(saveParams);
|
||||
}
|
||||
public AnalystRating SelectedItem
|
||||
{
|
||||
get
|
||||
{
|
||||
return selectedItem;
|
||||
}
|
||||
set
|
||||
{
|
||||
selectedItem = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
378
ViewModels/BlotterViewModel.cs
Normal file
@@ -0,0 +1,378 @@
|
||||
using System;
|
||||
using System.Windows.Input;
|
||||
using System.ComponentModel;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Collections.Specialized;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Threading;
|
||||
using System.Windows;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using MarketData;
|
||||
using MarketData.Utils;
|
||||
using MarketData.DataAccess;
|
||||
using TradeBlotter.DataAccess;
|
||||
using TradeBlotter.Command;
|
||||
using TradeBlotter.UIUtils;
|
||||
using TradeBlotter.Cache;
|
||||
using System.Windows.Forms;
|
||||
using MarketData.MarketDataModel;
|
||||
using TradeBlotter.Model;
|
||||
|
||||
namespace TradeBlotter.ViewModels
|
||||
{
|
||||
public delegate void EditHandler(int tradeId); // so we can post the event back up to the main window
|
||||
public delegate void DeleteHandler(int tradeId); // so we can post the event back up to the main window
|
||||
|
||||
public class BlotterViewModel : WorkspaceViewModel
|
||||
{
|
||||
private static readonly String LOADING_TRADES = "Loading Trades...";
|
||||
private static readonly String REFRESHING_PRICES = "Refreshing Prices...";
|
||||
private readonly TradeRepository tradeRepository;
|
||||
private PortfolioTrades portfolioTrades;
|
||||
double annualYieldAmt=double.NaN;
|
||||
double annualYieldPcnt=double.NaN;
|
||||
private RelayCommand refreshCommand;
|
||||
private RelayCommand deleteCommand;
|
||||
private RelayCommand editCommand;
|
||||
private EditHandler editHandler;
|
||||
private DeleteHandler deleteHandler;
|
||||
private TradeViewModel selectedItem = null;
|
||||
private bool busyIndicator = false;
|
||||
private String busyContent = LOADING_TRADES;
|
||||
private bool gridChanged = false;
|
||||
|
||||
public BlotterViewModel(TradeRepository tradeRepository,EditHandler editHandler,DeleteHandler deleteHandler)
|
||||
{
|
||||
this.editHandler = editHandler;
|
||||
this.deleteHandler = deleteHandler;
|
||||
base.DisplayName = "TradeView";
|
||||
this.tradeRepository = tradeRepository;
|
||||
this.CreateAllTrades();
|
||||
tradeRepository.TradeAdded += this.OnTradeAddedToRepository;
|
||||
}
|
||||
public override SaveParameters GetSaveParameters()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
public override void SetSaveParameters(SaveParameters saveParameters)
|
||||
{
|
||||
}
|
||||
public override bool CanPersist()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
protected override void OnDispose()
|
||||
{
|
||||
}
|
||||
public ObservableCollection<TradeViewModel> AllTrades
|
||||
{
|
||||
get; private set;
|
||||
}
|
||||
public bool BusyIndicator
|
||||
{
|
||||
get { return busyIndicator; }
|
||||
set
|
||||
{
|
||||
busyIndicator = value;
|
||||
base.OnPropertyChanged("BusyIndicator");
|
||||
}
|
||||
}
|
||||
public String BusyContent
|
||||
{
|
||||
get { return busyContent; }
|
||||
set
|
||||
{
|
||||
busyContent = value;
|
||||
base.OnPropertyChanged("BusyContent");
|
||||
}
|
||||
}
|
||||
public TradeViewModel SelectedItem
|
||||
{
|
||||
get
|
||||
{
|
||||
return selectedItem;
|
||||
}
|
||||
set
|
||||
{
|
||||
selectedItem = value;
|
||||
foreach (TradeViewModel tvm in this.AllTrades)
|
||||
{
|
||||
tvm.IsSelected = false;
|
||||
}
|
||||
if (null != selectedItem) selectedItem.IsSelected = true;
|
||||
}
|
||||
}
|
||||
private void CreateAllTrades()
|
||||
{
|
||||
BusyIndicator = true;
|
||||
Task workerTask=Task.Factory.StartNew(() =>
|
||||
{
|
||||
LoadPortfolioTrades();
|
||||
List<BlotterTradeModel> repositoryTrades=tradeRepository.GetTrades();
|
||||
repositoryTrades=repositoryTrades.OrderByDescending(x=>x.TradeDate).ThenBy(x=>x.TradeId).ToList();
|
||||
List<TradeViewModel> all = (from trade in repositoryTrades select new TradeViewModel(trade, tradeRepository)).ToList();
|
||||
double totalMarketValue = 0;
|
||||
foreach (TradeViewModel tradeViewModel in all)
|
||||
{
|
||||
if (!tradeViewModel.IsOpen) continue;
|
||||
totalMarketValue += Utility.ParseCurrency(tradeViewModel.MarketValue);
|
||||
}
|
||||
foreach (TradeViewModel tradeViewModel in all)
|
||||
{
|
||||
tradeViewModel.Weight = Utility.FormatPercent(Utility.ParseCurrency(tradeViewModel.MarketValue) / totalMarketValue);
|
||||
tradeViewModel.PropertyChanged += this.OnTradeViewModelPropertyChanged;
|
||||
}
|
||||
this.AllTrades = new ObservableCollection<TradeViewModel>(all);
|
||||
this.AllTrades.CollectionChanged += this.OnCollectionChanged;
|
||||
});
|
||||
workerTask.ContinueWith((continuation) =>
|
||||
{
|
||||
BusyIndicator = false;
|
||||
base.OnPropertyChanged("AllTrades");
|
||||
base.OnPropertyChanged("TotalExposure");
|
||||
base.OnPropertyChanged("TotalMarketValue");
|
||||
base.OnPropertyChanged("TotalGainLoss");
|
||||
base.OnPropertyChanged("TotalReturn");
|
||||
base.OnPropertyChanged("TotalGainLossAll");
|
||||
base.OnPropertyChanged("TotalReturnAll");
|
||||
base.OnPropertyChanged("AnnualDividendYieldAmt");
|
||||
base.OnPropertyChanged("AnnualDividendYieldPcnt");
|
||||
});
|
||||
}
|
||||
public void LoadPortfolioTrades()
|
||||
{
|
||||
portfolioTrades=PortfolioDA.GetOpenTrades();
|
||||
double weightAdjustedDividendYield=portfolioTrades.GetWeightAdjustedDividendYield();
|
||||
double exposure=portfolioTrades.Exposure();
|
||||
annualYieldAmt=weightAdjustedDividendYield*exposure;
|
||||
annualYieldPcnt=weightAdjustedDividendYield;
|
||||
}
|
||||
public String TotalExposure
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == this.AllTrades) return null;
|
||||
var openTrades = from trade in this.AllTrades where trade.IsOpen select trade;
|
||||
return Utility.FormatCurrency(openTrades.Sum(trade => Utility.ParseCurrency(trade.Exposure)));
|
||||
}
|
||||
}
|
||||
public String TotalMarketValue
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == this.AllTrades) return null;
|
||||
var openTrades = from trade in this.AllTrades where trade.IsOpen select trade;
|
||||
return Utility.FormatCurrency(openTrades.Sum(trade => Utility.ParseCurrency(trade.MarketValue)));
|
||||
}
|
||||
}
|
||||
public String TotalGainLoss
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == this.AllTrades) return null;
|
||||
var openTrades = from trade in this.AllTrades where trade.IsOpen select trade;
|
||||
return Utility.FormatCurrency(openTrades.Sum(trade => Utility.ParseCurrency(trade.MarketValue) - Utility.ParseCurrency(trade.Exposure)));
|
||||
}
|
||||
}
|
||||
public String TotalReturn
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == this.AllTrades) return null;
|
||||
var openTrades = from trade in this.AllTrades where trade.IsOpen select trade;
|
||||
double totalExposure = openTrades.Sum(trade => trade.Price * trade.Shares);
|
||||
double totalMarketValue = openTrades.Sum(trade => Utility.ParseCurrency(trade.CurrentPrice) * trade.Shares);
|
||||
return Utility.FormatPercent((totalMarketValue-totalExposure)/totalExposure);
|
||||
}
|
||||
}
|
||||
public String TotalGainLossAll
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == this.AllTrades) return null;
|
||||
var allTrades = from trade in this.AllTrades select trade;
|
||||
double totalExposure = allTrades.Sum(trade => trade.Price * trade.Shares);
|
||||
double totalMarketValue = allTrades.Sum(trade => Utility.ParseCurrency((trade.IsOpen ? trade.CurrentPrice : trade.SellPrice)) * trade.Shares);
|
||||
return Utility.FormatCurrency(totalMarketValue - totalExposure);
|
||||
}
|
||||
}
|
||||
public String TotalReturnAll
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == this.AllTrades) return null;
|
||||
var allTrades = from trade in this.AllTrades select trade;
|
||||
double totalExposure = allTrades.Sum(trade => trade.Price * trade.Shares);
|
||||
double totalMarketValue = allTrades.Sum(trade => Utility.ParseCurrency((trade.IsOpen?trade.CurrentPrice:trade.SellPrice))* trade.Shares);
|
||||
return Utility.FormatPercent((totalMarketValue - totalExposure) / totalExposure);
|
||||
}
|
||||
}
|
||||
public String AnnualDividendYieldPcnt
|
||||
{
|
||||
get
|
||||
{
|
||||
return Utility.FormatPercent(annualYieldPcnt);
|
||||
}
|
||||
}
|
||||
public String AnnualDividendYieldAmt
|
||||
{
|
||||
get
|
||||
{
|
||||
return Utility.FormatCurrency(annualYieldAmt);
|
||||
}
|
||||
}
|
||||
private void OnTradeAddedToRepository(Object sender, TradeAddedEventArgs e)
|
||||
{
|
||||
var viewModel = new TradeViewModel(e.NewTrade, tradeRepository);
|
||||
this.AllTrades.Add(viewModel);
|
||||
}
|
||||
private void OnTradeViewModelPropertyChanged(object sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
}
|
||||
private void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
|
||||
{
|
||||
if (e.NewItems != null && e.NewItems.Count != 0)
|
||||
foreach (TradeViewModel tradeVM in e.NewItems)
|
||||
tradeVM.PropertyChanged += this.OnTradeViewModelPropertyChanged;
|
||||
|
||||
if (e.OldItems != null && e.OldItems.Count != 0)
|
||||
foreach (TradeViewModel tradeVM in e.OldItems)
|
||||
tradeVM.PropertyChanged -= this.OnTradeViewModelPropertyChanged;
|
||||
}
|
||||
public String CompanyDescription
|
||||
{
|
||||
get
|
||||
{
|
||||
if(null== selectedItem || null==selectedItem.Symbol)return "No row selected.";
|
||||
CompanyProfile companyProfile=CompanyProfileDA.GetCompanyProfile(selectedItem.Symbol);
|
||||
if(null==companyProfile || null==companyProfile.Description)return "No description found.";
|
||||
return companyProfile.Description;
|
||||
}
|
||||
}
|
||||
// **************************************************************************************************************************
|
||||
// ******************************************************** R E F R E S H ***************************************************
|
||||
// **************************************************************************************************************************
|
||||
public bool GridChanged
|
||||
{
|
||||
get { return gridChanged; }
|
||||
set { gridChanged = value; base.OnPropertyChanged("GridChanged"); }
|
||||
}
|
||||
private void Refresh()
|
||||
{
|
||||
BusyContent = REFRESHING_PRICES;
|
||||
BusyIndicator = true;
|
||||
Dispatcher uiDispatcher = Dispatcher.CurrentDispatcher; // get the UI dispatcher
|
||||
Task workerTask = Task.Factory.StartNew(() =>
|
||||
{
|
||||
foreach (TradeViewModel tvm in this.AllTrades)
|
||||
{
|
||||
tvm.UseCache=true; // switch to cache when refreshing
|
||||
tvm.Invalidate();
|
||||
}
|
||||
});
|
||||
workerTask.ContinueWith((continuation) =>
|
||||
{
|
||||
BusyIndicator = false;
|
||||
BusyContent = LOADING_TRADES;
|
||||
uiDispatcher.Invoke((MethodInvoker)delegate()
|
||||
{
|
||||
foreach (TradeViewModel tvm in this.AllTrades)
|
||||
{
|
||||
tvm.Validate();
|
||||
}
|
||||
});
|
||||
base.OnPropertyChanged("TotalMarketValue");
|
||||
base.OnPropertyChanged("TotalGainLoss");
|
||||
base.OnPropertyChanged("TotalReturn");
|
||||
GridChanged = !GridChanged;
|
||||
});
|
||||
}
|
||||
private bool CanRefresh
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
public ICommand RefreshCommand
|
||||
{
|
||||
get
|
||||
{
|
||||
if (refreshCommand == null)
|
||||
{
|
||||
refreshCommand = new RelayCommand(param => this.Refresh(), param => this.CanRefresh);
|
||||
}
|
||||
return refreshCommand;
|
||||
}
|
||||
}
|
||||
// **************************************************************************************************************************
|
||||
// ******************************************************** E D I T ***************************************************
|
||||
// **************************************************************************************************************************
|
||||
private void Edit()
|
||||
{
|
||||
TradeViewModel tvmSelected = null;
|
||||
foreach (TradeViewModel tvm in this.AllTrades)
|
||||
{
|
||||
if (tvm.IsSelected) tvmSelected = tvm;
|
||||
}
|
||||
if (null == tvmSelected || null==editHandler) return;
|
||||
editHandler(tvmSelected.TradeId);
|
||||
}
|
||||
private bool CanEdit
|
||||
{
|
||||
get
|
||||
{
|
||||
return selectedItem == null ? false : true;
|
||||
}
|
||||
}
|
||||
public ICommand EditCommand
|
||||
{
|
||||
get
|
||||
{
|
||||
if (editCommand == null)
|
||||
{
|
||||
editCommand = new RelayCommand(param => this.Edit(), param => this.CanEdit);
|
||||
}
|
||||
return editCommand;
|
||||
}
|
||||
}
|
||||
|
||||
// **************************************************************************************************************************
|
||||
// ******************************************************** D E L E T E ***************************************************
|
||||
// **************************************************************************************************************************
|
||||
private void Delete()
|
||||
{
|
||||
TradeViewModel tvmToRemove=null;
|
||||
foreach (TradeViewModel tvm in this.AllTrades)
|
||||
{
|
||||
if (tvm.IsSelected) { tvmToRemove = tvm; break; }
|
||||
}
|
||||
if (null == tvmToRemove) return;
|
||||
string messageBoxText = "This operation cannot be undone, confirm delete trade_id("+tvmToRemove.TradeId+")";
|
||||
string caption = "eNavigator";
|
||||
MessageBoxButton button = MessageBoxButton.YesNoCancel;
|
||||
MessageBoxImage icon = MessageBoxImage.Warning;
|
||||
if(MessageBoxResult.Yes!=System.Windows.MessageBox.Show(messageBoxText, caption, button, icon))return;
|
||||
tradeRepository.Remove(tvmToRemove.TradeId);
|
||||
this.AllTrades.Remove(tvmToRemove);
|
||||
base.OnPropertyChanged("TotalMarketValue");
|
||||
base.OnPropertyChanged("TotalGainLoss");
|
||||
base.OnPropertyChanged("TotalReturn");
|
||||
if (null != deleteHandler) deleteHandler(tvmToRemove.TradeId);
|
||||
}
|
||||
private bool CanDelete
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
public ICommand DeleteCommand
|
||||
{
|
||||
get
|
||||
{
|
||||
if (deleteCommand == null)
|
||||
{
|
||||
deleteCommand = new RelayCommand(param => this.Delete(), param => this.CanDelete);
|
||||
}
|
||||
return deleteCommand;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
931
ViewModels/BollingerBandViewModel.cs
Normal file
@@ -0,0 +1,931 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Collections.Specialized;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
using MarketData;
|
||||
using MarketData.Numerical;
|
||||
using MarketData.Utils;
|
||||
using MarketData.MarketDataModel;
|
||||
using MarketData.Generator;
|
||||
using MarketData.Generator.GainLoss;
|
||||
using MarketData.DataAccess;
|
||||
using TradeBlotter.DataAccess;
|
||||
using TradeBlotter.Command;
|
||||
using TradeBlotter.Model;
|
||||
using TradeBlotter.Cache;
|
||||
using Microsoft.Research.DynamicDataDisplay.DataSources;
|
||||
using Microsoft.Research.DynamicDataDisplay.PointMarkers;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Threading;
|
||||
using System.Windows.Forms;
|
||||
using TradeBlotter.UIUtils;
|
||||
|
||||
|
||||
// Author:Sean Kessler
|
||||
|
||||
namespace TradeBlotter.ViewModels
|
||||
{
|
||||
public class BollingerBandViewModel : WorkspaceViewModel
|
||||
{
|
||||
private static readonly String BAND_MESSAGE="Generating Bollinger Band...";
|
||||
private static readonly String DATA_MESSAGE="Loading Pricing Data...";
|
||||
private BollingerBands bollingerBands;
|
||||
private StopLimit stopLimit; // This is the stop limit that is looked up in the database and displayed (if there is one)
|
||||
private StopLimits stopLimits; // These stop limits might be passed in with the SaveParams. (i.e.) MMTRend model passes in StopLimits. If these are passsed in then they are displayed instead of stopLimit.
|
||||
private String symbol;
|
||||
private String companyName;
|
||||
private Prices prices = null;
|
||||
private List<String> symbols;
|
||||
private List<String> watchLists;
|
||||
private String selectedWatchList;
|
||||
private RelayCommand refreshCommand;
|
||||
private List<Int32> dayCounts;
|
||||
private Int32 selectedDayCount;
|
||||
private PortfolioTrades portfolioTrades;
|
||||
private PortfolioTrades portfolioTradesLots;
|
||||
private InsiderTransactionSummaries insiderTransactionSummaries=null;
|
||||
private bool syncTradeToBand = true;
|
||||
private bool showTradeLabels = true;
|
||||
private bool showInsiderTransactions=true;
|
||||
private bool showRiskFree=false;
|
||||
private bool busyIndicator = false;
|
||||
private Price zeroPrice = null;
|
||||
private Price riskFreeRatePrice=null;
|
||||
private bool isLegendVisible = true;
|
||||
private bool useLeastSquaresFit=true;
|
||||
private String busyContent = BAND_MESSAGE;
|
||||
|
||||
private CompositeDataSource compositeDataSourceRiskFreeRatePoint=null;
|
||||
private CompositeDataSource compositeDataSourceZeroPoint=null;
|
||||
private CompositeDataSource compositeDataSourceStopLimit=null;
|
||||
|
||||
|
||||
private CompositeDataSource compositeDataSourceInsiderTransactionPointDisposedSmall=null;
|
||||
private CompositeDataSource compositeDataSourceInsiderTransactionPointDisposedMedium=null;
|
||||
private CompositeDataSource compositeDataSourceInsiderTransactionPointDisposedLarge=null;
|
||||
private CompositeDataSource compositeDataSourceInsiderTransactionPointAcquiredSmall=null;
|
||||
private CompositeDataSource compositeDataSourceInsiderTransactionPointAcquiredMedium=null;
|
||||
private CompositeDataSource compositeDataSourceInsiderTransactionPointAcquiredLarge=null;
|
||||
|
||||
private CompositeDataSource compositeDataSourceK=null;
|
||||
private CompositeDataSource compositeDataSourceKL1=null;
|
||||
private CompositeDataSource compositeDataSourceL=null;
|
||||
private CompositeDataSource compositeDataSourceLP1=null;
|
||||
private CompositeDataSource compositeDataSourceHigh=null;
|
||||
private CompositeDataSource compositeDataSourceLow=null;
|
||||
private CompositeDataSource compositeDataSourceClose=null;
|
||||
private CompositeDataSource compositeDataSourceSMAN=null;
|
||||
private CompositeDataSource compositeDataSourceVolume=null;
|
||||
private CompositeDataSource compositeDataSourceLeastSquares=null;
|
||||
private CompositeDataSource compositeDataSourceTradePoints=null;
|
||||
|
||||
public BollingerBandViewModel()
|
||||
{
|
||||
base.DisplayName = "Bollinger Band";
|
||||
watchLists = WatchListDA.GetWatchLists();
|
||||
watchLists.Insert(0, Constants.CONST_ALL);
|
||||
selectedWatchList = watchLists.Find(x => x.Equals("Valuations"));
|
||||
symbols = WatchListDA.GetWatchList(selectedWatchList);
|
||||
dayCounts = new List<Int32>();
|
||||
dayCounts.Add(60);
|
||||
dayCounts.Add(90);
|
||||
dayCounts.Add(180);
|
||||
dayCounts.Add(360);
|
||||
dayCounts.Add(720);
|
||||
dayCounts.Add(1440);
|
||||
dayCounts.Add(3600);
|
||||
selectedDayCount = dayCounts[2];
|
||||
PropertyChanged += OnBollingerBandViewModelPropertyChanged;
|
||||
}
|
||||
public override SaveParameters GetSaveParameters()
|
||||
{
|
||||
SaveParameters saveParams = new SaveParameters();
|
||||
if (null == symbol) return null;
|
||||
saveParams.Add(new KeyValuePair<String, String>("Type",GetType().Namespace+"."+GetType().Name));
|
||||
saveParams.Add(new KeyValuePair<String, String>("SelectedSymbol", symbol));
|
||||
saveParams.Add(new KeyValuePair<String, String>("SelectedWatchList", selectedWatchList));
|
||||
saveParams.Add(new KeyValuePair<String, String>("SelectedDayCount", selectedDayCount.ToString()));
|
||||
saveParams.Add(new KeyValuePair<String, String>("SyncTradeToBand", syncTradeToBand.ToString()));
|
||||
saveParams.Add(new KeyValuePair<String, String>("ShowTradeLabels", showTradeLabels.ToString()));
|
||||
saveParams.Add(new KeyValuePair<String, String>("ShowRiskFree", showRiskFree.ToString()));
|
||||
saveParams.Add(new KeyValuePair<String, String>("IsLegendVisible", isLegendVisible.ToString()));
|
||||
saveParams.Add(new KeyValuePair<String, String>("UseLeastSquaresFit", useLeastSquaresFit.ToString()));
|
||||
saveParams.Add(new KeyValuePair<String, String>("ShowInsiderTransactions", showInsiderTransactions.ToString()));
|
||||
if(null!=stopLimits && 0!=stopLimits.Count)
|
||||
{
|
||||
saveParams.Add(new KeyValuePair<String,String>("StopHistoryCount",stopLimits.Count.ToString()));
|
||||
for(int index=0;index<stopLimits.Count;index++)
|
||||
{
|
||||
String strItemKey=String.Format("StopHistory_{0}",index);
|
||||
StopLimit stopLimit=stopLimits[index];
|
||||
NVPCollection nvpCollection=stopLimit.ToNVPCollection();
|
||||
String strStopHistoryItem=nvpCollection.ToString();
|
||||
saveParams.Add(new KeyValuePair<String,String>(strItemKey,strStopHistoryItem));
|
||||
}
|
||||
}
|
||||
return saveParams;
|
||||
}
|
||||
public override void SetSaveParameters(SaveParameters saveParameters)
|
||||
{
|
||||
try
|
||||
{
|
||||
Referer=saveParameters.Referer;
|
||||
symbol = (from KeyValuePair<String, String> item in saveParameters where item.Key.Equals("SelectedSymbol") select item).FirstOrDefault().Value;
|
||||
selectedWatchList = (from KeyValuePair<String, String> item in saveParameters where item.Key.Equals("SelectedWatchList") select item).FirstOrDefault().Value;
|
||||
base.OnPropertyChanged("SelectedWatchList");
|
||||
selectedDayCount = Int32.Parse((from KeyValuePair<String, String> item in saveParameters where item.Key.Equals("SelectedDayCount") select item).FirstOrDefault().Value);
|
||||
try
|
||||
{
|
||||
if(saveParameters.ContainsKey("SyncTradeToBand"))syncTradeToBand=Boolean.Parse((from KeyValuePair<String,String> item in saveParameters where item.Key.Equals("SyncTradeToBand") select item).FirstOrDefault().Value);
|
||||
else syncTradeToBand=true;
|
||||
}
|
||||
catch (Exception) { syncTradeToBand = true; }
|
||||
try
|
||||
{
|
||||
if(saveParameters.ContainsKey("ShowTradeLabels"))showTradeLabels = Boolean.Parse((from KeyValuePair<String, String> item in saveParameters where item.Key.Equals("ShowTradeLabels") select item).FirstOrDefault().Value);
|
||||
else showTradeLabels=true;
|
||||
}
|
||||
catch (Exception) { showTradeLabels = true; }
|
||||
try
|
||||
{
|
||||
if(saveParameters.ContainsKey("IsLegendVisible"))isLegendVisible=Boolean.Parse((from KeyValuePair<String,String> item in saveParameters where item.Key.Equals("IsLegendVisible") select item).FirstOrDefault().Value);
|
||||
}
|
||||
catch (Exception){;}
|
||||
try
|
||||
{
|
||||
if(saveParameters.ContainsKey("UseLeastSquaresFit"))useLeastSquaresFit=Boolean.Parse((from KeyValuePair<String,String> item in saveParameters where item.Key.Equals("UseLeastSquaresFit") select item).FirstOrDefault().Value);
|
||||
}
|
||||
catch (Exception){;}
|
||||
try
|
||||
{
|
||||
if(saveParameters.ContainsKey("ShowInsiderTransactions"))showInsiderTransactions=Boolean.Parse((from KeyValuePair<String,String> item in saveParameters where item.Key.Equals("ShowInsiderTransactions") select item).FirstOrDefault().Value);
|
||||
}
|
||||
catch (Exception){;}
|
||||
try{showRiskFree = Boolean.Parse((from KeyValuePair<String, String> item in saveParameters where item.Key.Equals("ShowRiskFree") select item).FirstOrDefault().Value);}
|
||||
catch (Exception){;}
|
||||
|
||||
try
|
||||
{
|
||||
if(saveParameters.ContainsKey("StopHistoryCount"))
|
||||
{
|
||||
stopLimits=new StopLimits();
|
||||
int stopHistoryCount=int.Parse((from KeyValuePair<String,String> item in saveParameters where item.Key.Equals("StopHistoryCount") select item).FirstOrDefault().Value);
|
||||
for(int index=0;index<stopHistoryCount;index++)
|
||||
{
|
||||
String strItemKey=String.Format("StopHistory_{0}",index);
|
||||
String strStopHistoryItem=(from KeyValuePair<String,String> item in saveParameters where item.Key.Equals(strItemKey) select item).FirstOrDefault().Value;
|
||||
NVPCollection nvpCollection=new NVPCollection(strStopHistoryItem);
|
||||
StopLimit stopLimit=MarketData.MarketDataModel.StopLimit.FromNVPCollection(nvpCollection);
|
||||
stopLimits.Add(stopLimit);
|
||||
}
|
||||
stopLimits=new StopLimits(stopLimits.OrderBy(x => x.EffectiveDate).ToList());
|
||||
}
|
||||
}
|
||||
catch(Exception exception)
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Exception:{0}",exception.ToString()));
|
||||
}
|
||||
base.OnPropertyChanged("SelectedSymbol");
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
}
|
||||
public override bool CanPersist()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public bool BusyIndicator
|
||||
{
|
||||
get { return busyIndicator; }
|
||||
set
|
||||
{
|
||||
busyIndicator = value;
|
||||
base.OnPropertyChanged("BusyIndicator");
|
||||
}
|
||||
}
|
||||
public String BusyContent
|
||||
{
|
||||
get { return busyContent; }
|
||||
set
|
||||
{
|
||||
busyContent = value;
|
||||
base.OnPropertyChanged("BusyContent");
|
||||
}
|
||||
}
|
||||
private void OnBollingerBandViewModelPropertyChanged(object sender, PropertyChangedEventArgs eventArgs)
|
||||
{
|
||||
if (eventArgs.PropertyName.Equals("SelectedSymbol"))
|
||||
{
|
||||
InitializeDataSources();
|
||||
insiderTransactionSummaries=null;
|
||||
zeroPrice=null;
|
||||
riskFreeRatePrice=null;
|
||||
prices=null;
|
||||
portfolioTrades=null;
|
||||
portfolioTradesLots=null;
|
||||
stopLimit=null;
|
||||
}
|
||||
|
||||
if (eventArgs.PropertyName.Equals("SyncTradeToBand")||
|
||||
eventArgs.PropertyName.Equals("ShowTradeLabels")||
|
||||
eventArgs.PropertyName.Equals("SelectedSymbol")||
|
||||
eventArgs.PropertyName.Equals("ShowRiskFree")||
|
||||
eventArgs.PropertyName.Equals("LeastSquaresFit")||
|
||||
(eventArgs.PropertyName.Equals("SelectedDayCount")&&null!=symbol))
|
||||
{
|
||||
BusyIndicator=true;
|
||||
Task workerTask=Task.Factory.StartNew(()=>
|
||||
{
|
||||
base.DisplayName="Bollinger("+symbol+")";
|
||||
base.OnPropertyChanged("DisplayName");
|
||||
BusyContent=DATA_MESSAGE;
|
||||
|
||||
// DEBUG
|
||||
stopLimit=PortfolioDA.GetStopLimit(symbol);
|
||||
portfolioTrades = PortfolioDA.GetTradesSymbol(symbol);
|
||||
portfolioTradesLots=LotAggregator.CombineLots(portfolioTrades);
|
||||
if (null != portfolioTrades && 0 != portfolioTrades.Count)
|
||||
{
|
||||
DateGenerator dateGenerator = new DateGenerator();
|
||||
DateTime earliestTrade = portfolioTrades[0].TradeDate;
|
||||
earliestTrade = earliestTrade.AddDays(-30);
|
||||
int daysBetween = dateGenerator.DaysBetween(earliestTrade, DateTime.Now);
|
||||
if (daysBetween < selectedDayCount || !syncTradeToBand) prices = PricingDA.GetPrices(symbol, selectedDayCount);
|
||||
else prices = PricingDA.GetPrices(symbol, earliestTrade);
|
||||
|
||||
DateTime earliestInsiderTransactionDate=dateGenerator.GenerateFutureBusinessDate(prices[prices.Count-1].Date,30);
|
||||
insiderTransactionSummaries=InsiderTransactionDA.GetInsiderTransactionSummaries(symbol,earliestInsiderTransactionDate);
|
||||
|
||||
// calculate the break even price on the open trades for this symbol
|
||||
PortfolioTrades openTrades=portfolioTrades.GetOpenTrades();
|
||||
DateTime latestPricingDate = PricingDA.GetLatestDate(symbol);
|
||||
Price latestPrice = PricingDA.GetPrice(symbol, latestPricingDate);
|
||||
zeroPrice=ParityGenerator.GenerateGainLossValue(openTrades,latestPrice);
|
||||
// calculate the risk free rate price. This is arrived at by investing each of the amounts in the trades for this symbol at the risk free rate.
|
||||
// the total is then divided by the number of shares owned. So this price we be the true break even considering that we could have invested risk
|
||||
// free instead of owning this security.
|
||||
riskFreeRatePrice=RiskFreeRateGenerator.GeneratePriceAtRiskFreeRate(portfolioTrades);
|
||||
if (!syncTradeToBand)
|
||||
{
|
||||
DateTime earliestPricingDate = prices[prices.Count - 1].Date;
|
||||
earliestPricingDate = earliestPricingDate.AddDays(30);
|
||||
IEnumerable<PortfolioTrade> tradesInRange = (from portfolioTrade in portfolioTradesLots where portfolioTrade.TradeDate >= earliestPricingDate select portfolioTrade);
|
||||
portfolioTrades = new PortfolioTrades();
|
||||
foreach (PortfolioTrade portfolioTrade in tradesInRange) portfolioTrades.Add(portfolioTrade);
|
||||
portfolioTradesLots = portfolioTrades;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
prices = PricingDA.GetPrices(symbol, selectedDayCount);
|
||||
if (null != prices && 0 != prices.Count)
|
||||
{
|
||||
DateGenerator dateGenerator = new DateGenerator();
|
||||
DateTime earliestInsiderTransactionDate = dateGenerator.GenerateFutureBusinessDate(prices[prices.Count - 1].Date, 30);
|
||||
insiderTransactionSummaries = InsiderTransactionDA.GetInsiderTransactionSummaries(symbol, earliestInsiderTransactionDate);
|
||||
}
|
||||
}
|
||||
companyName = PricingDA.GetNameForSymbol(symbol);
|
||||
BusyContent=BAND_MESSAGE;
|
||||
bollingerBands = BollingerBandGenerator.GenerateBollingerBands(prices);
|
||||
CreateCompositeDataSources();
|
||||
});
|
||||
workerTask.ContinueWith((continuation)=>
|
||||
{
|
||||
BusyIndicator = false;
|
||||
base.OnPropertyChanged("K");
|
||||
base.OnPropertyChanged("KL1");
|
||||
base.OnPropertyChanged("L");
|
||||
base.OnPropertyChanged("LP1");
|
||||
base.OnPropertyChanged("High");
|
||||
base.OnPropertyChanged("Low");
|
||||
base.OnPropertyChanged("Close");
|
||||
base.OnPropertyChanged("SMAN");
|
||||
base.OnPropertyChanged("Volume");
|
||||
base.OnPropertyChanged("LeastSquares");
|
||||
base.OnPropertyChanged("Title");
|
||||
base.OnPropertyChanged("TradePoints");
|
||||
base.OnPropertyChanged("Markers");
|
||||
base.OnPropertyChanged("ZeroPoint");
|
||||
base.OnPropertyChanged("ZeroPointMarkers");
|
||||
base.OnPropertyChanged("StopLimit");
|
||||
base.OnPropertyChanged("StopLimitMarkers");
|
||||
base.OnPropertyChanged("RiskFreeRatePoint");
|
||||
base.OnPropertyChanged("RiskFreeRatePointMarkers");
|
||||
|
||||
base.OnPropertyChanged("InsiderTransactionPointDisposedSmall");
|
||||
base.OnPropertyChanged("InsiderTransactionPointMarkersDisposedSmall");
|
||||
base.OnPropertyChanged("InsiderTransactionPointDisposedMedium");
|
||||
base.OnPropertyChanged("InsiderTransactionPointMarkersDisposedMedium");
|
||||
base.OnPropertyChanged("InsiderTransactionPointDisposedLarge");
|
||||
base.OnPropertyChanged("InsiderTransactionPointMarkersDisposedLarge");
|
||||
|
||||
base.OnPropertyChanged("InsiderTransactionPointAcquiredSmall");
|
||||
base.OnPropertyChanged("InsiderTransactionPointMarkersAcquiredSmall");
|
||||
base.OnPropertyChanged("InsiderTransactionPointAcquiredMedium");
|
||||
base.OnPropertyChanged("InsiderTransactionPointMarkersAcquiredMedium");
|
||||
base.OnPropertyChanged("InsiderTransactionPointAcquiredLarge");
|
||||
base.OnPropertyChanged("InsiderTransactionPointMarkersAcquiredLarge");
|
||||
});
|
||||
}
|
||||
else if (eventArgs.PropertyName.Equals("SelectedWatchList"))
|
||||
{
|
||||
BusyIndicator = true;
|
||||
BusyContent = DATA_MESSAGE;
|
||||
Task workerTask = Task.Factory.StartNew(() =>
|
||||
{
|
||||
if (selectedWatchList.Equals(Constants.CONST_ALL)) symbols = PricingDA.GetSymbols();
|
||||
else symbols = WatchListDA.GetWatchList(selectedWatchList);
|
||||
});
|
||||
workerTask.ContinueWith((continuation) =>
|
||||
{
|
||||
BusyIndicator = false;
|
||||
BusyContent = BAND_MESSAGE;
|
||||
base.OnPropertyChanged("Symbols");
|
||||
});
|
||||
}
|
||||
}
|
||||
// *************************************************************************** C U S T O M B E H A V I O R **************************************************
|
||||
public Boolean LeastSquaresFit
|
||||
{
|
||||
get
|
||||
{
|
||||
return useLeastSquaresFit;
|
||||
}
|
||||
set
|
||||
{
|
||||
useLeastSquaresFit = value;
|
||||
base.OnPropertyChanged("LeastSquaresFit");
|
||||
}
|
||||
}
|
||||
public Boolean CheckBoxLegendVisible
|
||||
{
|
||||
get
|
||||
{
|
||||
return isLegendVisible;
|
||||
}
|
||||
set
|
||||
{
|
||||
isLegendVisible = value;
|
||||
base.OnPropertyChanged("CheckBoxLegendVisible");
|
||||
base.OnPropertyChanged("LegendVisible");
|
||||
}
|
||||
}
|
||||
public String LegendVisible
|
||||
{
|
||||
get
|
||||
{
|
||||
if (isLegendVisible) return "true";
|
||||
return "false";
|
||||
}
|
||||
set
|
||||
{
|
||||
isLegendVisible = Boolean.Parse(value);
|
||||
base.OnPropertyChanged("LegendVisible");
|
||||
}
|
||||
}
|
||||
public bool ShowRiskFree
|
||||
{
|
||||
get
|
||||
{
|
||||
return showRiskFree;
|
||||
}
|
||||
set
|
||||
{
|
||||
showRiskFree = value;
|
||||
base.OnPropertyChanged("ShowRiskFree");
|
||||
}
|
||||
}
|
||||
public bool ShowTradeLabels
|
||||
{
|
||||
get
|
||||
{
|
||||
return showTradeLabels;
|
||||
}
|
||||
set
|
||||
{
|
||||
showTradeLabels = value;
|
||||
if(showTradeLabels)syncTradeToBand=true;
|
||||
base.OnPropertyChanged("ShowTradeLabels");
|
||||
}
|
||||
}
|
||||
public bool SyncTradeToBand
|
||||
{
|
||||
get
|
||||
{
|
||||
return syncTradeToBand;
|
||||
}
|
||||
set
|
||||
{
|
||||
syncTradeToBand = value;
|
||||
if (syncTradeToBand) showTradeLabels = true;
|
||||
base.OnPropertyChanged("SyncTradeToBand");
|
||||
}
|
||||
}
|
||||
// ************************************************************ C o m p o s i t e D a t a S o u r c e s *************************************************
|
||||
public void CreateCompositeDataSources()
|
||||
{
|
||||
if(null==prices||0==prices.Count)return;
|
||||
double minClose=(from Price price in prices select price.Close).Min();
|
||||
// get the maximum date in the bollinger band series
|
||||
DateTime maxBollingerDate=(from BollingerBandElement bollingerBandElement in bollingerBands select bollingerBandElement.Date).Max();
|
||||
// ensure that the insider transactions are clipped to the bollingerband max date. There are some items in insider transaction summaries (options dated in the future) that will throw the graphic out of proportion
|
||||
InsiderTransactionSummaries disposedSummaries=new InsiderTransactionSummaries((from InsiderTransactionSummary insiderTransactionSummary in insiderTransactionSummaries where insiderTransactionSummary.NumberOfSharesAcquiredDisposed<0 && insiderTransactionSummary.TransactionDate.Date<=maxBollingerDate select insiderTransactionSummary).ToList());
|
||||
InsiderTransactionSummaries acquiredSummaries=new InsiderTransactionSummaries((from InsiderTransactionSummary insiderTransactionSummary in insiderTransactionSummaries where insiderTransactionSummary.NumberOfSharesAcquiredDisposed>0 && insiderTransactionSummary.TransactionDate.Date<=maxBollingerDate select insiderTransactionSummary).ToList());
|
||||
|
||||
BinCollection<InsiderTransactionSummary> disposedSummariesBin=BinHelper<InsiderTransactionSummary>.CreateBins(new BinItems<InsiderTransactionSummary>(disposedSummaries),3);
|
||||
BinCollection<InsiderTransactionSummary> acquiredSummariesBin=BinHelper<InsiderTransactionSummary>.CreateBins(new BinItems<InsiderTransactionSummary>(acquiredSummaries),3);
|
||||
|
||||
compositeDataSourceRiskFreeRatePoint=GainLossModel.Price(riskFreeRatePrice);
|
||||
compositeDataSourceZeroPoint= GainLossModel.Price(zeroPrice);
|
||||
|
||||
if(null!=stopLimits)
|
||||
{
|
||||
compositeDataSourceStopLimit=StopLimitCompositeModel.CreateCompositeDataSource(stopLimits);
|
||||
}
|
||||
else if(null!=stopLimit && null!=zeroPrice)
|
||||
{
|
||||
compositeDataSourceStopLimit=GainLossModel.CreateCompositeDataSource(zeroPrice.Date,stopLimit.StopPrice);
|
||||
}
|
||||
|
||||
compositeDataSourceInsiderTransactionPointDisposedSmall=InsiderTransactionModel.InsiderTransactionSummaries(new InsiderTransactionSummaries(disposedSummariesBin[2]),minClose);
|
||||
compositeDataSourceInsiderTransactionPointDisposedMedium=InsiderTransactionModel.InsiderTransactionSummaries(new InsiderTransactionSummaries(disposedSummariesBin[1]),minClose);
|
||||
compositeDataSourceInsiderTransactionPointDisposedLarge=InsiderTransactionModel.InsiderTransactionSummaries(new InsiderTransactionSummaries(disposedSummariesBin[0]),minClose);
|
||||
compositeDataSourceInsiderTransactionPointAcquiredSmall=InsiderTransactionModel.InsiderTransactionSummaries(new InsiderTransactionSummaries(acquiredSummariesBin[0]),minClose);
|
||||
compositeDataSourceInsiderTransactionPointAcquiredMedium=InsiderTransactionModel.InsiderTransactionSummaries(new InsiderTransactionSummaries(acquiredSummariesBin[1]),minClose);
|
||||
compositeDataSourceInsiderTransactionPointAcquiredLarge=InsiderTransactionModel.InsiderTransactionSummaries(new InsiderTransactionSummaries(acquiredSummariesBin[2]),minClose);
|
||||
|
||||
compositeDataSourceK =BollingerBandModel.K(bollingerBands);
|
||||
compositeDataSourceKL1 =BollingerBandModel.KL1(bollingerBands);
|
||||
compositeDataSourceL =BollingerBandModel.L(bollingerBands);
|
||||
compositeDataSourceLP1 =BollingerBandModel.LP1(bollingerBands);
|
||||
compositeDataSourceHigh =BollingerBandModel.High(bollingerBands);
|
||||
compositeDataSourceLow =BollingerBandModel.Low(bollingerBands);
|
||||
compositeDataSourceClose =BollingerBandModel.Close(bollingerBands);
|
||||
compositeDataSourceSMAN =BollingerBandModel.SMAN(bollingerBands);
|
||||
compositeDataSourceVolume =BollingerBandModel.Volume(bollingerBands);
|
||||
|
||||
compositeDataSourceLeastSquares = BollingerBandModel.LeastSquares(bollingerBands);
|
||||
|
||||
compositeDataSourceTradePoints = PortfolioTradeModel.PortfolioTrades(portfolioTradesLots);
|
||||
}
|
||||
public void InitializeDataSources()
|
||||
{
|
||||
if(compositeDataSourceStopLimit!=null)compositeDataSourceStopLimit.Clear();
|
||||
if(compositeDataSourceRiskFreeRatePoint!=null)compositeDataSourceRiskFreeRatePoint.Clear();
|
||||
if(compositeDataSourceZeroPoint!=null)compositeDataSourceZeroPoint.Clear();
|
||||
|
||||
if(compositeDataSourceInsiderTransactionPointDisposedSmall!=null)compositeDataSourceInsiderTransactionPointDisposedSmall.Clear();
|
||||
if(compositeDataSourceInsiderTransactionPointDisposedMedium!=null)compositeDataSourceInsiderTransactionPointDisposedMedium.Clear();
|
||||
if(compositeDataSourceInsiderTransactionPointDisposedLarge!=null)compositeDataSourceInsiderTransactionPointDisposedLarge.Clear();
|
||||
|
||||
if(compositeDataSourceInsiderTransactionPointAcquiredSmall!=null)compositeDataSourceInsiderTransactionPointAcquiredSmall.Clear();
|
||||
if(compositeDataSourceInsiderTransactionPointAcquiredMedium!=null)compositeDataSourceInsiderTransactionPointAcquiredMedium.Clear();
|
||||
if(compositeDataSourceInsiderTransactionPointAcquiredLarge!=null)compositeDataSourceInsiderTransactionPointAcquiredLarge.Clear();
|
||||
|
||||
if(compositeDataSourceK!=null)compositeDataSourceK.Clear();
|
||||
if(compositeDataSourceKL1!=null)compositeDataSourceKL1.Clear();
|
||||
if(compositeDataSourceL!=null)compositeDataSourceL.Clear();
|
||||
if(compositeDataSourceLP1!=null)compositeDataSourceLP1.Clear();
|
||||
if(compositeDataSourceHigh!=null)compositeDataSourceHigh.Clear();
|
||||
if(compositeDataSourceLow!=null)compositeDataSourceLow.Clear();
|
||||
if(compositeDataSourceClose!=null)compositeDataSourceClose.Clear();
|
||||
if(compositeDataSourceSMAN!=null)compositeDataSourceSMAN.Clear();
|
||||
if(compositeDataSourceVolume!=null)compositeDataSourceVolume.Clear();
|
||||
if(compositeDataSourceLeastSquares!=null)compositeDataSourceLeastSquares.Clear();
|
||||
if (compositeDataSourceTradePoints != null) compositeDataSourceTradePoints.Clear();
|
||||
}
|
||||
public CompositeDataSource RiskFreeRatePoint
|
||||
{
|
||||
get
|
||||
{
|
||||
if(!showRiskFree)return null;
|
||||
return compositeDataSourceRiskFreeRatePoint;
|
||||
}
|
||||
}
|
||||
|
||||
public CompositeDataSource ZeroPoint
|
||||
{
|
||||
get
|
||||
{
|
||||
return compositeDataSourceZeroPoint;
|
||||
}
|
||||
}
|
||||
public CompositeDataSource StopLimit
|
||||
{
|
||||
get
|
||||
{
|
||||
return compositeDataSourceStopLimit;
|
||||
}
|
||||
}
|
||||
// **************************************************************** I N S I D E R T R A N S A C T I O N S *************************************************
|
||||
public CompositeDataSource InsiderTransactionPointDisposedSmall
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!showInsiderTransactions || null == insiderTransactionSummaries || null==prices) return null;
|
||||
return compositeDataSourceInsiderTransactionPointDisposedSmall;
|
||||
}
|
||||
}
|
||||
|
||||
public CenteredTextMarker[] InsiderTransactionPointMarkersDisposedSmall
|
||||
{
|
||||
get
|
||||
{
|
||||
return null; // not displaying any text markers for disposed shares yet
|
||||
}
|
||||
}
|
||||
public CompositeDataSource InsiderTransactionPointDisposedMedium
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!showInsiderTransactions || null == insiderTransactionSummaries || null==prices) return null;
|
||||
return compositeDataSourceInsiderTransactionPointDisposedMedium;
|
||||
}
|
||||
}
|
||||
|
||||
public CenteredTextMarker[] InsiderTransactionPointMarkersDisposedMedium
|
||||
{
|
||||
get
|
||||
{
|
||||
return null; // not displaying any text markers for disposed shares yet
|
||||
}
|
||||
}
|
||||
public CompositeDataSource InsiderTransactionPointDisposedLarge
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!showInsiderTransactions || null == insiderTransactionSummaries || null==prices) return null;
|
||||
return compositeDataSourceInsiderTransactionPointDisposedLarge;
|
||||
}
|
||||
}
|
||||
|
||||
public CenteredTextMarker[] InsiderTransactionPointMarkersDisposedLarge
|
||||
{
|
||||
get
|
||||
{
|
||||
return null; // not displaying any text markers for disposed shares yet
|
||||
}
|
||||
}
|
||||
// *****************************************************************************************************************************************************
|
||||
public CompositeDataSource InsiderTransactionPointAcquiredSmall
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!showInsiderTransactions || null == insiderTransactionSummaries || null==prices) return null;
|
||||
return compositeDataSourceInsiderTransactionPointAcquiredSmall;
|
||||
}
|
||||
}
|
||||
public CenteredTextMarker[] InsiderTransactionPointMarkersAcquiredSmall
|
||||
{
|
||||
get
|
||||
{
|
||||
return null; // not displaying any text markers for acquired shares yet.
|
||||
}
|
||||
}
|
||||
public CompositeDataSource InsiderTransactionPointAcquiredMedium
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!showInsiderTransactions || null == insiderTransactionSummaries || null==prices) return null;
|
||||
return compositeDataSourceInsiderTransactionPointAcquiredMedium;
|
||||
}
|
||||
}
|
||||
public CenteredTextMarker[] InsiderTransactionPointMarkersAcquiredMedium
|
||||
{
|
||||
get
|
||||
{
|
||||
return null; // not displaying any text markers for acquired shares yet.
|
||||
}
|
||||
}
|
||||
public CompositeDataSource InsiderTransactionPointAcquiredLarge
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!showInsiderTransactions || null == insiderTransactionSummaries || null==prices) return null;
|
||||
return compositeDataSourceInsiderTransactionPointAcquiredLarge;
|
||||
}
|
||||
}
|
||||
public CenteredTextMarker[] InsiderTransactionPointMarkersAcquiredLarge
|
||||
{
|
||||
get
|
||||
{
|
||||
return null; // not displaying any text markers for acquired shares yet.
|
||||
}
|
||||
}
|
||||
// *********************************************************************************************************************************************************************
|
||||
public CompositeDataSource K
|
||||
{
|
||||
get
|
||||
{
|
||||
return compositeDataSourceK;
|
||||
}
|
||||
}
|
||||
public CompositeDataSource KL1
|
||||
{
|
||||
get
|
||||
{
|
||||
return compositeDataSourceKL1;
|
||||
}
|
||||
}
|
||||
|
||||
public CompositeDataSource L
|
||||
{
|
||||
get
|
||||
{
|
||||
return compositeDataSourceL;
|
||||
}
|
||||
}
|
||||
public CompositeDataSource LP1
|
||||
{
|
||||
get
|
||||
{
|
||||
return compositeDataSourceLP1;
|
||||
}
|
||||
}
|
||||
public CompositeDataSource High
|
||||
{
|
||||
get
|
||||
{
|
||||
return compositeDataSourceHigh;
|
||||
}
|
||||
}
|
||||
public CompositeDataSource Low
|
||||
{
|
||||
get
|
||||
{
|
||||
return compositeDataSourceLow;
|
||||
}
|
||||
}
|
||||
public CompositeDataSource Close
|
||||
{
|
||||
get
|
||||
{
|
||||
return compositeDataSourceClose;
|
||||
}
|
||||
}
|
||||
public CompositeDataSource SMAN
|
||||
{
|
||||
get
|
||||
{
|
||||
return compositeDataSourceSMAN;
|
||||
}
|
||||
}
|
||||
public CompositeDataSource Volume
|
||||
{
|
||||
get
|
||||
{
|
||||
return compositeDataSourceVolume;
|
||||
}
|
||||
}
|
||||
// ********************************************************************* L E A S T S Q U A R E S *************************************************************
|
||||
public CompositeDataSource LeastSquares
|
||||
{
|
||||
get
|
||||
{
|
||||
if(!useLeastSquaresFit||null==bollingerBands)return null;
|
||||
return compositeDataSourceLeastSquares;
|
||||
}
|
||||
}
|
||||
// ***************************************************************************************************************************************************************
|
||||
public CompositeDataSource TradePoints
|
||||
{
|
||||
get
|
||||
{
|
||||
return compositeDataSourceTradePoints;
|
||||
}
|
||||
}
|
||||
public CenteredTextMarker[] Markers
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == portfolioTradesLots || 0 == portfolioTradesLots.Count || !showTradeLabels) return null;
|
||||
TextMarkerOffsets textMarkerOffsets = new TextMarkerOffsets(35, 18);
|
||||
List<CenteredTextMarker> centeredTextMarkers = new List<CenteredTextMarker>();
|
||||
for (int index = 0; index < portfolioTradesLots.Count; index++)
|
||||
{
|
||||
CenteredTextMarker centerTextMarker = new CenteredTextMarker();
|
||||
PortfolioTrade portfolioTrade = portfolioTradesLots[index];
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.Append(portfolioTrade.BuySell.Equals("B") ? "Buy " : "Sell ");
|
||||
sb.Append(Utility.FormatNumber(portfolioTrade.Shares));
|
||||
sb.Append("@");
|
||||
sb.Append(Utility.FormatCurrency(portfolioTrade.Price));
|
||||
centerTextMarker.Text = sb.ToString();
|
||||
centerTextMarker.HorizontalShift = "0";
|
||||
centerTextMarker.VerticalShift = textMarkerOffsets.GetOffset(portfolioTrade).ToString();
|
||||
centeredTextMarkers.Add(centerTextMarker);
|
||||
}
|
||||
return centeredTextMarkers.ToArray();
|
||||
}
|
||||
}
|
||||
public CenteredTextMarker[] RiskFreeRatePointMarkers
|
||||
{
|
||||
get
|
||||
{
|
||||
List<CenteredTextMarker> centeredTextMarkers = new List<CenteredTextMarker>();
|
||||
if (null == riskFreeRatePrice || !showTradeLabels ||!showRiskFree) return null;
|
||||
CenteredTextMarker centerTextMarker = new CenteredTextMarker();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.Append("1yTsy ");
|
||||
sb.Append(Utility.FormatCurrency(riskFreeRatePrice.Close));
|
||||
centerTextMarker.Text = sb.ToString();
|
||||
centeredTextMarkers.Add(centerTextMarker);
|
||||
return centeredTextMarkers.ToArray();
|
||||
}
|
||||
}
|
||||
public CenteredTextMarker[] ZeroPointMarkers
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == zeroPrice || !showTradeLabels) return null;
|
||||
List<CenteredTextMarker> centeredTextMarkers = new List<CenteredTextMarker>();
|
||||
CenteredTextMarker centerTextMarker = new CenteredTextMarker();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.Append("Even ");
|
||||
sb.Append(Utility.FormatCurrency(zeroPrice.Close));
|
||||
Price latestPrice=prices[0];
|
||||
double parityOffsetPercent=(latestPrice.Close-zeroPrice.Close)/zeroPrice.Close;
|
||||
sb.Append("(").Append(parityOffsetPercent<0?"":"+").Append(Utility.FormatPercent(parityOffsetPercent)).Append(")");
|
||||
centerTextMarker.Text = sb.ToString();
|
||||
centeredTextMarkers.Add(centerTextMarker);
|
||||
centerTextMarker.VerticalShift="40";
|
||||
centerTextMarker.HorizontalShift="32";
|
||||
return centeredTextMarkers.ToArray();
|
||||
}
|
||||
}
|
||||
public CenteredTextMarker[] StopLimitMarkers
|
||||
{
|
||||
get
|
||||
{
|
||||
List<CenteredTextMarker> centeredTextMarkers=new List<CenteredTextMarker>();
|
||||
if(!showTradeLabels) return null;
|
||||
if(null!=stopLimits)
|
||||
{
|
||||
for(int index=0;index<stopLimits.Count;index++)
|
||||
{
|
||||
StopLimit limit=stopLimits[index];
|
||||
CenteredTextMarker centerTextMarker=new CenteredTextMarker();
|
||||
|
||||
StringBuilder sb=new StringBuilder();
|
||||
sb.Append(limit.StopType).Append(" ");
|
||||
sb.Append(Utility.FormatCurrency(limit.StopPrice));
|
||||
if(index==stopLimits.Count-1)
|
||||
{
|
||||
Price latestPrice=prices[0]; // always use the most recent price when calculating the spread (in percent) from the active stop limit.
|
||||
double percentOffsetFromLow=((latestPrice.Low-limit.StopPrice)/limit.StopPrice);
|
||||
sb.Append(" (").Append(percentOffsetFromLow>0?"+":"").Append(Utility.FormatPercent(percentOffsetFromLow)).Append(")");
|
||||
}
|
||||
centerTextMarker.Text=sb.ToString();
|
||||
if(0==index&&stopLimits.Count>1) centerTextMarker.VerticalShift="25";
|
||||
else centerTextMarker.VerticalShift="40";
|
||||
centerTextMarker.HorizontalShift="32";
|
||||
centeredTextMarkers.Add(centerTextMarker);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(null==zeroPrice)return null;
|
||||
if(null==stopLimit||null==zeroPrice||!showTradeLabels) return null;
|
||||
CenteredTextMarker centerTextMarker=new CenteredTextMarker();
|
||||
Price latestPrice=prices[0];
|
||||
double percentOffsetFromLow=((latestPrice.Low-stopLimit.StopPrice)/stopLimit.StopPrice);
|
||||
StringBuilder sb=new StringBuilder();
|
||||
sb.Append(stopLimit.StopType).Append(" ");
|
||||
sb.Append(Utility.FormatCurrency(stopLimit.StopPrice));
|
||||
sb.Append(" (").Append(percentOffsetFromLow>0?"+":"").Append(Utility.FormatPercent(percentOffsetFromLow)).Append(")");
|
||||
centerTextMarker.Text=sb.ToString();
|
||||
centeredTextMarkers.Add(centerTextMarker);
|
||||
centerTextMarker.VerticalShift="40";
|
||||
centerTextMarker.HorizontalShift="32";
|
||||
}
|
||||
return centeredTextMarkers.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
// ************************************************************************************************************************************************************************
|
||||
public override String Title
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == companyName || null == prices || 0 == prices.Count) return "";
|
||||
String displayCompanyName=companyName;
|
||||
if(displayCompanyName.Length>40)displayCompanyName=displayCompanyName.Substring(0,40)+"...";
|
||||
StringBuilder sb=new StringBuilder();
|
||||
float change=float.NaN;
|
||||
Prices prices2day=new Prices(prices.Take(2).ToList());
|
||||
if(2==prices2day.Count)change=prices2day.GetReturns()[0];
|
||||
sb.Append(displayCompanyName);
|
||||
sb.Append(" (").Append(symbol).Append(") ");
|
||||
sb.Append(Utility.DateTimeToStringMMHDDHYYYY(prices[prices.Count-1].Date));
|
||||
sb.Append(" Thru ");
|
||||
sb.Append(Utility.DateTimeToStringMMHDDHYYYY(prices[0].Date));
|
||||
sb.Append(" (").Append(Utility.FormatCurrency(prices[0].Close));
|
||||
sb.Append("/").Append(Utility.FormatCurrency(prices[0].Low));
|
||||
if(!float.IsNaN(change))
|
||||
{
|
||||
sb.Append(",");
|
||||
sb.Append(change>=0.00?"+":"").Append(Utility.FormatPercent((double)change));
|
||||
}
|
||||
sb.Append(")");
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
public Boolean Visibility
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
public List<Int32> DayCounts
|
||||
{
|
||||
get{return dayCounts;}
|
||||
}
|
||||
public Int32 SelectedDayCount
|
||||
{
|
||||
get { return selectedDayCount; }
|
||||
set { selectedDayCount = value; base.OnPropertyChanged("SelectedDayCount"); }
|
||||
}
|
||||
public List<String> Symbols
|
||||
{
|
||||
get
|
||||
{
|
||||
return symbols;
|
||||
}
|
||||
}
|
||||
public String SelectedSymbol
|
||||
{
|
||||
get { return symbol; }
|
||||
set
|
||||
{
|
||||
if (value == symbol || String.IsNullOrEmpty(value)) return;
|
||||
symbol = value;
|
||||
base.OnPropertyChanged("SelectedSymbol");
|
||||
}
|
||||
}
|
||||
public List<String> WatchListNames
|
||||
{
|
||||
get
|
||||
{
|
||||
return watchLists;
|
||||
}
|
||||
set { ;}
|
||||
}
|
||||
public String SelectedWatchList
|
||||
{
|
||||
get { return selectedWatchList; }
|
||||
set { selectedWatchList = value; base.OnPropertyChanged("SelectedWatchList"); }
|
||||
}
|
||||
private void Refresh()
|
||||
{
|
||||
base.OnPropertyChanged("SelectedSymbol");
|
||||
}
|
||||
private bool CanRefresh
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
public ICommand RefreshCommand
|
||||
{
|
||||
get
|
||||
{
|
||||
if (refreshCommand == null)
|
||||
{
|
||||
refreshCommand = new RelayCommand(param => this.Refresh(),param=>this.CanRefresh);
|
||||
}
|
||||
return refreshCommand;
|
||||
}
|
||||
}
|
||||
|
||||
public Boolean CheckBoxShowInsiderTransactions
|
||||
{
|
||||
get
|
||||
{
|
||||
return showInsiderTransactions;
|
||||
}
|
||||
set
|
||||
{
|
||||
showInsiderTransactions = value;
|
||||
base.OnPropertyChanged("CheckBoxShowInsiderTransactions");
|
||||
base.OnPropertyChanged("InsiderTransactionPointDisposedSmall");
|
||||
base.OnPropertyChanged("InsiderTransactionPointMarkersDisposedSmall");
|
||||
base.OnPropertyChanged("InsiderTransactionPointDisposedMedium");
|
||||
base.OnPropertyChanged("InsiderTransactionPointMarkersDisposedMedium");
|
||||
base.OnPropertyChanged("InsiderTransactionPointDisposedLarge");
|
||||
base.OnPropertyChanged("InsiderTransactionPointMarkersDisposedLarge");
|
||||
|
||||
base.OnPropertyChanged("InsiderTransactionPointAcquiredSmall");
|
||||
base.OnPropertyChanged("InsiderTransactionPointMarkersAcquiredSmall");
|
||||
base.OnPropertyChanged("InsiderTransactionPointAcquiredMedium");
|
||||
base.OnPropertyChanged("InsiderTransactionPointMarkersAcquiredMedium");
|
||||
base.OnPropertyChanged("InsiderTransactionPointAcquiredLarge");
|
||||
base.OnPropertyChanged("InsiderTransactionPointMarkersAcquiredLarge");
|
||||
base.OnPropertyChanged("LeastSquares");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
1263
ViewModels/CMMomentumViewModel.cs
Normal file
1544
ViewModels/CMTTrendViewModel.cs
Normal file
30
ViewModels/CommandViewModel.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Windows.Input;
|
||||
using System.Text;
|
||||
|
||||
namespace TradeBlotter.ViewModels
|
||||
{
|
||||
public class CommandViewModel : ViewModelBase
|
||||
{
|
||||
public CommandViewModel(String displayName, ICommand command)
|
||||
{
|
||||
if (null == command) throw new ArgumentNullException("command");
|
||||
base.DisplayName = displayName;
|
||||
this.Command = command;
|
||||
}
|
||||
public ICommand Command { get; private set; }
|
||||
public override SaveParameters GetSaveParameters()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
public override void SetSaveParameters(SaveParameters saveParameters)
|
||||
{
|
||||
}
|
||||
public override bool CanPersist()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
674
ViewModels/DCFValuationViewModel.cs
Normal file
@@ -0,0 +1,674 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Collections.Specialized;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Input;
|
||||
using System.Threading.Tasks;
|
||||
using MarketData;
|
||||
using MarketData.Numerical;
|
||||
using MarketData.Utils;
|
||||
using MarketData.MarketDataModel;
|
||||
using MarketData.Generator;
|
||||
using MarketData.DataAccess;
|
||||
using TradeBlotter.DataAccess;
|
||||
using TradeBlotter.Command;
|
||||
using TradeBlotter.Model;
|
||||
using Microsoft.Research.DynamicDataDisplay.DataSources;
|
||||
|
||||
namespace TradeBlotter.ViewModels
|
||||
{
|
||||
public class DCFValuationViewModel : WorkspaceViewModel
|
||||
{
|
||||
private List<String> symbols;
|
||||
private List<String> watchLists;
|
||||
private String selectedWatchList;
|
||||
private String selectedSymbol;
|
||||
private String companyName;
|
||||
private ObservableCollection<ReturnItem> dcf = null;
|
||||
private bool busyIndicator = false;
|
||||
private DCFValuation dcfValuation = null;
|
||||
|
||||
public DCFValuationViewModel()
|
||||
{
|
||||
base.DisplayName = "DCF Valuation";
|
||||
watchLists = WatchListDA.GetWatchLists();
|
||||
watchLists.Insert(0, Constants.CONST_ALL);
|
||||
selectedWatchList = watchLists.Find(x => x.Equals("Valuations"));
|
||||
symbols = WatchListDA.GetWatchList(selectedWatchList);
|
||||
selectedSymbol = null;
|
||||
PropertyChanged += OnDCFViewModelPropertyChanged;
|
||||
base.OnPropertyChanged("SelectedSymbol");
|
||||
}
|
||||
// ******************************************************************************************** P E R S I S T E N C E ********************************************************************************************
|
||||
public override bool CanPersist()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public override SaveParameters GetSaveParameters()
|
||||
{
|
||||
SaveParameters saveParams = new SaveParameters();
|
||||
if (null == selectedSymbol) return null;
|
||||
saveParams.Add(new KeyValuePair<String, String>("Type", GetType().Namespace + "." + GetType().Name));
|
||||
saveParams.Add(new KeyValuePair<String, String>("SelectedSymbol", selectedSymbol));
|
||||
saveParams.Add(new KeyValuePair<String, String>("SelectedWatchList", selectedWatchList));
|
||||
return saveParams;
|
||||
}
|
||||
public override void SetSaveParameters(SaveParameters saveParameters)
|
||||
{
|
||||
try
|
||||
{
|
||||
if(saveParameters.ContainsKey("SelectedSymbol")) selectedSymbol=(from KeyValuePair<String,String> item in saveParameters where item.Key.Equals("SelectedSymbol") select item).FirstOrDefault().Value;
|
||||
if(saveParameters.ContainsKey("SelectedWatchList")) selectedWatchList=(from KeyValuePair<String,String> item in saveParameters where item.Key.Equals("SelectedWatchList") select item).FirstOrDefault().Value;
|
||||
Referer=saveParameters.Referer;
|
||||
base.OnPropertyChanged("SelectedWatchList");
|
||||
base.OnPropertyChanged("SelectedSymbol");
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Exception:{0}",exception.ToString()));
|
||||
}
|
||||
}
|
||||
// ******************************************************************************************************************************************************
|
||||
public bool BusyIndicator
|
||||
{
|
||||
get { return busyIndicator; }
|
||||
set
|
||||
{
|
||||
busyIndicator = value;
|
||||
base.OnPropertyChanged("BusyIndicator");
|
||||
}
|
||||
}
|
||||
public ObservableCollection<ReturnItem> AllDCF
|
||||
{
|
||||
get
|
||||
{
|
||||
return dcf;
|
||||
}
|
||||
set
|
||||
{
|
||||
dcf = value;
|
||||
base.OnPropertyChanged("AllDCF");
|
||||
}
|
||||
}
|
||||
private void OnDCFViewModelPropertyChanged(object sender, PropertyChangedEventArgs eventArgs)
|
||||
{
|
||||
if (eventArgs.PropertyName.Equals("SelectedSymbol"))
|
||||
{
|
||||
if(null==selectedSymbol)return;
|
||||
base.DisplayName = "Discounted Cashflow Valuation(" + selectedSymbol + ")";
|
||||
base.OnPropertyChanged("DisplayName");
|
||||
HandleSelectedSymbol();
|
||||
}
|
||||
else if (eventArgs.PropertyName.Equals("SelectedWatchList"))
|
||||
{
|
||||
if(null==selectedWatchList)return;
|
||||
HandleSelectedWatchList();
|
||||
}
|
||||
}
|
||||
private void HandleSelectedSymbol()
|
||||
{
|
||||
BusyIndicator = true;
|
||||
Task workerTask = Task.Factory.StartNew(() =>
|
||||
{
|
||||
if (null != selectedSymbol)
|
||||
{
|
||||
dcf = null;
|
||||
companyName = PricingDA.GetNameForSymbol(selectedSymbol);
|
||||
dcfValuation = DCFGenerator.GenerateDCFValuation(selectedSymbol);
|
||||
if (null != dcfValuation.ReturnItems && 0 != dcfValuation.ReturnItems.Count)
|
||||
{
|
||||
dcf = new ObservableCollection<ReturnItem>();
|
||||
for(int index=0;index<dcfValuation.ReturnItems.Count;index++)
|
||||
{
|
||||
ReturnItem returnItem=dcfValuation.ReturnItems[index];
|
||||
dcf.Add(returnItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
workerTask.ContinueWith((continuation) =>
|
||||
{
|
||||
BusyIndicator = false;
|
||||
UpdateData();
|
||||
UpdateDescriptions();
|
||||
});
|
||||
}
|
||||
private void UpdateData()
|
||||
{
|
||||
base.OnPropertyChanged("AllDCF");
|
||||
base.OnPropertyChanged("Beta");
|
||||
base.OnPropertyChanged("HistoricalMarketReturn");
|
||||
base.OnPropertyChanged("RiskFreeRate");
|
||||
base.OnPropertyChanged("MarketCap");
|
||||
base.OnPropertyChanged("TotalDebt");
|
||||
base.OnPropertyChanged("WACC");
|
||||
base.OnPropertyChanged("ROIC");
|
||||
base.OnPropertyChanged("CapitalBackground");
|
||||
base.OnPropertyChanged("CostOfDebt");
|
||||
base.OnPropertyChanged("CostOfEquity");
|
||||
base.OnPropertyChanged("TaxRate");
|
||||
base.OnPropertyChanged("TotalEquity");
|
||||
base.OnPropertyChanged("TotalCapitalInvested");
|
||||
base.OnPropertyChanged("InterestExpense");
|
||||
base.OnPropertyChanged("OutstandingShares");
|
||||
base.OnPropertyChanged("PresentValue");
|
||||
base.OnPropertyChanged("EstimatedStockPrice");
|
||||
base.OnPropertyChanged("MOS");
|
||||
base.OnPropertyChanged("MOSBackground");
|
||||
base.OnPropertyChanged("MOS80");
|
||||
base.OnPropertyChanged("MOS80Background");
|
||||
base.OnPropertyChanged("IntrinsicValue");
|
||||
base.OnPropertyChanged("RGVIntrinsic");
|
||||
base.OnPropertyChanged("IntrinsicValueRevised");
|
||||
base.OnPropertyChanged("RGVIntrinsicValueRevised");
|
||||
base.OnPropertyChanged("CurrentPrice");
|
||||
base.OnPropertyChanged("PriceDate");
|
||||
base.OnPropertyChanged("FreeCashflowGrowth");
|
||||
base.OnPropertyChanged("Message");
|
||||
base.OnPropertyChanged("Title");
|
||||
}
|
||||
private void UpdateDescriptions()
|
||||
{
|
||||
base.OnPropertyChanged("BetaDescription");
|
||||
base.OnPropertyChanged("InterestExpenseDescription");
|
||||
base.OnPropertyChanged("CostOfEquityDescription");
|
||||
base.OnPropertyChanged("CostOfDebtDescription");
|
||||
base.OnPropertyChanged("ROICDescription");
|
||||
base.OnPropertyChanged("WACCDescription");
|
||||
base.OnPropertyChanged("TotalCapitalInvestedDescription");
|
||||
base.OnPropertyChanged("TotalLongAndShortTermDebtDescription");
|
||||
base.OnPropertyChanged("TotalEquityDescription");
|
||||
base.OnPropertyChanged("RiskFreeRateDescription");
|
||||
base.OnPropertyChanged("HistoricalMarketReturnDescription");
|
||||
base.OnPropertyChanged("OutstandingSharesDescription");
|
||||
base.OnPropertyChanged("MOSDescription");
|
||||
base.OnPropertyChanged("MOS80Description");
|
||||
base.OnPropertyChanged("SumOfDiscountedCashflowsDescription");
|
||||
base.OnPropertyChanged("EstimatedStockPriceDescription");
|
||||
base.OnPropertyChanged("LatestPriceDescription");
|
||||
base.OnPropertyChanged("PriceDateDescription");
|
||||
base.OnPropertyChanged("IntrinsicValueDescription");
|
||||
base.OnPropertyChanged("IntrinsicValueRevisedDescription");
|
||||
base.OnPropertyChanged("RGVIntrinsicRevDescription");
|
||||
base.OnPropertyChanged("FreeCashflowGrowthDescription");
|
||||
}
|
||||
public void OnErrorItemHandler(String symbol, String message)
|
||||
{
|
||||
}
|
||||
private void HandleSelectedWatchList()
|
||||
{
|
||||
if (selectedWatchList.Equals(Constants.CONST_ALL)) symbols = PricingDA.GetSymbols();
|
||||
else
|
||||
{
|
||||
symbols = WatchListDA.GetWatchList(selectedWatchList);
|
||||
}
|
||||
base.OnPropertyChanged("Symbols");
|
||||
}
|
||||
// ************************************************************************************************************************************************************************
|
||||
// ********************************************************************************** C O L O R S C H E M E **************************************************************
|
||||
// ************************************************************************************************************************************************************************
|
||||
public Brush CapitalBackground
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == dcfValuation || !dcfValuation.Success) return null;
|
||||
if (dcfValuation.Enhancements.ROIC > dcfValuation.WACC) return new SolidColorBrush(Colors.LightGreen);
|
||||
return new SolidColorBrush(Colors.Red);
|
||||
}
|
||||
}
|
||||
public Brush MOSBackground
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == dcfValuation || !dcfValuation.Success || null == dcfValuation.CurrentPrice) return null;
|
||||
if (dcfValuation.CurrentPrice.Close > dcfValuation.StockPriceValuation) return new SolidColorBrush(Colors.Red);
|
||||
return new SolidColorBrush(Colors.LightGreen);
|
||||
}
|
||||
}
|
||||
public Brush MOS80Background
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == dcfValuation || !dcfValuation.Success || null == dcfValuation.CurrentPrice) return null;
|
||||
if (dcfValuation.CurrentPrice.Close > dcfValuation.StockPriceValuation) return new SolidColorBrush(Colors.Red);
|
||||
return new SolidColorBrush(Colors.LightGreen);
|
||||
}
|
||||
}
|
||||
// ************************************************************************************************************************************************************************
|
||||
public override String Title
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null != companyName && null != selectedSymbol) return "Discounted Cashflow Valuation - (" + selectedSymbol + ") " + companyName;
|
||||
return "Discounted Cashflow Valuation";
|
||||
}
|
||||
}
|
||||
public String Beta
|
||||
{
|
||||
get
|
||||
{
|
||||
return dcfValuation == null || !dcfValuation.Success || double.NaN.Equals(dcfValuation.Beta)? Constants.CONST_DASHES : Utility.FormatNumber(dcfValuation.Beta,2);
|
||||
}
|
||||
}
|
||||
public String HistoricalMarketReturn
|
||||
{
|
||||
get
|
||||
{
|
||||
return dcfValuation == null || !dcfValuation.Success || double.NaN.Equals(dcfValuation.MarketReturn) ? Constants.CONST_DASHES : Utility.FormatPercent(dcfValuation.MarketReturn);
|
||||
}
|
||||
}
|
||||
public String RiskFreeRate
|
||||
{
|
||||
get
|
||||
{
|
||||
return dcfValuation == null || !dcfValuation.Success || double.NaN.Equals(dcfValuation.RiskFreeRate) ? Constants.CONST_DASHES : Utility.FormatPercent(dcfValuation.RiskFreeRate);
|
||||
}
|
||||
}
|
||||
public String MarketCap
|
||||
{
|
||||
get
|
||||
{
|
||||
return dcfValuation == null || !dcfValuation.Success || double.NaN.Equals(dcfValuation.MarketValueOfEquity) ? Constants.CONST_DASHES : Utility.FormatCurrency(dcfValuation.MarketValueOfEquity);
|
||||
}
|
||||
}
|
||||
public String TotalDebt
|
||||
{
|
||||
get
|
||||
{
|
||||
return dcfValuation == null || !dcfValuation.Success || double.NaN.Equals(dcfValuation.TotalDebt) ? Constants.CONST_DASHES : Utility.FormatCurrency(dcfValuation.TotalDebt);
|
||||
}
|
||||
}
|
||||
public String WACC
|
||||
{
|
||||
get
|
||||
{
|
||||
return dcfValuation == null || !dcfValuation.Success || double.NaN.Equals(dcfValuation.WACC) ? Constants.CONST_DASHES : Utility.FormatPercent(dcfValuation.WACC);
|
||||
}
|
||||
}
|
||||
public String ROIC
|
||||
{
|
||||
get
|
||||
{
|
||||
return dcfValuation == null || !dcfValuation.Success || double.NaN.Equals(dcfValuation.Enhancements.ROIC) ? Constants.CONST_DASHES : Utility.FormatPercent(dcfValuation.Enhancements.ROIC);
|
||||
}
|
||||
}
|
||||
public String CostOfDebt
|
||||
{
|
||||
get
|
||||
{
|
||||
return dcfValuation == null || !dcfValuation.Success || double.NaN.Equals(dcfValuation.CostOfDebt) ? Constants.CONST_DASHES : Utility.FormatPercent(dcfValuation.CostOfDebt);
|
||||
}
|
||||
}
|
||||
public String CostOfEquity
|
||||
{
|
||||
get
|
||||
{
|
||||
return dcfValuation == null || !dcfValuation.Success || double.NaN.Equals(dcfValuation.CostOfEquity) ? Constants.CONST_DASHES : Utility.FormatPercent(dcfValuation.CostOfEquity);
|
||||
}
|
||||
}
|
||||
public String TaxRate
|
||||
{
|
||||
get
|
||||
{
|
||||
return dcfValuation == null || !dcfValuation.Success || double.NaN.Equals(dcfValuation.CorporateTaxRate) ? Constants.CONST_DASHES : Utility.FormatPercent(dcfValuation.CorporateTaxRate);
|
||||
}
|
||||
}
|
||||
public String TotalEquity
|
||||
{
|
||||
get
|
||||
{
|
||||
return dcfValuation == null || !dcfValuation.Success || double.NaN.Equals(dcfValuation.MarketValueOfEquity) ? Constants.CONST_DASHES : Utility.FormatCurrency(dcfValuation.MarketValueOfEquity);
|
||||
}
|
||||
}
|
||||
public String TotalCapitalInvested
|
||||
{
|
||||
get
|
||||
{
|
||||
return dcfValuation == null || !dcfValuation.Success || double.NaN.Equals(dcfValuation.TotalCapitalInvested) ? Constants.CONST_DASHES : Utility.FormatCurrency(dcfValuation.TotalCapitalInvested);
|
||||
}
|
||||
}
|
||||
public String InterestExpense
|
||||
{
|
||||
get
|
||||
{
|
||||
return dcfValuation == null || !dcfValuation.Success || double.NaN.Equals(dcfValuation.InterestExpense) ? Constants.CONST_DASHES : Utility.FormatCurrency(dcfValuation.InterestExpense);
|
||||
}
|
||||
}
|
||||
public String OutstandingShares
|
||||
{
|
||||
get
|
||||
{
|
||||
return dcfValuation == null || !dcfValuation.Success || double.NaN.Equals(dcfValuation.OutstandingShares) ? Constants.CONST_DASHES : Utility.FormatNumber(dcfValuation.OutstandingShares, 0, true);
|
||||
}
|
||||
}
|
||||
public String PresentValue
|
||||
{
|
||||
get
|
||||
{
|
||||
return dcfValuation == null || !dcfValuation.Success || double.NaN.Equals(dcfValuation.PresentValue) ? Constants.CONST_DASHES : Utility.FormatCurrency(dcfValuation.PresentValue);
|
||||
}
|
||||
}
|
||||
public String EstimatedStockPrice
|
||||
{
|
||||
get
|
||||
{
|
||||
return dcfValuation == null || !dcfValuation.Success || double.NaN.Equals(dcfValuation.StockPriceValuation) ? Constants.CONST_DASHES : Utility.FormatCurrency(dcfValuation.StockPriceValuation);
|
||||
}
|
||||
}
|
||||
public String CurrentPrice
|
||||
{
|
||||
get
|
||||
{
|
||||
return dcfValuation == null || !dcfValuation.Success || null == dcfValuation.CurrentPrice || double.NaN.Equals(dcfValuation.CurrentPrice.Close) ? Constants.CONST_DASHES : Utility.FormatCurrency(dcfValuation.CurrentPrice.Close);
|
||||
}
|
||||
}
|
||||
public String PriceDate
|
||||
{
|
||||
get
|
||||
{
|
||||
return dcfValuation == null || !dcfValuation.Success || null == dcfValuation.CurrentPrice ? Constants.CONST_DASHES : Utility.DateTimeToStringMMHDDHYYYY(dcfValuation.CurrentPrice.Date);
|
||||
}
|
||||
}
|
||||
public String FreeCashflowGrowth
|
||||
{
|
||||
get
|
||||
{
|
||||
return dcfValuation == null || !dcfValuation.Success || double.NaN.Equals(dcfValuation.FreeCashflowGrowth) ? Constants.CONST_DASHES : Utility.FormatPercent(dcfValuation.FreeCashflowGrowth);
|
||||
}
|
||||
}
|
||||
public String MOS
|
||||
{
|
||||
get
|
||||
{
|
||||
return dcfValuation == null || !dcfValuation.Success || double.NaN.Equals(dcfValuation.Enhancements.MOS) ? Constants.CONST_DASHES : Utility.FormatCurrency(dcfValuation.Enhancements.MOS);
|
||||
}
|
||||
}
|
||||
public String MOS80
|
||||
{
|
||||
get
|
||||
{
|
||||
return dcfValuation == null || !dcfValuation.Success || double.NaN.Equals(dcfValuation.Enhancements.MOS80) ? Constants.CONST_DASHES : Utility.FormatCurrency(dcfValuation.Enhancements.MOS80);
|
||||
}
|
||||
}
|
||||
public String IntrinsicValue
|
||||
{
|
||||
get
|
||||
{
|
||||
return dcfValuation == null || !dcfValuation.Success || double.NaN.Equals(dcfValuation.Enhancements.IntrinsicValue) ? Constants.CONST_DASHES : Utility.FormatCurrency(dcfValuation.Enhancements.IntrinsicValue);
|
||||
}
|
||||
}
|
||||
public String RGVIntrinsic
|
||||
{
|
||||
get
|
||||
{
|
||||
return dcfValuation == null || !dcfValuation.Success || double.NaN.Equals(dcfValuation.Enhancements.RGVIntrinsic) ? Constants.CONST_DASHES : Utility.FormatCurrency(dcfValuation.Enhancements.RGVIntrinsic);
|
||||
}
|
||||
}
|
||||
public String IntrinsicValueRevised
|
||||
{
|
||||
get
|
||||
{
|
||||
return dcfValuation == null || !dcfValuation.Success || double.NaN.Equals(dcfValuation.Enhancements.IntrinsicValueRevised) ? Constants.CONST_DASHES : Utility.FormatCurrency(dcfValuation.Enhancements.IntrinsicValueRevised);
|
||||
}
|
||||
}
|
||||
public String RGVIntrinsicValueRevised
|
||||
{
|
||||
get
|
||||
{
|
||||
return dcfValuation == null || !dcfValuation.Success || double.NaN.Equals(dcfValuation.Enhancements.RGVIntrinsicRevised) ? Constants.CONST_DASHES : Utility.FormatCurrency(dcfValuation.Enhancements.RGVIntrinsicRevised);
|
||||
}
|
||||
}
|
||||
public String Message
|
||||
{
|
||||
get
|
||||
{
|
||||
return dcfValuation == null ? Constants.CONST_DASHES : dcfValuation.Message;
|
||||
}
|
||||
}
|
||||
public List<String> Symbols
|
||||
{
|
||||
get
|
||||
{
|
||||
return symbols;
|
||||
}
|
||||
}
|
||||
public String SelectedSymbol
|
||||
{
|
||||
get
|
||||
{
|
||||
return selectedSymbol;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value == selectedSymbol || String.IsNullOrEmpty(value)) return;
|
||||
selectedSymbol = value;
|
||||
base.OnPropertyChanged("SelectedSymbol");
|
||||
}
|
||||
}
|
||||
public List<String> WatchListNames
|
||||
{
|
||||
get
|
||||
{
|
||||
return watchLists;
|
||||
}
|
||||
set { ;}
|
||||
}
|
||||
public String SelectedWatchList
|
||||
{
|
||||
get { return selectedWatchList; }
|
||||
set { selectedWatchList = value; base.OnPropertyChanged("SelectedWatchList"); }
|
||||
}
|
||||
// ************************************************************************************************************************************************************************************************************************************************
|
||||
// ************************************************************************************************ T O O L T I P C A L L O U T S **************************************************************************************************************
|
||||
// ************************************************************************************************************************************************************************************************************************************************
|
||||
public String HistoricalMarketReturnDescription
|
||||
{
|
||||
get
|
||||
{
|
||||
try
|
||||
{
|
||||
StringBuilder sb=new StringBuilder();
|
||||
if(dcfValuation.UseMarketReturn)sb.Append("Using a calculated market return of ").Append(Utility.FormatPercent(dcfValuation.MarketReturn,2));
|
||||
else sb.Append("Using a constant market return of ").Append(Utility.FormatPercent(dcfValuation.MarketReturn,2));
|
||||
return sb.ToString();
|
||||
}
|
||||
catch(Exception)
|
||||
{
|
||||
return Constants.NA;
|
||||
}
|
||||
}
|
||||
}
|
||||
public String BetaDescription
|
||||
{
|
||||
get
|
||||
{
|
||||
try
|
||||
{
|
||||
StringBuilder sb=new StringBuilder();
|
||||
sb.Append("Beta is a measure of a stock's volatility in relation to the overall market. By definition, the market, such as the S&P 500 Index, has a beta of 1.0, and individual stocks are ranked according to how").Append("\n");
|
||||
sb.Append("much they deviate from the market. A stock that swings more than the market has a beta above 1.0. If a stock moves less than the market, the stock's beta is less than 1.0. ").Append("\n");
|
||||
sb.Append("High-beta stocks are supposed to be riskier but provide higher return potential; low-beta stocks pose less risk but also lower returns. ").Append("\n");
|
||||
sb.Append("Beta = 36 month internally calculated beta.").Append("\n");
|
||||
sb.Append("Beta = Covariance(Ra,Rm)/Variance(Ra). Where Rm = Return of the market (SPY), Ra = Return of the asset.").Append("\n");
|
||||
sb.Append(dcfValuation.Symbol).Append(" has a Beta of ").Append(Utility.FormatNumber(dcfValuation.Beta,2)).Append(" which is ").Append(dcfValuation.Beta>1?"more volatile ":"less volatile ").Append("than the market.").Append("\n");
|
||||
sb.Append(dcfValuation.Symbol).Append(" offers ").Append(dcfValuation.Beta>1?"more risk but more return potential ":"less risk but less return potential ").Append("than the market.").Append("\n");
|
||||
return sb.ToString();
|
||||
}
|
||||
catch(Exception)
|
||||
{
|
||||
return Constants.NA;
|
||||
}
|
||||
}
|
||||
}
|
||||
public String InterestExpenseDescription
|
||||
{
|
||||
get
|
||||
{
|
||||
return "Interest Expense (Annual): This is sourced from Historical(M*) as 'InterestExpense' if available otherwise from the IncomeStatement as 'InterestExpense'";
|
||||
}
|
||||
}
|
||||
public String CostOfEquityDescription
|
||||
{
|
||||
get
|
||||
{
|
||||
try
|
||||
{
|
||||
StringBuilder sb=new StringBuilder();
|
||||
sb.Append("Cost of equity is the return that a company requires for an investment or project, or the return that an individual requires for an equity investment.").Append("\n");
|
||||
sb.Append("Cost of Equity: Using CAPM cost of equity is calculated as rE = RFR + Beta * (Rm - RFR). Where RFR=Risk Free Rate, Beta=Market Beta, Rm=Annual Return.").Append("\n");
|
||||
sb.Append("rE = ").Append(Utility.FormatNumber(dcfValuation.RiskFreeRate,2)).Append(" + ");
|
||||
sb.Append(Utility.FormatNumber(dcfValuation.Beta,2)).Append(" * ").Append("(");
|
||||
sb.Append(Utility.FormatNumber(dcfValuation.MarketReturn)).Append(" - ").Append(Utility.FormatNumber(dcfValuation.RiskFreeRate,2)).Append(")");
|
||||
if(dcfValuation.UseMarketReturn)sb.Append("Using a calculated market return of ").Append(Utility.FormatNumber(dcfValuation.MarketReturn,2));
|
||||
else sb.Append("Using a constant market return of ").Append(Utility.FormatNumber(dcfValuation.MarketReturn,2));
|
||||
return sb.ToString();
|
||||
}
|
||||
catch(Exception)
|
||||
{
|
||||
return Constants.NA;
|
||||
}
|
||||
}
|
||||
}
|
||||
public String CostOfDebtDescription
|
||||
{
|
||||
get
|
||||
{
|
||||
try
|
||||
{
|
||||
StringBuilder sb=new StringBuilder();
|
||||
sb.Append("Cost of debt is the effective interest rate that a company pays on its debts, such as bonds and loans.").Append("\n");
|
||||
sb.Append("Cost of Debt rD = ( Ei / D) * (1 - Tc).").Append("Where Ei = Interest Expense, D = Total Debt, Tc = Tax Rate.").Append("\n");
|
||||
sb.Append("rD = ").Append(Utility.FormatNumber(dcfValuation.InterestExpense,2,true)).Append(" / ").Append(Utility.FormatNumber(dcfValuation.TotalDebt,2,true)).Append(")");
|
||||
sb.Append(" * ").Append("(").Append(Utility.FormatNumber(1,2)).Append(" - ").Append(Utility.FormatNumber(dcfValuation.CorporateTaxRate,2)).Append(")");
|
||||
return sb.ToString();
|
||||
}
|
||||
catch(Exception)
|
||||
{
|
||||
return Constants.NA;
|
||||
}
|
||||
}
|
||||
}
|
||||
public String RiskFreeRateDescription
|
||||
{
|
||||
get
|
||||
{
|
||||
return "Current yield on 90 day (3M) Treasury. This can be verified by going to the \"Treasury Yield Curve\" tab and looking at the current 3M value.";
|
||||
}
|
||||
}
|
||||
public String ROICDescription
|
||||
{
|
||||
get
|
||||
{
|
||||
StringBuilder sb=new StringBuilder();
|
||||
sb.Append("Return on Invested Capital. Sourced from historical time series").Append("\n");
|
||||
sb.Append(@"Return on Invested Capital (ROIC) is a return ratio that expresses recurring operating profits as a percentage of the company's net operational assets ").Append("\n");
|
||||
sb.Append("The profit figure used is earnings before interest and taxes or EBIT and is unaffected by capital structure.").Append("\n");
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
public String WACCDescription
|
||||
{
|
||||
get
|
||||
{
|
||||
try
|
||||
{
|
||||
StringBuilder sb=new StringBuilder();
|
||||
sb.Append("Weighted average cost of capital (WACC) represents a firm’s average after-tax cost of capital from all sources, including common stock, preferred stock, bonds, and other forms of debt.").Append("\n");
|
||||
sb.Append("WACC is the average rate that a company expects to pay to finance its assets.").Append("\n");
|
||||
sb.Append("WACC is a common way to determine required rate of return (RRR) because it expresses, in a single number, the return that both bondholders and shareholders demand to provide the company with capital").Append("\n");
|
||||
sb.Append("WACC = rE * (E / V) + rD * (1 - Tc) * (D / V) .").Append("\n");
|
||||
sb.Append("Where rE = Cost of Equity, E = Total Equity, V = Total Capital Invested, rD = Cost of Debt, Tc = Tax Rate, D = Total Debt").Append("\n");
|
||||
sb.Append(Utility.FormatNumber(dcfValuation.CostOfEquity,2,true)).Append(" * " ).Append("(").Append(Utility.FormatNumber(dcfValuation.MarketValueOfEquity,2,true)).Append(" / ").Append(Utility.FormatNumber(dcfValuation.TotalCapitalInvested,2,true)).Append(")");
|
||||
sb.Append(" + ");
|
||||
sb.Append("(");
|
||||
sb.Append(Utility.FormatNumber(dcfValuation.CostOfDebt,2,true)).Append(" * ").Append("(").Append(Utility.FormatNumber(dcfValuation.MarketValueOfDebt,2,true)).Append(" / ").Append(Utility.FormatNumber(dcfValuation.TotalCapitalInvested,2,true)).Append(")");
|
||||
sb.Append(" * ").Append("(").Append(Utility.FormatNumber(1,2)).Append(" - ").Append(Utility.FormatNumber(dcfValuation.CorporateTaxRate,2)).Append(")");
|
||||
sb.Append(")");
|
||||
sb.Append("\n");
|
||||
return sb.ToString();
|
||||
}
|
||||
catch(Exception)
|
||||
{
|
||||
return Constants.NA;
|
||||
}
|
||||
}
|
||||
}
|
||||
public String TotalCapitalInvestedDescription
|
||||
{
|
||||
get
|
||||
{
|
||||
StringBuilder sb=new StringBuilder();
|
||||
sb.Append("Total Capital Invested : ");
|
||||
sb.Append("V = MV(D) + MV(E) Where MV(D) = Market value of debt, MV(E) = Market value of equity.").Append("\n");
|
||||
sb.Append("Market value of debt is sourced from Fundamentals").Append("\n");
|
||||
sb.Append("Market value of equity is sourced from Fundamentals").Append("\n");
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
public String EstimatedStockPriceDescription
|
||||
{
|
||||
get
|
||||
{
|
||||
StringBuilder sb=new StringBuilder();
|
||||
sb.Append("Estimated Stock Price : This is the sum of the discounted cashflows minus debt; then divided by outstanding shares.").Append("\n");
|
||||
sb.Append("Estimated Stock Price = (Present Value - Debt) / Outstanding Shares.").Append("\n");
|
||||
sb.Append("(").Append(Utility.FormatNumber(dcfValuation.PresentValue,2,true)).Append(" - ").Append(Utility.FormatNumber(dcfValuation.TotalDebt,2,true)).Append(")").Append(" / ").Append(Utility.FormatNumber(dcfValuation.OutstandingShares,2,true)).Append("\n");
|
||||
sb.Append("Please refer to Debt and Oustanding Shares to see the source of those values").Append("\n");
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
public String TotalLongAndShortTermDebtDescription
|
||||
{
|
||||
get{return "Total Long and Short Term Debt : This value if sourced from Fundamentals as TotalDebt";}
|
||||
}
|
||||
public String TotalEquityDescription
|
||||
{
|
||||
get{return "Total Equity : This value if sourced from Fundamentals as MarketCap";}
|
||||
}
|
||||
public String OutstandingSharesDescription
|
||||
{
|
||||
get{return "Outstanding Shares : This is sourced from Fundamentals as SharesOutstanding";}
|
||||
}
|
||||
public String MOSDescription
|
||||
{
|
||||
get{return "Est. Stock Price *.5";}
|
||||
}
|
||||
public String MOS80Description
|
||||
{
|
||||
get{return "Est. Stock Price *.8";}
|
||||
}
|
||||
public String SumOfDiscountedCashflowsDescription
|
||||
{
|
||||
get{return "Sum of discounted cashflows. This is also known as the PresentValue.";}
|
||||
}
|
||||
public String LatestPriceDescription
|
||||
{
|
||||
get{return "Latest closing price in database.";}
|
||||
}
|
||||
public String PriceDateDescription
|
||||
{
|
||||
get{return "Date of latest closing price in database.";}
|
||||
}
|
||||
public String IntrinsicValueDescription
|
||||
{
|
||||
get{return "Benjamin Graham : EPS*(8.5+(2*EPSGrowth))";}
|
||||
}
|
||||
public String IntrinsicValueRevisedDescription
|
||||
{
|
||||
get{return "Benjamin Graham : (EPS*(8.5+(2*EPSGrowth))+4.4) / Yield on 20-year AAA bonds.";}
|
||||
}
|
||||
public String RGVIntrinsicRevDescription
|
||||
{
|
||||
get{return "Intrinsic Value Rev./ Last closing price.";}
|
||||
}
|
||||
public String FreeCashflowGrowthDescription
|
||||
{
|
||||
get{return "Mean of freecashflow returns.";}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
196
ViewModels/DividendHistoryViewModel.cs
Normal file
@@ -0,0 +1,196 @@
|
||||
using System;
|
||||
using System.Windows.Input;
|
||||
using System.ComponentModel;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Collections.Specialized;
|
||||
using System.Windows;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using MarketData;
|
||||
using MarketData.Utils;
|
||||
using MarketData.DataAccess;
|
||||
using MarketData.MarketDataModel;
|
||||
using TradeBlotter.DataAccess;
|
||||
using TradeBlotter.Command;
|
||||
using TradeBlotter.Model;
|
||||
|
||||
namespace TradeBlotter.ViewModels
|
||||
{
|
||||
public class DividendHistoryViewModel : WorkspaceViewModel
|
||||
{
|
||||
private List<String> watchLists;
|
||||
private List<String> symbols;
|
||||
private String selectedWatchList;
|
||||
private String symbol;
|
||||
private String selectedCompanyName;
|
||||
private RelayCommand refreshCommand;
|
||||
private RelayCommand getLatestDivExDatesCommand;
|
||||
private bool busyIndicator = false;
|
||||
|
||||
public DividendHistoryViewModel()
|
||||
{
|
||||
base.DisplayName = "DividendHistory";
|
||||
watchLists = WatchListDA.GetWatchLists();
|
||||
watchLists.Insert(0, Constants.CONST_ALL);
|
||||
selectedWatchList = watchLists.Find(x => x.Equals("Valuations"));
|
||||
symbols = WatchListDA.GetWatchList(selectedWatchList);
|
||||
PropertyChanged += OnDividendHistoryViewModelPropertyChanged;
|
||||
}
|
||||
public override SaveParameters GetSaveParameters()
|
||||
{
|
||||
SaveParameters saveParams = new SaveParameters();
|
||||
if (null == symbol) return null;
|
||||
saveParams.Add(new KeyValuePair<String, String>("Type", GetType().Namespace + "." + GetType().Name));
|
||||
saveParams.Add(new KeyValuePair<String, String>("SelectedSymbol", symbol));
|
||||
saveParams.Add(new KeyValuePair<String, String>("SelectedWatchList", selectedWatchList));
|
||||
return saveParams;
|
||||
}
|
||||
public override void SetSaveParameters(SaveParameters saveParameters)
|
||||
{
|
||||
try
|
||||
{
|
||||
symbol = (from KeyValuePair<String, String> item in saveParameters where item.Key.Equals("SelectedSymbol") select item).FirstOrDefault().Value;
|
||||
selectedWatchList = (from KeyValuePair<String, String> item in saveParameters where item.Key.Equals("SelectedWatchList") select item).FirstOrDefault().Value;
|
||||
Referer=saveParameters.Referer;
|
||||
base.OnPropertyChanged("SelectedWatchList");
|
||||
base.OnPropertyChanged("SelectedSymbol");
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Exception:{0}",exception.ToString()));
|
||||
}
|
||||
}
|
||||
public override bool CanPersist()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public ObservableCollection<DividendHistoryItem> AllDividendHistory
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
public bool BusyIndicator
|
||||
{
|
||||
get { return busyIndicator; }
|
||||
set
|
||||
{
|
||||
busyIndicator = value;
|
||||
base.OnPropertyChanged("BusyIndicator");
|
||||
}
|
||||
}
|
||||
private void OnDividendHistoryViewModelPropertyChanged(object sender, PropertyChangedEventArgs eventArgs)
|
||||
{
|
||||
if (eventArgs.PropertyName.Equals("SelectedSymbol") && null != symbol)
|
||||
{
|
||||
BusyIndicator = true;
|
||||
Task workerTask = Task.Factory.StartNew(() =>
|
||||
{
|
||||
base.DisplayName = "Dividend History (" + symbol + ")";
|
||||
base.OnPropertyChanged("DisplayName");
|
||||
String companyName = PricingDA.GetNameForSymbol(symbol);
|
||||
selectedCompanyName = PricingDA.GetNameForSymbol(symbol);
|
||||
List<PriceModel> priceModels = new List<PriceModel>();
|
||||
List<PriceModel> priceModelList = priceModels.ToList();
|
||||
DividendHistory dividendHistory=DividendHistoryDA.GetDividendHistory(symbol);
|
||||
if(null!=dividendHistory && 0!=dividendHistory.Count)
|
||||
this.AllDividendHistory = new ObservableCollection<DividendHistoryItem>(dividendHistory);
|
||||
else this.AllDividendHistory = new ObservableCollection<DividendHistoryItem>();
|
||||
});
|
||||
workerTask.ContinueWith((continuation) =>
|
||||
{
|
||||
BusyIndicator = false;
|
||||
base.OnPropertyChanged("AllDividendHistory");
|
||||
base.OnPropertyChanged("Title");
|
||||
});
|
||||
}
|
||||
else if (eventArgs.PropertyName.Equals("SelectedWatchList"))
|
||||
{
|
||||
if (selectedWatchList.Equals(Constants.CONST_ALL)) symbols = PricingDA.GetSymbols();
|
||||
else symbols = WatchListDA.GetWatchList(selectedWatchList);
|
||||
base.OnPropertyChanged("Symbols");
|
||||
}
|
||||
}
|
||||
public override String Title
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null != selectedCompanyName && null!=symbol) return selectedCompanyName+" ("+symbol+")";
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public List<String> WatchListNames
|
||||
{
|
||||
get
|
||||
{
|
||||
return watchLists;
|
||||
}
|
||||
set { ;}
|
||||
}
|
||||
public String SelectedWatchList
|
||||
{
|
||||
get { return selectedWatchList; }
|
||||
set { selectedWatchList = value; base.OnPropertyChanged("SelectedWatchList"); }
|
||||
}
|
||||
public List<String> Symbols
|
||||
{
|
||||
get
|
||||
{
|
||||
return symbols;
|
||||
}
|
||||
}
|
||||
public String SelectedSymbol
|
||||
{
|
||||
get { return symbol; }
|
||||
set
|
||||
{
|
||||
if (value == symbol || String.IsNullOrEmpty(value)) return;
|
||||
symbol = value;
|
||||
base.OnPropertyChanged("SelectedSymbol");
|
||||
}
|
||||
}
|
||||
private void Refresh()
|
||||
{
|
||||
base.OnPropertyChanged("SelectedSymbol");
|
||||
}
|
||||
public ICommand RefreshCommand
|
||||
{
|
||||
get
|
||||
{
|
||||
if (refreshCommand == null)
|
||||
{
|
||||
refreshCommand = new RelayCommand(param => this.Refresh(), param => { return true; });
|
||||
}
|
||||
return refreshCommand;
|
||||
}
|
||||
}
|
||||
public void GetLatestDivExDates()
|
||||
{
|
||||
BusyIndicator = true;
|
||||
Task workerTask = Task.Factory.StartNew(() =>
|
||||
{
|
||||
List<DivExDateItem> divExDates = DividendHistoryDA.GetLatestDivExDates();
|
||||
DividendHistory dividendHistory = DividendHistoryDA.GetDividendHistory(divExDates);
|
||||
if (null != dividendHistory && 0 != dividendHistory.Count)
|
||||
this.AllDividendHistory = new ObservableCollection<DividendHistoryItem>(dividendHistory);
|
||||
});
|
||||
workerTask.ContinueWith((continuation) =>
|
||||
{
|
||||
BusyIndicator = false;
|
||||
base.OnPropertyChanged("AllDividendHistory");
|
||||
});
|
||||
}
|
||||
public ICommand GetLatestDivExDatesCommand
|
||||
{
|
||||
get
|
||||
{
|
||||
if (getLatestDivExDatesCommand == null)
|
||||
{
|
||||
getLatestDivExDatesCommand = new RelayCommand(param => this.GetLatestDivExDates(), param => { return true; });
|
||||
}
|
||||
return getLatestDivExDatesCommand;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
382
ViewModels/DividendPaymentViewModel.cs
Normal file
@@ -0,0 +1,382 @@
|
||||
using System;
|
||||
using System.Windows.Input;
|
||||
using System.ComponentModel;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Collections.Specialized;
|
||||
using System.Windows;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Research.DynamicDataDisplay.DataSources;
|
||||
using Microsoft.Research.DynamicDataDisplay.PointMarkers;
|
||||
using MarketData;
|
||||
using MarketData.Utils;
|
||||
using MarketData.DataAccess;
|
||||
using MarketData.MarketDataModel;
|
||||
using TradeBlotter.DataAccess;
|
||||
using TradeBlotter.Command;
|
||||
using TradeBlotter.Model;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace TradeBlotter.ViewModels
|
||||
{
|
||||
public class DividendPaymentViewModel : WorkspaceViewModel
|
||||
{
|
||||
private List<String> accounts;
|
||||
private List<String> symbols;
|
||||
private String selectedAccounts;
|
||||
|
||||
private String selectedSymbols;
|
||||
private ObservableCollection<String> selectedSymbolsOverride = new ObservableCollection<String>();
|
||||
private DividendPaymentModelCollection dividendPaymentModelCollection = null;
|
||||
private String saveDocument;
|
||||
private RelayCommand saveCommand;
|
||||
private RelayCommand refreshCommand;
|
||||
private bool showLabels = true;
|
||||
private bool busyIndicator = false;
|
||||
private bool ignoreSelectedSymbols = true;
|
||||
private CompositeDataSource valuePointsCompositeDataSource;
|
||||
private CompositeDataSource valuesCompositeDataSource;
|
||||
|
||||
public DividendPaymentViewModel(bool loadedFromParams=false)
|
||||
{
|
||||
base.DisplayName = "Dividend Payments";
|
||||
accounts = DividendPaymentDA.GetDividendPaymentAccounts();
|
||||
accounts.Insert(0, Constants.CONST_ALL);
|
||||
selectedAccounts = accounts.Find(x => x.Equals(Constants.CONST_ALL));
|
||||
symbols = DividendPaymentDA.GetDividendPaymentSymbols(selectedAccounts);
|
||||
symbols.Insert(0, Constants.CONST_ALL);
|
||||
selectedSymbols = symbols[0];
|
||||
PropertyChanged += OnViewModelPropertyChanged;
|
||||
if (!loadedFromParams)
|
||||
{
|
||||
base.OnPropertyChanged("SelectedAccounts");
|
||||
base.OnPropertyChanged("SelectedItemsOverride");
|
||||
}
|
||||
}
|
||||
public void CreateCompositeDataSources()
|
||||
{
|
||||
if (null == dividendPaymentModelCollection) return;
|
||||
valuePointsCompositeDataSource = dividendPaymentModelCollection.CollectionToCompositeDataSource(true);
|
||||
valuesCompositeDataSource = dividendPaymentModelCollection.ToCompositeDataSource(true);
|
||||
}
|
||||
public void InitializeDataSources()
|
||||
{
|
||||
dividendPaymentModelCollection = null;
|
||||
if (valuePointsCompositeDataSource != null) valuePointsCompositeDataSource.Clear();
|
||||
if (valuesCompositeDataSource != null) valuesCompositeDataSource.Clear();
|
||||
base.OnPropertyChanged("DividendPayments");
|
||||
base.OnPropertyChanged("Values");
|
||||
base.OnPropertyChanged("ValuePoints");
|
||||
base.OnPropertyChanged("Markers");
|
||||
}
|
||||
|
||||
public override SaveParameters GetSaveParameters()
|
||||
{
|
||||
SaveParameters saveParams = new SaveParameters();
|
||||
saveParams.Add(new KeyValuePair<String, String>("Type", GetType().Namespace + "." + GetType().Name));
|
||||
saveParams.Add(new KeyValuePair<String, String>("SelectedSymbols", Utility.ListToString(Utility.ToList(selectedSymbols),'|')));
|
||||
saveParams.Add(new KeyValuePair<String, String>("SelectedAccounts", Utility.ListToString(Utility.ToList(selectedAccounts),'|')));
|
||||
saveParams.Add(new KeyValuePair<String, String>("Symbols", Utility.ListToString(symbols,'|')));
|
||||
saveParams.Add(new KeyValuePair<String, String>("Accounts", Utility.ListToString(accounts, '|')));
|
||||
return saveParams;
|
||||
}
|
||||
public override void SetSaveParameters(SaveParameters saveParameters)
|
||||
{
|
||||
try
|
||||
{
|
||||
Referer = saveParameters.Referer;
|
||||
if(saveParameters.ContainsKey("SelectedSymbols")) selectedSymbols=Utility.ListToString(Utility.ToList((from KeyValuePair<String,String> item in saveParameters where item.Key.Equals("SelectedSymbols") select item).FirstOrDefault().Value,'|'),',');
|
||||
if(saveParameters.ContainsKey("SelectedAccounts")) selectedAccounts=Utility.ListToString(Utility.ToList((from KeyValuePair<String,String> item in saveParameters where item.Key.Equals("SelectedAccounts") select item).FirstOrDefault().Value,'|'),',');
|
||||
if(saveParameters.ContainsKey("Symbols")) symbols=Utility.ToList((from KeyValuePair<String,String> item in saveParameters where item.Key.Equals("Symbols") select item).FirstOrDefault().Value,'|');
|
||||
if(saveParameters.ContainsKey("Accounts")) accounts=Utility.ToList((from KeyValuePair<String,String> item in saveParameters where item.Key.Equals("Accounts") select item).FirstOrDefault().Value,'|');
|
||||
ignoreSelectedSymbols = false;
|
||||
base.OnPropertyChanged("SelectedSymbols");
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Exception:{0}",exception.ToString()));
|
||||
}
|
||||
}
|
||||
public override bool CanPersist()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public ObservableCollection<DividendPaymentModel> DividendPayments
|
||||
{
|
||||
get
|
||||
{
|
||||
return dividendPaymentModelCollection;
|
||||
}
|
||||
}
|
||||
public bool BusyIndicator
|
||||
{
|
||||
get { return busyIndicator; }
|
||||
set
|
||||
{
|
||||
busyIndicator = value;
|
||||
base.OnPropertyChanged("BusyIndicator");
|
||||
}
|
||||
}
|
||||
private void OnViewModelPropertyChanged(object sender, PropertyChangedEventArgs eventArgs)
|
||||
{
|
||||
if (eventArgs.PropertyName.Equals("SelectedSymbols") && ignoreSelectedSymbols)
|
||||
{
|
||||
ignoreSelectedSymbols = false;
|
||||
return;
|
||||
}
|
||||
else if (eventArgs.PropertyName.Equals("SelectedSymbols"))
|
||||
{
|
||||
BusyIndicator = true;
|
||||
Task workerTask = Task.Factory.StartNew(() =>
|
||||
{
|
||||
InitializeDataSources();
|
||||
CheckSelectedItems();
|
||||
String accounts = null;
|
||||
if (selectedAccounts.Equals(Constants.CONST_ALL)) accounts = Utility.ListToString(DividendPaymentDA.GetDividendPaymentAccounts());
|
||||
else accounts = selectedAccounts;
|
||||
if (!"".Equals(selectedSymbols))
|
||||
{
|
||||
List<String> selectedAccountsInternal = GetSelectedItemsInternal(accounts);
|
||||
List<String> selectedSymbolsInternal = GetSelectedItemsInternal(selectedSymbols);
|
||||
DividendPayments dividendPayments = DividendPaymentDA.GetDividendPaymentsForAccountsAndSymbols(selectedAccountsInternal, selectedSymbolsInternal);
|
||||
dividendPaymentModelCollection = new DividendPaymentModelCollection(dividendPayments);
|
||||
CreateCompositeDataSources();
|
||||
}
|
||||
});
|
||||
workerTask.ContinueWith((continuation) =>
|
||||
{
|
||||
BusyIndicator = false;
|
||||
base.OnPropertyChanged("DividendPayments");
|
||||
base.OnPropertyChanged("Values");
|
||||
base.OnPropertyChanged("ValuePoints");
|
||||
base.OnPropertyChanged("Markers");
|
||||
});
|
||||
}
|
||||
else if (eventArgs.PropertyName.Equals("SelectedAccounts"))
|
||||
{
|
||||
BusyIndicator = true;
|
||||
Task workerTask = Task.Factory.StartNew(() =>
|
||||
{
|
||||
InitializeDataSources();
|
||||
ignoreSelectedSymbols = true;
|
||||
if (selectedAccounts.Equals(Constants.CONST_ALL)) symbols = DividendPaymentDA.GetDividendPaymentSymbols();
|
||||
else symbols = DividendPaymentDA.GetDividendPaymentSymbols(GetSelectedItemsInternal(selectedAccounts));
|
||||
if (symbols.Count > 1) symbols.Insert(0, Constants.CONST_ALL);
|
||||
Symbols = symbols;
|
||||
if (symbols.Count > 0)
|
||||
{
|
||||
SelectedSymbols = symbols[0];
|
||||
// SetSelectedItems(symbols[0]);
|
||||
List<String> selectedAccountsInternal = GetSelectedItemsInternal(selectedAccounts);
|
||||
List<String> selectedSymbolsInternal = GetSelectedItemsInternal(selectedSymbols);
|
||||
DividendPayments dividendPayments = DividendPaymentDA.GetDividendPaymentsForAccountsAndSymbols(selectedAccountsInternal, selectedSymbolsInternal);
|
||||
dividendPaymentModelCollection = new DividendPaymentModelCollection(dividendPayments);
|
||||
CreateCompositeDataSources();
|
||||
}
|
||||
else dividendPaymentModelCollection = null;
|
||||
});
|
||||
workerTask.ContinueWith((continuation) =>
|
||||
{
|
||||
BusyIndicator = false;
|
||||
ignoreSelectedSymbols = false;
|
||||
base.OnPropertyChanged("DividendPayments");
|
||||
base.OnPropertyChanged("Values");
|
||||
base.OnPropertyChanged("ValuePoints");
|
||||
base.OnPropertyChanged("Markers");
|
||||
});
|
||||
}
|
||||
}
|
||||
public override String Title
|
||||
{
|
||||
get
|
||||
{
|
||||
return "Dividend Payments";
|
||||
}
|
||||
}
|
||||
public List<String> Accounts
|
||||
{
|
||||
get
|
||||
{
|
||||
return accounts;
|
||||
}
|
||||
set { ;}
|
||||
}
|
||||
// Note : if more than one item is selected in the Symbols list we remove {All} from the selection list. However, WPFToolkit CheckBoxCombo does not update the check mark on the {All} item
|
||||
// so it remains visibly checked even though it is not checked.
|
||||
public String SelectedAccounts
|
||||
{
|
||||
get
|
||||
{
|
||||
return selectedAccounts ;
|
||||
}
|
||||
set
|
||||
{
|
||||
List<String> selectedAccountsList = Utility.ToList(value);
|
||||
if (selectedAccountsList.Count > 1) selectedAccountsList.Remove(Constants.CONST_ALL);
|
||||
selectedAccounts = Utility.ListToString(selectedAccountsList);
|
||||
base.OnPropertyChanged("SelectedAccounts");
|
||||
}
|
||||
}
|
||||
private static List<String> GetSelectedItemsInternal(String selectedItemsStr)
|
||||
{
|
||||
List<String> selectedItems = Utility.ToList(selectedItemsStr);
|
||||
List<String> selectedItemsInternal = new List<String>();
|
||||
foreach (String selectedItem in selectedItems)
|
||||
{
|
||||
selectedItemsInternal.Add(selectedItem);
|
||||
}
|
||||
return selectedItemsInternal;
|
||||
}
|
||||
public List<String> Symbols
|
||||
{
|
||||
get
|
||||
{
|
||||
return symbols;
|
||||
}
|
||||
set
|
||||
{
|
||||
symbols = value;
|
||||
base.OnPropertyChanged("Symbols");
|
||||
}
|
||||
}
|
||||
// Note : if more than one item is selected in the Symbols list we remove {All} from the selection list. However, WPFToolkit CheckBoxCombo does not update the check mark on the {All} item
|
||||
// so it remains visibly checked even though it is not checked.
|
||||
public String SelectedSymbols
|
||||
{
|
||||
get
|
||||
{
|
||||
return selectedSymbols;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (null != value)
|
||||
{
|
||||
List<String> selectedSymbolsList = Utility.ToList(value);
|
||||
if (selectedSymbolsList.Count > 1) selectedSymbolsList.Remove(Constants.CONST_ALL);
|
||||
selectedSymbols = Utility.ListToString(selectedSymbolsList);
|
||||
base.OnPropertyChanged("SelectedSymbols");
|
||||
}
|
||||
}
|
||||
}
|
||||
private void CheckSelectedItems()
|
||||
{
|
||||
Application.Current.Dispatcher.Invoke((System.Windows.Forms.MethodInvoker)delegate()
|
||||
{
|
||||
if (null == selectedSymbolsOverride) return;
|
||||
if (selectedSymbolsOverride.Count > 1)
|
||||
{
|
||||
selectedSymbolsOverride.Remove(Constants.CONST_ALL);
|
||||
}
|
||||
else if (0 == selectedSymbolsOverride.Count)
|
||||
{ // select {All}
|
||||
selectedSymbolsOverride.Add(Constants.CONST_ALL);
|
||||
}
|
||||
});
|
||||
}
|
||||
public ObservableCollection<String> SelectedItemsOverride
|
||||
{
|
||||
get
|
||||
{
|
||||
return selectedSymbolsOverride;
|
||||
}
|
||||
set
|
||||
{
|
||||
selectedSymbolsOverride = value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public CompositeDataSource ValuePoints
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == dividendPaymentModelCollection) return null;
|
||||
|
||||
return valuePointsCompositeDataSource;
|
||||
}
|
||||
}
|
||||
public CompositeDataSource Values
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == dividendPaymentModelCollection) return null;
|
||||
|
||||
return valuesCompositeDataSource;
|
||||
}
|
||||
}
|
||||
// This just adds a lot of noise to the screen
|
||||
public CenteredTextMarker[] Markers
|
||||
{
|
||||
get
|
||||
{
|
||||
return null;
|
||||
//if (!showLabels) return null;
|
||||
//if (null == dividendPaymentModelCollection) return null;
|
||||
//List<CenteredTextMarker> centeredTextMarkers = new List<CenteredTextMarker>();
|
||||
//for (int index = 0; index < dividendPaymentModelCollection.Count; index++)
|
||||
//{
|
||||
// CenteredTextMarker centerTextMarker = new CenteredTextMarker();
|
||||
// DividendPaymentModel dividendPaymentModel = dividendPaymentModelCollection[index];
|
||||
// StringBuilder sb = new StringBuilder();
|
||||
// sb.Append("(").Append(Utility.FormatCurrency(dividendPaymentModel.TotalAmount)).Append(")");
|
||||
// centerTextMarker.Text = sb.ToString();
|
||||
// centeredTextMarkers.Add(centerTextMarker);
|
||||
//}
|
||||
//return centeredTextMarkers.ToArray();
|
||||
}
|
||||
}
|
||||
private void Refresh()
|
||||
{
|
||||
accounts = DividendPaymentDA.GetDividendPaymentAccounts();
|
||||
accounts.Insert(0, Constants.CONST_ALL);
|
||||
selectedAccounts = accounts.Find(x => x.Equals(Constants.CONST_ALL));
|
||||
symbols = DividendPaymentDA.GetDividendPaymentSymbols(selectedAccounts);
|
||||
symbols.Insert(0, Constants.CONST_ALL);
|
||||
selectedSymbols = symbols[0];
|
||||
base.OnPropertyChanged("SelectedAccounts");
|
||||
}
|
||||
private bool CanRefresh
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
public ICommand RefreshCommand
|
||||
{
|
||||
get
|
||||
{
|
||||
if (refreshCommand == null)
|
||||
{
|
||||
refreshCommand = new RelayCommand(param => this.Refresh(), param => this.CanRefresh);
|
||||
}
|
||||
return refreshCommand;
|
||||
}
|
||||
}
|
||||
public String SaveDocument
|
||||
{
|
||||
get { return saveDocument; }
|
||||
set { saveDocument = value; base.OnPropertyChanged("SaveDocument"); }
|
||||
}
|
||||
private void Save()
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.Append("DividendPayments_").Append(DateTime.Now.ToShortDateString()).Append(".xls");
|
||||
SaveDocument = sb.ToString();
|
||||
}
|
||||
private bool CanSave
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
public ICommand SaveCommand
|
||||
{
|
||||
get
|
||||
{
|
||||
if (saveCommand == null)
|
||||
{
|
||||
saveCommand = new RelayCommand(param => this.Save(), param => this.CanSave);
|
||||
}
|
||||
return saveCommand;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
750
ViewModels/DividendRiskParityViewModel.cs
Normal file
@@ -0,0 +1,750 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Collections.Specialized;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Input;
|
||||
using System.Threading.Tasks;
|
||||
using MarketData;
|
||||
using MarketData.Numerical;
|
||||
using MarketData.Utils;
|
||||
using MarketData.MarketDataModel;
|
||||
using MarketData.Generator;
|
||||
using MarketData.DataAccess;
|
||||
using TradeBlotter.DataAccess;
|
||||
using TradeBlotter.Command;
|
||||
using TradeBlotter.Model;
|
||||
using Microsoft.Research.DynamicDataDisplay.DataSources;
|
||||
using MarketData.DividendRiskParity;
|
||||
using TradeBlotter.UIUtils;
|
||||
|
||||
namespace TradeBlotter.ViewModels
|
||||
{
|
||||
public class DividendRiskParityViewModel : WorkspaceViewModel
|
||||
{
|
||||
private List<String> symbols;
|
||||
private String selectedSymbol;
|
||||
private String companyName;
|
||||
private bool busyIndicator = false;
|
||||
private PortfolioTrades portfolioTrades;
|
||||
private DividendRiskParityPositionCollection dividendRiskParityPositionCollection;
|
||||
private ObservableCollection<DividendRiskParityPosition> allPositions=new ObservableCollection<DividendRiskParityPosition>();
|
||||
private DividendRiskParityPosition dividendRiskParityPositionProforma = null;
|
||||
private DividendRiskParityResult dividendRiskParityResult;
|
||||
private DividendRiskParityResult dividendRiskParityResultProforma;
|
||||
private double aum = double.NaN;
|
||||
private Price currentPrice = null;
|
||||
|
||||
private RelayCommand proformaAddRiskParityPositionCommand;
|
||||
private RelayCommand proformaAddRiskParityPositionEnabledCommand;
|
||||
private RelayCommand resetCommand;
|
||||
|
||||
// MENU COMMANDS
|
||||
private RelayCommand bollingerBandCommand = null;
|
||||
private RelayCommand dividendHistoryCommand = null;
|
||||
private RelayCommand stickerValuationCommand = null;
|
||||
private RelayCommand displayHistoricalCommand = null;
|
||||
private RelayCommand stochasticsCommand = null;
|
||||
private RelayCommand relativeStrengthCommand = null;
|
||||
private RelayCommand macdCommand = null;
|
||||
private RelayCommand movingAverageCommand;
|
||||
private RelayCommand priceHistoryCommand = null;
|
||||
private RelayCommand dcfValuationCommand = null;
|
||||
private RelayCommand displayAnalystRatingsCommand = null;
|
||||
private RelayCommand displayHeadlinesCommand = null;
|
||||
|
||||
public DividendRiskParityViewModel()
|
||||
{
|
||||
base.DisplayName = "Dividend Risk Parity";
|
||||
symbols=PortfolioDA.GetOpenSymbols();
|
||||
PortfolioTrades allTrades = PortfolioDA.GetOpenTrades();
|
||||
aum= allTrades.Sum(x => x.Exposure());
|
||||
base.OnPropertyChanged("Aum");
|
||||
selectedSymbol = null;
|
||||
PropertyChanged += OnDividendRiskParityViewModelPropertyChanged;
|
||||
base.OnPropertyChanged("SelectedSymbol");
|
||||
}
|
||||
// ******************************************************************************************** P E R S I S T E N C E ********************************************************************************************
|
||||
public override bool CanPersist()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public override SaveParameters GetSaveParameters()
|
||||
{
|
||||
//return null;
|
||||
SaveParameters saveParams = new SaveParameters();
|
||||
if (null == selectedSymbol) return null;
|
||||
saveParams.Add(new KeyValuePair<String, String>("Type", GetType().Namespace + "." + GetType().Name));
|
||||
saveParams.Add(new KeyValuePair<String, String>("SelectedSymbol", selectedSymbol));
|
||||
saveParams.Add(new KeyValuePair<String, String>("Aum", aum.ToString()));
|
||||
if(null!=currentPrice)
|
||||
{
|
||||
saveParams.Add((new KeyValuePair<String, String>("CurrentPrice", currentPrice.Close.ToString())));
|
||||
saveParams.Add((new KeyValuePair<String, String>("PricingDate", Utility.DateTimeToStringMMHDDHYYYY(currentPrice.Date))));
|
||||
}
|
||||
if (null != dividendRiskParityPositionProforma) saveParams.Add(new KeyValuePair<String, String>("DividendRiskParityPositionProforma", dividendRiskParityPositionProforma.ToString()));
|
||||
return saveParams;
|
||||
}
|
||||
public override void SetSaveParameters(SaveParameters saveParameters)
|
||||
{
|
||||
try
|
||||
{
|
||||
dividendRiskParityResult = null;
|
||||
dividendRiskParityResultProforma = null;
|
||||
dividendRiskParityPositionProforma = null;
|
||||
selectedSymbol = (from KeyValuePair<String, String> item in saveParameters where item.Key.Equals("SelectedSymbol") select item).FirstOrDefault().Value;
|
||||
aum = double.NaN;
|
||||
String strAum=(from KeyValuePair<String, String> item in saveParameters where item.Key.Equals("Aum") select item).FirstOrDefault().Value;
|
||||
if(null!=strAum)aum=double.Parse(strAum);
|
||||
else
|
||||
{
|
||||
PortfolioTrades allTrades = PortfolioDA.GetOpenTrades();
|
||||
aum= allTrades.Sum(x => x.Exposure());
|
||||
}
|
||||
String strCurrentPrice = (from KeyValuePair<String, String> item in saveParameters where item.Key.Equals("CurrentPrice") select item).FirstOrDefault().Value;
|
||||
String strPricingDate= (from KeyValuePair<String, String> item in saveParameters where item.Key.Equals("PricingDate") select item).FirstOrDefault().Value;
|
||||
if (null != strCurrentPrice && null != strPricingDate)
|
||||
{
|
||||
currentPrice = new Price();
|
||||
currentPrice.Close = double.Parse(strCurrentPrice);
|
||||
currentPrice.Date = DateTime.Parse(strPricingDate);
|
||||
}
|
||||
String strDividendRiskParityPositionProforma = (from KeyValuePair<String, String> item in saveParameters where item.Key.Equals("DividendRiskParityPositionProforma") select item).FirstOrDefault().Value;
|
||||
if (null != strDividendRiskParityPositionProforma && !"".Equals(strDividendRiskParityPositionProforma))
|
||||
{
|
||||
dividendRiskParityPositionProforma = DividendRiskParityPosition.FromString(strDividendRiskParityPositionProforma);
|
||||
}
|
||||
Referer = saveParameters.Referer;
|
||||
companyName = PricingDA.GetNameForSymbol(selectedSymbol);
|
||||
portfolioTrades = PortfolioDA.GetOpenTradesSymbol(selectedSymbol);
|
||||
dividendRiskParityPositionCollection = new DividendRiskParityPositionCollection(portfolioTrades);
|
||||
if(null==currentPrice)currentPrice = PricingDA.GetPrice(portfolioTrades.Take(1).FirstOrDefault().Symbol);
|
||||
dividendRiskParityResult = DividendRiskParityGenerator.GenerateDividendRiskParity(currentPrice, aum, dividendRiskParityPositionCollection);
|
||||
foreach (DividendRiskParityPosition dividendRiskParityPosition in dividendRiskParityPositionCollection) allPositions.Add(dividendRiskParityPosition);
|
||||
if (null != dividendRiskParityPositionProforma)
|
||||
{
|
||||
dividendRiskParityPositionProforma.PurchasePrice = currentPrice.Close; // must be taken from the stored pricing data
|
||||
dividendRiskParityPositionProforma.TradeDate = currentPrice.Date;
|
||||
dividendRiskParityPositionCollection.Add(dividendRiskParityPositionProforma);
|
||||
dividendRiskParityResultProforma = DividendRiskParityGenerator.GenerateDividendRiskParity(currentPrice, aum, dividendRiskParityPositionCollection);
|
||||
allPositions = new ObservableCollection<DividendRiskParityPosition>();
|
||||
foreach (DividendRiskParityPosition dividendRiskParityPosition in dividendRiskParityPositionCollection) allPositions.Add(dividendRiskParityPosition);
|
||||
}
|
||||
base.OnPropertyChanged("AllPositions");
|
||||
base.OnPropertyChanged("Title");
|
||||
base.OnPropertyChanged("Aum");
|
||||
base.OnPropertyChanged("ProformaAddRiskParityPositionEnabled");
|
||||
UpdateDividendRiskParityResultProforma();
|
||||
UpdateDividendRiskParityResult();
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
MDTrace.WriteLine(String.Format("Exception:{0}",exception.ToString()));
|
||||
}
|
||||
}
|
||||
// ******************************************************************************************************************************************************
|
||||
public bool BusyIndicator
|
||||
{
|
||||
get { return busyIndicator; }
|
||||
set
|
||||
{
|
||||
busyIndicator = value;
|
||||
base.OnPropertyChanged("BusyIndicator");
|
||||
}
|
||||
}
|
||||
public ObservableCollection<DividendRiskParityPosition> AllPositions
|
||||
{
|
||||
get
|
||||
{
|
||||
return allPositions;
|
||||
}
|
||||
set
|
||||
{
|
||||
allPositions = value;
|
||||
base.OnPropertyChanged("AllPositions");
|
||||
}
|
||||
}
|
||||
private void OnDividendRiskParityViewModelPropertyChanged(object sender, PropertyChangedEventArgs eventArgs)
|
||||
{
|
||||
if (eventArgs.PropertyName.Equals("SelectedSymbol"))
|
||||
{
|
||||
base.DisplayName = "Dividend Risk Parity(" + selectedSymbol + ")";
|
||||
base.OnPropertyChanged("DisplayName");
|
||||
HandleSelectedSymbol();
|
||||
}
|
||||
}
|
||||
private void HandleSelectedSymbol()
|
||||
{
|
||||
BusyIndicator = true;
|
||||
Task workerTask = Task.Factory.StartNew(() =>
|
||||
{
|
||||
if (null != selectedSymbol)
|
||||
{
|
||||
companyName = PricingDA.GetNameForSymbol(SelectedSymbol);
|
||||
dividendRiskParityResult = null;
|
||||
dividendRiskParityResultProforma = null;
|
||||
dividendRiskParityPositionProforma = null;
|
||||
portfolioTrades = PortfolioDA.GetOpenTradesSymbol(selectedSymbol);
|
||||
dividendRiskParityPositionCollection= new DividendRiskParityPositionCollection(portfolioTrades);
|
||||
allPositions=new ObservableCollection<DividendRiskParityPosition>();
|
||||
currentPrice=PricingDA.GetPrice(portfolioTrades.Take(1).FirstOrDefault().Symbol);
|
||||
dividendRiskParityResult = DividendRiskParityGenerator.GenerateDividendRiskParity(currentPrice, aum, dividendRiskParityPositionCollection);
|
||||
foreach (DividendRiskParityPosition dividendRiskParityPosition in dividendRiskParityPositionCollection) allPositions.Add(dividendRiskParityPosition);
|
||||
}
|
||||
});
|
||||
workerTask.ContinueWith((continuation) =>
|
||||
{
|
||||
BusyIndicator = false;
|
||||
base.OnPropertyChanged("AllPositions");
|
||||
base.OnPropertyChanged("Title");
|
||||
base.OnPropertyChanged("CurrentPrice");
|
||||
base.OnPropertyChanged("PricingDate");
|
||||
base.OnPropertyChanged("ProformaAddRiskParityPositionEnabled");
|
||||
UpdateDividendRiskParityResult();
|
||||
UpdateDividendRiskParityResultProforma();
|
||||
});
|
||||
}
|
||||
public void OnErrorItemHandler(String symbol, String message)
|
||||
{
|
||||
}
|
||||
public void UpdateDividendRiskParityResult()
|
||||
{
|
||||
base.OnPropertyChanged("Parity");
|
||||
base.OnPropertyChanged("ParityPercent");
|
||||
base.OnPropertyChanged("CostBasis");
|
||||
base.OnPropertyChanged("Aum");
|
||||
base.OnPropertyChanged("AllocationPercent");
|
||||
base.OnPropertyChanged("AnnualDividend");
|
||||
base.OnPropertyChanged("DividendYearsToParity");
|
||||
base.OnPropertyChanged("DaysSinceLastTraded");
|
||||
base.OnPropertyChanged("CurrentDividendPercent");
|
||||
base.OnPropertyChanged("AdditionalDividendPerYear");
|
||||
base.OnPropertyChanged("YieldPercent");
|
||||
}
|
||||
public void UpdateDividendRiskParityResultProforma()
|
||||
{
|
||||
base.OnPropertyChanged("ParityProforma");
|
||||
base.OnPropertyChanged("ParityPercentProforma");
|
||||
base.OnPropertyChanged("CostBasisProforma");
|
||||
base.OnPropertyChanged("AumProforma");
|
||||
base.OnPropertyChanged("AllocationPercentProforma");
|
||||
base.OnPropertyChanged("AnnualDividendProforma");
|
||||
base.OnPropertyChanged("DividendYearsToParityProforma");
|
||||
base.OnPropertyChanged("DaysSinceLastTradedProforma");
|
||||
base.OnPropertyChanged("CurrentDividendPercentProforma");
|
||||
base.OnPropertyChanged("AdditionalDividendPerYearProforma");
|
||||
base.OnPropertyChanged("YieldPercentProforma");
|
||||
}
|
||||
// *****************************************************************************************************************************************************************
|
||||
// ****************************************************************************** C O N T E X T M E N U *********************************************************
|
||||
// *****************************************************************************************************************************************************************
|
||||
|
||||
public ObservableCollection<MenuItem> MenuItems
|
||||
{
|
||||
get
|
||||
{
|
||||
ObservableCollection<MenuItem> collection = new ObservableCollection<MenuItem>();
|
||||
collection.Add(new MenuItem() { Text = "Display Bollinger Band", MenuItemClickedCommand = DisplayBollingerBand, StaysOpenOnClick = false });
|
||||
collection.Add(new MenuItem() { Text = "Display Dividend History", MenuItemClickedCommand = DisplayDividendHistory, StaysOpenOnClick = false });
|
||||
collection.Add(new MenuItem() { Text = "Display Sticker Valuation", MenuItemClickedCommand = DisplayStickerValuation, StaysOpenOnClick = false });
|
||||
collection.Add(new MenuItem() { Text = "Display Historical", MenuItemClickedCommand = DisplayHistorical, StaysOpenOnClick = false });
|
||||
collection.Add(new MenuItem() { Text = "Display Stochastics", MenuItemClickedCommand = DisplayStochastic, StaysOpenOnClick = false });
|
||||
collection.Add(new MenuItem() { Text = "Display Relative Strength", MenuItemClickedCommand = DisplayRelativeStrength, StaysOpenOnClick = false });
|
||||
collection.Add(new MenuItem() { Text = "Display MACD", MenuItemClickedCommand = DisplayMACD, StaysOpenOnClick = false });
|
||||
collection.Add(new MenuItem() { Text = "Display Moving Average", MenuItemClickedCommand = DisplayMovingAverage, StaysOpenOnClick = false });
|
||||
collection.Add(new MenuItem() { Text = "Display Price History", MenuItemClickedCommand = DisplayPriceHistory, StaysOpenOnClick = false });
|
||||
collection.Add(new MenuItem() { Text = "Display DCF Valuation", MenuItemClickedCommand = DisplayDCFValuation, StaysOpenOnClick = false });
|
||||
collection.Add(new MenuItem() { Text = "Display Analyst Ratings", MenuItemClickedCommand = DisplayAnalystRatings, StaysOpenOnClick = false });
|
||||
collection.Add(new MenuItem() { Text = "Display Headlines", MenuItemClickedCommand = DisplayHeadlines, StaysOpenOnClick = false });
|
||||
return collection;
|
||||
}
|
||||
}
|
||||
public ICommand DisplayBollingerBand
|
||||
{
|
||||
get
|
||||
{
|
||||
if (bollingerBandCommand == null)
|
||||
{
|
||||
bollingerBandCommand = new RelayCommand(param => this.DisplayBollingerBandCommand(),
|
||||
param => { return null != selectedSymbol ; });
|
||||
}
|
||||
return bollingerBandCommand;
|
||||
}
|
||||
}
|
||||
public ICommand DisplayDividendHistory
|
||||
{
|
||||
get
|
||||
{
|
||||
if (dividendHistoryCommand == null)
|
||||
{
|
||||
dividendHistoryCommand = new RelayCommand(param =>
|
||||
{
|
||||
SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.DividendHistoryViewModel,SelectedSymbol," + selectedSymbol + ",SelectedWatchList,{All}");
|
||||
saveParams.Referer = this;
|
||||
WorkspaceInstantiator.Invoke(saveParams);
|
||||
}, param => { return null != selectedSymbol; });
|
||||
}
|
||||
return dividendHistoryCommand;
|
||||
}
|
||||
}
|
||||
public ICommand DisplayStickerValuation
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == stickerValuationCommand)
|
||||
{
|
||||
stickerValuationCommand = new RelayCommand(param =>
|
||||
{
|
||||
SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.StickerPriceViewModel,SelectedSymbol," + selectedSymbol + ",SelectedWatchList,{All}");
|
||||
saveParams.Referer = this;
|
||||
WorkspaceInstantiator.Invoke(saveParams);
|
||||
}, param => { return null != selectedSymbol && null != selectedSymbol; });
|
||||
}
|
||||
return stickerValuationCommand;
|
||||
}
|
||||
}
|
||||
public ICommand DisplayHistorical
|
||||
{
|
||||
get
|
||||
{
|
||||
if (displayHistoricalCommand == null)
|
||||
{
|
||||
displayHistoricalCommand = new RelayCommand(param =>
|
||||
{
|
||||
SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.HistoricalViewModel,SelectedSymbol," + selectedSymbol + ",SelectedWatchList,{All}");
|
||||
saveParams.Referer = this;
|
||||
WorkspaceInstantiator.Invoke(saveParams);
|
||||
}, param => { return null != selectedSymbol && null != selectedSymbol; });
|
||||
}
|
||||
return displayHistoricalCommand;
|
||||
}
|
||||
}
|
||||
public ICommand DisplayStochastic
|
||||
{
|
||||
get
|
||||
{
|
||||
if (stochasticsCommand == null)
|
||||
{
|
||||
stochasticsCommand = new RelayCommand(param => this.DisplayStochasticCommand(),
|
||||
param => { return null != selectedSymbol; });
|
||||
}
|
||||
return stochasticsCommand;
|
||||
}
|
||||
}
|
||||
public ICommand DisplayRelativeStrength
|
||||
{
|
||||
get
|
||||
{
|
||||
if (relativeStrengthCommand == null)
|
||||
{
|
||||
relativeStrengthCommand = new RelayCommand(param => this.DisplayRelativeStrengthCommand(),
|
||||
param => { return null != selectedSymbol; });
|
||||
}
|
||||
return relativeStrengthCommand;
|
||||
}
|
||||
}
|
||||
public ICommand DisplayMACD
|
||||
{
|
||||
get
|
||||
{
|
||||
if (macdCommand == null)
|
||||
{
|
||||
macdCommand = new RelayCommand(param => this.DisplayMACDCommand(),
|
||||
param => { return null != selectedSymbol; });
|
||||
}
|
||||
return macdCommand;
|
||||
}
|
||||
}
|
||||
public ICommand DisplayMovingAverage
|
||||
{
|
||||
get
|
||||
{
|
||||
if (movingAverageCommand == null)
|
||||
{
|
||||
movingAverageCommand = new RelayCommand(param => this.DisplayMovingAverageCommand(), param => { return null != selectedSymbol; });
|
||||
}
|
||||
return movingAverageCommand;
|
||||
}
|
||||
}
|
||||
public ICommand DisplayPriceHistory
|
||||
{
|
||||
get
|
||||
{
|
||||
if (priceHistoryCommand == null)
|
||||
{
|
||||
priceHistoryCommand = new RelayCommand(param => this.DisplayPriceHistoryCommand(),
|
||||
param => { return null != selectedSymbol; });
|
||||
}
|
||||
return priceHistoryCommand;
|
||||
}
|
||||
}
|
||||
public ICommand DisplayDCFValuation
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == dcfValuationCommand)
|
||||
{
|
||||
dcfValuationCommand = new RelayCommand(param =>
|
||||
{
|
||||
SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.DCFValuationViewModel,SelectedSymbol," + selectedSymbol + ",SelectedWatchList,{All}");
|
||||
saveParams.Referer = this;
|
||||
WorkspaceInstantiator.Invoke(saveParams);
|
||||
}, param => { return null != selectedSymbol; });
|
||||
}
|
||||
return dcfValuationCommand;
|
||||
}
|
||||
}
|
||||
public ICommand DisplayAnalystRatings
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == displayAnalystRatingsCommand)
|
||||
{
|
||||
displayAnalystRatingsCommand = new RelayCommand(param =>
|
||||
{
|
||||
SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.AnalystRatingsViewModel,SelectedSymbol," + selectedSymbol + ",SelectedWatchList,{All}");
|
||||
saveParams.Referer = this;
|
||||
WorkspaceInstantiator.Invoke(saveParams);
|
||||
}, param => { return null != selectedSymbol; });
|
||||
}
|
||||
return displayAnalystRatingsCommand;
|
||||
}
|
||||
}
|
||||
public ICommand DisplayHeadlines
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == displayHeadlinesCommand)
|
||||
{
|
||||
displayHeadlinesCommand = new RelayCommand(param =>
|
||||
{
|
||||
SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.HeadlinesViewModel,SelectedSymbol," + selectedSymbol + ",SelectedWatchList,Valuations");
|
||||
saveParams.Referer = this;
|
||||
WorkspaceInstantiator.Invoke(saveParams);
|
||||
}, param => { return null != selectedSymbol; });
|
||||
}
|
||||
return displayHeadlinesCommand;
|
||||
}
|
||||
}
|
||||
// **************************************************************************************************************************************************************************************
|
||||
// ******************************************************************************** C O M M A N D S *************************************************************************************
|
||||
// **************************************************************************************************************************************************************************************
|
||||
public void DisplayBollingerBandCommand()
|
||||
{
|
||||
SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.BollingerBandViewModel,SelectedSymbol," + selectedSymbol + ",SelectedWatchList,{All},SelectedDayCount,180,SyncTradeToBand,FALSE");
|
||||
saveParams.Referer = this;
|
||||
WorkspaceInstantiator.Invoke(saveParams);
|
||||
}
|
||||
public void DisplayStochasticCommand()
|
||||
{
|
||||
SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.StochasticsViewModel,SelectedSymbol," + selectedSymbol + ",SelectedWatchList,{All},SelectedDayCount,90");
|
||||
saveParams.Referer = this;
|
||||
WorkspaceInstantiator.Invoke(saveParams);
|
||||
}
|
||||
public void DisplayRelativeStrengthCommand()
|
||||
{
|
||||
SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.RSIViewModel,SelectedSymbol," + selectedSymbol + ",SelectedWatchList,{All},SelectedDayCount,60,SelectedRSIDayCount,3");
|
||||
saveParams.Referer = this;
|
||||
WorkspaceInstantiator.Invoke(saveParams);
|
||||
}
|
||||
public void DisplayMACDCommand()
|
||||
{
|
||||
SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.MACDViewModel,SelectedSymbol," + selectedSymbol + ",SelectedWatchList,{All},SelectedDayCount,90");
|
||||
saveParams.Referer = this;
|
||||
WorkspaceInstantiator.Invoke(saveParams);
|
||||
}
|
||||
public void DisplayMovingAverageCommand()
|
||||
{
|
||||
SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.MovingAverageViewModel,SelectedSymbol," + selectedSymbol + ",SelectedWatchList,{All},SelectedDayCount,360");
|
||||
saveParams.Referer = this;
|
||||
WorkspaceInstantiator.Invoke(saveParams);
|
||||
}
|
||||
public void DisplayPriceHistoryCommand()
|
||||
{
|
||||
SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.PricingViewModel,SelectedSymbol," + selectedSymbol + ",SelectedWatchList,{All},SelectedDayCount,90");
|
||||
saveParams.Referer = this;
|
||||
WorkspaceInstantiator.Invoke(saveParams);
|
||||
}
|
||||
// *****************************************************************************************************************************************************************
|
||||
// ****************************************************************************** I C O M M A N D ****************************************************************
|
||||
// *****************************************************************************************************************************************************************
|
||||
public ICommand ProformaAddRiskParityPositionCommand
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == proformaAddRiskParityPositionCommand)
|
||||
{
|
||||
proformaAddRiskParityPositionCommand = new RelayCommand(param =>
|
||||
{
|
||||
if (null != dividendRiskParityPositionCollection && 0 != dividendRiskParityPositionCollection.Count)
|
||||
{
|
||||
String symbol = dividendRiskParityPositionCollection.Take(1).FirstOrDefault().Symbol;
|
||||
DateTime pricingDate=PricingDA.GetLatestDate();
|
||||
ProformaAddRiskDividendParityPositionDialogResult proformaAddRiskDividendParityPositionDialogResult=ProformaAddRiskDividendParityPositionDialog.Prompt("Proforma Add Risk Parity Position", symbol, pricingDate, dividendRiskParityPositionCollection);
|
||||
if (true == proformaAddRiskDividendParityPositionDialogResult.Success)
|
||||
{
|
||||
dividendRiskParityPositionProforma = proformaAddRiskDividendParityPositionDialogResult.DividendRiskParityPositionProforma;
|
||||
dividendRiskParityPositionCollection = proformaAddRiskDividendParityPositionDialogResult.DividendRiskParityPositionCollection;
|
||||
currentPrice = PricingDA.GetPrice(dividendRiskParityPositionCollection.Take(1).FirstOrDefault().Symbol);
|
||||
dividendRiskParityResultProforma = DividendRiskParityGenerator.GenerateDividendRiskParity(currentPrice, aum, dividendRiskParityPositionCollection);
|
||||
allPositions = new ObservableCollection<DividendRiskParityPosition>();
|
||||
foreach (DividendRiskParityPosition dividendRiskParityPosition in dividendRiskParityPositionCollection) allPositions.Add(dividendRiskParityPosition);
|
||||
base.OnPropertyChanged("AllPositions");
|
||||
base.OnPropertyChanged("CurrentPrice");
|
||||
base.OnPropertyChanged("PricingDate");
|
||||
base.OnPropertyChanged("ProformaAddRiskParityPositionEnabled");
|
||||
UpdateDividendRiskParityResultProforma();
|
||||
}
|
||||
}
|
||||
}, param => { return true; });
|
||||
}
|
||||
return proformaAddRiskParityPositionCommand;
|
||||
}
|
||||
}
|
||||
public bool ProformaAddRiskParityPositionEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
if(null==dividendRiskParityPositionCollection)return false;
|
||||
int proformaRecords=dividendRiskParityPositionCollection.Where(x=>x.TypeOfPosition.Equals(DividendRiskParityPosition.PositionType.Proforma)).Count();
|
||||
return proformaRecords>0?false:true;
|
||||
}
|
||||
}
|
||||
public ICommand ResetCommand
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == resetCommand)
|
||||
{
|
||||
resetCommand = new RelayCommand(param =>
|
||||
{
|
||||
dividendRiskParityResult = null;
|
||||
dividendRiskParityResultProforma = null;
|
||||
base.OnPropertyChanged("SelectedSymbol");
|
||||
}, param => { return true; });
|
||||
}
|
||||
return resetCommand;
|
||||
}
|
||||
}
|
||||
// ************************************************************************************************************************************************************************
|
||||
// ************************************************************** D I V I D E N D R I S K P A R I T Y R E S U L T ******************************************************
|
||||
// ************************************************************************************************************************************************************************
|
||||
// ************************************************************************************************************************************************************************
|
||||
public String Parity
|
||||
{
|
||||
get
|
||||
{
|
||||
return null==dividendRiskParityResult?Constants.CONST_DASHES:Utility.FormatCurrency(dividendRiskParityResult.ParityPrice.Close, 2);
|
||||
}
|
||||
}
|
||||
public String ParityPercent
|
||||
{
|
||||
get
|
||||
{
|
||||
return null == dividendRiskParityResult ? Constants.CONST_DASHES : Utility.FormatPercent(dividendRiskParityResult.ParityPercent/100.00);
|
||||
}
|
||||
}
|
||||
public String YieldPercent
|
||||
{
|
||||
get
|
||||
{
|
||||
return null == dividendRiskParityResult ? Constants.CONST_DASHES : Utility.FormatPercent(dividendRiskParityResult.YieldPercent / 100.00);
|
||||
}
|
||||
}
|
||||
public String CostBasis
|
||||
{
|
||||
get
|
||||
{
|
||||
return null == dividendRiskParityResult ? Constants.CONST_DASHES : Utility.FormatCurrency(dividendRiskParityResult.CostBasis, 2);
|
||||
}
|
||||
}
|
||||
public String Aum
|
||||
{
|
||||
get
|
||||
{
|
||||
return null == dividendRiskParityResult ? Constants.CONST_DASHES : Utility.FormatCurrency(dividendRiskParityResult.Aum, 2);
|
||||
}
|
||||
}
|
||||
public String AllocationPercent
|
||||
{
|
||||
get
|
||||
{
|
||||
return null == dividendRiskParityResult ? Constants.CONST_DASHES : Utility.FormatPercent(dividendRiskParityResult.AllocationPercent / 100.00);
|
||||
}
|
||||
}
|
||||
public String AnnualDividend
|
||||
{
|
||||
get
|
||||
{
|
||||
return null == dividendRiskParityResult ? Constants.CONST_DASHES : Utility.FormatCurrency(dividendRiskParityResult.AnnualDividend, 2);
|
||||
}
|
||||
}
|
||||
public String DividendYearsToParity
|
||||
{
|
||||
get
|
||||
{
|
||||
return null == dividendRiskParityResult ? Constants.CONST_DASHES : Utility.FormatNumber(dividendRiskParityResult.DividendYearsToParity, 2);
|
||||
}
|
||||
}
|
||||
public String DaysSinceLastTraded
|
||||
{
|
||||
get
|
||||
{
|
||||
return null == dividendRiskParityResult ? Constants.CONST_DASHES : Utility.FormatNumber(dividendRiskParityResult.DaysSinceLastTraded,0,true);
|
||||
}
|
||||
}
|
||||
public String CurrentDividendPercent
|
||||
{
|
||||
get
|
||||
{
|
||||
return null == dividendRiskParityResult ? Constants.CONST_DASHES : Utility.FormatPercent(dividendRiskParityResult.CurrentDividendPercent/100.00);
|
||||
}
|
||||
}
|
||||
public String AdditionalDividendPerYear
|
||||
{
|
||||
get
|
||||
{
|
||||
return null == dividendRiskParityResult ? Constants.CONST_DASHES : Utility.FormatCurrency(dividendRiskParityResult.AdditionalDividendPerYer);
|
||||
}
|
||||
}
|
||||
// ************************************************************************************************************************************************************************
|
||||
// ********************************************************* D I V I D E N D R I S K P A R I T Y R E S U L T P R O F O R A ******************************************
|
||||
// ************************************************************************************************************************************************************************
|
||||
// ************************************************************************************************************************************************************************
|
||||
public String ParityProforma
|
||||
{
|
||||
get
|
||||
{
|
||||
return null == dividendRiskParityResultProforma ? Constants.CONST_DASHES : Utility.FormatCurrency(dividendRiskParityResultProforma.ParityPrice.Close, 2);
|
||||
}
|
||||
}
|
||||
public String ParityPercentProforma
|
||||
{
|
||||
get
|
||||
{
|
||||
return null == dividendRiskParityResultProforma ? Constants.CONST_DASHES : Utility.FormatPercent(dividendRiskParityResultProforma.ParityPercent / 100.00);
|
||||
}
|
||||
}
|
||||
public String YieldPercentProforma
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == dividendRiskParityResultProforma) return Constants.CONST_DASHES;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
double yieldDifferenceBasisPoints = ((dividendRiskParityResultProforma.YieldPercent - dividendRiskParityResult.YieldPercent)*100.00);
|
||||
sb.Append(Utility.FormatPercent(dividendRiskParityResultProforma.YieldPercent / 100.00)).Append("(").Append(yieldDifferenceBasisPoints < 0 ? "" : "+").Append(Utility.FormatNumber(yieldDifferenceBasisPoints,2)).Append("bps)");
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
public String CostBasisProforma
|
||||
{
|
||||
get
|
||||
{
|
||||
return null == dividendRiskParityResultProforma ? Constants.CONST_DASHES : Utility.FormatCurrency(dividendRiskParityResultProforma.CostBasis, 2);
|
||||
}
|
||||
}
|
||||
public String AumProforma
|
||||
{
|
||||
get
|
||||
{
|
||||
return null == dividendRiskParityResultProforma ? Constants.CONST_DASHES : Utility.FormatCurrency(dividendRiskParityResultProforma.Aum, 2);
|
||||
}
|
||||
}
|
||||
public String AllocationPercentProforma
|
||||
{
|
||||
get
|
||||
{
|
||||
return null == dividendRiskParityResultProforma ? Constants.CONST_DASHES : Utility.FormatPercent(dividendRiskParityResultProforma.AllocationPercent / 100.00);
|
||||
}
|
||||
}
|
||||
public String AnnualDividendProforma
|
||||
{
|
||||
get
|
||||
{
|
||||
return null == dividendRiskParityResultProforma ? Constants.CONST_DASHES : Utility.FormatCurrency(dividendRiskParityResultProforma.AnnualDividend, 2);
|
||||
}
|
||||
}
|
||||
public String DividendYearsToParityProforma
|
||||
{
|
||||
get
|
||||
{
|
||||
return null == dividendRiskParityResultProforma ? Constants.CONST_DASHES : Utility.FormatNumber(dividendRiskParityResultProforma.DividendYearsToParity, 2);
|
||||
}
|
||||
}
|
||||
public String DaysSinceLastTradedProforma
|
||||
{
|
||||
get
|
||||
{
|
||||
return null == dividendRiskParityResultProforma ? Constants.CONST_DASHES : Utility.FormatNumber(dividendRiskParityResultProforma.DaysSinceLastTraded,0,true);
|
||||
}
|
||||
}
|
||||
public String CurrentDividendPercentProforma
|
||||
{
|
||||
get
|
||||
{
|
||||
return null == dividendRiskParityResultProforma ? Constants.CONST_DASHES : Utility.FormatPercent(dividendRiskParityResultProforma.CurrentDividendPercent / 100.00);
|
||||
}
|
||||
}
|
||||
public String AdditionalDividendPerYearProforma
|
||||
{
|
||||
get
|
||||
{
|
||||
return null == dividendRiskParityResultProforma ? Constants.CONST_DASHES : Utility.FormatCurrency(dividendRiskParityResultProforma.AdditionalDividendPerYer);
|
||||
}
|
||||
}
|
||||
// ***********************************************************************************************************************************************************************************
|
||||
public String CurrentPrice
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == currentPrice) return Constants.CONST_DASHES;
|
||||
return Utility.FormatCurrency(currentPrice.Close);
|
||||
}
|
||||
}
|
||||
public String PricingDate
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == currentPrice) return Constants.CONST_DASHES;
|
||||
return Utility.DateTimeToStringMMHDDHYYYY(currentPrice.Date);
|
||||
}
|
||||
}
|
||||
public String TotalAum
|
||||
{
|
||||
get { return Utility.FormatCurrency(aum); }
|
||||
}
|
||||
public List<String> Symbols
|
||||
{
|
||||
get
|
||||
{
|
||||
return symbols;
|
||||
}
|
||||
}
|
||||
public override String Title
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null != companyName && null != selectedSymbol) return "Dividend Risk Parity - (" + selectedSymbol + ") " + companyName;
|
||||
return "Dividend Risk Parity";
|
||||
}
|
||||
}
|
||||
public String SelectedSymbol
|
||||
{
|
||||
get
|
||||
{
|
||||
return selectedSymbol;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value == selectedSymbol || String.IsNullOrEmpty(value)) return;
|
||||
selectedSymbol = value;
|
||||
base.OnPropertyChanged("SelectedSymbol");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
614
ViewModels/ETFHoldingViewModel.cs
Normal file
@@ -0,0 +1,614 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Windows.Input;
|
||||
using System.Threading.Tasks;
|
||||
using MarketData.MarketDataModel;
|
||||
using MarketData.DataAccess;
|
||||
using MarketData;
|
||||
using TradeBlotter.Command;
|
||||
using TradeBlotter.Model;
|
||||
using System.Windows;
|
||||
using System.Text;
|
||||
|
||||
namespace TradeBlotter.ViewModels
|
||||
{
|
||||
public class ETFHoldingViewModel : WorkspaceViewModel
|
||||
{
|
||||
private ETFHoldingModel selectedItem = null;
|
||||
private List<String> etfSymbols;
|
||||
private String selectedSymbol;
|
||||
private String selectedCompanyName;
|
||||
private bool isSearchSymbolChecked = true;
|
||||
private bool isSearchTextChecked = false;
|
||||
private String searchValue;
|
||||
private RelayCommand searchCommand;
|
||||
private RelayCommand displayAnalystRatingsUnderlying;
|
||||
private RelayCommand displayBollingerBandETF;
|
||||
private RelayCommand displayBollingerBandUnderlying;
|
||||
private RelayCommand displayStochasticsETF;
|
||||
private RelayCommand displayStochasticsUnderlying;
|
||||
private RelayCommand displayMACDETF;
|
||||
private RelayCommand displayMACDUnderlying;
|
||||
private RelayCommand displayPriceHistoryETF;
|
||||
private RelayCommand displayPriceHistoryUnderlying;
|
||||
private RelayCommand displayDCFValuationUnderlying;
|
||||
private RelayCommand displayStickerValuationUnderlying;
|
||||
private RelayCommand displayHistoricalCommand=null;
|
||||
private RelayCommand displaySECFilingsCommand;
|
||||
private RelayCommand addToWatchListCommand;
|
||||
private RelayCommand removeFromWatchListCommand;
|
||||
private String title;
|
||||
private bool busyIndicator = false;
|
||||
|
||||
public ETFHoldingViewModel()
|
||||
{
|
||||
base.DisplayName = "ETFHoldingView";
|
||||
etfSymbols = PricingDA.GetSymbolsETF();
|
||||
PropertyChanged += OnETFHoldingViewModelPropertyChanged;
|
||||
}
|
||||
public override SaveParameters GetSaveParameters()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
public override void SetSaveParameters(SaveParameters saveParameters)
|
||||
{
|
||||
}
|
||||
public override bool CanPersist()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public ObservableCollection<ETFHoldingModel> AllETFHoldings
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
public bool BusyIndicator
|
||||
{
|
||||
get { return busyIndicator; }
|
||||
set { busyIndicator = value; }
|
||||
}
|
||||
private void CreateAllETFHoldings()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (null == selectedSymbol) return;
|
||||
BusyIndicator = true;
|
||||
Task workerTask = Task.Factory.StartNew(() =>
|
||||
{
|
||||
ETFHoldings etfHoldings = ETFHoldingsDA.GetETFHoldings(selectedSymbol);
|
||||
List<ETFHoldingModel> etfHoldingModelList = new List<ETFHoldingModel>();
|
||||
foreach (ETFHolding etfHolding in etfHoldings) etfHoldingModelList.Add(new ETFHoldingModel(etfHolding));
|
||||
this.AllETFHoldings = new ObservableCollection<ETFHoldingModel>(etfHoldingModelList);
|
||||
});
|
||||
workerTask.ContinueWith((continuation) =>
|
||||
{
|
||||
BusyIndicator = false;
|
||||
base.OnPropertyChanged("AllETFHoldings");
|
||||
});
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,exception);
|
||||
}
|
||||
}
|
||||
private void OnETFHoldingViewModelPropertyChanged(object sender, PropertyChangedEventArgs eventArgs)
|
||||
{
|
||||
if (eventArgs.PropertyName.Equals("SelectedSymbol"))
|
||||
{
|
||||
BusyIndicator = true;
|
||||
Task workerTask = Task.Factory.StartNew(() =>
|
||||
{
|
||||
title = null;
|
||||
CreateAllETFHoldings();
|
||||
selectedCompanyName = PricingDA.GetNameForSymbol(selectedSymbol);
|
||||
});
|
||||
workerTask.ContinueWith((continuation) =>
|
||||
{
|
||||
BusyIndicator = false;
|
||||
base.OnPropertyChanged("AllETFHoldings");
|
||||
base.OnPropertyChanged("Title");
|
||||
});
|
||||
}
|
||||
}
|
||||
public ObservableCollection<MenuItem> MenuItems
|
||||
{
|
||||
get
|
||||
{
|
||||
ObservableCollection<MenuItem> collection = new ObservableCollection<MenuItem>();
|
||||
collection.Add(new MenuItem() { Text = "Underlying - Display Bollinger Band",MenuItemClickedCommand=DisplayBollingerBandUnderlying,StaysOpenOnClick=false });
|
||||
collection.Add(new MenuItem() { Text = "Underlying - Display Analyst Ratings", MenuItemClickedCommand = DisplayAnalystRatings, StaysOpenOnClick = false });
|
||||
collection.Add(new MenuItem() { Text = "Underlying - Display Sticker Valuation", MenuItemClickedCommand = DisplayStickerValuationUnderlying, StaysOpenOnClick = false });
|
||||
collection.Add(new MenuItem() { Text = "Underlying - Display Historical", MenuItemClickedCommand = DisplayHistoricalUnderlying, StaysOpenOnClick = false });
|
||||
collection.Add(new MenuItem() { Text = "Underlying - Display Stochastics", MenuItemClickedCommand = DisplayStochasticsUnderlying, StaysOpenOnClick = false });
|
||||
collection.Add(new MenuItem() { Text = "Underlying - Display MACD", MenuItemClickedCommand = DisplayMACDUnderlying, StaysOpenOnClick = false });
|
||||
collection.Add(new MenuItem() { Text = "Underlying - Display Price History", MenuItemClickedCommand = DisplayPriceHistoryUnderlying, StaysOpenOnClick = false });
|
||||
collection.Add(new MenuItem() { Text = "Underlying - Display DCF Valuation", MenuItemClickedCommand = DisplayDCFValuationUnderlying, StaysOpenOnClick = false });
|
||||
collection.Add(new MenuItem() { Text = "Underlying - Display SEC Filings", MenuItemClickedCommand = DisplaySECFilings, StaysOpenOnClick = false });
|
||||
collection.Add(new MenuItem() { Text = "Underlying - Remove from Watchlist", MenuItemClickedCommand = RemoveFromWatchList, StaysOpenOnClick = false });
|
||||
collection.Add(new MenuItem() { Text = "Underlying - Add To Watchlist", MenuItemClickedCommand = AddToWatchList, StaysOpenOnClick = false });
|
||||
collection.Add(new MenuItem() { Text = "ETF - Display Bollinger Band", MenuItemClickedCommand = DisplayBollingerBandETF, StaysOpenOnClick = false });
|
||||
collection.Add(new MenuItem() { Text = "ETF - Display Stochastics", MenuItemClickedCommand = DisplayStochasticsETF, StaysOpenOnClick = false });
|
||||
collection.Add(new MenuItem() { Text = "ETF - Display MACD", MenuItemClickedCommand = DisplayMACDETF, StaysOpenOnClick = false });
|
||||
collection.Add(new MenuItem() { Text = "ETF - Display Price History", MenuItemClickedCommand = DisplayPriceHistoryETF, StaysOpenOnClick = false });
|
||||
return collection;
|
||||
}
|
||||
}
|
||||
public ICommand AddToWatchList
|
||||
{
|
||||
get
|
||||
{
|
||||
if (addToWatchListCommand == null)
|
||||
{
|
||||
addToWatchListCommand = new RelayCommand(param => this.AddToWatchListCommand(),
|
||||
param =>
|
||||
{
|
||||
if (null == selectedItem || null == selectedItem.HoldingSymbol) return false;
|
||||
if (WatchListDA.IsInWatchList(selectedItem.HoldingSymbol)) return false;
|
||||
return true;
|
||||
});
|
||||
}
|
||||
return addToWatchListCommand;
|
||||
}
|
||||
}
|
||||
public ICommand RemoveFromWatchList
|
||||
{
|
||||
get
|
||||
{
|
||||
if (removeFromWatchListCommand == null)
|
||||
{
|
||||
removeFromWatchListCommand = new RelayCommand(param => this.RemoveFromWatchListCommand(),
|
||||
param =>
|
||||
{
|
||||
if (null == selectedItem || null == selectedItem.HoldingSymbol) return false;
|
||||
if (!WatchListDA.IsInWatchList(selectedItem.HoldingSymbol)) return false;
|
||||
return true;
|
||||
});
|
||||
}
|
||||
return removeFromWatchListCommand;
|
||||
}
|
||||
}
|
||||
public ICommand DisplaySECFilings
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == displaySECFilingsCommand)
|
||||
{
|
||||
displaySECFilingsCommand = new RelayCommand(param =>
|
||||
{
|
||||
SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.SECFilingViewModel,SelectedSymbol," + selectedItem.HoldingSymbol + ",SelectedWatchList,Valuations");
|
||||
saveParams.Referer=this;
|
||||
WorkspaceInstantiator.Invoke(saveParams);
|
||||
}, param => { return null != selectedItem && null!=selectedItem.HoldingSymbol; });
|
||||
}
|
||||
return displaySECFilingsCommand;
|
||||
}
|
||||
}
|
||||
public ICommand DisplayAnalystRatings
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == displayAnalystRatingsUnderlying)
|
||||
{
|
||||
displayAnalystRatingsUnderlying = new RelayCommand(param =>
|
||||
{
|
||||
String companyName = PricingDA.GetNameForSymbol(selectedSymbol);
|
||||
SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.AnalystRatingsViewModel,SelectedSymbol," + selectedItem.HoldingSymbol + ",SelectedWatchList,{All},SelectedDate,{All},SelectedCompany,"+companyName);
|
||||
saveParams.Referer=this;
|
||||
WorkspaceInstantiator.Invoke(saveParams);
|
||||
}, param =>
|
||||
{
|
||||
if(null==selectedItem || null==selectedItem.HoldingSymbol || selectedItem.HoldingSymbol.Equals("N/A") )return false;
|
||||
return true;
|
||||
// return !(null != selectedItem && selectedItem.HoldingSymbol.Equals("N/A"));
|
||||
});
|
||||
}
|
||||
return displayAnalystRatingsUnderlying;
|
||||
}
|
||||
}
|
||||
public ICommand DisplayStickerValuationUnderlying
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == displayStickerValuationUnderlying)
|
||||
{
|
||||
displayStickerValuationUnderlying = new RelayCommand(param =>
|
||||
{
|
||||
SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.StickerPriceViewModel,SelectedSymbol," + selectedItem.HoldingSymbol + ",SelectedWatchList,{All}");
|
||||
saveParams.Referer=this;
|
||||
WorkspaceInstantiator.Invoke(saveParams);
|
||||
}, param =>
|
||||
{
|
||||
if(null==selectedItem || null==selectedItem.HoldingSymbol || selectedItem.HoldingSymbol.Equals("N/A") )return false;
|
||||
return true;
|
||||
// return !(null != selectedItem && selectedItem.HoldingSymbol.Equals("N/A"));
|
||||
});
|
||||
}
|
||||
return displayStickerValuationUnderlying;
|
||||
}
|
||||
}
|
||||
public ICommand DisplayHistoricalUnderlying
|
||||
{
|
||||
get
|
||||
{
|
||||
if (displayHistoricalCommand == null)
|
||||
{
|
||||
displayHistoricalCommand = new RelayCommand(param =>
|
||||
{
|
||||
SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.HistoricalViewModel,SelectedSymbol," + selectedItem.HoldingSymbol + ",SelectedWatchList,{All}");
|
||||
saveParams.Referer=this;
|
||||
WorkspaceInstantiator.Invoke(saveParams);
|
||||
}, param =>
|
||||
{
|
||||
if(null==selectedItem || null==selectedItem.HoldingSymbol || selectedItem.HoldingSymbol.Equals("N/A") )return false;
|
||||
return true;
|
||||
});
|
||||
}
|
||||
return displayHistoricalCommand;
|
||||
}
|
||||
}
|
||||
public ICommand DisplayDCFValuationUnderlying
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == displayDCFValuationUnderlying)
|
||||
{
|
||||
displayDCFValuationUnderlying = new RelayCommand(param =>
|
||||
{
|
||||
SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.DCFValuationViewModel,SelectedSymbol," + selectedItem.HoldingSymbol + ",SelectedWatchList,{All}");
|
||||
saveParams.Referer=this;
|
||||
WorkspaceInstantiator.Invoke(saveParams);
|
||||
}, param =>
|
||||
{
|
||||
if(null==selectedItem || null==selectedItem.HoldingSymbol || selectedItem.HoldingSymbol.Equals("N/A") )return false;
|
||||
return true;
|
||||
// return !(null != selectedItem && selectedItem.HoldingSymbol.Equals("N/A"));
|
||||
});
|
||||
}
|
||||
return displayDCFValuationUnderlying;
|
||||
}
|
||||
}
|
||||
public ICommand DisplayBollingerBandETF
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == displayBollingerBandETF)
|
||||
{
|
||||
displayBollingerBandETF = new RelayCommand(param =>
|
||||
{
|
||||
SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.BollingerBandViewModel,SelectedSymbol," + selectedItem.ETFHoldingSymbol + ",SelectedWatchList,{All},SelectedDayCount,180");
|
||||
saveParams.Referer=this;
|
||||
WorkspaceInstantiator.Invoke(saveParams);
|
||||
}, param =>
|
||||
{
|
||||
if(null==selectedItem || null==selectedItem.ETFHoldingSymbol || selectedItem.ETFHoldingSymbol.Equals("N/A"))return false;
|
||||
return true;
|
||||
// return !(null==selectedItem);
|
||||
});
|
||||
}
|
||||
return displayBollingerBandETF;
|
||||
}
|
||||
}
|
||||
public ICommand DisplayBollingerBandUnderlying
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == displayBollingerBandUnderlying)
|
||||
{
|
||||
displayBollingerBandUnderlying = new RelayCommand(param =>
|
||||
{
|
||||
SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.BollingerBandViewModel,SelectedSymbol," + selectedItem.HoldingSymbol + ",SelectedWatchList,{All},SelectedDayCount,180");
|
||||
saveParams.Referer=this;
|
||||
WorkspaceInstantiator.Invoke(saveParams);
|
||||
}, param =>
|
||||
{
|
||||
if(null==selectedItem || null==selectedItem.HoldingSymbol || selectedItem.HoldingSymbol.Equals("N/A") )return false;
|
||||
return true;
|
||||
// return !(null != selectedItem && selectedItem.HoldingSymbol.Equals("N/A"));
|
||||
});
|
||||
}
|
||||
return displayBollingerBandUnderlying;
|
||||
}
|
||||
}
|
||||
public ICommand DisplayStochasticsETF
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == displayStochasticsETF)
|
||||
{
|
||||
displayStochasticsETF = new RelayCommand(param =>
|
||||
{
|
||||
SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.StochasticsViewModel,SelectedSymbol," + selectedItem.ETFHoldingSymbol + ",SelectedWatchList,{All},SelectedDayCount,180");
|
||||
saveParams.Referer=this;
|
||||
WorkspaceInstantiator.Invoke(saveParams);
|
||||
}, param =>
|
||||
{
|
||||
if(null==selectedItem || null==selectedItem.ETFHoldingSymbol || selectedItem.ETFHoldingSymbol.Equals("N/A"))return false;
|
||||
return true;
|
||||
// return !(null==selectedItem);
|
||||
});
|
||||
}
|
||||
return displayStochasticsETF;
|
||||
}
|
||||
}
|
||||
public ICommand DisplayStochasticsUnderlying
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == displayStochasticsUnderlying)
|
||||
{
|
||||
displayStochasticsUnderlying = new RelayCommand(param =>
|
||||
{
|
||||
SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.StochasticsViewModel,SelectedSymbol," + selectedItem.HoldingSymbol + ",SelectedWatchList,{All},SelectedDayCount,180");
|
||||
saveParams.Referer=this;
|
||||
WorkspaceInstantiator.Invoke(saveParams);
|
||||
}, param =>
|
||||
{
|
||||
if(null==selectedItem || null==selectedItem.HoldingSymbol || selectedItem.HoldingSymbol.Equals("N/A") )return false;
|
||||
return true;
|
||||
// return !(null != selectedItem && selectedItem.HoldingSymbol.Equals("N/A"));
|
||||
});
|
||||
}
|
||||
return displayStochasticsUnderlying;
|
||||
}
|
||||
}
|
||||
public ICommand DisplayMACDETF
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == displayMACDETF)
|
||||
{
|
||||
displayMACDETF = new RelayCommand(param =>
|
||||
{
|
||||
SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.MACDViewModel,SelectedSymbol," + selectedItem.ETFHoldingSymbol + ",SelectedWatchList,{All},SelectedDayCount,180");
|
||||
saveParams.Referer=this;
|
||||
WorkspaceInstantiator.Invoke(saveParams);
|
||||
}, param =>
|
||||
{
|
||||
if(null==selectedItem || null==selectedItem.ETFHoldingSymbol || selectedItem.ETFHoldingSymbol.Equals("N/A"))return false;
|
||||
return true;
|
||||
// return !(null==selectedItem);
|
||||
});
|
||||
}
|
||||
return displayMACDETF;
|
||||
}
|
||||
}
|
||||
public ICommand DisplayMACDUnderlying
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == displayMACDUnderlying)
|
||||
{
|
||||
displayMACDUnderlying = new RelayCommand(param =>
|
||||
{
|
||||
SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.MACDViewModel,SelectedSymbol," + selectedItem.HoldingSymbol + ",SelectedWatchList,{All},SelectedDayCount,180");
|
||||
saveParams.Referer=this;
|
||||
WorkspaceInstantiator.Invoke(saveParams);
|
||||
}, param =>
|
||||
{
|
||||
if(null==selectedItem || null==selectedItem.HoldingSymbol || selectedItem.HoldingSymbol.Equals("N/A") )return false;
|
||||
return true;
|
||||
// return !(null != selectedItem && selectedItem.HoldingSymbol.Equals("N/A"));
|
||||
});
|
||||
}
|
||||
return displayMACDUnderlying;
|
||||
}
|
||||
}
|
||||
public ICommand DisplayPriceHistoryETF
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == displayPriceHistoryETF)
|
||||
{
|
||||
displayPriceHistoryETF = new RelayCommand(param =>
|
||||
{
|
||||
SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.PricingViewModel,SelectedSymbol," + selectedItem.ETFHoldingSymbol + ",SelectedWatchList,{All},SelectedDayCount,180");
|
||||
saveParams.Referer=this;
|
||||
WorkspaceInstantiator.Invoke(saveParams);
|
||||
}, param =>
|
||||
{
|
||||
if(null==selectedItem || null==selectedItem.ETFHoldingSymbol || selectedItem.ETFHoldingSymbol.Equals("N/A"))return false;
|
||||
return true;
|
||||
// return !(null==selectedItem);
|
||||
});
|
||||
}
|
||||
return displayPriceHistoryETF;
|
||||
}
|
||||
}
|
||||
public ICommand DisplayPriceHistoryUnderlying
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == displayPriceHistoryUnderlying)
|
||||
{
|
||||
displayPriceHistoryUnderlying = new RelayCommand(param =>
|
||||
{
|
||||
SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.PricingViewModel,SelectedSymbol," + selectedItem.HoldingSymbol + ",SelectedWatchList,{All},SelectedDayCount,180");
|
||||
saveParams.Referer=this;
|
||||
WorkspaceInstantiator.Invoke(saveParams);
|
||||
}, param =>
|
||||
{
|
||||
if(null==selectedItem || null==selectedItem.HoldingSymbol || selectedItem.HoldingSymbol.Equals("N/A") )return false;
|
||||
return true;
|
||||
// return !(null != selectedItem && selectedItem.HoldingSymbol.Equals("N/A"));
|
||||
});
|
||||
}
|
||||
return displayPriceHistoryUnderlying;
|
||||
}
|
||||
}
|
||||
// ***************************************************************************************************************************
|
||||
public List<String> ETFSymbols
|
||||
{
|
||||
get { return etfSymbols; }
|
||||
}
|
||||
public String SelectedSymbol
|
||||
{
|
||||
get { return selectedSymbol; }
|
||||
set { selectedSymbol = value; base.OnPropertyChanged("SelectedSymbol"); }
|
||||
}
|
||||
public override string DisplayName
|
||||
{
|
||||
get { return base.DisplayName; }
|
||||
}
|
||||
public override String Title
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null != title) return title;
|
||||
return null==selectedCompanyName?null:selectedCompanyName+"("+selectedSymbol+") (Top 10 Holdings)";
|
||||
}
|
||||
}
|
||||
public Boolean IsSearchSymbolChecked
|
||||
{
|
||||
get { return isSearchSymbolChecked; }
|
||||
set { isSearchSymbolChecked = value; base.OnPropertyChanged("IsSearchSymbolChecked"); }
|
||||
}
|
||||
public Boolean IsSearchTextChecked
|
||||
{
|
||||
get { return isSearchTextChecked; }
|
||||
set { isSearchTextChecked = value; base.OnPropertyChanged("IsSearchTextChecked"); }
|
||||
}
|
||||
public String SearchValue
|
||||
{
|
||||
get { return searchValue; }
|
||||
set
|
||||
{
|
||||
searchValue = value;
|
||||
}
|
||||
}
|
||||
public ICommand SearchCommand
|
||||
{
|
||||
get
|
||||
{
|
||||
if (searchCommand == null)
|
||||
{
|
||||
searchCommand = new RelayCommand(param => this.Search(), param => this.CanSearch);
|
||||
}
|
||||
return searchCommand;
|
||||
}
|
||||
}
|
||||
public void Search()
|
||||
{
|
||||
if(isSearchSymbolChecked)
|
||||
{
|
||||
BusyIndicator = true;
|
||||
Task workerTask = Task.Factory.StartNew(() =>
|
||||
{
|
||||
ETFHoldings etfHoldings = ETFHoldingsDA.GetETFHoldingsWithExposureToSymbolLike(searchValue);
|
||||
List<ETFHoldingModel> etfHoldingModelList = new List<ETFHoldingModel>();
|
||||
foreach (ETFHolding etfHolding in etfHoldings) etfHoldingModelList.Add(new ETFHoldingModel(etfHolding));
|
||||
this.AllETFHoldings = new ObservableCollection<ETFHoldingModel>(etfHoldingModelList);
|
||||
title = "ETF's with exposure to symbol like '" + searchValue + "'";
|
||||
});
|
||||
workerTask.ContinueWith((continuation) =>
|
||||
{
|
||||
BusyIndicator = false;
|
||||
base.OnPropertyChanged("AllETFHoldings");
|
||||
base.OnPropertyChanged("Title");
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
BusyIndicator = true;
|
||||
Task workerTask = Task.Factory.StartNew(() =>
|
||||
{
|
||||
ETFHoldings etfHoldings = ETFHoldingsDA.GetETFHoldingsWithExposureToCompanyLike(searchValue);
|
||||
List<ETFHoldingModel> etfHoldingModelList = new List<ETFHoldingModel>();
|
||||
foreach (ETFHolding etfHolding in etfHoldings) etfHoldingModelList.Add(new ETFHoldingModel(etfHolding));
|
||||
this.AllETFHoldings = new ObservableCollection<ETFHoldingModel>(etfHoldingModelList);
|
||||
title = "ETF's with exposure to company like '" + searchValue + "'";
|
||||
});
|
||||
workerTask.ContinueWith((continuation) =>
|
||||
{
|
||||
BusyIndicator = false;
|
||||
base.OnPropertyChanged("AllETFHoldings");
|
||||
base.OnPropertyChanged("Title");
|
||||
});
|
||||
}
|
||||
}
|
||||
private bool CanSearch
|
||||
{
|
||||
get
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
public ETFHoldingModel SelectedItem
|
||||
{
|
||||
get
|
||||
{
|
||||
return selectedItem;
|
||||
}
|
||||
set
|
||||
{
|
||||
selectedItem = value;
|
||||
}
|
||||
}
|
||||
public void AddToWatchListCommand()
|
||||
{
|
||||
if (WatchListDA.IsInWatchList(selectedItem.HoldingSymbol))
|
||||
{
|
||||
System.Windows.MessageBox.Show("'" + selectedItem.HoldingSymbol + "' is already in watchlist", "Info", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
return;
|
||||
}
|
||||
if (!WatchListDA.AddToWatchList(selectedItem.HoldingSymbol))
|
||||
{
|
||||
System.Windows.MessageBox.Show("Error adding '" + selectedItem.HoldingSymbol + "' to watchlist", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||
}
|
||||
else
|
||||
{
|
||||
System.Windows.MessageBox.Show("Added '" + selectedItem.HoldingSymbol + "'", "Success", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
}
|
||||
}
|
||||
public void RemoveFromWatchListCommand()
|
||||
{
|
||||
if (!WatchListDA.IsInWatchList(selectedItem.HoldingSymbol))
|
||||
{
|
||||
System.Windows.MessageBox.Show("'" + selectedItem.HoldingSymbol + "' is not in watchlist", "Info", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
return;
|
||||
}
|
||||
if (!WatchListDA.RemoveFromWatchList(selectedItem.HoldingSymbol))
|
||||
{
|
||||
System.Windows.MessageBox.Show("Error removing '" + selectedItem.HoldingSymbol + "' from watchlist", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||
}
|
||||
else
|
||||
{
|
||||
System.Windows.MessageBox.Show("Removed '" + selectedItem.HoldingSymbol + "'", "Success", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
}
|
||||
}
|
||||
// ********************************************************************** T O O L T I P C A L L O U T S **************************************************************
|
||||
public String ETFSymbolDescription
|
||||
{
|
||||
get
|
||||
{
|
||||
if(null==selectedItem||null==selectedItem.ETFHoldingSymbol) return "No row selected.";
|
||||
StringBuilder sb=new StringBuilder();
|
||||
CompanyProfile companyProfile=CompanyProfileDA.GetCompanyProfile(selectedItem.ETFHoldingSymbol);
|
||||
if(null!=companyProfile&&null!=companyProfile.Symbol&&null!=companyProfile.CompanyName) sb.Append(companyProfile.Symbol).Append(" - ").Append(companyProfile.CompanyName).Append("\n");
|
||||
String sector=PricingDA.GetSectorForSymbol(selectedItem.ETFHoldingSymbol);
|
||||
String industry=PricingDA.GetIndustryForSymbol(selectedItem.ETFHoldingSymbol);
|
||||
if(!String.IsNullOrEmpty(sector))sb.Append(sector);
|
||||
if(!String.IsNullOrEmpty(industry))sb.Append("/").Append(industry);
|
||||
if(null!=companyProfile && null!=companyProfile.Description)sb.Append("\n").Append(companyProfile.Description);
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
public String HoldingSymbolDescription
|
||||
{
|
||||
get
|
||||
{
|
||||
if(null==selectedItem||null==selectedItem.HoldingSymbol) return "No row selected.";
|
||||
StringBuilder sb=new StringBuilder();
|
||||
CompanyProfile companyProfile=CompanyProfileDA.GetCompanyProfile(selectedItem.HoldingSymbol);
|
||||
if(null!=companyProfile&&null!=companyProfile.Symbol&&null!=companyProfile.CompanyName)sb.Append(companyProfile.Symbol).Append(" - ").Append(companyProfile.CompanyName).Append("\n");
|
||||
String sector=PricingDA.GetSectorForSymbol(selectedItem.HoldingSymbol);
|
||||
String industry=PricingDA.GetIndustryForSymbol(selectedItem.HoldingSymbol);
|
||||
if(!String.IsNullOrEmpty(sector)) sb.Append(sector);
|
||||
if(!String.IsNullOrEmpty(industry)) sb.Append("/").Append(industry);
|
||||
if(null!=companyProfile&&null!=companyProfile.Description) sb.Append("\n").Append(companyProfile.Description);
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
396
ViewModels/EarningsAnnouncementViewModel.cs
Normal file
@@ -0,0 +1,396 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Collections.Specialized;
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Input;
|
||||
using System.Media;
|
||||
using MarketData;
|
||||
using MarketData.Utils;
|
||||
using MarketData.MarketDataModel;
|
||||
using MarketData.Generator;
|
||||
using MarketData.DataAccess;
|
||||
using TradeBlotter.DataAccess;
|
||||
using TradeBlotter.Command;
|
||||
using TradeBlotter.Model;
|
||||
using Microsoft.Research.DynamicDataDisplay.DataSources;
|
||||
|
||||
namespace TradeBlotter.ViewModels
|
||||
{
|
||||
public class EarningsAnnouncementViewModel : WorkspaceViewModel
|
||||
{
|
||||
private RelayCommand analystRatingsCommand=null;
|
||||
private RelayCommand stochasticsCommand=null;
|
||||
private RelayCommand relativeStrengthCommand=null;
|
||||
private RelayCommand macdCommand=null;
|
||||
private RelayCommand bollingerBandCommand=null;
|
||||
private RelayCommand valuationCommand=null;
|
||||
private RelayCommand priceHistoryCommand=null;
|
||||
private RelayCommand displayStickerValuationCommand=null;
|
||||
private RelayCommand displayDCFValuationCommand=null;
|
||||
private RelayCommand refreshCommand=null;
|
||||
private RelayCommand dividendHistoryCommand=null;
|
||||
private RelayCommand displayHistoricalCommand=null;
|
||||
private RelayCommand displayHeadlinesCommand=null;
|
||||
private EarningsAnnouncementModel selectedItem;
|
||||
private bool busyIndicator = false;
|
||||
private String busyContent = "Loading Earnings Announcements...";
|
||||
private int daysOut=30;
|
||||
private ObservableCollection<EarningsAnnouncementModel> allItems;
|
||||
|
||||
public EarningsAnnouncementViewModel()
|
||||
{
|
||||
base.DisplayName = "Earnings Announcements";
|
||||
LoadItems();
|
||||
PropertyChanged += OnEarningsAnnouncementViewModelPropertyChanged;
|
||||
}
|
||||
public override SaveParameters GetSaveParameters()
|
||||
{
|
||||
SaveParameters saveParams = new SaveParameters();
|
||||
saveParams.Add(new KeyValuePair<String, String>("Type",GetType().Namespace+"."+GetType().Name));
|
||||
saveParams.Add(new KeyValuePair<String, String>("DaysOut", daysOut.ToString()));
|
||||
return saveParams;
|
||||
}
|
||||
public override void SetSaveParameters(SaveParameters saveParameters)
|
||||
{
|
||||
try
|
||||
{
|
||||
daysOut = int.Parse((from KeyValuePair<String, String> item in saveParameters where item.Key.Equals("DaysOut") select item).FirstOrDefault().Value);
|
||||
Referer=saveParameters.Referer;
|
||||
base.OnPropertyChanged("DaysOut");
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
} }
|
||||
public override bool CanPersist()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
private void OnEarningsAnnouncementViewModelPropertyChanged(object sender, PropertyChangedEventArgs eventArgs)
|
||||
{
|
||||
}
|
||||
public ObservableCollection<EarningsAnnouncementModel> AllItems
|
||||
{
|
||||
get { return allItems; }
|
||||
}
|
||||
public ObservableCollection<MenuItem> MenuItems
|
||||
{
|
||||
get
|
||||
{
|
||||
ObservableCollection<MenuItem> collection = new ObservableCollection<MenuItem>();
|
||||
collection.Add(new MenuItem() { Text = "Display Bollinger Band", MenuItemClickedCommand = DisplayBollingerBand, StaysOpenOnClick = false });
|
||||
collection.Add(new MenuItem() { Text = "Display Dividend History", MenuItemClickedCommand = DisplayDividendHistory, StaysOpenOnClick = false });
|
||||
collection.Add(new MenuItem() { Text = "Display Sticker Valuation", MenuItemClickedCommand = DisplayStickerValuation, StaysOpenOnClick = false });
|
||||
collection.Add(new MenuItem() { Text = "Display Historical", MenuItemClickedCommand = DisplayHistorical, StaysOpenOnClick = false });
|
||||
collection.Add(new MenuItem() { Text = "Display Stochastics", MenuItemClickedCommand = DisplayStochastics, StaysOpenOnClick = false });
|
||||
collection.Add(new MenuItem() { Text = "Display Relative Strength", MenuItemClickedCommand=DisplayRelativeStrength, StaysOpenOnClick = false });
|
||||
collection.Add(new MenuItem() { Text = "Display MACD", MenuItemClickedCommand = DisplayMACD, StaysOpenOnClick = false });
|
||||
collection.Add(new MenuItem() { Text = "Display Price History", MenuItemClickedCommand = DisplayPriceHistory, StaysOpenOnClick = false });
|
||||
collection.Add(new MenuItem() { Text = "Display DCF Valuation", MenuItemClickedCommand = DisplayDCFValuation, StaysOpenOnClick = false });
|
||||
collection.Add(new MenuItem() { Text = "Display Analyst Ratings", MenuItemClickedCommand = DisplayAnalystRatings, StaysOpenOnClick = false });
|
||||
collection.Add(new MenuItem() { Text = "Display Headlines", MenuItemClickedCommand = DisplayHeadlines, StaysOpenOnClick = false });
|
||||
collection.Add(new MenuItem() { Text = "Display Valuation", MenuItemClickedCommand = DisplayValuation, StaysOpenOnClick = false });
|
||||
return collection;
|
||||
}
|
||||
}
|
||||
public bool BusyIndicator
|
||||
{
|
||||
get { return busyIndicator; }
|
||||
set
|
||||
{
|
||||
busyIndicator = value;
|
||||
base.OnPropertyChanged("BusyIndicator");
|
||||
}
|
||||
}
|
||||
public String BusyContent
|
||||
{
|
||||
get { return busyContent; }
|
||||
set
|
||||
{
|
||||
busyContent = value;
|
||||
base.OnPropertyChanged("BusyContent");
|
||||
}
|
||||
}
|
||||
private void LoadItems()
|
||||
{
|
||||
BusyIndicator = true;
|
||||
bool itemsToday = false;
|
||||
Task workerTask = Task.Factory.StartNew(() =>
|
||||
{
|
||||
allItems=GetEarningsAnnouncements(daysOut);
|
||||
});
|
||||
workerTask.ContinueWith((continuation)=>
|
||||
{
|
||||
BusyIndicator = false;
|
||||
base.OnPropertyChanged("AllItems");
|
||||
base.OnPropertyChanged("Title");
|
||||
});
|
||||
}
|
||||
public static ObservableCollection<EarningsAnnouncementModel> GetEarningsAnnouncements(int daysOutstanding)
|
||||
{
|
||||
List<EarningsAnnouncementModel> earningsAnnouncementModels = new List<EarningsAnnouncementModel>();
|
||||
List<String> symbols = WatchListDA.GetWatchList("valuations");
|
||||
if(null==symbols)return new ObservableCollection<EarningsAnnouncementModel>();
|
||||
foreach (String symbol in symbols)
|
||||
{
|
||||
EarningsAnnouncementModel earningsAnnouncementModel=CompositeDA.GetEarningsAnnouncement(symbol);
|
||||
if(null==earningsAnnouncementModel)continue;
|
||||
if (Math.Abs(earningsAnnouncementModel.DaysFromToday) >= daysOutstanding) continue;
|
||||
earningsAnnouncementModels.Add(earningsAnnouncementModel);
|
||||
}
|
||||
earningsAnnouncementModels.Sort();
|
||||
return new ObservableCollection<EarningsAnnouncementModel>(earningsAnnouncementModels);
|
||||
}
|
||||
public int DaysOut
|
||||
{
|
||||
get { return daysOut; }
|
||||
set { daysOut = value; base.OnPropertyChanged("DaysOut"); }
|
||||
}
|
||||
public override String Title
|
||||
{
|
||||
get { return "Earnings Announcements Next " + daysOut + " Days"; }
|
||||
}
|
||||
private void Refresh()
|
||||
{
|
||||
LoadItems();
|
||||
}
|
||||
private bool CanRefresh
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
public ICommand DisplayAnalystRatings
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null==analystRatingsCommand)
|
||||
{
|
||||
analystRatingsCommand = new RelayCommand(param =>
|
||||
{
|
||||
SaveParameters saveParams = new SaveParameters();
|
||||
String companyName = PricingDA.GetNameForSymbol(selectedItem.Symbol);
|
||||
saveParams.Add(new KeyValuePair<String, String>("Type", "TradeBlotter.ViewModels.AnalystRatingsViewModel"));
|
||||
saveParams.Add(new KeyValuePair<String, String>("SelectedSymbol", selectedItem.Symbol));
|
||||
saveParams.Add(new KeyValuePair<String, String>("SelectedCompany", companyName));
|
||||
saveParams.Add(new KeyValuePair<String, String>("SelectedWatchList", Constants.CONST_ALL));
|
||||
saveParams.Referer=this;
|
||||
WorkspaceInstantiator.Invoke(saveParams);
|
||||
}, param => { return null==selectedItem||null==selectedItem.Symbol?false:true; });
|
||||
}
|
||||
return analystRatingsCommand;
|
||||
}
|
||||
}
|
||||
public ICommand DisplayStochastics
|
||||
{
|
||||
get
|
||||
{
|
||||
if (stochasticsCommand == null)
|
||||
{
|
||||
stochasticsCommand = new RelayCommand(param => this.DisplayStochasticsCommand(), param => { return null!=selectedItem&&null!=selectedItem.Symbol?true:false; });
|
||||
}
|
||||
return stochasticsCommand;
|
||||
}
|
||||
}
|
||||
public void DisplayStochasticsCommand()
|
||||
{
|
||||
SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.StochasticsViewModel,SelectedSymbol," + selectedItem.Symbol + ",SelectedWatchList,{All},SelectedDayCount,180");
|
||||
saveParams.Referer=this;
|
||||
WorkspaceInstantiator.Invoke(saveParams);
|
||||
}
|
||||
public ICommand DisplayRelativeStrength
|
||||
{
|
||||
get
|
||||
{
|
||||
if (relativeStrengthCommand == null)
|
||||
{
|
||||
relativeStrengthCommand = new RelayCommand(param => this.DisplayRelativeStrengthCommand(),
|
||||
param => { return null != selectedItem && null!=selectedItem.Symbol; });
|
||||
}
|
||||
return relativeStrengthCommand;
|
||||
}
|
||||
}
|
||||
public void DisplayRelativeStrengthCommand()
|
||||
{
|
||||
SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.RSIViewModel,SelectedSymbol," + selectedItem.Symbol + ",SelectedWatchList,{All},SelectedDayCount,60,SelectedRSIDayCount,14");
|
||||
saveParams.Referer=this;
|
||||
WorkspaceInstantiator.Invoke(saveParams);
|
||||
}
|
||||
public ICommand DisplayStickerValuation
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == displayStickerValuationCommand)
|
||||
{
|
||||
displayStickerValuationCommand = new RelayCommand(param =>
|
||||
{
|
||||
SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.StickerPriceViewModel,SelectedSymbol," + selectedItem.Symbol + ",SelectedWatchList,{All}");
|
||||
saveParams.Referer=this;
|
||||
WorkspaceInstantiator.Invoke(saveParams);
|
||||
}, param => { return null != selectedItem && null != selectedItem.Symbol; });
|
||||
}
|
||||
return displayStickerValuationCommand;
|
||||
}
|
||||
}
|
||||
public ICommand DisplayDCFValuation
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == displayDCFValuationCommand)
|
||||
{
|
||||
displayDCFValuationCommand = new RelayCommand(param =>
|
||||
{
|
||||
SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.DCFValuationViewModel,SelectedSymbol," + selectedItem.Symbol + ",SelectedWatchList,{All}");
|
||||
saveParams.Referer=this;
|
||||
WorkspaceInstantiator.Invoke(saveParams);
|
||||
}, param => { return null != selectedItem && null != selectedItem.Symbol; });
|
||||
}
|
||||
return displayDCFValuationCommand;
|
||||
}
|
||||
}
|
||||
public ICommand DisplayMACD
|
||||
{
|
||||
get
|
||||
{
|
||||
if (macdCommand == null)
|
||||
{
|
||||
macdCommand = new RelayCommand(param => this.DisplayMACDCommand(), param => { return null!=selectedItem&&null!=selectedItem.Symbol?true:false; });
|
||||
}
|
||||
return macdCommand;
|
||||
}
|
||||
}
|
||||
public void DisplayMACDCommand()
|
||||
{
|
||||
SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.MACDViewModel,SelectedSymbol," + selectedItem.Symbol + ",SelectedWatchList,{All},SelectedDayCount,180");
|
||||
saveParams.Referer=this;
|
||||
WorkspaceInstantiator.Invoke(saveParams);
|
||||
}
|
||||
public ICommand DisplayPriceHistory
|
||||
{
|
||||
get
|
||||
{
|
||||
if (priceHistoryCommand == null)
|
||||
{
|
||||
priceHistoryCommand = new RelayCommand(param => this.DisplayPriceHistoryCommand(), param => { return null!=selectedItem&&null!=selectedItem.Symbol?true:false; });
|
||||
}
|
||||
return priceHistoryCommand;
|
||||
}
|
||||
}
|
||||
public void DisplayPriceHistoryCommand()
|
||||
{
|
||||
SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.PricingViewModel,SelectedSymbol," + selectedItem.Symbol + ",SelectedWatchList,{All},SelectedDayCount,180");
|
||||
saveParams.Referer=this;
|
||||
WorkspaceInstantiator.Invoke(saveParams);
|
||||
}
|
||||
public ICommand DisplayBollingerBand
|
||||
{
|
||||
get
|
||||
{
|
||||
if (bollingerBandCommand == null)
|
||||
{
|
||||
bollingerBandCommand = new RelayCommand(param => this.DisplayBollingerBandCommand(), param => { return null!=selectedItem&&null!=selectedItem.Symbol?true:false; });
|
||||
}
|
||||
return bollingerBandCommand;
|
||||
}
|
||||
}
|
||||
public ICommand DisplayDividendHistory
|
||||
{
|
||||
get
|
||||
{
|
||||
if (dividendHistoryCommand == null)
|
||||
{
|
||||
dividendHistoryCommand = new RelayCommand(param =>
|
||||
{
|
||||
SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.DividendHistoryViewModel,SelectedSymbol," + selectedItem.Symbol + ",SelectedWatchList,{All}");
|
||||
saveParams.Referer=this;
|
||||
WorkspaceInstantiator.Invoke(saveParams);
|
||||
}, param => { return null != selectedItem && null != selectedItem.Symbol; });
|
||||
}
|
||||
return dividendHistoryCommand;
|
||||
}
|
||||
}
|
||||
public ICommand DisplayHistorical
|
||||
{
|
||||
get
|
||||
{
|
||||
if (displayHistoricalCommand == null)
|
||||
{
|
||||
displayHistoricalCommand = new RelayCommand(param =>
|
||||
{
|
||||
SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.HistoricalViewModel,SelectedSymbol," + selectedItem.Symbol + ",SelectedWatchList,{All}");
|
||||
saveParams.Referer=this;
|
||||
WorkspaceInstantiator.Invoke(saveParams);
|
||||
}, param => { return null != selectedItem && null != selectedItem.Symbol; });
|
||||
}
|
||||
return displayHistoricalCommand;
|
||||
}
|
||||
}
|
||||
public ICommand DisplayHeadlines
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == displayHeadlinesCommand)
|
||||
{
|
||||
displayHeadlinesCommand = new RelayCommand(param =>
|
||||
{
|
||||
SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.HeadlinesViewModel,SelectedSymbol," + selectedItem.Symbol + ",SelectedWatchList,Valuations");
|
||||
saveParams.Referer=this;
|
||||
WorkspaceInstantiator.Invoke(saveParams);
|
||||
}, param => { return null != selectedItem && null!=selectedItem.Symbol; });
|
||||
}
|
||||
return displayHeadlinesCommand;
|
||||
}
|
||||
}
|
||||
// *****************************************************************************************************************************************************************************
|
||||
public void DisplayBollingerBandCommand()
|
||||
{
|
||||
SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.BollingerBandViewModel,SelectedSymbol,"+selectedItem.Symbol+",SelectedWatchList,{All},SelectedDayCount,180");
|
||||
saveParams.Referer=this;
|
||||
WorkspaceInstantiator.Invoke(saveParams);
|
||||
}
|
||||
public ICommand DisplayValuation
|
||||
{
|
||||
get
|
||||
{
|
||||
if (valuationCommand == null)
|
||||
{
|
||||
valuationCommand = new RelayCommand(param => this.DisplayValuationCommand(), param => { return true; });
|
||||
}
|
||||
return valuationCommand;
|
||||
}
|
||||
}
|
||||
public void DisplayValuationCommand()
|
||||
{
|
||||
List<DateTime> valuationDates = ValuationDA.GetValuationDates();
|
||||
if (null == valuationDates || 0 == valuationDates.Count) return;
|
||||
DateTime valuationDate = valuationDates[0];
|
||||
SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.ValuationsViewModel,SelectedValuationDate," + valuationDate);
|
||||
saveParams.Referer=this;
|
||||
WorkspaceInstantiator.Invoke(saveParams);
|
||||
}
|
||||
public ICommand RefreshCommand
|
||||
{
|
||||
get
|
||||
{
|
||||
if (refreshCommand == null)
|
||||
{
|
||||
refreshCommand = new RelayCommand(param => this.Refresh(), param => this.CanRefresh);
|
||||
}
|
||||
return refreshCommand;
|
||||
}
|
||||
}
|
||||
public EarningsAnnouncementModel SelectedItem
|
||||
{
|
||||
get
|
||||
{
|
||||
return selectedItem;
|
||||
}
|
||||
set
|
||||
{
|
||||
selectedItem = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
163
ViewModels/FeedStatisticsViewModel.cs
Normal file
@@ -0,0 +1,163 @@
|
||||
using System;
|
||||
using System.Windows.Input;
|
||||
using System.ComponentModel;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Collections.Specialized;
|
||||
using System.Windows;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Research.DynamicDataDisplay.DataSources;
|
||||
using Microsoft.Research.DynamicDataDisplay.PointMarkers;
|
||||
using MarketData;
|
||||
using MarketData.Utils;
|
||||
using MarketData.DataAccess;
|
||||
using MarketData.MarketDataModel;
|
||||
using TradeBlotter.DataAccess;
|
||||
using TradeBlotter.Command;
|
||||
using TradeBlotter.Model;
|
||||
using MarketData.Cache;
|
||||
using TradeBlotter.Cache;
|
||||
|
||||
namespace TradeBlotter.ViewModels
|
||||
{
|
||||
public class FeedStatisticsViewModel : WorkspaceViewModel
|
||||
{
|
||||
private String selectedFeedStatisticType=null;
|
||||
private List<String> feedTypes=null;
|
||||
private FeedStatistics feedStatistics = null;
|
||||
private bool busyIndicator = false;
|
||||
private RelayCommand refreshCommand;
|
||||
private RelayCommand clearCacheCommand;
|
||||
|
||||
public FeedStatisticsViewModel()
|
||||
{
|
||||
base.DisplayName = "Feed Statistics";
|
||||
feedTypes = FeedStatistic.GetFeedStatisticTypes();
|
||||
PropertyChanged += OnViewModelPropertyChanged;
|
||||
}
|
||||
public override SaveParameters GetSaveParameters()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
public override void SetSaveParameters(SaveParameters saveParameters)
|
||||
{
|
||||
}
|
||||
public override bool CanPersist()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public ObservableCollection<FeedStatistic> AllItems
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
public bool BusyIndicator
|
||||
{
|
||||
get { return busyIndicator; }
|
||||
set
|
||||
{
|
||||
busyIndicator = value;
|
||||
base.OnPropertyChanged("BusyIndicator");
|
||||
}
|
||||
}
|
||||
private void OnViewModelPropertyChanged(object sender, PropertyChangedEventArgs eventArgs)
|
||||
{
|
||||
if (eventArgs.PropertyName.Equals("SelectedFeedType"))
|
||||
{
|
||||
BusyIndicator = true;
|
||||
Task workerTask = Task.Factory.StartNew(() =>
|
||||
{
|
||||
base.DisplayName = "Feed Statistics(" + selectedFeedStatisticType + ")";
|
||||
base.OnPropertyChanged("DisplayName");
|
||||
feedStatistics=CompositeDA.GetFeedStatistics(FeedStatistic.FromString(selectedFeedStatisticType));
|
||||
this.AllItems = new ObservableCollection<FeedStatistic>(feedStatistics);
|
||||
});
|
||||
workerTask.ContinueWith((continuation) =>
|
||||
{
|
||||
BusyIndicator = false;
|
||||
base.OnPropertyChanged("AllItems");
|
||||
base.OnPropertyChanged("Statistics");
|
||||
base.OnPropertyChanged("Title");
|
||||
});
|
||||
}
|
||||
}
|
||||
public override String Title
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == selectedFeedStatisticType ) return "";
|
||||
return selectedFeedStatisticType;
|
||||
}
|
||||
}
|
||||
public List<String> FeedTypes
|
||||
{
|
||||
get
|
||||
{
|
||||
return feedTypes;
|
||||
}
|
||||
set { ;}
|
||||
}
|
||||
public String SelectedFeedType
|
||||
{
|
||||
get { return selectedFeedStatisticType; }
|
||||
set { selectedFeedStatisticType = value; base.OnPropertyChanged("SelectedFeedType"); }
|
||||
}
|
||||
public CompositeDataSource Statistics
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetCompositeDataSource();
|
||||
}
|
||||
}
|
||||
private CompositeDataSource GetCompositeDataSource()
|
||||
{
|
||||
if (null == feedStatistics) return null;
|
||||
CompositeDataSource compositeDataSource;
|
||||
var xData = new EnumerableDataSource<DateTime>(feedStatistics.Select(x => x.Date.Date));
|
||||
xData.SetXMapping(x => (x.Ticks / 10000000000.0));
|
||||
var yData = new EnumerableDataSource<double>(feedStatistics.Select(y => (double)y.Records));
|
||||
yData.SetYMapping(y => y);
|
||||
compositeDataSource = xData.Join(yData);
|
||||
return compositeDataSource;
|
||||
}
|
||||
public ICommand RefreshCommand
|
||||
{
|
||||
get
|
||||
{
|
||||
if(refreshCommand==null)
|
||||
{
|
||||
refreshCommand=new RelayCommand(param => this.Refresh(),param => this.CanRefresh);
|
||||
}
|
||||
return refreshCommand;
|
||||
}
|
||||
}
|
||||
public ICommand ClearCacheCommand
|
||||
{
|
||||
get
|
||||
{
|
||||
if(clearCacheCommand==null)
|
||||
{
|
||||
clearCacheCommand=new RelayCommand(param => this.ClearCache(),param => {return true;});
|
||||
}
|
||||
return clearCacheCommand;
|
||||
}
|
||||
}
|
||||
private void ClearCache()
|
||||
{
|
||||
try{LocalPriceCache.GetInstance().Clear();}catch(Exception){;}
|
||||
try{GBPriceCache.GetInstance().Clear();}catch(Exception){;}
|
||||
try{PriceCache.GetInstance().Clear();}catch(Exception){;}
|
||||
MessageBox.Show("All caches have been re-intiialized.",base.DisplayName);
|
||||
}
|
||||
private void Refresh()
|
||||
{
|
||||
base.OnPropertyChanged("SelectedFeedType");
|
||||
}
|
||||
private bool CanRefresh
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
}
|
||||
}
|
||||
372
ViewModels/FloatingWindowViewModel.cs
Normal file
@@ -0,0 +1,372 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.ComponentModel;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Collections.Specialized;
|
||||
using System.Collections.Generic;
|
||||
using System.Windows.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading;
|
||||
using System.Windows;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Data;
|
||||
using MarketData.MarketDataModel;
|
||||
using MarketData.DataAccess;
|
||||
using MarketData.Utils;
|
||||
using MarketData.Integration;
|
||||
using MarketData;
|
||||
using TradeBlotter.Command;
|
||||
using TradeBlotter.ViewModels;
|
||||
using TradeBlotter.Model;
|
||||
using TradeBlotter.DataAccess;
|
||||
using TradeBlotter.Cache;
|
||||
using TradeBlotter.UIUtils;
|
||||
using System.Windows.Media;
|
||||
using Forms=System.Windows.Forms;
|
||||
using MarketData.Numerical;
|
||||
using System.Windows.Controls;
|
||||
using Ticker.Animation;
|
||||
using Ticker.Views;
|
||||
using Ticker.Models;
|
||||
using TradeBlotter.Views;
|
||||
using System.Windows.Input;
|
||||
using System.Configuration;
|
||||
|
||||
namespace TradeBlotter.ViewModels
|
||||
{
|
||||
public class FloatingWindowViewModel : WorkspaceViewModel
|
||||
{
|
||||
private static int FLOATING_WINDOW_FEED_INTERVAL_MINUTES=1; // This is the amount of time between feed pulls
|
||||
private readonly FeedManager manager = null;
|
||||
private Ticker<TickerItemView> ticker=null;
|
||||
private Panel mainPanel=null;
|
||||
private bool isPaused=false;
|
||||
private int itemCount=0;
|
||||
private RelayCommand togglePlayPausedCommand;
|
||||
private DateTime lastEarningsAnnouncementBroadcast;
|
||||
private DateTime lastAnalystRatingsBroadcast;
|
||||
private DateTime lastPremarketBroadcast;
|
||||
|
||||
public FloatingWindowViewModel(Panel panel)
|
||||
{
|
||||
manager=new FeedManager();
|
||||
manager.FeedIntervalMinutes=FLOATING_WINDOW_FEED_INTERVAL_MINUTES;
|
||||
mainPanel=panel;
|
||||
ticker = new Ticker<TickerItemView>(mainPanel);
|
||||
ticker.ItemDisplayed += ticker_ItemDisplayed;
|
||||
manager.FeedSourceEventHandler+=GetFeedItemsEventHandler;
|
||||
manager.NewFeedItem+= (o,e)=>AddItem(e.Item);
|
||||
base.OnPropertyChanged("IsPaused");
|
||||
PropertyChanged += OnFloatingViewModelPropertyChanged;
|
||||
manager.Start();
|
||||
ticker.Start();
|
||||
}
|
||||
public override SaveParameters GetSaveParameters()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
private void OnFloatingViewModelPropertyChanged(object sender, PropertyChangedEventArgs eventArgs)
|
||||
{
|
||||
if (eventArgs.PropertyName.Equals("IsPaused"))
|
||||
{
|
||||
if(IsPaused && ticker.IsRunning)
|
||||
{
|
||||
ticker.Stop();
|
||||
}
|
||||
else if(!IsPaused && !ticker.IsRunning)
|
||||
{
|
||||
ticker.Start();
|
||||
}
|
||||
}
|
||||
}
|
||||
// The feed does not persist contents between successive runs. It uses feed cache to filter previously displayed items for the day
|
||||
public override void SetSaveParameters(SaveParameters saveParameters)
|
||||
{
|
||||
}
|
||||
public override bool CanPersist()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
//*****************************************************************************************************************************************************************************
|
||||
private void AddItem(FeedItem item)
|
||||
{
|
||||
Application.Current.Dispatcher.Invoke((Forms.MethodInvoker)delegate()
|
||||
{
|
||||
ticker.Items.Enqueue(new TickerItemView(item));
|
||||
});
|
||||
}
|
||||
public String ItemCount
|
||||
{
|
||||
get{return itemCount.ToString();}
|
||||
set{itemCount=int.Parse(value);base.OnPropertyChanged("ItemCount");}
|
||||
}
|
||||
public bool IsPaused
|
||||
{
|
||||
get{return isPaused;}
|
||||
set{isPaused=value;base.OnPropertyChanged("IsPaused");}
|
||||
}
|
||||
public ICommand TogglePlayPauseCommand
|
||||
{
|
||||
get
|
||||
{
|
||||
if (togglePlayPausedCommand == null)
|
||||
{
|
||||
togglePlayPausedCommand = new RelayCommand(action => {IsPaused=!IsPaused;},action => { return true; });
|
||||
}
|
||||
return togglePlayPausedCommand;
|
||||
}
|
||||
}
|
||||
private void ticker_ItemDisplayed(object sender, ItemEventArgs<TickerItemView> e)
|
||||
{
|
||||
manager.MarkFeedAsRead(e.Item.FeedItem);
|
||||
itemCount=manager.GetFeedItemCount();
|
||||
base.OnPropertyChanged("ItemCount");
|
||||
}
|
||||
public List<FeedItem> GetFeedItemsEventHandler()
|
||||
{
|
||||
bool itemsAdded=false;
|
||||
List<FeedItem> feedItems=new List<FeedItem>();
|
||||
List<String> openSymbols=new List<String>();
|
||||
|
||||
List<FeedItem> networkStatusFeedItems=NetworkStatusToFeedItems();
|
||||
if(null!=networkStatusFeedItems){feedItems.AddRange(networkStatusFeedItems);itemsAdded=networkStatusFeedItems.Count>0?true:itemsAdded;}
|
||||
|
||||
if((Utility.IsEpoch(lastPremarketBroadcast)||DateTime.Now-lastPremarketBroadcast>new TimeSpan(0,5,0))) // earnings broadcast every 5 minutes
|
||||
{
|
||||
lastPremarketBroadcast=DateTime.Now;
|
||||
List<FeedItem> premarketFeedItems=PremarketToFeedItems();
|
||||
if(null!=premarketFeedItems) { feedItems.AddRange(premarketFeedItems); itemsAdded=premarketFeedItems.Count>0?true:itemsAdded; }
|
||||
}
|
||||
|
||||
List<FeedItem> headlineFeedItems=HeadlinesToFeedItems();
|
||||
if(null!=headlineFeedItems){feedItems.AddRange(headlineFeedItems);itemsAdded=headlineFeedItems.Count>0?true:itemsAdded;}
|
||||
|
||||
try{openSymbols=PortfolioDA.GetOpenSymbols();}catch(Exception){;}
|
||||
List<FeedItem> openPricesFeedItems=OpenPricesToFeedItems(openSymbols);
|
||||
if(null!=openPricesFeedItems){feedItems.AddRange(openPricesFeedItems);itemsAdded=openPricesFeedItems.Count>0?true:itemsAdded;}
|
||||
|
||||
if(Utility.IsEpoch(lastAnalystRatingsBroadcast)||DateTime.Now-lastAnalystRatingsBroadcast>new TimeSpan(0,20,0)) // analyst ratings broadcast every 20 minutes
|
||||
{
|
||||
lastAnalystRatingsBroadcast=DateTime.Now;
|
||||
List<FeedItem> analystRatingsFeedItems=AnalystRatingsToFeedItems(openSymbols);
|
||||
if(null!=analystRatingsFeedItems){feedItems.AddRange(analystRatingsFeedItems);itemsAdded=analystRatingsFeedItems.Count>0?true:itemsAdded;}
|
||||
}
|
||||
|
||||
if(Utility.IsEpoch(lastEarningsAnnouncementBroadcast)||DateTime.Now-lastEarningsAnnouncementBroadcast>new TimeSpan(0,20,0)) // earnings broadcast every 20 minutes
|
||||
{
|
||||
lastEarningsAnnouncementBroadcast=DateTime.Now;
|
||||
List<FeedItem> earningsAnnouncementFeedItems=EarningsAnnouncementsToFeedItems(openSymbols);
|
||||
if(null!=earningsAnnouncementFeedItems){feedItems.AddRange(earningsAnnouncementFeedItems);itemsAdded=earningsAnnouncementFeedItems.Count>0?true:itemsAdded;}
|
||||
}
|
||||
return feedItems;
|
||||
}
|
||||
// ***************************************************************************************************************************************************
|
||||
// ************************************************************************ F E E D C O N V E R T E R S ********************************************
|
||||
// ***************************************************************************************************************************************************
|
||||
private List<FeedItem> NetworkStatusToFeedItems()
|
||||
{
|
||||
List<FeedItem> feedItems=new List<FeedItem>();
|
||||
|
||||
try
|
||||
{
|
||||
//if(NetworkStatus.IsNetworkAvailable())return null;
|
||||
if(NetworkStatus.IsInternetConnected())return null;
|
||||
FeedItem feedItem=new FeedItem();
|
||||
feedItem.Description="Network is unavailable";
|
||||
feedItem.Title=String.Format("Network is unavailable");
|
||||
feedItem.Link="http://192.168.1.1/";
|
||||
feedItem.Source="Network";
|
||||
feedItem.PubDate=DateTime.Now.ToShortDateString()+" "+Utility.DateTimeToStringHHMMSS(DateTime.Now);
|
||||
feedItem.Guid="Network"+feedItem.PubDate;
|
||||
feedItem.BrushAssigment=FeedBrushes.BrushColor.Red;
|
||||
feedItems.Add(feedItem);
|
||||
return feedItems;
|
||||
}
|
||||
catch(Exception exception)
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,exception.ToString());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
private List<FeedItem> PremarketToFeedItems()
|
||||
{
|
||||
List<FeedItem> feedItems=new List<FeedItem>();
|
||||
|
||||
try
|
||||
{
|
||||
String tickerPremarketFeedIdleAfter=ConfigurationManager.AppSettings["TickerPremarketFeedIdleAfter"];
|
||||
if(null==tickerPremarketFeedIdleAfter)tickerPremarketFeedIdleAfter="09:30:00";
|
||||
TimeSpan cutoff=TimeSpan.Parse(tickerPremarketFeedIdleAfter);
|
||||
if(DateTime.Now.TimeOfDay>cutoff)return feedItems;
|
||||
PremarketElements premarketElements=PremarketDA.GetLatestPremarketData();
|
||||
if(null==premarketElements||0==premarketElements.Count)return feedItems;
|
||||
foreach(PremarketElement premarketElement in premarketElements)
|
||||
{
|
||||
FeedItem feedItem=new FeedItem();
|
||||
feedItem.Description=premarketElement.Market;
|
||||
feedItem.Title=String.Format("{0} {1}({2})",premarketElement.Market,Utility.FormatNumber(premarketElement.ChangeValue,2),Utility.FormatPercent(premarketElement.ChangePercent/100.00));
|
||||
feedItem.Link="https://money.cnn.com/data/premarket//";
|
||||
feedItem.Source="CNN";
|
||||
feedItem.PubDate=premarketElement.Timestamp.ToShortDateString()+" "+Utility.DateTimeToStringHHMMSS(premarketElement.Timestamp);
|
||||
feedItem.Guid=premarketElement.Market+feedItem.PubDate;
|
||||
if(premarketElement.ChangePercent<0)feedItem.BrushAssigment=FeedBrushes.BrushColor.Red;
|
||||
else feedItem.BrushAssigment=FeedBrushes.BrushColor.Green;
|
||||
feedItems.Add(feedItem);
|
||||
}
|
||||
return feedItems;
|
||||
}
|
||||
catch(Exception exception)
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,exception.ToString());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
private List<FeedItem> EarningsAnnouncementsToFeedItems(List<String> openSymbols)
|
||||
{
|
||||
List<FeedItem> feedItems=new List<FeedItem>();
|
||||
int maxDaysFromToday=2;
|
||||
|
||||
try
|
||||
{
|
||||
DateTime today=DateTime.Now;
|
||||
String tickerEarningsAnnouncementMaxDays=ConfigurationManager.AppSettings["TickerEarningsAnnouncementMaxDays"];
|
||||
if(null!=tickerEarningsAnnouncementMaxDays)int.TryParse(tickerEarningsAnnouncementMaxDays,out maxDaysFromToday);
|
||||
List<EarningsAnnouncementModel> earningsAnnouncementModels = new List<EarningsAnnouncementModel>();
|
||||
List<String> symbols = WatchListDA.GetWatchList("valuations");
|
||||
foreach (String symbol in symbols)
|
||||
{
|
||||
EarningsAnnouncementModel earningsAnnouncementModel=CompositeDA.GetEarningsAnnouncement(symbol);
|
||||
if(null==earningsAnnouncementModel)continue;
|
||||
if (earningsAnnouncementModel.DaysFromToday > maxDaysFromToday || earningsAnnouncementModel.DaysFromToday<0) continue;
|
||||
earningsAnnouncementModels.Add(earningsAnnouncementModel);
|
||||
}
|
||||
earningsAnnouncementModels.Sort();
|
||||
foreach(EarningsAnnouncementModel earningsAnnouncementModel in earningsAnnouncementModels)
|
||||
{
|
||||
int days=Math.Abs(earningsAnnouncementModel.DaysFromToday);
|
||||
FeedItem feedItem=new FeedItem();
|
||||
feedItem.Description=earningsAnnouncementModel.Symbol;
|
||||
if(0==days)feedItem.Title=String.Format("Earnings Annoucement for {0} due today",earningsAnnouncementModel.Symbol);
|
||||
else feedItem.Title=String.Format("Earnings Annoucement for {0} due in {1} {2} ",earningsAnnouncementModel.Symbol,days,days>1?"days":"day");;
|
||||
feedItem.Link="https://www.zacks.com/stock/research/"+earningsAnnouncementModel.Symbol+"/earnings-announcements";
|
||||
feedItem.Source="Earnings Announcements";
|
||||
feedItem.PubDate=today.ToShortDateString()+" "+Utility.DateTimeToStringHHMMSS(DateTime.Now);
|
||||
feedItem.Guid="Earnings Announcement "+earningsAnnouncementModel.Symbol+" "+today+" "+Utility.DateTimeToStringHHMMSS(DateTime.Now);
|
||||
if(openSymbols.Any(x=>x.Equals(earningsAnnouncementModel.Symbol)))feedItem.BrushAssigment=FeedBrushes.BrushColor.Red;
|
||||
feedItems.Add(feedItem);
|
||||
}
|
||||
return feedItems;
|
||||
}
|
||||
catch(Exception exception)
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,exception.ToString());
|
||||
return feedItems;
|
||||
}
|
||||
}
|
||||
private List<FeedItem> AnalystRatingsToFeedItems(List<String> openSymbols)
|
||||
{
|
||||
List<FeedItem> feedItems=new List<FeedItem>();
|
||||
List<String> watchListSymbols = WatchListDA.GetWatchList("valuations");
|
||||
if(null==watchListSymbols)watchListSymbols=new List<String>();
|
||||
if(null==openSymbols)openSymbols=new List<String>();
|
||||
try
|
||||
{
|
||||
DateTime today=DateTime.Now;
|
||||
AnalystRatings analystRatings=AnalystRatingsDA.GetAnalystRatings(today);
|
||||
foreach(AnalystRating analystRating in analystRatings)
|
||||
{
|
||||
if(!openSymbols.Any(x=>x.Equals(analystRating.Symbol)) && !watchListSymbols.Any(x=>x.Equals(analystRating.Symbol)))continue;
|
||||
StringBuilder sb=new StringBuilder();
|
||||
FeedItem feedItem=new FeedItem();
|
||||
sb.Append(analystRating.Symbol).Append("(").Append(analystRating.Type).Append(")").Append(":").Append(analystRating.RatingsChange);
|
||||
if(0.00!=analystRating.PriceTarget)sb.Append(":").Append(Utility.FormatCurrency(analystRating.PriceTarget));
|
||||
String lineData=sb.ToString();
|
||||
feedItem.Description=analystRating.Symbol;
|
||||
feedItem.Title=lineData;
|
||||
feedItem.Link="https://www.google.com/search?q="+Uri.EscapeDataString(analystRating.Symbol)+"/";
|
||||
feedItem.Source="Analyst Ratings";
|
||||
feedItem.PubDate=today.ToShortDateString()+" "+Utility.DateTimeToStringHHMMSS(DateTime.Now);
|
||||
feedItem.Guid="Analyst Ratings"+analystRating.Symbol+" "+today+" "+Utility.DateTimeToStringHHMMSS(DateTime.Now);;
|
||||
if(openSymbols.Any(x=>x.Equals(analystRating.Symbol)&&analystRating.Type.Equals("Downgrades")))feedItem.BrushAssigment=FeedBrushes.BrushColor.Red;
|
||||
else if(openSymbols.Any(x=>x.Equals(analystRating.Symbol)&&analystRating.Type.Equals("Upgrades"))) feedItem.BrushAssigment=FeedBrushes.BrushColor.Green;
|
||||
feedItems.Add(feedItem);
|
||||
}
|
||||
return feedItems;
|
||||
}
|
||||
catch(Exception exception)
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,exception.ToString());
|
||||
return feedItems;
|
||||
}
|
||||
}
|
||||
private List<FeedItem> OpenPricesToFeedItems(List<String> openSymbols)
|
||||
{
|
||||
List<FeedItem> feedItems=new List<FeedItem>();
|
||||
try
|
||||
{
|
||||
DateTime pricingDate=DateTime.Now;
|
||||
DateGenerator dateGenerator=new DateGenerator();
|
||||
foreach(String symbol in openSymbols)
|
||||
{
|
||||
Price todaysPrice=PricingDA.GetPrice(symbol);
|
||||
if(null==todaysPrice)continue;
|
||||
DateTime prevDate=dateGenerator.FindPrevBusinessDay(todaysPrice.Date);
|
||||
Price prevPrice=PricingDA.GetPrice(symbol,prevDate);
|
||||
if(null==prevPrice)continue;
|
||||
double change=(todaysPrice.Close-prevPrice.Close)/prevPrice.Close;
|
||||
String strPercentChange=Utility.FormatPercent(change);
|
||||
FeedItem feedItem=new FeedItem();
|
||||
feedItem.Description=symbol;
|
||||
feedItem.Title=symbol+":"+strPercentChange;
|
||||
feedItem.Link="https://www.google.com/search?q="+Uri.EscapeDataString(symbol)+"/";
|
||||
feedItem.Source="Price Feed";
|
||||
feedItem.PubDate=todaysPrice.Date.ToShortDateString()+" "+Utility.DateTimeToStringHHMMSS(DateTime.Now);
|
||||
feedItem.Guid=symbol+todaysPrice.Date.ToShortDateString()+":"+strPercentChange;
|
||||
if(change<0)feedItem.BrushAssigment=FeedBrushes.BrushColor.Red;
|
||||
else if(change>0)feedItem.BrushAssigment=FeedBrushes.BrushColor.Green;
|
||||
else feedItem.BrushAssigment=FeedBrushes.BrushColor.Normal;
|
||||
feedItems.Add(feedItem);
|
||||
}
|
||||
return feedItems;
|
||||
}
|
||||
catch(Exception exception)
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,exception.ToString());
|
||||
return feedItems;
|
||||
}
|
||||
}
|
||||
private List<FeedItem> HeadlinesToFeedItems()
|
||||
{
|
||||
List<FeedItem> feedItems=new List<FeedItem>();
|
||||
try
|
||||
{
|
||||
DateTime today=DateTime.Now;
|
||||
MarketData.MarketDataModel.Headlines headlines=HeadlinesDA.GetHeadlines(today);
|
||||
for(int index=0;index<headlines.Count;index++)
|
||||
{
|
||||
MarketData.MarketDataModel.Headline headline=headlines[index];
|
||||
FeedItem feedItem=new FeedItem();
|
||||
feedItem.Description=headline.Entry;
|
||||
feedItem.Title=headline.Symbol+":"+headline.Entry;
|
||||
feedItem.Link="https://www.google.com/search?q="+Uri.EscapeDataString(headline.Entry)+"/";
|
||||
feedItem.Source=headline.Source;
|
||||
feedItem.PubDate=headline.Date.ToShortDateString()+" "+Utility.DateTimeToStringHHMMSS(headline.Modified);
|
||||
feedItem.Guid=headline.Symbol+headline.Date.ToShortDateString()+":"+Utility.DateTimeToStringHHMMSS(headline.Modified)+":"+headline.Entry;
|
||||
feedItems.Add(feedItem);
|
||||
}
|
||||
return feedItems;
|
||||
}
|
||||
catch(Exception exception)
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,exception.ToString());
|
||||
return feedItems;
|
||||
}
|
||||
}
|
||||
public virtual void Dispose()
|
||||
{
|
||||
if(null!=ticker)ticker.Stop();
|
||||
if(null!=manager)manager.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
1027
ViewModels/GainLossViewModel.cs
Normal file
770
ViewModels/HeadlinesViewModel.cs
Normal file
@@ -0,0 +1,770 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Collections.Specialized;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Input;
|
||||
using System.Threading.Tasks;
|
||||
using MarketData;
|
||||
using MarketData.Utils;
|
||||
using MarketData.MarketDataModel;
|
||||
using MarketData.Generator;
|
||||
using MarketData.DataAccess;
|
||||
using TradeBlotter.DataAccess;
|
||||
using TradeBlotter.Command;
|
||||
using TradeBlotter.Model;
|
||||
using Microsoft.Research.DynamicDataDisplay.DataSources;
|
||||
using System.Threading;
|
||||
using System.Windows;
|
||||
|
||||
namespace TradeBlotter.ViewModels
|
||||
{
|
||||
public class HeadlinesViewModel : WorkspaceViewModel
|
||||
{
|
||||
private enum Tasks{SelectedSymbol,SelectedDate};
|
||||
private Dictionary<Tasks,Semaphore> semaphorePool=new Dictionary<Tasks,Semaphore>();
|
||||
private const String DISPLAY_NAME = "Headlines";
|
||||
private List<String> symbols;
|
||||
private List<String> watchLists;
|
||||
private List<String> dates;
|
||||
private String selectedWatchList;
|
||||
private String selectedSymbol;
|
||||
private String selectedCompany;
|
||||
private String selectedDate = null;
|
||||
private ObservableCollection<HeadlineSentiment> headlinesSentimentCollection = null;
|
||||
private bool busyIndicator = false;
|
||||
private RelayCommand browserCommand;
|
||||
private RelayCommand refreshCommand;
|
||||
private RelayCommand stochasticsCommand;
|
||||
private RelayCommand relativeStrengthCommand;
|
||||
private RelayCommand macdCommand;
|
||||
private RelayCommand bollingerBandCommand;
|
||||
private RelayCommand priceHistoryCommand;
|
||||
private RelayCommand stickerValuationCommand;
|
||||
private RelayCommand dcfValuationCommand;
|
||||
private RelayCommand dividendHistoryCommand;
|
||||
private RelayCommand analystRatingsCommand;
|
||||
private RelayCommand displaySECFilingsCommand;
|
||||
private RelayCommand movingAverageCommand;
|
||||
private RelayCommand displayHistoricalCommand;
|
||||
private RelayCommand displayHeadlinesCommand;
|
||||
private RelayCommand removeFromWatchListCommand;
|
||||
private RelayCommand addToWatchListCommand;
|
||||
private RelayCommand proformaDividendRiskCommand = null;
|
||||
private HeadlineSentiment selectedItem;
|
||||
|
||||
public HeadlinesViewModel(bool loadedFromParams=false)
|
||||
{
|
||||
semaphorePool.Add(Tasks.SelectedSymbol,new Semaphore(1,1));
|
||||
semaphorePool.Add(Tasks.SelectedDate,new Semaphore(1,1));
|
||||
base.DisplayName = DISPLAY_NAME;
|
||||
watchLists = WatchListDA.GetWatchLists();
|
||||
watchLists.Insert(0, Constants.CONST_ALL);
|
||||
selectedWatchList = watchLists.Find(x => x.Equals("Valuations"));
|
||||
symbols = WatchListDA.GetWatchList(selectedWatchList);
|
||||
symbols.Insert(0, Constants.CONST_ALL);
|
||||
selectedSymbol=symbols[0];
|
||||
dates = HeadlinesDA.GetHeadlineDates();
|
||||
if(dates.Count>0)selectedDate = dates[0];
|
||||
PropertyChanged += OnHeadlinesViewModelPropertyChanged;
|
||||
if(!loadedFromParams)base.OnPropertyChanged("SelectedSymbol");
|
||||
}
|
||||
// ******************************************************************************************** P E R S I S T E N C E ********************************************************************************************
|
||||
public override bool CanPersist()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public override SaveParameters GetSaveParameters()
|
||||
{
|
||||
SaveParameters saveParams = new SaveParameters();
|
||||
if (null == selectedSymbol) return null;
|
||||
saveParams.Add(new KeyValuePair<String, String>("Type", GetType().Namespace + "." + GetType().Name));
|
||||
saveParams.Add(new KeyValuePair<String, String>("SelectedSymbol", selectedSymbol));
|
||||
saveParams.Add(new KeyValuePair<String, String>("SelectedCompany", selectedCompany));
|
||||
saveParams.Add(new KeyValuePair<String, String>("SelectedWatchList", selectedWatchList));
|
||||
saveParams.Add(new KeyValuePair<String, String>("SelectedDate", selectedDate));
|
||||
return saveParams;
|
||||
}
|
||||
public override void SetSaveParameters(SaveParameters saveParameters)
|
||||
{
|
||||
try
|
||||
{
|
||||
selectedSymbol = (from KeyValuePair<String, String> item in saveParameters where item.Key.Equals("SelectedSymbol") select item).FirstOrDefault().Value;
|
||||
selectedWatchList = (from KeyValuePair<String, String> item in saveParameters where item.Key.Equals("SelectedWatchList") select item).FirstOrDefault().Value;
|
||||
selectedCompany = (from KeyValuePair<String, String> item in saveParameters where item.Key.Equals("SelectedCompany") select item).FirstOrDefault().Value;
|
||||
selectedDate = (from KeyValuePair<String, String> item in saveParameters where item.Key.Equals("SelectedDate") select item).FirstOrDefault().Value;
|
||||
if(null==selectedCompany)selectedCompany=PricingDA.GetNameForSymbol(selectedSymbol);
|
||||
if (null == selectedDate || selectedDate!=DateTime.Now.Date.ToShortDateString()) selectedDate = HeadlinesDA.GetMaxHeadlineDate().ToShortDateString();
|
||||
Referer=saveParameters.Referer;
|
||||
base.OnPropertyChanged("SelectedWatchList");
|
||||
base.OnPropertyChanged("SelectedSymbol");
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Exception:{0}", exception.ToString()));
|
||||
}
|
||||
}
|
||||
// ******************************************************************************************************************************************************
|
||||
public bool BusyIndicator
|
||||
{
|
||||
get { return busyIndicator; }
|
||||
set
|
||||
{
|
||||
busyIndicator = value;
|
||||
base.OnPropertyChanged("BusyIndicator");
|
||||
}
|
||||
}
|
||||
public ObservableCollection<MenuItem> MenuItems
|
||||
{
|
||||
get
|
||||
{
|
||||
ObservableCollection<MenuItem> collection = new ObservableCollection<MenuItem>();
|
||||
collection.Add(new MenuItem() { Text = "Search for articles", MenuItemClickedCommand = DisplayBrowserSearch, StaysOpenOnClick = false });
|
||||
collection.Add(new MenuItem() { Text = "Display Bollinger Band", MenuItemClickedCommand = DisplayBollingerBand, StaysOpenOnClick = false });
|
||||
collection.Add(new MenuItem() { Text = "Display Sticker Valuation", MenuItemClickedCommand = DisplayStickerValuation, StaysOpenOnClick = false });
|
||||
collection.Add(new MenuItem() { Text = "Display Dividend History", MenuItemClickedCommand = DisplayDividendHistory, StaysOpenOnClick = false });
|
||||
collection.Add(new MenuItem() { Text = "Display Proforma Dividend Risk", MenuItemClickedCommand = DisplayProformaDividendRisk, StaysOpenOnClick = false });
|
||||
collection.Add(new MenuItem() { Text = "Display Historical", MenuItemClickedCommand = DisplayHistorical, StaysOpenOnClick = false });
|
||||
collection.Add(new MenuItem() { Text = "Display Analyst Ratings", MenuItemClickedCommand = DisplayAnalystRatings, StaysOpenOnClick = false });
|
||||
collection.Add(new MenuItem() { Text = "Display Stochastics", MenuItemClickedCommand = DisplayStochastics, StaysOpenOnClick = false });
|
||||
collection.Add(new MenuItem() { Text = "Display Relative Strength", MenuItemClickedCommand=DisplayRelativeStrength, StaysOpenOnClick = false });
|
||||
collection.Add(new MenuItem() { Text = "Display MACD", MenuItemClickedCommand = DisplayMACD, StaysOpenOnClick = false });
|
||||
collection.Add(new MenuItem() { Text = "Display Moving Average", MenuItemClickedCommand = DisplayMovingAverage, StaysOpenOnClick = false });
|
||||
collection.Add(new MenuItem() { Text = "Display Price History", MenuItemClickedCommand = DisplayPriceHistory, StaysOpenOnClick = false });
|
||||
collection.Add(new MenuItem() { Text = "Display DCF Valuation", MenuItemClickedCommand = DisplayDCFValuation, StaysOpenOnClick = false });
|
||||
collection.Add(new MenuItem() { Text = "Display SEC Filings", MenuItemClickedCommand = DisplaySECFilings, StaysOpenOnClick = false });
|
||||
collection.Add(new MenuItem() { Text = "Display Headlines", MenuItemClickedCommand = DisplayHeadlines, StaysOpenOnClick = false });
|
||||
collection.Add(new MenuItem() { Text = "Remove from Watchlist", MenuItemClickedCommand = RemoveFromWatchList, StaysOpenOnClick = false });
|
||||
collection.Add(new MenuItem() { Text = "Add to Watchlist", MenuItemClickedCommand = AddToWatchList, StaysOpenOnClick = false });
|
||||
return collection;
|
||||
}
|
||||
}
|
||||
private void OnHeadlinesViewModelPropertyChanged(object sender, PropertyChangedEventArgs eventArgs)
|
||||
{
|
||||
if (eventArgs.PropertyName.Equals("SelectedDate") )
|
||||
{
|
||||
HandleSelectedDate();
|
||||
}
|
||||
else if (eventArgs.PropertyName.Equals("SelectedSymbol"))
|
||||
{
|
||||
HandleSelectedSymbol();
|
||||
}
|
||||
else if (eventArgs.PropertyName.Equals("SelectedWatchList"))
|
||||
{
|
||||
HandleSelectedWatchList();
|
||||
}
|
||||
}
|
||||
private void HandleSelectedDate()
|
||||
{
|
||||
try
|
||||
{
|
||||
semaphorePool[Tasks.SelectedDate].WaitOne();
|
||||
BusyIndicator = true;
|
||||
Task workerTask = Task.Factory.StartNew(() =>
|
||||
{
|
||||
if (Constants.CONST_ALL.Equals(selectedDate))
|
||||
{
|
||||
Headlines headlines=HeadlinesDA.GetHeadlines(selectedSymbol);
|
||||
HeadlinesSentiment headlinesSentiment=SentimentGenerator.GetInstance().ProcessHeadlines(headlines);
|
||||
selectedCompany = PricingDA.GetNameForSymbol(selectedSymbol);
|
||||
if (null != headlinesSentiment && 0 != headlinesSentiment.Count) headlinesSentimentCollection = new ObservableCollection<HeadlineSentiment>(headlinesSentiment);
|
||||
else headlinesSentimentCollection = null;
|
||||
}
|
||||
else if (null != selectedSymbol && !Constants.CONST_ALL.Equals(selectedSymbol))
|
||||
{
|
||||
Headlines headlines = HeadlinesDA.GetHeadlines(selectedSymbol, DateTime.Parse(selectedDate));
|
||||
HeadlinesSentiment headlinesSentiment=SentimentGenerator.GetInstance().ProcessHeadlines(headlines);
|
||||
selectedCompany = PricingDA.GetNameForSymbol(selectedSymbol);
|
||||
if (null != headlinesSentiment && 0 != headlinesSentiment.Count) headlinesSentimentCollection = new ObservableCollection<HeadlineSentiment>(headlinesSentiment);
|
||||
else headlinesSentimentCollection = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
Headlines headlines = HeadlinesDA.GetHeadlines(DateTime.Parse(selectedDate));
|
||||
HeadlinesSentiment headlinesSentiment=SentimentGenerator.GetInstance().ProcessHeadlines(headlines);
|
||||
if (null != headlinesSentiment && 0 != headlinesSentiment.Count) headlinesSentimentCollection = new ObservableCollection<HeadlineSentiment>(headlinesSentiment);
|
||||
else headlinesSentimentCollection = null;
|
||||
}
|
||||
});
|
||||
workerTask.ContinueWith((continuation)=>
|
||||
{
|
||||
BusyIndicator = false;
|
||||
base.OnPropertyChanged("AllItems");
|
||||
base.OnPropertyChanged("Title");
|
||||
});
|
||||
}
|
||||
finally
|
||||
{
|
||||
semaphorePool[Tasks.SelectedDate].Release();
|
||||
}
|
||||
}
|
||||
private void HandleSelectedSymbol()
|
||||
{
|
||||
try
|
||||
{
|
||||
semaphorePool[Tasks.SelectedSymbol].WaitOne();
|
||||
BusyIndicator = true;
|
||||
Task workerTask = Task.Factory.StartNew(() =>
|
||||
{
|
||||
// SentimentGenerator sentimentGenerator=new SentimentGenerator();
|
||||
if (null != selectedSymbol && !Constants.CONST_ALL.Equals(selectedSymbol))
|
||||
{
|
||||
base.DisplayName = DISPLAY_NAME + "(" + selectedSymbol + ")";
|
||||
Headlines headlines = HeadlinesDA.GetHeadlines(selectedSymbol);
|
||||
HeadlinesSentiment headlinesSentiment=SentimentGenerator.GetInstance().ProcessHeadlines(headlines);
|
||||
selectedCompany = PricingDA.GetNameForSymbol(selectedSymbol);
|
||||
if (null != headlinesSentiment && 0 != headlinesSentiment.Count) headlinesSentimentCollection = new ObservableCollection<HeadlineSentiment>(headlinesSentiment);
|
||||
else headlinesSentimentCollection = null;
|
||||
// if (null != headlines && 0 != headlines.Count) headlinesCollection = new ObservableCollection<Headline>(headlines);
|
||||
// else headlinesCollection = null;
|
||||
}
|
||||
else if (null == selectedSymbol || Constants.CONST_ALL.Equals(selectedSymbol))
|
||||
{
|
||||
Headlines headlines = null;
|
||||
if (null == selectedDate || Constants.CONST_ALL.Equals(selectedDate)) headlines = HeadlinesDA.GetHeadlines();
|
||||
else headlines = HeadlinesDA.GetHeadlines(DateTime.Parse(selectedDate));
|
||||
HeadlinesSentiment headlinesSentiment=SentimentGenerator.GetInstance().ProcessHeadlines(headlines);
|
||||
if (null != headlinesSentiment && 0 != headlinesSentiment.Count) headlinesSentimentCollection = new ObservableCollection<HeadlineSentiment>(headlinesSentiment);
|
||||
else headlinesSentimentCollection = null;
|
||||
//if (null != headlines && 0 != headlines.Count) headlinesCollection = new ObservableCollection<Headline>(headlines);
|
||||
//else headlinesCollection = null;
|
||||
}
|
||||
});
|
||||
workerTask.ContinueWith((continuation) =>
|
||||
{
|
||||
BusyIndicator = false;
|
||||
base.OnPropertyChanged("AllItems");
|
||||
base.OnPropertyChanged("Title");
|
||||
base.OnPropertyChanged("DisplayName");
|
||||
});
|
||||
}
|
||||
finally
|
||||
{
|
||||
semaphorePool[Tasks.SelectedSymbol].Release();
|
||||
}
|
||||
}
|
||||
private void HandleSelectedWatchList()
|
||||
{
|
||||
if (selectedWatchList.Equals(Constants.CONST_ALL)) symbols = PricingDA.GetSymbols();
|
||||
else
|
||||
{
|
||||
symbols = WatchListDA.GetWatchList(selectedWatchList);
|
||||
symbols.Insert(0, Constants.CONST_ALL);
|
||||
}
|
||||
base.OnPropertyChanged("Symbols");
|
||||
}
|
||||
//public ObservableCollection<Headline> AllItems
|
||||
//{
|
||||
// get { return headlinesCollection; }
|
||||
//}
|
||||
public ObservableCollection<HeadlineSentiment> AllItems
|
||||
{
|
||||
get { return headlinesSentimentCollection; }
|
||||
}
|
||||
// ************************************************************************ T O O L T I P C A L L O U T S ****************************************************************
|
||||
public String Description
|
||||
{
|
||||
get
|
||||
{
|
||||
if(null== selectedItem || null==selectedItem.Symbol)return "No row selected.";
|
||||
CompanyProfile companyProfile=CompanyProfileDA.GetCompanyProfile(selectedItem.Symbol);
|
||||
if(null==companyProfile || null==companyProfile.Description)return "No description found.";
|
||||
return companyProfile.Description;
|
||||
}
|
||||
}
|
||||
public String Parity
|
||||
{
|
||||
get
|
||||
{
|
||||
if(null== selectedItem || null==selectedItem.Symbol)return "No row selected.";
|
||||
StringBuilder sb=new StringBuilder();
|
||||
PortfolioTrades portfolioTrades=PortfolioDA.GetOpenTradesSymbol(selectedItem.Symbol);
|
||||
DateTime currentDate=PricingDA.GetLatestDate(selectedItem.Symbol);
|
||||
if(null!=portfolioTrades&&0!=portfolioTrades.Count)
|
||||
{
|
||||
sb.Append("You own this security (").Append(selectedItem.Symbol).Append(") in ").Append(portfolioTrades.Count).Append(" lot(s). ").Append("Exposure:").Append(Utility.FormatCurrency(portfolioTrades.Sum(x=>x.Exposure())));
|
||||
ParityElement parityElement=ParityGenerator.GenerateBreakEven(selectedItem.Symbol);
|
||||
if(null!=parityElement)
|
||||
{
|
||||
sb.Append("\n").Append(parityElement.ToString());
|
||||
}
|
||||
}
|
||||
else sb.Append("You don't hold any shares of '").Append(selectedItem.Symbol).Append("'");
|
||||
sb.Append(".");
|
||||
DateGenerator dateGenerator=new DateGenerator();
|
||||
DateTime priorDate=dateGenerator.FindPrevBusinessDay(currentDate);
|
||||
Price p1=PricingDA.GetPrice(selectedItem.Symbol,currentDate);
|
||||
Price p2=PricingDA.GetPrice(selectedItem.Symbol,priorDate);
|
||||
if(null==p2&&null!=p1)
|
||||
{
|
||||
priorDate=dateGenerator.FindPrevBusinessDay(priorDate);
|
||||
p2=PricingDA.GetPrice(selectedItem.Symbol,priorDate);
|
||||
}
|
||||
if(null==p1||null==p2)return sb.ToString();
|
||||
sb.Append("\n");
|
||||
double change=(p1.Close-p2.Close)/p2.Close;
|
||||
sb.Append(String.Format("Latest Price {0} {1} ({2}{3})",Utility.DateTimeToStringMMSDDSYYYY(p1.Date),Utility.FormatCurrency(p1.Close),change<0?"-":"+",Utility.FormatPercent(Math.Abs(change))));
|
||||
return sb.ToString();
|
||||
|
||||
}
|
||||
}
|
||||
public override String DisplayName
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null != selectedSymbol && !Constants.CONST_ALL.Equals(selectedSymbol))return "Headline (" + selectedSymbol + ")";
|
||||
else return "Headlines";
|
||||
}
|
||||
}
|
||||
public override String Title
|
||||
{
|
||||
get
|
||||
{
|
||||
StringBuilder sb=new StringBuilder();
|
||||
sb.Append("");
|
||||
if(null!=headlinesSentimentCollection&&0!=headlinesSentimentCollection.Count) sb.Append(headlinesSentimentCollection.Count).Append(" ");
|
||||
if (null != selectedSymbol && !Constants.CONST_ALL.Equals(selectedSymbol))sb.Append("Headline (").Append(selectedSymbol).Append(")");
|
||||
else sb.Append("Headlines");
|
||||
if(null!=selectedDate)
|
||||
{
|
||||
DateTime selectedDateDt=DateTime.Parse(selectedDate);
|
||||
sb.Append(" on ").Append(selectedDateDt.DayOfWeek).Append(", ").Append(Utility.DateTimeToStringMMMM(selectedDateDt)).Append(" ").Append(selectedDateDt.Day).Append(", ").Append(selectedDateDt.Year);
|
||||
}
|
||||
if(null!=headlinesSentimentCollection)
|
||||
{
|
||||
double negativeCount=(from HeadlineSentiment s in headlinesSentimentCollection where s.Sentiment.Equals(LexicalElement.NEGATIVE_SENTIMENT) select s).ToList().Count();
|
||||
double positiveCount=(from HeadlineSentiment s in headlinesSentimentCollection where s.Sentiment.Equals(LexicalElement.POSITIVE_SENTIMENT) select s).ToList().Count();
|
||||
sb.Append(" (Sentiment : ").Append(Utility.FormatPercent(positiveCount/(positiveCount+negativeCount))).Append(")");
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
private void Refresh()
|
||||
{
|
||||
symbols = WatchListDA.GetWatchList(selectedWatchList);
|
||||
symbols.Insert(0, Constants.CONST_ALL);
|
||||
selectedSymbol=symbols[0];
|
||||
dates = HeadlinesDA.GetHeadlineDates();
|
||||
dates.Insert(0, Constants.CONST_ALL);
|
||||
if (dates.Count > 1) selectedDate = dates[1];
|
||||
else selectedDate = dates[0];
|
||||
base.OnPropertyChanged("Symbols");
|
||||
base.OnPropertyChanged("Dates");
|
||||
base.OnPropertyChanged("SelectedDate");
|
||||
base.OnPropertyChanged("SelectedSymbol");
|
||||
base.OnPropertyChanged("Title");
|
||||
}
|
||||
private bool CanReset
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
public ICommand RefreshCommand
|
||||
{
|
||||
get
|
||||
{
|
||||
if (refreshCommand == null)
|
||||
{
|
||||
refreshCommand = new RelayCommand(param => this.Refresh(), param => {return true;});
|
||||
}
|
||||
return refreshCommand;
|
||||
}
|
||||
}
|
||||
public List<String> Dates
|
||||
{
|
||||
get
|
||||
{
|
||||
return dates;
|
||||
}
|
||||
}
|
||||
public List<String> Symbols
|
||||
{
|
||||
get
|
||||
{
|
||||
return symbols;
|
||||
}
|
||||
}
|
||||
public String SelectedSymbol
|
||||
{
|
||||
get
|
||||
{
|
||||
return selectedSymbol;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value == selectedSymbol || String.IsNullOrEmpty(value)) return;
|
||||
selectedSymbol = value;
|
||||
base.OnPropertyChanged("SelectedSymbol");
|
||||
}
|
||||
}
|
||||
public String SelectedDate
|
||||
{
|
||||
get { return selectedDate; }
|
||||
set
|
||||
{
|
||||
selectedDate = value;
|
||||
base.OnPropertyChanged("SelectedDate");
|
||||
}
|
||||
}
|
||||
public List<String> WatchListNames
|
||||
{
|
||||
get
|
||||
{
|
||||
return watchLists;
|
||||
}
|
||||
set { ;}
|
||||
}
|
||||
public String SelectedWatchList
|
||||
{
|
||||
get { return selectedWatchList; }
|
||||
set { selectedWatchList = value; base.OnPropertyChanged("SelectedWatchList"); }
|
||||
}
|
||||
// **************************************************************************************************************************************************************
|
||||
// ********************************************************************* I C O M M A N D ************************************************************************
|
||||
// **************************************************************************************************************************************************************
|
||||
public ICommand DisplayHistorical
|
||||
{
|
||||
get
|
||||
{
|
||||
if (displayHistoricalCommand == null)
|
||||
{
|
||||
displayHistoricalCommand = new RelayCommand(param =>
|
||||
{
|
||||
SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.HistoricalViewModel,SelectedSymbol," + selectedItem.Symbol + ",SelectedWatchList,{All}");
|
||||
saveParams.Referer=this;
|
||||
WorkspaceInstantiator.Invoke(saveParams);
|
||||
}, param => { return null != selectedItem && null != selectedItem.Symbol; });
|
||||
}
|
||||
return displayHistoricalCommand;
|
||||
}
|
||||
}
|
||||
public ICommand DisplayBrowserSearch
|
||||
{
|
||||
get
|
||||
{
|
||||
if (browserCommand == null)
|
||||
{
|
||||
browserCommand = new RelayCommand(param => this.BrowserSearch(), param => { return null != selectedItem && null != selectedItem.Symbol;;});
|
||||
}
|
||||
return browserCommand;
|
||||
}
|
||||
}
|
||||
public ICommand DisplaySECFilings
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == displaySECFilingsCommand)
|
||||
{
|
||||
displaySECFilingsCommand = new RelayCommand(param =>
|
||||
{
|
||||
SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.SECFilingViewModel,SelectedSymbol," + selectedItem.Symbol + ",SelectedWatchList,Valuations");
|
||||
saveParams.Referer=this;
|
||||
WorkspaceInstantiator.Invoke(saveParams);
|
||||
}, param => { return null != selectedItem && null!=selectedItem.Symbol; });
|
||||
}
|
||||
return displaySECFilingsCommand;
|
||||
}
|
||||
}
|
||||
public ICommand DisplayAnalystRatings
|
||||
{
|
||||
get
|
||||
{
|
||||
if (analystRatingsCommand == null)
|
||||
{
|
||||
analystRatingsCommand = new RelayCommand(param => this.DisplayAnalystRatingsCommand(), param => { return null != selectedItem && null != selectedItem.Symbol; });
|
||||
}
|
||||
return analystRatingsCommand;
|
||||
}
|
||||
}
|
||||
public ICommand DisplayMACD
|
||||
{
|
||||
get
|
||||
{
|
||||
if (macdCommand == null)
|
||||
{
|
||||
macdCommand = new RelayCommand(param => this.DisplayMACDCommand(), param => { return null != selectedItem && null != selectedItem.Symbol; });
|
||||
}
|
||||
return macdCommand;
|
||||
}
|
||||
}
|
||||
public ICommand DisplayMovingAverage
|
||||
{
|
||||
get
|
||||
{
|
||||
if (movingAverageCommand == null)
|
||||
{
|
||||
movingAverageCommand = new RelayCommand(param => this.DisplayMovingAverageCommand(), param => { return null != selectedItem && null != selectedItem.Symbol; });
|
||||
}
|
||||
return movingAverageCommand;
|
||||
}
|
||||
}
|
||||
public ICommand DisplayStochastics
|
||||
{
|
||||
get
|
||||
{
|
||||
if (stochasticsCommand == null)
|
||||
{
|
||||
stochasticsCommand = new RelayCommand(param => this.DisplayStochasticsCommand(), param => { return null != selectedItem && null != selectedItem.Symbol; });
|
||||
}
|
||||
return stochasticsCommand;
|
||||
}
|
||||
}
|
||||
public ICommand DisplayRelativeStrength
|
||||
{
|
||||
get
|
||||
{
|
||||
if (relativeStrengthCommand == null)
|
||||
{
|
||||
relativeStrengthCommand = new RelayCommand(param => this.DisplayRelativeStrengthCommand(),
|
||||
param => { return null != selectedItem && null!=selectedItem.Symbol; });
|
||||
}
|
||||
return relativeStrengthCommand;
|
||||
}
|
||||
}
|
||||
public ICommand DisplayHeadlines
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == displayHeadlinesCommand)
|
||||
{
|
||||
displayHeadlinesCommand = new RelayCommand(param =>
|
||||
{
|
||||
SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.HeadlinesViewModel,SelectedSymbol," + selectedItem.Symbol + ",SelectedWatchList,Valuations");
|
||||
saveParams.Referer=this;
|
||||
WorkspaceInstantiator.Invoke(saveParams);
|
||||
}, param => { return null != selectedItem && null!=selectedItem.Symbol; });
|
||||
}
|
||||
return displayHeadlinesCommand;
|
||||
}
|
||||
}
|
||||
public ICommand RemoveFromWatchList
|
||||
{
|
||||
get
|
||||
{
|
||||
if (removeFromWatchListCommand == null)
|
||||
{
|
||||
removeFromWatchListCommand = new RelayCommand(param => this.RemoveFromWatchListCommand(selectedItem.Symbol),
|
||||
param =>
|
||||
{
|
||||
if (null == selectedItem || null == selectedItem.Symbol) return false;
|
||||
if (!WatchListDA.IsInWatchList(selectedItem.Symbol)) return false;
|
||||
PortfolioTrades portfolioTrades=PortfolioDA.GetOpenTradesSymbol(selectedItem.Symbol);
|
||||
if(null!=portfolioTrades&&0!=portfolioTrades.Count)return false;
|
||||
return true;
|
||||
});
|
||||
}
|
||||
return removeFromWatchListCommand;
|
||||
}
|
||||
}
|
||||
public ICommand AddToWatchList
|
||||
{
|
||||
get
|
||||
{
|
||||
if (addToWatchListCommand == null)
|
||||
{
|
||||
addToWatchListCommand = new RelayCommand(param => this.AddToWatchListCommand(selectedItem.Symbol),
|
||||
param =>
|
||||
{
|
||||
if(null==selectedItem || null==selectedItem.Symbol)return false;
|
||||
if (WatchListDA.IsInWatchList(selectedItem.Symbol)) return false;
|
||||
return true;
|
||||
});
|
||||
}
|
||||
return addToWatchListCommand;
|
||||
}
|
||||
}
|
||||
// *********************************************************************************************************************************************************************
|
||||
public void RemoveFromWatchListCommand(String symbol)
|
||||
{
|
||||
if (!WatchListDA.IsInWatchList(symbol))
|
||||
{
|
||||
System.Windows.MessageBox.Show("'" + symbol + "' is not in watchlist", "Info", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
return;
|
||||
}
|
||||
if (!WatchListDA.RemoveFromWatchList(symbol))
|
||||
{
|
||||
System.Windows.MessageBox.Show("Error removing '" + selectedItem.Symbol + "' from watchlist", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||
}
|
||||
else
|
||||
{
|
||||
System.Windows.MessageBox.Show("Removed '" + selectedItem.Symbol + "'", "Success", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
}
|
||||
}
|
||||
public void AddToWatchListCommand(String symbol)
|
||||
{
|
||||
if (WatchListDA.IsInWatchList(symbol))
|
||||
{
|
||||
System.Windows.MessageBox.Show("'"+symbol+"' is already in watchlist","Info", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
return;
|
||||
}
|
||||
if (!WatchListDA.AddToWatchList(symbol))
|
||||
{
|
||||
System.Windows.MessageBox.Show("Error adding '"+symbol+"' to watchlist","Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||
}
|
||||
else
|
||||
{
|
||||
System.Windows.MessageBox.Show("Added '"+symbol+"'","Success", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
}
|
||||
}
|
||||
public void DisplayAnalystRatingsCommand()
|
||||
{
|
||||
SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.AnalystRatingsViewModel,SelectedSymbol," + selectedItem.Symbol + ",SelectedWatchList,{All}");
|
||||
saveParams.Referer=this;
|
||||
WorkspaceInstantiator.Invoke(saveParams);
|
||||
}
|
||||
public void BrowserSearch()
|
||||
{
|
||||
Utility.LaunchBrowserSearch(selectedItem.Entry);
|
||||
}
|
||||
public void DisplayStochasticsCommand()
|
||||
{
|
||||
SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.StochasticsViewModel,SelectedSymbol," + selectedItem.Symbol + ",SelectedWatchList,{All},SelectedDayCount,180");
|
||||
saveParams.Referer=this;
|
||||
WorkspaceInstantiator.Invoke(saveParams);
|
||||
}
|
||||
public void DisplayRelativeStrengthCommand()
|
||||
{
|
||||
SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.RSIViewModel,SelectedSymbol," + selectedItem.Symbol + ",SelectedWatchList,{All},SelectedDayCount,60,SelectedRSIDayCount,14");
|
||||
saveParams.Referer=this;
|
||||
WorkspaceInstantiator.Invoke(saveParams);
|
||||
}
|
||||
public void DisplayMACDCommand()
|
||||
{
|
||||
SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.MACDViewModel,SelectedSymbol," + selectedItem.Symbol + ",SelectedWatchList,{All},SelectedDayCount,180");
|
||||
saveParams.Referer=this;
|
||||
WorkspaceInstantiator.Invoke(saveParams);
|
||||
}
|
||||
public void DisplayMovingAverageCommand()
|
||||
{
|
||||
SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.MovingAverageViewModel,SelectedSymbol," + selectedItem.Symbol + ",SelectedWatchList,{All},SelectedDayCount,360");
|
||||
saveParams.Referer=this;
|
||||
WorkspaceInstantiator.Invoke(saveParams);
|
||||
}
|
||||
public ICommand DisplayStickerValuation
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == stickerValuationCommand)
|
||||
{
|
||||
stickerValuationCommand = new RelayCommand(param =>
|
||||
{
|
||||
SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.StickerPriceViewModel,SelectedSymbol," + selectedItem.Symbol + ",SelectedWatchList,{All}");
|
||||
saveParams.Referer=this;
|
||||
WorkspaceInstantiator.Invoke(saveParams);
|
||||
}, param => { return null != selectedItem && null!=selectedItem.Symbol; });
|
||||
}
|
||||
return stickerValuationCommand;
|
||||
}
|
||||
}
|
||||
public ICommand DisplayDCFValuation
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == dcfValuationCommand)
|
||||
{
|
||||
dcfValuationCommand = new RelayCommand(param =>
|
||||
{
|
||||
SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.DCFValuationViewModel,SelectedSymbol," + selectedItem.Symbol + ",SelectedWatchList,{All}");
|
||||
saveParams.Referer=this;
|
||||
WorkspaceInstantiator.Invoke(saveParams);
|
||||
}, param => { return null != selectedItem && null!=selectedItem.Symbol; });
|
||||
}
|
||||
return dcfValuationCommand;
|
||||
}
|
||||
}
|
||||
public ICommand DisplayPriceHistory
|
||||
{
|
||||
get
|
||||
{
|
||||
if (priceHistoryCommand == null)
|
||||
{
|
||||
priceHistoryCommand = new RelayCommand(param => this.DisplayPriceHistoryCommand(), param => { return null != selectedItem && null != selectedItem.Symbol; });
|
||||
}
|
||||
return priceHistoryCommand;
|
||||
}
|
||||
}
|
||||
public ICommand DisplayDividendHistory
|
||||
{
|
||||
get
|
||||
{
|
||||
if (dividendHistoryCommand == null)
|
||||
{
|
||||
dividendHistoryCommand = new RelayCommand(param =>
|
||||
{
|
||||
SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.DividendHistoryViewModel,SelectedSymbol," + selectedItem.Symbol + ",SelectedWatchList,{All}");
|
||||
saveParams.Referer=this;
|
||||
WorkspaceInstantiator.Invoke(saveParams);
|
||||
}, param => { return null != selectedItem && null != selectedItem.Symbol; });
|
||||
}
|
||||
return dividendHistoryCommand;
|
||||
}
|
||||
}
|
||||
public ICommand DisplayProformaDividendRisk
|
||||
{
|
||||
get
|
||||
{
|
||||
if (proformaDividendRiskCommand == null)
|
||||
{
|
||||
proformaDividendRiskCommand = new RelayCommand(param =>
|
||||
{
|
||||
SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.DividendRiskParityViewModel,SelectedSymbol," + selectedItem.Symbol + "");
|
||||
saveParams.Referer = this;
|
||||
WorkspaceInstantiator.Invoke(saveParams);
|
||||
}, param =>
|
||||
{
|
||||
if(null==selectedItem || null==selectedItem.Symbol)return false;
|
||||
PortfolioTrades portfolioTrades = PortfolioDA.GetOpenTradesSymbol(selectedItem.Symbol);
|
||||
return null!=portfolioTrades && 0!=portfolioTrades.Count;
|
||||
});
|
||||
}
|
||||
return proformaDividendRiskCommand;
|
||||
}
|
||||
}
|
||||
public void DisplayPriceHistoryCommand()
|
||||
{
|
||||
SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.PricingViewModel,SelectedSymbol," + selectedItem.Symbol + ",SelectedWatchList,{All},SelectedDayCount,180");
|
||||
saveParams.Referer=this;
|
||||
WorkspaceInstantiator.Invoke(saveParams);
|
||||
}
|
||||
public ICommand DisplayBollingerBand
|
||||
{
|
||||
get
|
||||
{
|
||||
if (bollingerBandCommand == null)
|
||||
{
|
||||
bollingerBandCommand = new RelayCommand(param => this.DisplayBollingerBandCommand(), param => { return null != selectedItem && null != selectedItem.Symbol; });
|
||||
}
|
||||
return bollingerBandCommand;
|
||||
}
|
||||
}
|
||||
public void DisplayBollingerBandCommand()
|
||||
{
|
||||
SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.BollingerBandViewModel,SelectedSymbol," + selectedItem.Symbol + ",SelectedWatchList,{All},SelectedDayCount,180");
|
||||
saveParams.Referer=this;
|
||||
WorkspaceInstantiator.Invoke(saveParams);
|
||||
}
|
||||
public HeadlineSentiment SelectedItem
|
||||
{
|
||||
get
|
||||
{
|
||||
return selectedItem;
|
||||
}
|
||||
set
|
||||
{
|
||||
selectedItem = value;
|
||||
}
|
||||
}
|
||||
//public Headline SelectedItem
|
||||
//{
|
||||
// get
|
||||
// {
|
||||
// return selectedItem;
|
||||
// }
|
||||
// set
|
||||
// {
|
||||
// selectedItem = value;
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
612
ViewModels/HistoricalViewModel.cs
Normal file
@@ -0,0 +1,612 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Collections.Specialized;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
using MarketData.Utils;
|
||||
using MarketData.MarketDataModel;
|
||||
using MarketData.DataAccess;
|
||||
using MarketData.Generator;
|
||||
using TradeBlotter.Command;
|
||||
using Microsoft.Research.DynamicDataDisplay.DataSources;
|
||||
using TradeBlotter.Model;
|
||||
using TradeBlotter.UIUtils;
|
||||
|
||||
namespace TradeBlotter.ViewModels
|
||||
{
|
||||
public class HistoricalViewModel : WorkspaceViewModel
|
||||
{
|
||||
private String companyName;
|
||||
private List<String> symbols;
|
||||
private List<String> watchLists;
|
||||
private String selectedWatchList;
|
||||
private String selectedSymbol;
|
||||
private RelayCommand refreshCommand;
|
||||
private TimeSeriesCollection bvpsSeries;
|
||||
private TimeSeriesCollection epsSeries;
|
||||
private TimeSeriesCollection freeCashflowSeries;
|
||||
private TimeSeriesCollection operatingCashflowSeries;
|
||||
private TimeSeriesCollection operatingIncomeSeries;
|
||||
private TimeSeriesCollection revenueSeries;
|
||||
private TimeSeriesCollection roicSeries;
|
||||
private TimeSeriesCollection roaSeries;
|
||||
private TimeSeriesCollection workingCapitalSeries;
|
||||
private TimeSeriesCollection quarterlyRevenueSeries;
|
||||
private TimeSeriesCollection inventorySeries;
|
||||
private TimeSeriesCollection quarterlyInventorySeries;
|
||||
private TimeSeriesCollection goodwillSeries;
|
||||
private TimeSeriesCollection quarterlyGoodwillSeries;
|
||||
private TimeSeriesCollection netIncomeAvailableToCommonShareholdersSeries;
|
||||
private TimeSeriesCollection peSeries;
|
||||
private TimeSeriesCollection profitMarginSeries;
|
||||
private TimeSeriesCollection combinedSeries;
|
||||
private TimeSeriesCollection totalCashSeries;
|
||||
private DividendLoadCollection dividendLoadSeries;
|
||||
private TimeSeriesCollection debtToEquitySeries;
|
||||
private bool busyIndicator = false;
|
||||
|
||||
public HistoricalViewModel()
|
||||
{
|
||||
base.DisplayName = "HistoricalView";
|
||||
watchLists = WatchListDA.GetWatchLists();
|
||||
watchLists.Insert(0, Constants.CONST_ALL);
|
||||
selectedWatchList = watchLists.Find(x => x.Equals("Valuations"));
|
||||
symbols = WatchListDA.GetWatchList(selectedWatchList);
|
||||
PropertyChanged += OnHistoricalViewModelPropertyChanged;
|
||||
}
|
||||
public override SaveParameters GetSaveParameters()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
public override void SetSaveParameters(SaveParameters saveParameters)
|
||||
{
|
||||
try
|
||||
{
|
||||
selectedSymbol = (from KeyValuePair<String, String> item in saveParameters where item.Key.Equals("SelectedSymbol") select item).FirstOrDefault().Value;
|
||||
selectedWatchList = (from KeyValuePair<String, String> item in saveParameters where item.Key.Equals("SelectedWatchList") select item).FirstOrDefault().Value;
|
||||
Referer=saveParameters.Referer;
|
||||
base.OnPropertyChanged("SelectedWatchList");
|
||||
base.OnPropertyChanged("SelectedSymbol");
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
}
|
||||
public override bool CanPersist()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
private void OnHistoricalViewModelPropertyChanged(object sender, PropertyChangedEventArgs eventArgs)
|
||||
{
|
||||
if (eventArgs.PropertyName.Equals("SelectedSymbol"))
|
||||
{
|
||||
BusyIndicator = true;
|
||||
Task workerTask = Task.Factory.StartNew(() =>
|
||||
{
|
||||
companyName = PricingDA.GetNameForSymbol(selectedSymbol);
|
||||
bvpsSeries = HistoricalDA.GetTimeSeries(selectedSymbol, TimeSeriesElement.ElementType.BVPS);
|
||||
epsSeries = HistoricalDA.GetTimeSeries(selectedSymbol, TimeSeriesElement.ElementType.EPS);
|
||||
freeCashflowSeries = HistoricalDA.GetTimeSeries(selectedSymbol, TimeSeriesElement.ElementType.FreeCashflow);
|
||||
operatingCashflowSeries = HistoricalDA.GetTimeSeries(selectedSymbol, TimeSeriesElement.ElementType.OperatingCashflow);
|
||||
operatingIncomeSeries = HistoricalDA.GetTimeSeries(selectedSymbol, TimeSeriesElement.ElementType.OperatingIncome);
|
||||
revenueSeries = HistoricalDA.GetTimeSeries(selectedSymbol, TimeSeriesElement.ElementType.Revenue);
|
||||
roicSeries = HistoricalDA.GetTimeSeries(selectedSymbol, TimeSeriesElement.ElementType.ROIC);
|
||||
roaSeries = HistoricalDA.GetTimeSeries(selectedSymbol, TimeSeriesElement.ElementType.ROA);
|
||||
workingCapitalSeries = HistoricalDA.GetTimeSeries(selectedSymbol, TimeSeriesElement.ElementType.WorkingCapital);
|
||||
netIncomeAvailableToCommonShareholdersSeries = HistoricalDA.GetTimeSeries(selectedSymbol,TimeSeriesElement.ElementType.NetIncomeAvailableToCommonShareholders);
|
||||
quarterlyRevenueSeries = IncomeStatementDA.GetRevenue(selectedSymbol, IncomeStatement.PeriodType.Quarterly);
|
||||
quarterlyInventorySeries = BalanceSheetDA.GetInventory(selectedSymbol, BalanceSheet.PeriodType.Quarterly);
|
||||
inventorySeries = BalanceSheetDA.GetInventory(selectedSymbol, BalanceSheet.PeriodType.Annual);
|
||||
quarterlyGoodwillSeries = BalanceSheetDA.GetGoodwill(selectedSymbol, BalanceSheet.PeriodType.Quarterly);
|
||||
goodwillSeries = BalanceSheetDA.GetGoodwill(selectedSymbol, BalanceSheet.PeriodType.Annual);
|
||||
peSeries = FundamentalDA.GetPERatio(selectedSymbol);
|
||||
profitMarginSeries=IncomeStatementDA.GetProfitMargin(selectedSymbol);
|
||||
combinedSeries=CreateROICWACCSeries();
|
||||
totalCashSeries=FundamentalDA.GetTotalCashMils(selectedSymbol);
|
||||
dividendLoadSeries=CompositeDA.GetDividendLoad(selectedSymbol);
|
||||
debtToEquitySeries=CompositeDA.GetDebtToEquity(selectedSymbol);
|
||||
});
|
||||
workerTask.ContinueWith((continuation) =>
|
||||
{
|
||||
BusyIndicator = false;
|
||||
base.OnPropertyChanged("BVPS");
|
||||
base.OnPropertyChanged("BVPSTitle");
|
||||
base.OnPropertyChanged("CompanyName");
|
||||
base.OnPropertyChanged("EPS");
|
||||
base.OnPropertyChanged("EPSTitle");
|
||||
base.OnPropertyChanged("FreeCashflow");
|
||||
base.OnPropertyChanged("FCFTitle");
|
||||
base.OnPropertyChanged("OperatingCashflow");
|
||||
base.OnPropertyChanged("OCFTitle");
|
||||
base.OnPropertyChanged("OperatingIncome");
|
||||
base.OnPropertyChanged("OITitle");
|
||||
base.OnPropertyChanged("Revenue");
|
||||
base.OnPropertyChanged("RevenueTitle");
|
||||
base.OnPropertyChanged("QuarterlyRevenue");
|
||||
base.OnPropertyChanged("QuarterlyRevenueTitle");
|
||||
base.OnPropertyChanged("ROIC");
|
||||
base.OnPropertyChanged("ROA");
|
||||
base.OnPropertyChanged("ROICWACC");
|
||||
base.OnPropertyChanged("NetIncomeAvailableToCommonShareholders");
|
||||
base.OnPropertyChanged("PE");
|
||||
base.OnPropertyChanged("ProfitMargin");
|
||||
base.OnPropertyChanged("TotalCash");
|
||||
base.OnPropertyChanged("DividendLoad");
|
||||
base.OnPropertyChanged("DebtToEquity");
|
||||
|
||||
base.OnPropertyChanged("ROICTitle");
|
||||
base.OnPropertyChanged("ROICROATitle");
|
||||
base.OnPropertyChanged("ROATitle");
|
||||
base.OnPropertyChanged("WorkingCapital");
|
||||
base.OnPropertyChanged("WorkingCapitalTitle");
|
||||
base.OnPropertyChanged("Inventory");
|
||||
base.OnPropertyChanged("InventoryTitle");
|
||||
base.OnPropertyChanged("QuarterlyInventory");
|
||||
base.OnPropertyChanged("QuarterlyInventoryTitle");
|
||||
base.OnPropertyChanged("Goodwill");
|
||||
base.OnPropertyChanged("GoodwillTitle");
|
||||
base.OnPropertyChanged("QuarterlyGoodwill");
|
||||
base.OnPropertyChanged("QuarterlyGoodwillTitle");
|
||||
base.OnPropertyChanged("NetIncomeAvailableToCommonShareholdersTitle");
|
||||
base.OnPropertyChanged("PETitle");
|
||||
base.OnPropertyChanged("ProfitMarginTitle");
|
||||
base.OnPropertyChanged("TotalCashTitle");
|
||||
base.OnPropertyChanged("Title");
|
||||
base.OnPropertyChanged("DividendLoadTitle");
|
||||
base.OnPropertyChanged("DebtToEquityTitle");
|
||||
});
|
||||
}
|
||||
else if (eventArgs.PropertyName.Equals("SelectedWatchList"))
|
||||
{
|
||||
if (selectedWatchList.Equals(Constants.CONST_ALL)) symbols = PricingDA.GetSymbols();
|
||||
else symbols = WatchListDA.GetWatchList(selectedWatchList);
|
||||
base.OnPropertyChanged("Symbols");
|
||||
}
|
||||
}
|
||||
// **********************************************************************************************
|
||||
public bool BusyIndicator
|
||||
{
|
||||
get { return busyIndicator; }
|
||||
set
|
||||
{
|
||||
busyIndicator = value;
|
||||
base.OnPropertyChanged("BusyIndicator");
|
||||
}
|
||||
}
|
||||
public String TotalCashTitle
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == companyName || null == totalCashSeries || 0 == totalCashSeries.Count) return "";
|
||||
return Utility.DateTimeToStringMMHDDHYYYY(totalCashSeries[totalCashSeries.Count-1].AsOf) + " Thru " + Utility.DateTimeToStringMMHDDHYYYY(totalCashSeries[0].AsOf);
|
||||
}
|
||||
}
|
||||
public String ProfitMarginTitle
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == companyName || null == profitMarginSeries || 0 == profitMarginSeries.Count) return "";
|
||||
return Utility.DateTimeToStringMMHDDHYYYY(profitMarginSeries[profitMarginSeries.Count-1].AsOf) + " Thru " + Utility.DateTimeToStringMMHDDHYYYY(profitMarginSeries[0].AsOf);
|
||||
}
|
||||
}
|
||||
public String PETitle
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == companyName || null == peSeries || 0 == peSeries.Count) return "";
|
||||
return Utility.DateTimeToStringMMHDDHYYYY(peSeries[peSeries.Count-1].AsOf) + " Thru " + Utility.DateTimeToStringMMHDDHYYYY(peSeries[0].AsOf);
|
||||
}
|
||||
}
|
||||
public String BVPSTitle
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == companyName || null == bvpsSeries || 0 == bvpsSeries.Count) return "";
|
||||
return Utility.DateTimeToStringMMHDDHYYYY(bvpsSeries[bvpsSeries.Count-1].AsOf) + " Thru " + Utility.DateTimeToStringMMHDDHYYYY(bvpsSeries[0].AsOf);
|
||||
}
|
||||
}
|
||||
public String EPSTitle
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == companyName || null == epsSeries || 0 == epsSeries.Count) return "";
|
||||
return Utility.DateTimeToStringMMHDDHYYYY(epsSeries[epsSeries.Count - 1].AsOf) + " Thru " + Utility.DateTimeToStringMMHDDHYYYY(epsSeries[0].AsOf);
|
||||
}
|
||||
}
|
||||
public String FCFTitle
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == companyName || null == freeCashflowSeries || 0 == freeCashflowSeries.Count) return "";
|
||||
return Utility.DateTimeToStringMMHDDHYYYY(freeCashflowSeries[freeCashflowSeries.Count - 1].AsOf) + " Thru " + Utility.DateTimeToStringMMHDDHYYYY(freeCashflowSeries[0].AsOf);
|
||||
}
|
||||
}
|
||||
public String OCFTitle
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == companyName || null == operatingCashflowSeries || 0 == operatingCashflowSeries.Count) return "";
|
||||
return Utility.DateTimeToStringMMHDDHYYYY(operatingCashflowSeries[operatingCashflowSeries.Count - 1].AsOf) + " Thru " + Utility.DateTimeToStringMMHDDHYYYY(operatingCashflowSeries[0].AsOf);
|
||||
}
|
||||
}
|
||||
public String OITitle
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == companyName || null == operatingIncomeSeries || 0 == operatingIncomeSeries.Count) return "";
|
||||
return Utility.DateTimeToStringMMHDDHYYYY(operatingIncomeSeries[operatingIncomeSeries.Count - 1].AsOf) + " Thru " + Utility.DateTimeToStringMMHDDHYYYY(operatingIncomeSeries[0].AsOf);
|
||||
}
|
||||
}
|
||||
public String RevenueTitle
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == companyName || null == revenueSeries || 0 == revenueSeries.Count) return "";
|
||||
return Utility.DateTimeToStringMMHDDHYYYY(revenueSeries[revenueSeries.Count - 1].AsOf) + " Thru " + Utility.DateTimeToStringMMHDDHYYYY(revenueSeries[0].AsOf);
|
||||
}
|
||||
}
|
||||
public String QuarterlyRevenueTitle
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == companyName || null == quarterlyRevenueSeries || 0 == quarterlyRevenueSeries.Count) return "";
|
||||
return Utility.DateTimeToStringMMHDDHYYYY(quarterlyRevenueSeries[quarterlyRevenueSeries.Count - 1].AsOf) + " Thru " + Utility.DateTimeToStringMMHDDHYYYY(quarterlyRevenueSeries[0].AsOf);
|
||||
}
|
||||
}
|
||||
public String InventoryTitle
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == companyName || null == inventorySeries || 0 == inventorySeries.Count) return "";
|
||||
return Utility.DateTimeToStringMMHDDHYYYY(inventorySeries[inventorySeries.Count - 1].AsOf) + " Thru " + Utility.DateTimeToStringMMHDDHYYYY(inventorySeries[0].AsOf);
|
||||
}
|
||||
}
|
||||
public String QuarterlyInventoryTitle
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == companyName || null == quarterlyInventorySeries || 0 == quarterlyInventorySeries.Count) return "";
|
||||
return Utility.DateTimeToStringMMHDDHYYYY(quarterlyInventorySeries[quarterlyInventorySeries.Count - 1].AsOf) + " Thru " + Utility.DateTimeToStringMMHDDHYYYY(quarterlyInventorySeries[0].AsOf);
|
||||
}
|
||||
}
|
||||
public String GoodwillTitle
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == companyName || null == goodwillSeries || 0 == goodwillSeries.Count) return "";
|
||||
return Utility.DateTimeToStringMMHDDHYYYY(goodwillSeries[goodwillSeries.Count - 1].AsOf) + " Thru " + Utility.DateTimeToStringMMHDDHYYYY(goodwillSeries[0].AsOf);
|
||||
}
|
||||
}
|
||||
public String QuarterlyGoodwillTitle
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == companyName || null == quarterlyGoodwillSeries || 0 == quarterlyGoodwillSeries.Count) return "";
|
||||
return Utility.DateTimeToStringMMHDDHYYYY(quarterlyGoodwillSeries[quarterlyGoodwillSeries.Count - 1].AsOf) + " Thru " + Utility.DateTimeToStringMMHDDHYYYY(quarterlyGoodwillSeries[0].AsOf);
|
||||
}
|
||||
}
|
||||
public String ROICTitle
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == companyName || null == roicSeries || 0 == roicSeries.Count) return "";
|
||||
return Utility.DateTimeToStringMMHDDHYYYY(roicSeries[roicSeries.Count - 1].AsOf) + " Thru " + Utility.DateTimeToStringMMHDDHYYYY(roicSeries[0].AsOf);
|
||||
}
|
||||
}
|
||||
public String WorkingCapitalTitle
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == companyName || null == workingCapitalSeries || 0 == workingCapitalSeries.Count) return "";
|
||||
return Utility.DateTimeToStringMMHDDHYYYY(workingCapitalSeries[workingCapitalSeries.Count - 1].AsOf) + " Thru " + Utility.DateTimeToStringMMHDDHYYYY(workingCapitalSeries[0].AsOf);
|
||||
}
|
||||
}
|
||||
public String ROICROATitle
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == companyName || null == roicSeries || 0 == roicSeries.Count || null==roaSeries || 0==roaSeries.Count) return "";
|
||||
return Utility.DateTimeToStringMMHDDHYYYY(roicSeries[roicSeries.Count - 1].AsOf) + " Thru " + Utility.DateTimeToStringMMHDDHYYYY(roicSeries[0].AsOf);
|
||||
}
|
||||
}
|
||||
public String ROATitle
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == companyName || null==roaSeries || 0==roaSeries.Count) return "";
|
||||
return Utility.DateTimeToStringMMHDDHYYYY(roicSeries[roaSeries.Count - 1].AsOf) + " Thru " + Utility.DateTimeToStringMMHDDHYYYY(roaSeries[0].AsOf);
|
||||
}
|
||||
}
|
||||
public String NetIncomeAvailableToCommonShareholdersTitle
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == companyName || null == netIncomeAvailableToCommonShareholdersSeries || 0 == netIncomeAvailableToCommonShareholdersSeries.Count) return "";
|
||||
return Utility.DateTimeToStringMMHDDHYYYY(netIncomeAvailableToCommonShareholdersSeries[netIncomeAvailableToCommonShareholdersSeries.Count - 1].AsOf) + " Thru " + Utility.DateTimeToStringMMHDDHYYYY(netIncomeAvailableToCommonShareholdersSeries[0].AsOf);
|
||||
}
|
||||
}
|
||||
public String DividendLoadTitle
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == companyName || null == dividendLoadSeries || 0 == dividendLoadSeries.Count) return "";
|
||||
return dividendLoadSeries[dividendLoadSeries.Count - 1].Year.ToString() + " Thru " + dividendLoadSeries[0].Year.ToString();
|
||||
}
|
||||
}
|
||||
public String DebtToEquityTitle
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == companyName || null == debtToEquitySeries || 0 == debtToEquitySeries.Count) return "";
|
||||
return debtToEquitySeries[debtToEquitySeries.Count - 1].AsOf.ToString() + " Thru " + debtToEquitySeries[0].AsOf.ToString();
|
||||
}
|
||||
}
|
||||
//**********************************C O M P O S I T E D A T A S O U R C E****************************************************************************
|
||||
public CompositeDataSource TotalCash
|
||||
{
|
||||
get
|
||||
{
|
||||
CompositeDataSource compositeDataSource = TimeSeriesModel.GenerateCompositeDataSource(totalCashSeries);
|
||||
return compositeDataSource;
|
||||
}
|
||||
}
|
||||
public CompositeDataSource ProfitMargin
|
||||
{
|
||||
get
|
||||
{
|
||||
CompositeDataSource compositeDataSource = TimeSeriesModel.GenerateCompositeDataSource(profitMarginSeries);
|
||||
return compositeDataSource;
|
||||
}
|
||||
}
|
||||
public CompositeDataSource PE
|
||||
{
|
||||
get
|
||||
{
|
||||
CompositeDataSource compositeDataSource = TimeSeriesModel.GenerateCompositeDataSource(peSeries);
|
||||
return compositeDataSource;
|
||||
}
|
||||
}
|
||||
public CompositeDataSource BVPS
|
||||
{
|
||||
get
|
||||
{
|
||||
CompositeDataSource compositeDataSource = TimeSeriesModel.GenerateCompositeDataSource(bvpsSeries);
|
||||
return compositeDataSource;
|
||||
}
|
||||
}
|
||||
public CompositeDataSource EPS
|
||||
{
|
||||
get
|
||||
{
|
||||
CompositeDataSource compositeDataSource = TimeSeriesModel.GenerateCompositeDataSource(epsSeries);
|
||||
return compositeDataSource;
|
||||
}
|
||||
}
|
||||
public CompositeDataSource FreeCashflow
|
||||
{
|
||||
get
|
||||
{
|
||||
CompositeDataSource compositeDataSource = TimeSeriesModel.GenerateCompositeDataSource(freeCashflowSeries, new ValueConverter(MilsConverter));
|
||||
return compositeDataSource;
|
||||
}
|
||||
}
|
||||
public CompositeDataSource OperatingCashflow
|
||||
{
|
||||
get
|
||||
{
|
||||
CompositeDataSource compositeDataSource = TimeSeriesModel.GenerateCompositeDataSource(operatingCashflowSeries, new ValueConverter(MilsConverter));
|
||||
return compositeDataSource;
|
||||
}
|
||||
}
|
||||
public CompositeDataSource OperatingIncome
|
||||
{
|
||||
get
|
||||
{
|
||||
CompositeDataSource compositeDataSource = TimeSeriesModel.GenerateCompositeDataSource(operatingIncomeSeries, new ValueConverter(MilsConverter));
|
||||
return compositeDataSource;
|
||||
}
|
||||
}
|
||||
public CompositeDataSource Revenue
|
||||
{
|
||||
get
|
||||
{
|
||||
CompositeDataSource compositeDataSource = TimeSeriesModel.GenerateCompositeDataSource(revenueSeries, new ValueConverter(MilsConverter));
|
||||
return compositeDataSource;
|
||||
}
|
||||
}
|
||||
public CompositeDataSource QuarterlyRevenue
|
||||
{
|
||||
get
|
||||
{
|
||||
CompositeDataSource compositeDataSource = TimeSeriesModel.GenerateCompositeDataSource(quarterlyRevenueSeries, new ValueConverter(MilsConverter));
|
||||
return compositeDataSource;
|
||||
}
|
||||
}
|
||||
public CompositeDataSource Inventory
|
||||
{
|
||||
get
|
||||
{
|
||||
CompositeDataSource compositeDataSource = TimeSeriesModel.GenerateCompositeDataSource(inventorySeries, new ValueConverter(MilsConverter));
|
||||
return compositeDataSource;
|
||||
}
|
||||
}
|
||||
public CompositeDataSource QuarterlyInventory
|
||||
{
|
||||
get
|
||||
{
|
||||
CompositeDataSource compositeDataSource = TimeSeriesModel.GenerateCompositeDataSource(quarterlyInventorySeries, new ValueConverter(MilsConverter));
|
||||
return compositeDataSource;
|
||||
}
|
||||
}
|
||||
public CompositeDataSource Goodwill
|
||||
{
|
||||
get
|
||||
{
|
||||
CompositeDataSource compositeDataSource = TimeSeriesModel.GenerateCompositeDataSource(goodwillSeries, new ValueConverter(MilsConverter));
|
||||
return compositeDataSource;
|
||||
}
|
||||
}
|
||||
public CompositeDataSource QuarterlyGoodwill
|
||||
{
|
||||
get
|
||||
{
|
||||
CompositeDataSource compositeDataSource = TimeSeriesModel.GenerateCompositeDataSource(quarterlyGoodwillSeries, new ValueConverter(MilsConverter));
|
||||
return compositeDataSource;
|
||||
}
|
||||
}
|
||||
public CompositeDataSource ROIC
|
||||
{
|
||||
get
|
||||
{
|
||||
CompositeDataSource compositeDataSource = TimeSeriesModel.GenerateCompositeDataSource(roicSeries);
|
||||
return compositeDataSource;
|
||||
}
|
||||
}
|
||||
public CompositeDataSource ROA
|
||||
{
|
||||
get
|
||||
{
|
||||
CompositeDataSource compositeDataSource = TimeSeriesModel.GenerateCompositeDataSource(roaSeries);
|
||||
return compositeDataSource;
|
||||
}
|
||||
}
|
||||
public CompositeDataSource ROICWACC
|
||||
{
|
||||
get
|
||||
{
|
||||
CompositeDataSource compositeDataSource = TimeSeriesModel.GenerateCompositeDataSource(combinedSeries);
|
||||
return compositeDataSource;
|
||||
}
|
||||
}
|
||||
public CompositeDataSource WorkingCapital
|
||||
{
|
||||
get
|
||||
{
|
||||
CompositeDataSource compositeDataSource = TimeSeriesModel.GenerateCompositeDataSource(workingCapitalSeries, new ValueConverter(MilsConverter));
|
||||
return compositeDataSource;
|
||||
}
|
||||
}
|
||||
public CompositeDataSource NetIncomeAvailableToCommonShareholders
|
||||
{
|
||||
get
|
||||
{
|
||||
CompositeDataSource compositeDataSource = TimeSeriesModel.GenerateCompositeDataSource(netIncomeAvailableToCommonShareholdersSeries);
|
||||
return compositeDataSource;
|
||||
}
|
||||
}
|
||||
public CompositeDataSource DividendLoad
|
||||
{
|
||||
get
|
||||
{
|
||||
CompositeDataSource compositeDataSource = DividendLoadModel.GenerateCompositeDataSource(dividendLoadSeries);
|
||||
return compositeDataSource;
|
||||
}
|
||||
}
|
||||
public CompositeDataSource DebtToEquity
|
||||
{
|
||||
get
|
||||
{
|
||||
CompositeDataSource compositeDataSource = TimeSeriesModel.GenerateCompositeDataSource(debtToEquitySeries);
|
||||
return compositeDataSource;
|
||||
}
|
||||
}
|
||||
// **************************************************************************************************
|
||||
private TimeSeriesCollection CreateROICWACCSeries()
|
||||
{
|
||||
TimeSeriesCollection combinedSeriesCollection=new TimeSeriesCollection();
|
||||
if(null==roicSeries||0==roicSeries.Count)return combinedSeriesCollection;
|
||||
foreach(TimeSeriesElement roicSeriesElement in roicSeries)
|
||||
{
|
||||
double wacc=DCFGenerator.CalculateWACC(roicSeriesElement.Symbol,roicSeriesElement.AsOf);
|
||||
if(double.IsNaN(wacc))continue;
|
||||
TimeSeriesElement timeSeriesElement=new TimeSeriesElement();
|
||||
timeSeriesElement.Symbol=roicSeriesElement.Symbol;
|
||||
timeSeriesElement.AsOf=roicSeriesElement.AsOf;
|
||||
timeSeriesElement.Value=roicSeriesElement.Value-(wacc*100.00);
|
||||
combinedSeriesCollection.Add(timeSeriesElement);
|
||||
}
|
||||
return combinedSeriesCollection;
|
||||
}
|
||||
public double MilsConverter(double value)
|
||||
{
|
||||
return value / 1000000;
|
||||
}
|
||||
// **********************************************************************************************
|
||||
public String CompanyName
|
||||
{
|
||||
get { return companyName; }
|
||||
}
|
||||
public override String Title
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == CompanyName || null == SelectedSymbol) return "";
|
||||
return CompanyName + " (" + SelectedSymbol + " )";
|
||||
}
|
||||
}
|
||||
// **********************************************************************************************
|
||||
public List<String> Symbols
|
||||
{
|
||||
get
|
||||
{
|
||||
return symbols;
|
||||
}
|
||||
}
|
||||
//**************************************************************************************************************
|
||||
public String SelectedSymbol
|
||||
{
|
||||
get { return selectedSymbol; }
|
||||
set
|
||||
{
|
||||
if (value == selectedSymbol || String.IsNullOrEmpty(value)) return;
|
||||
selectedSymbol = value;
|
||||
base.OnPropertyChanged("SelectedSymbol");
|
||||
}
|
||||
}
|
||||
public List<String> WatchListNames
|
||||
{
|
||||
get
|
||||
{
|
||||
return watchLists;
|
||||
}
|
||||
set { ;}
|
||||
}
|
||||
public String SelectedWatchList
|
||||
{
|
||||
get { return selectedWatchList; }
|
||||
set { selectedWatchList = value; base.OnPropertyChanged("SelectedWatchList"); }
|
||||
}
|
||||
//**************************************************************************************************************
|
||||
private void Refresh()
|
||||
{
|
||||
base.OnPropertyChanged("SelectedSymbol");
|
||||
}
|
||||
private bool CanRefresh
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
public ICommand RefreshCommand
|
||||
{
|
||||
get
|
||||
{
|
||||
if (refreshCommand == null)
|
||||
{
|
||||
refreshCommand = new RelayCommand(param => this.Refresh(), param => this.CanRefresh);
|
||||
// portfolioHoldings.ForEach(portfolioHolding => new Action(delegate() { portfolioHolding.WeightExp = portfolioHolding.Exposure / totalPortfolioExposure; }).Invoke());
|
||||
|
||||
//if (movingAverageCommand == null)
|
||||
//{
|
||||
// movingAverageCommand = new RelayCommand(param => this.DisplayMovingAverageCommand(), param => { return null != selectedGainLossSummaryItem && null != selectedGainLossSummaryItem.Symbol; });
|
||||
//}
|
||||
|
||||
|
||||
}
|
||||
return refreshCommand;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
368
ViewModels/MACDViewModel.cs
Normal file
@@ -0,0 +1,368 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Collections.Specialized;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
using MarketData;
|
||||
using MarketData.Utils;
|
||||
using MarketData.MarketDataModel;
|
||||
using MarketData.Generator;
|
||||
using MarketData.DataAccess;
|
||||
using TradeBlotter.DataAccess;
|
||||
using TradeBlotter.Model;
|
||||
using TradeBlotter.Command;
|
||||
using Microsoft.Research.DynamicDataDisplay.DataSources;
|
||||
|
||||
namespace TradeBlotter.ViewModels
|
||||
{
|
||||
public class MACDViewModel : WorkspaceViewModel
|
||||
{
|
||||
private MACDFastSlowSignals macdFastSlowSignals;
|
||||
public enum SignalIndicator{SlowWeakSell=0,SlowWeakBuy,SlowStrongSell,SlowStrongBuy,FastWeakBuy,FastWeakSell,FastStrongBuy,FastStrongSell};
|
||||
Signals[] signals=new Signals[((int)SignalIndicator.FastStrongSell)+1];
|
||||
private String symbol;
|
||||
private String companyName;
|
||||
private List<String> symbols;
|
||||
private List<String> watchLists;
|
||||
private String selectedWatchList;
|
||||
private RelayCommand refreshCommand;
|
||||
private List<Int32> dayCounts;
|
||||
private Int32 selectedDayCount;
|
||||
private bool isLegendVisible = true;
|
||||
private bool busyIndicator = false;
|
||||
|
||||
public MACDViewModel()
|
||||
{
|
||||
base.DisplayName = "MACDView";
|
||||
watchLists = WatchListDA.GetWatchLists();
|
||||
watchLists.Insert(0, Constants.CONST_ALL);
|
||||
selectedWatchList = watchLists.Find(x => x.Equals("Valuations"));
|
||||
symbols = WatchListDA.GetWatchList(selectedWatchList);
|
||||
dayCounts = new List<Int32>();
|
||||
dayCounts.Add(60);
|
||||
dayCounts.Add(90);
|
||||
dayCounts.Add(180);
|
||||
dayCounts.Add(360);
|
||||
dayCounts.Add(720);
|
||||
dayCounts.Add(1440);
|
||||
dayCounts.Add(3600);
|
||||
selectedDayCount = dayCounts[1];
|
||||
PropertyChanged += OnMACDViewModelPropertyChanged;
|
||||
}
|
||||
public override SaveParameters GetSaveParameters()
|
||||
{
|
||||
SaveParameters saveParams = new SaveParameters();
|
||||
if (null == symbol) return null;
|
||||
saveParams.Add(new KeyValuePair<String, String>("Type", GetType().Namespace + "." + GetType().Name));
|
||||
saveParams.Add(new KeyValuePair<String, String>("SelectedSymbol", symbol));
|
||||
saveParams.Add(new KeyValuePair<String, String>("SelectedWatchList", selectedWatchList));
|
||||
saveParams.Add(new KeyValuePair<String, String>("SelectedDayCount", selectedDayCount.ToString()));
|
||||
saveParams.Add(new KeyValuePair<String, String>("IsLegendVisible", isLegendVisible.ToString()));
|
||||
return saveParams;
|
||||
}
|
||||
public override void SetSaveParameters(SaveParameters saveParameters)
|
||||
{
|
||||
try
|
||||
{
|
||||
symbol = (from KeyValuePair<String, String> item in saveParameters where item.Key.Equals("SelectedSymbol") select item).FirstOrDefault().Value;
|
||||
selectedWatchList = (from KeyValuePair<String, String> item in saveParameters where item.Key.Equals("SelectedWatchList") select item).FirstOrDefault().Value;
|
||||
base.OnPropertyChanged("SelectedWatchList");
|
||||
selectedDayCount = Int32.Parse((from KeyValuePair<String, String> item in saveParameters where item.Key.Equals("SelectedDayCount") select item).FirstOrDefault().Value);
|
||||
try { isLegendVisible = Boolean.Parse((from KeyValuePair<String, String> item in saveParameters where item.Key.Equals("IsLegendVisible") select item).FirstOrDefault().Value); }
|
||||
catch (Exception exception)
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Exception:{0}",exception.ToString()));
|
||||
}
|
||||
Referer=saveParameters.Referer;
|
||||
base.OnPropertyChanged("SelectedSymbol");
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Exception:{0}",exception.ToString()));
|
||||
}
|
||||
}
|
||||
public override bool CanPersist()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public bool BusyIndicator
|
||||
{
|
||||
get { return busyIndicator; }
|
||||
set
|
||||
{
|
||||
busyIndicator = value;
|
||||
base.OnPropertyChanged("BusyIndicator");
|
||||
}
|
||||
}
|
||||
private void OnMACDViewModelPropertyChanged(object sender, PropertyChangedEventArgs eventArgs)
|
||||
{
|
||||
if (eventArgs.PropertyName.Equals("SelectedSymbol")||(eventArgs.PropertyName.Equals("SelectedDayCount")&&null!=symbol))
|
||||
{
|
||||
BusyIndicator = true;
|
||||
Task workerTask = Task.Factory.StartNew(() =>
|
||||
{
|
||||
base.DisplayName = "MACD (" + symbol + ")";
|
||||
base.OnPropertyChanged("DisplayName");
|
||||
base.OnPropertyChanged("Title");
|
||||
macdFastSlowSignals = MACDGenerator.GenerateMACD(symbol, selectedDayCount);
|
||||
|
||||
signals[(int)SignalIndicator.SlowWeakSell]=macdFastSlowSignals.SlowCondensedSignals.WeakSellSignals;
|
||||
signals[(int)SignalIndicator.SlowWeakBuy]=macdFastSlowSignals.SlowCondensedSignals.WeakBuySignals;
|
||||
signals[(int)SignalIndicator.SlowStrongSell]=macdFastSlowSignals.SlowCondensedSignals.StrongSellSignals;
|
||||
signals[(int)SignalIndicator.SlowStrongBuy]=macdFastSlowSignals.SlowCondensedSignals.StrongBuySignals;
|
||||
signals[(int)SignalIndicator.FastWeakSell]=macdFastSlowSignals.FastCondensedSignals.WeakSellSignals;
|
||||
signals[(int)SignalIndicator.FastWeakBuy]=macdFastSlowSignals.FastCondensedSignals.WeakBuySignals;
|
||||
signals[(int)SignalIndicator.FastStrongSell]=macdFastSlowSignals.FastCondensedSignals.StrongSellSignals;
|
||||
signals[(int)SignalIndicator.FastStrongBuy]=macdFastSlowSignals.FastCondensedSignals.StrongBuySignals;
|
||||
|
||||
companyName = PricingDA.GetNameForSymbol(symbol);
|
||||
});
|
||||
workerTask.ContinueWith((continuation) =>
|
||||
{
|
||||
BusyIndicator = false;
|
||||
base.OnPropertyChanged("SignalSlow");
|
||||
base.OnPropertyChanged("MACDSlow");
|
||||
base.OnPropertyChanged("SignalFast");
|
||||
base.OnPropertyChanged("MACDFast");
|
||||
|
||||
base.OnPropertyChanged("MACDFastWeakBuy");
|
||||
base.OnPropertyChanged("MACDFastStrongBuy");
|
||||
base.OnPropertyChanged("MACDFastWeakSell");
|
||||
base.OnPropertyChanged("MACDFastStrongSell");
|
||||
base.OnPropertyChanged("MACDSlowWeakBuy");
|
||||
base.OnPropertyChanged("MACDSlowStrongBuy");
|
||||
base.OnPropertyChanged("MACDSlowWeakSell");
|
||||
base.OnPropertyChanged("MACDSlowStrongSell");
|
||||
|
||||
base.OnPropertyChanged("TitleSlow");
|
||||
base.OnPropertyChanged("TitleFast");
|
||||
base.OnPropertyChanged("LegendVisible");
|
||||
});
|
||||
}
|
||||
else if (eventArgs.PropertyName.Equals("SelectedWatchList"))
|
||||
{
|
||||
if (selectedWatchList.Equals(Constants.CONST_ALL)) symbols = PricingDA.GetSymbols();
|
||||
else symbols = WatchListDA.GetWatchList(selectedWatchList);
|
||||
base.OnPropertyChanged("Symbols");
|
||||
}
|
||||
}
|
||||
// ****************************************************** C O M P O S I T E S O U R C E S S I G N A L S B U Y S / S E L L S****************************************************
|
||||
// Slow buy/sell signal markers
|
||||
public CompositeDataSource MACDSlowWeakBuy
|
||||
{
|
||||
get
|
||||
{
|
||||
if(null==signals||0==signals.Length||null==macdFastSlowSignals)return null;
|
||||
CompositeDataSource compositeDataSource = MACDModel.Signals(signals[(int)SignalIndicator.SlowWeakBuy],macdFastSlowSignals.MinSlowMACD);
|
||||
return compositeDataSource;
|
||||
}
|
||||
}
|
||||
public CompositeDataSource MACDSlowStrongBuy
|
||||
{
|
||||
get
|
||||
{
|
||||
if(null==signals||0==signals.Length||null==macdFastSlowSignals)return null;
|
||||
CompositeDataSource compositeDataSource = MACDModel.Signals(signals[(int)SignalIndicator.SlowStrongBuy],macdFastSlowSignals.MinSlowMACD);
|
||||
return compositeDataSource;
|
||||
}
|
||||
}
|
||||
public CompositeDataSource MACDSlowWeakSell
|
||||
{
|
||||
get
|
||||
{
|
||||
if(null==signals||0==signals.Length||null==macdFastSlowSignals)return null;
|
||||
CompositeDataSource compositeDataSource = MACDModel.Signals(signals[(int)SignalIndicator.SlowWeakSell],macdFastSlowSignals.MinSlowMACD);
|
||||
return compositeDataSource;
|
||||
}
|
||||
}
|
||||
public CompositeDataSource MACDSlowStrongSell
|
||||
{
|
||||
get
|
||||
{
|
||||
if(null==signals||0==signals.Length||null==macdFastSlowSignals)return null;
|
||||
CompositeDataSource compositeDataSource = MACDModel.Signals(signals[(int)SignalIndicator.SlowStrongSell],macdFastSlowSignals.MinSlowMACD);
|
||||
return compositeDataSource;
|
||||
}
|
||||
}
|
||||
// Fast buy/sell signal markers
|
||||
|
||||
public CompositeDataSource MACDFastWeakBuy
|
||||
{
|
||||
get
|
||||
{
|
||||
if(null==signals||0==signals.Length||null==macdFastSlowSignals)return null;
|
||||
CompositeDataSource compositeDataSource = MACDModel.Signals(signals[(int)SignalIndicator.FastWeakBuy],macdFastSlowSignals.MinFastMACD);
|
||||
return compositeDataSource;
|
||||
}
|
||||
}
|
||||
public CompositeDataSource MACDFastStrongBuy
|
||||
{
|
||||
get
|
||||
{
|
||||
if(null==signals||0==signals.Length||null==macdFastSlowSignals)return null;
|
||||
CompositeDataSource compositeDataSource = MACDModel.Signals(signals[(int)SignalIndicator.FastStrongBuy],macdFastSlowSignals.MinFastMACD);
|
||||
return compositeDataSource;
|
||||
}
|
||||
}
|
||||
public CompositeDataSource MACDFastWeakSell
|
||||
{
|
||||
get
|
||||
{
|
||||
if(null==signals||0==signals.Length||null==macdFastSlowSignals)return null;
|
||||
CompositeDataSource compositeDataSource = MACDModel.Signals(signals[(int)SignalIndicator.FastWeakSell],macdFastSlowSignals.MinFastMACD);
|
||||
return compositeDataSource;
|
||||
}
|
||||
}
|
||||
public CompositeDataSource MACDFastStrongSell
|
||||
{
|
||||
get
|
||||
{
|
||||
if(null==signals||0==signals.Length||null==macdFastSlowSignals)return null;
|
||||
CompositeDataSource compositeDataSource = MACDModel.Signals(signals[(int)SignalIndicator.FastStrongSell],macdFastSlowSignals.MinFastMACD);
|
||||
return compositeDataSource;
|
||||
}
|
||||
}
|
||||
// *********************************************************** C O M P O S I T E S O U R C E S M A C D ****************************************************
|
||||
public CompositeDataSource SignalSlow
|
||||
{
|
||||
get
|
||||
{
|
||||
if(null==macdFastSlowSignals)return null;
|
||||
CompositeDataSource compositeDataSource = MACDModel.SignalSlow(macdFastSlowSignals);
|
||||
return compositeDataSource;
|
||||
}
|
||||
}
|
||||
public CompositeDataSource MACDSlow
|
||||
{
|
||||
get
|
||||
{
|
||||
if(null==macdFastSlowSignals)return null;
|
||||
CompositeDataSource compositeDataSource = MACDModel.MACDSlow(macdFastSlowSignals);
|
||||
return compositeDataSource;
|
||||
}
|
||||
}
|
||||
public CompositeDataSource SignalFast
|
||||
{
|
||||
get
|
||||
{
|
||||
if(null==macdFastSlowSignals)return null;
|
||||
CompositeDataSource compositeDataSource = MACDModel.SignalFast(macdFastSlowSignals);
|
||||
return compositeDataSource;
|
||||
}
|
||||
}
|
||||
public CompositeDataSource MACDFast
|
||||
{
|
||||
get
|
||||
{
|
||||
if(null==macdFastSlowSignals)return null;
|
||||
CompositeDataSource compositeDataSource = MACDModel.MACDFast(macdFastSlowSignals);
|
||||
return compositeDataSource;
|
||||
}
|
||||
}
|
||||
public String TitleSlow
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == companyName || null == macdFastSlowSignals || 0 == macdFastSlowSignals.Count) return "";
|
||||
return companyName + " (" + symbol + ") " + Utility.DateTimeToStringMMHDDHYYYY(macdFastSlowSignals.FromDate) + " Thru " + Utility.DateTimeToStringMMHDDHYYYY(macdFastSlowSignals.ThruDate)+" \nMACD(12,26,9)";
|
||||
}
|
||||
}
|
||||
public String TitleFast
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == companyName || null == macdFastSlowSignals || 0 == macdFastSlowSignals.Count) return "";
|
||||
return companyName + " (" + symbol + ") " + Utility.DateTimeToStringMMHDDHYYYY(macdFastSlowSignals.FromDate) + " Thru " + Utility.DateTimeToStringMMHDDHYYYY(macdFastSlowSignals.ThruDate)+" \nMACD(8,17,9)";
|
||||
}
|
||||
}
|
||||
public Boolean Visibility
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
public Boolean CheckBoxLegendVisible
|
||||
{
|
||||
get
|
||||
{
|
||||
return isLegendVisible;
|
||||
}
|
||||
set
|
||||
{
|
||||
isLegendVisible = value;
|
||||
base.OnPropertyChanged("CheckBoxLegendVisible");
|
||||
base.OnPropertyChanged("LegendVisible");
|
||||
}
|
||||
}
|
||||
public String LegendVisible
|
||||
{
|
||||
get
|
||||
{
|
||||
if (isLegendVisible) return "true";
|
||||
return "false";
|
||||
}
|
||||
set
|
||||
{
|
||||
isLegendVisible = Boolean.Parse(value);
|
||||
base.OnPropertyChanged("LegendVisible");
|
||||
}
|
||||
}
|
||||
public List<Int32> DayCounts
|
||||
{
|
||||
get { return dayCounts; }
|
||||
}
|
||||
public Int32 SelectedDayCount
|
||||
{
|
||||
get { return selectedDayCount; }
|
||||
set { selectedDayCount = value; base.OnPropertyChanged("SelectedDayCount"); }
|
||||
}
|
||||
public List<String> Symbols
|
||||
{
|
||||
get
|
||||
{
|
||||
return symbols;
|
||||
}
|
||||
}
|
||||
public String SelectedSymbol
|
||||
{
|
||||
get { return symbol; }
|
||||
set
|
||||
{
|
||||
if (value == symbol || String.IsNullOrEmpty(value)) return;
|
||||
symbol = value;
|
||||
base.OnPropertyChanged("SelectedSymbol");
|
||||
}
|
||||
}
|
||||
public List<String> WatchListNames
|
||||
{
|
||||
get
|
||||
{
|
||||
return watchLists;
|
||||
}
|
||||
set { ;}
|
||||
}
|
||||
public String SelectedWatchList
|
||||
{
|
||||
get { return selectedWatchList; }
|
||||
set { selectedWatchList = value; base.OnPropertyChanged("SelectedWatchList"); }
|
||||
}
|
||||
private void Refresh()
|
||||
{
|
||||
base.OnPropertyChanged("SelectedSymbol");
|
||||
}
|
||||
private Boolean CanRefresh
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
public ICommand RefreshCommand
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == refreshCommand) refreshCommand = new RelayCommand(param => Refresh(), param => CanRefresh);
|
||||
return refreshCommand;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||