Ejemplo n.º 1
0
        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;
        }
Ejemplo n.º 2
0
        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;
        }