Add framework for BollingerBandView

This commit is contained in:
2025-06-13 16:54:40 -04:00
parent b337170c39
commit 9d7a18df54
13 changed files with 916 additions and 67 deletions

View File

@@ -0,0 +1,69 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Avalonia.Controls;
using Avalonia.Media;
using Avalonia.Platform.Storage;
using CommunityToolkit.Mvvm.Input;
using Eremex.AvaloniaUI.Controls;
using MarketData;
using MarketData.DataAccess;
using MarketData.Generator;
using MarketData.Generator.CMMomentum;
using MarketData.Generator.Interface;
using MarketData.Generator.Model;
using MarketData.MarketDataModel;
using MarketData.Utils;
using PortfolioManager.DataSeriesViewModels;
using PortfolioManager.Dialogs;
using PortfolioManager.Models;
using PortfolioManager.UIUtils;
using Position = MarketData.Generator.CMMomentum.Position;
namespace PortfolioManager.ViewModels
{
public partial class BollingerBandViewModel : WorkspaceViewModel
{
private bool isBusy = false;
public BollingerBandViewModel()
{
DisplayName = "BollingerBand View";
}
public bool IsBusy
{
get
{
return isBusy;
}
set
{
isBusy = value;
base.OnPropertyChanged("IsBusy");
}
}
// ******************************************************************* P E R S I S T E N C E ***************************************************
public override bool CanPersist()
{
return false;
}
public override SaveParameters GetSaveParameters()
{
return null;
}
public override void SetSaveParameters(SaveParameters saveParameters)
{
return;
}
}
}

View File

