Skip to content

Commit

Permalink
Update Status Bar when backend calls completed successfully
Browse files Browse the repository at this point in the history
  • Loading branch information
bleunguts committed Jan 29, 2024
1 parent 86734a7 commit 83c0f37
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions Shell/Screens/TradingSignals/SingleViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ namespace Shell.Screens.TradingSignals;
[Export(typeof(IScreen)), PartCreationPolicy(CreationPolicy.NonShared)]
public partial class SingleViewModel : Screen
{
private readonly IEventAggregator _eventAggregator;
private readonly IEventAggregator _events;
private readonly IGatewayApiClient _gatewayApiClient;

[ImportingConstructor]
public SingleViewModel(
IEventAggregator eventAggregator,
IGatewayApiClient gatewayApiClient)
{
_eventAggregator = eventAggregator;
_events = eventAggregator;
_gatewayApiClient = gatewayApiClient;

DisplayName = "Mean Reversion strategy (Backtesting)";
Expand Down Expand Up @@ -209,6 +209,8 @@ public async Task Compute()
YearlyPnLTable = new DataTable();
var pnls = await _gatewayApiClient.ComputeLongShortPnlMatrix(Ticker, FromDate, ToDate, Notional);
UpdateStatus($"ComputeLongShortPnlMatrix with {pnls.Count()} results received.");
var builder = new PnlRankingTableBuilder();
builder.SetRows(pnls);
PnLRankingTable = builder.Build();
Expand Down Expand Up @@ -238,7 +240,8 @@ static PnlRankingTableBuilder PnlRankingTableDefaults(string ticker, int movingW
public async void HurstCalc()
{
var input = await _gatewayApiClient.GetHurst(Ticker, FromDate, ToDate);

UpdateStatus($"Fetched Hurst value from Backend for ticker={Ticker} from {FromDate} to {ToDate}");

var l = input.Where(x => x.HasValue).Select(x => x.Value).ToList();
if(l.Count == 0)
{
Expand Down Expand Up @@ -295,6 +298,8 @@ private static (int movingWindow, double signalIn, double signalOut, bool IsRein
private async Task DisplayPnl(int movingWindow, double signalIn, double signalOut, bool IsReinvest, double pnl, double sharpe, int numTrades)
{
var strategyResults = await _gatewayApiClient.ComputeLongShortPnl(Ticker, FromDate, ToDate, movingWindow, Notional, signalIn, signalOut, _movingAverageImpl);
UpdateStatus($"ComputeLongShortPnl results received from Backend, {strategyResults.StrategyPnls.Count()} strategies received, {strategyResults.YearlyStrategyPnls.Count()} yearly pnl results received, {strategyResults.StrategyDrawdowns.Count()} drawdowns received.");

// main table populated
var builder2 = new PnLTableBuilder();
builder2.SetRows(strategyResults.StrategyPnls);
Expand All @@ -316,6 +321,8 @@ private async Task DisplayPriceAndSignalViewAsync(int movingWindow)
try
{
var smoothenedSignals = await _gatewayApiClient.GetMovingAverageSignals(Ticker, FromDate, ToDate, movingWindow, _movingAverageImpl);
UpdateStatus($"Fetched MovingAverageSignals from Backend, {smoothenedSignals.Count()} smoothened signals received, movingWindow={movingWindow}, movingAverageTyp={_movingAverageImpl}");

_signals = new BindableCollection<PriceSignal>(smoothenedSignals);

var priceChart = PlotPriceChart(_signals);
Expand Down Expand Up @@ -502,7 +509,10 @@ private void DisplayAccumulatedPnlAndDrawdownForStrategyView(IEnumerable<Strateg

return (series, title, yAxes);
}

private void UpdateStatus(string status)
{
_events.PublishOnUIThread(new ModelEvents(new List<object>(new object[] { status })));
}
static class DummyData
{
public static IEnumerable<MatrixStrategyPnl> DummyPnLRankingTable => new List<MatrixStrategyPnl>()
Expand Down

0 comments on commit 83c0f37

Please sign in to comment.