public void Snapshot(double fiat, double security, double securityPrice, double benchmarkPrice = 0) { if (benchmarkPrice == 0) { benchmarkPrice = securityPrice; } double portfolioValue = fiat + security * securityPrice; bool hasOne = Snapshots.Count > 0; var newSnapshot = new PortfolioSnapshot() { Time = DateTime.Now, Fiat = fiat, Security = security, SecurityPrice = securityPrice, PortfolioValue = portfolioValue, PL = Snapshots.Count > 0 ? portfolioValue / Snapshots.Last().PortfolioValue - 1 : 0.0, CumulativePL = hasOne ? portfolioValue / Snapshots.First().PortfolioValue - 1 : 0.0, BenchmarkPrice = benchmarkPrice, BenchmarkPL = hasOne ? benchmarkPrice / Snapshots.Last().BenchmarkPrice - 1 : 0.0, BenchmarkCumulativePL = hasOne ? benchmarkPrice / Snapshots.First().BenchmarkPrice - 1 : 0.0 }; Snapshots.Add(newSnapshot); SnapshotEvent?.Invoke(this, newSnapshot); CachedSharpeRatio = null; }
private void buttonCapture_Click(object sender, EventArgs e) { if (SnapshotEvent == null) { return; } HImage ho_Image = SnapshotEvent.Invoke(); int num = this._images.Count; this._images.Add(ho_Image); this.listBox1.Items.Add($"图像 {num + 1:d2}"); this.listBox1.SelectedIndex = num; }
private async void OnTick(object sender, EventArgs e) { _dispatcherTimer.Stop(); var getSnapshotCommandDto = new GetSnapshotAdminCommandDto(); var response = await _connection.DispatchCommandAsync <GetSnapshotAdminCommandResponseDto>(getSnapshotCommandDto, CancellationToken.None); var snapshotEvent = new SnapshotEvent { Snapshot = response }; _eventAggregator.PublishOnUIThread(snapshotEvent); _dispatcherTimer.Start(); }
private void ApplyEvent(SnapshotEvent e) { Id = e.Id; UpdatedAt = e.UpdatedAt; }