@@ -20,12 +20,13 @@ using MarketData.MarketDataModel.GainLoss;
using MarketData.Utils;
using PortfolioManager.DataSeriesViewModels;
using PortfolioManager.Models;
using PortfolioManager.UIUtils;
namespace PortfolioManager.ViewModels
{
public partial class GainLossViewModel : WorkspaceViewModel
{
private const String ALL = "{ALL}";
private const String ALL = UIConstants.CONST_ALL;
private enum Tasks { Accounts, SelectedSymbol, SelectedAccounts, LeastSquaresFit, UseDividends };
private Dictionary<Tasks, Semaphore> semaphorePool = new Dictionary<Tasks, Semaphore>();
private PortfolioTrades portfolioTrades = null;
@@ -54,7 +55,6 @@ namespace PortfolioManager.ViewModels
public GainLossViewModel()
{
DisplayName = "GainLossView";
semaphorePool.Add(Tasks.SelectedSymbol, new Semaphore(1, 1));
semaphorePool.Add(Tasks.SelectedAccounts, new Semaphore(1, 1));

View File

@@ -151,13 +151,6 @@ namespace PortfolioManager.ViewModels
HandleToggleReturnOrPercent();
}
// This is not currently being displayed
[RelayCommand]
public void Run()
{
RunCandidateGenerator();
}
[RelayCommand]
public async Task LoadFile()
{
@@ -285,36 +278,6 @@ namespace PortfolioManager.ViewModels
base.OnPropertyChanged("GraphTitle");
}
// This is not currently being dispplayed
private void RunCandidateGenerator()
{
try
{
if (null == sessionParams) return;
DateGenerator dateGenerator = new DateGenerator();
DateTime selectedDate = dateGenerator.FindPrevBusinessDay(sessionParams.TradeDate);
IsBusy = true;
Task workerTask = Task.Factory.StartNew(() =>
{
MGSHConfiguration localConfiguration = new MGSHConfiguration();
localConfiguration.MaxPositions = int.Parse(nvpDictionary["MaxPositions"].Value);
localConfiguration.HoldingPeriod = int.Parse(nvpDictionary["HoldingPeriod"].Value);
MGSHMomentumCandidates candidates = MGSHMomentumGenerator.GenerateMomentumWithFallback(selectedDate, configuration == null ? localConfiguration : configuration);
momentumCandidates = new ObservableCollection<MGSHMomentumCandidate>();
foreach (MGSHMomentumCandidate momentumCandidate in candidates) momentumCandidates.Add(momentumCandidate);
});
workerTask.ContinueWith((continuation) =>
{
IsBusy = false;
base.OnPropertyChanged("AllItems");
base.OnPropertyChanged("Title");
});
}
finally
{
}
}
public async Task LoadTradeFile()
{
TopLevel topLevel = TopLevel.GetTopLevel(GetTopLevelWindow());

View File

@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Runtime.CompilerServices;
using System.Text;
using Avalonia.Threading;
using MarketData.Cache;
@@ -94,6 +95,7 @@ namespace PortfolioManager.ViewModels
{
return new List<CommandViewModel>()
{
new CommandViewModel("Bollinger Bands", new MyRelayCommand(ParamArrayAttribute => this.ViewBollingerBands())),
new CommandViewModel("Gain/Loss", new MyRelayCommand(ParamArrayAttribute => this.ViewGainLoss())),
new CommandViewModel("Momentum Model", new MyRelayCommand(ParamArrayAttribute => this.ViewMomentum())),
new CommandViewModel("MGSHMomentum Model", new MyRelayCommand(ParamArrayAttribute => this.ViewMGSHMomentum())),
@@ -101,18 +103,34 @@ namespace PortfolioManager.ViewModels
new CommandViewModel("CMTrend Model", new MyRelayCommand(ParamArrayAttribute => this.ViewCMTrend()))
};
}
private void ViewCMTrend()
private void ViewBollingerBands()
{
CMTrendViewModel workspace = null;
BollingerBandViewModel workspace = null;
if (null == workspace)
{
workspace = new CMTrendViewModel();
workspace = new BollingerBandViewModel();
workspace.WorkspaceInstantiator = InstantiateWorkspace;
workspace.Referer = GetReferal();
// AddMenuItem(workspace);
this.Workspaces.Add(workspace);
this.Workspaces.Add(workspace);
}
this.SetActiveWorkspace(workspace);
}
private void ViewCMTrend()
{
CMTrendViewModel workspace = null;
if (null == workspace)
{
workspace = new CMTrendViewModel();
workspace.WorkspaceInstantiator = InstantiateWorkspace;
workspace.Referer = GetReferal();
// AddMenuItem(workspace);
this.Workspaces.Add(workspace);
}
this.SetActiveWorkspace(workspace);
}
private void ViewGainLoss()
{
@@ -121,8 +139,9 @@ namespace PortfolioManager.ViewModels
{
workspace = new GainLossViewModel();
workspace.WorkspaceInstantiator = InstantiateWorkspace;
workspace.Referer = GetReferal();
// AddMenuItem(workspace);
this.Workspaces.Add(workspace);
this.Workspaces.Add(workspace);
}
this.SetActiveWorkspace(workspace);
}
@@ -134,6 +153,7 @@ namespace PortfolioManager.ViewModels
{
workspace = new MGSHMomentumViewModel();
workspace.WorkspaceInstantiator = InstantiateWorkspace;
workspace.Referer = GetReferal();
// AddMenuItem(workspace);
this.Workspaces.Add(workspace);
}
@@ -147,8 +167,9 @@ namespace PortfolioManager.ViewModels
{
workspace = new MomentumViewModel();
workspace.WorkspaceInstantiator = InstantiateWorkspace;
workspace.Referer = GetReferal();
// AddMenuItem(workspace);
this.Workspaces.Add(workspace);
this.Workspaces.Add(workspace);
}
this.SetActiveWorkspace(workspace);
}
@@ -160,9 +181,11 @@ namespace PortfolioManager.ViewModels
{
workspace = new CMMomentumViewModel();
workspace.WorkspaceInstantiator = InstantiateWorkspace;
workspace.Referer = GetReferal();
// AddMenuItem(workspace);
this.Workspaces.Add(workspace);
this.Workspaces.Add(workspace);
}
this.SetActiveWorkspace(workspace);
}
@@ -220,20 +243,26 @@ namespace PortfolioManager.ViewModels
SelectedIndex = itemIndex;
}
private WorkspaceViewModel GetReferal()
{
if (null == workspaces || 0 == workspaces.Count) return null;
return workspaces[workspaces.Count-1];
}
public int SelectedIndex
{
get
{
get
{
return selectedIndex;
}
set
{
selectedIndex = value;
TabIndexArgs args = new TabIndexArgs() { Index = selectedIndex };
OnIndexChangeEventHandler.Invoke(this, args);
base.OnPropertyChanged("SelectedIndex");
}
return selectedIndex;
}
set
{
selectedIndex = value;
TabIndexArgs args = new TabIndexArgs() { Index = selectedIndex };
OnIndexChangeEventHandler.Invoke(this, args);
base.OnPropertyChanged("SelectedIndex");
}
}
public void InstantiateWorkspace(SaveParameters saveParameters)
{

View File

@@ -2,7 +2,6 @@ using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -220,7 +219,6 @@ namespace PortfolioManager.ViewModels
}
}
public CompositeDataSource Data
{
get
@@ -493,7 +491,6 @@ namespace PortfolioManager.ViewModels
base.OnPropertyChanged("Title");
base.OnPropertyChanged("DisplayName");
base.OnPropertyChanged("AllPositions");
// base.OnPropertyChanged("CanMonitor");
base.OnPropertyChanged("CashBalance");
base.OnPropertyChanged("NonTradeableCash");
base.OnPropertyChanged("ModelExpectation");

View File

@@ -2,13 +2,10 @@
using System.IO;
using System.Collections.Generic;
using System.Collections.ObjectModel;
//using System.Windows.Data;
//using System.Windows.Forms;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
//using MarketData;
using System.Reflection;
using MarketData;
@@ -115,6 +112,7 @@ namespace PortfolioManager.ViewModels
for (int index = 0; index < workspaceViewModelPersistenceCollection.Count; index++)
{
WorkspaceViewModelPersistenceHolder workspaceViewModelPersistenceHolder = workspaceViewModelPersistenceCollection[index];
if (index > 0) workspaceViewModelPersistenceHolder.Workspace.Referer = workspaceViewModelPersistenceCollection[index - 1].Workspace;
workspaces.Add(workspaceViewModelPersistenceHolder.Workspace);
workspaceViewModelPersistenceHolder.Workspace.SetSaveParameters(workspaceViewModelPersistenceHolder.WorkspaceParameters);
if (index == workspaceViewModelPersistenceCollection.Count - 1)