-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBestWorstStocks.cs
More file actions
63 lines (52 loc) · 2.53 KB
/
BestWorstStocks.cs
File metadata and controls
63 lines (52 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace StockDataVisualizer
{
public partial class BestWorstStocks : Form
{
private StockDataVisualizer parent;
private BindingList<Recommend> bestPerformingStock = new BindingList<Recommend>();
private BindingList<Recommend> worstPerformingStock = new BindingList<Recommend>();
public BestWorstStocks()
{
InitializeComponent();
}
public BestWorstStocks(StockDataVisualizer parent)
{
this.parent = parent;
InitializeComponent();
this.bestperfGrid.DataSource = bestPerformingStock;
this.worstPerfGrid.DataSource = worstPerformingStock;
var binding = new Binding("Text",bestPerformingStock,null);
this.bestperfGrid.DataBindings.Add(binding);
this.Activated += new EventHandler(BestWorstStocks_Activated);
}
void BestWorstStocks_Activated(object sender, EventArgs e)
{
BuildList();
}
private void BuildList()
{
Logger.Instance.Log("BestWorstStocks - Building List of Best & Worst performing stocks");
var stockList = ((StockDataVisualizer)this.parent).StockRepository;
var pickTopTwoBestPerformers = (from stk in stockList
where stk.MarketPrice > stk.Close
orderby stk.MarketPrice descending
select new Recommend() { Company = stk.Company, MarketPrice = stk.MarketPrice, Recommendation = "Buy", YesterdaysClosePrice = stk.Close, MarketOpenPrice = stk.Open }).Take(2).ToList();
var pickTopTwoWorstPerformers = (from stk in stockList
where stk.MarketPrice < stk.Close
orderby stk.MarketPrice ascending
select new Recommend() { Company = stk.Company, MarketPrice = stk.MarketPrice, Recommendation = "Sell", YesterdaysClosePrice = stk.Close, MarketOpenPrice = stk.Open}).Take(2).ToList();
bestPerformingStock.Clear();
pickTopTwoBestPerformers.ForEach(p => bestPerformingStock.Add(p));
worstPerformingStock.Clear();
pickTopTwoWorstPerformers.ForEach(p => worstPerformingStock.Add(p));
}
}
}