1
1
using System ;
2
- using System . Collections . Generic ;
3
- using System . Configuration ;
4
- using System . Diagnostics ;
5
2
using System . IO ;
6
3
using System . Threading . Tasks ;
7
4
using RussellScreener . DataAccess ;
@@ -18,32 +15,34 @@ public class Program {
18
15
/// <param name="args">Command-line arguments. Not used</param>
19
16
/// <returns>Task for async running</returns>
20
17
public static async Task Main ( string [ ] args ) {
21
- StockRepositoryManager manager = new StockRepositoryManager ( ) ;
22
-
23
- SixSwissManager swissManager = new SixSwissManager ( ) ;
24
- // StockRepository stockRepository = await swissManager.DownloadSwissStockInfos(@".\countries\switzerland\swiss-listings.csv");
25
-
26
- // manager.WriteStockRepositoryCache(stockRepository, swissManager.GetCacheFileName());
27
- var stockRepository = manager . ReadStockRepositoryFromCache ( swissManager . GetCacheFileName ( ) ) ;
28
-
29
- var screener = new Screener ( ) ;
30
- Console . WriteLine ( "Analyzing data..." ) ;
31
- var finalPortfolio = screener . PickStocks ( stockRepository ) ;
32
- string xlxsFilename = ConfigurationManager . AppSettings [ "ModelPortfolioExcelFile" ] ;
33
-
34
- ExcelManager excelManager = new ExcelManager ( ) ;
35
- excelManager . WriteExcelFile ( xlxsFilename , finalPortfolio , stockRepository . Stocks ) ;
18
+ Console . WriteLine ( "1. Russell 1000" ) ;
19
+ Console . WriteLine ( "2. Swiss Stocks" ) ;
20
+ Console . WriteLine ( "-- Other keys to Exit --" ) ;
21
+ var choice = Console . ReadKey ( ) . Key ;
22
+
23
+ BaseDataAccessManager manager = null ;
24
+ string xlsxFilename = null ;
25
+ if ( choice == ConsoleKey . D1 ) {
26
+ manager = new IexManager ( ) ;
27
+ xlsxFilename = "russell_portfolio.xlsx" ;
28
+ } else if ( choice == ConsoleKey . D2 ) {
29
+ manager = new SixSwissManager ( ) ;
30
+ xlsxFilename = "six_swiss_portfolio.xlsx" ;
31
+ } else {
32
+ return ;
33
+ }
36
34
37
- // await ApplyRussell1000( );
35
+ await Process ( manager , xlsxFilename ) ;
38
36
}
39
37
40
- private static async Task ApplyRussell1000 ( ) {
41
- IexManager iex = new IexManager ( ) ;
42
- var cacheName = iex . GetCacheFileName ( ) ;
38
+ private static async Task Process ( BaseDataAccessManager dataAccessManager , string outputXlsFilename ) {
39
+ var cacheName = dataAccessManager . GetCacheFileName ( ) ;
43
40
FileInfo cacheFileInfo = new FileInfo ( cacheName ) ;
44
41
45
- // Main workflow
46
- // 1. Load data from iShares (the Russell 100 current composition. See DownloadISharesComposition method)
42
+ Screener screener = new Screener ( ) ;
43
+
44
+ // Main workflow for Russell 1000. Workflows with other data access managers are similar.
45
+ // 1. Load data from iShares (the Russell 1000 current composition. See DownloadISharesComposition method)
47
46
// 2. Extract tickers
48
47
// 3. Load data from IEX for each ticker (metrics + company info)
49
48
// 4. Store these info into a "StockRepository" which is then saved on disk and used as a cache
@@ -52,8 +51,6 @@ private static async Task ApplyRussell1000() {
52
51
// 6. Apply the strategy rules, get a list of stocks for the portfolio
53
52
// 7. Generate an Excel file with results
54
53
55
- Screener screener = new Screener ( ) ;
56
-
57
54
bool refreshCache ;
58
55
if ( ! cacheFileInfo . Exists ) {
59
56
Console . WriteLine ( "No cache with stocks information exists." ) ;
@@ -65,14 +62,12 @@ private static async Task ApplyRussell1000() {
65
62
}
66
63
67
64
StockRepositoryManager manager = new StockRepositoryManager ( ) ;
68
-
69
65
StockRepository stockRepository ;
70
66
71
67
if ( refreshCache ) {
72
68
Console . WriteLine ( "Refreshing the cache. Download will start now, please wait..." ) ;
73
- iex . DownloadISharesComposition ( ETF_FILENAME ) ;
74
- List < string > tickers = iex . ExtractISharesTickers ( ETF_FILENAME ) ;
75
- stockRepository = await iex . DownloadAllStocksFromIex ( tickers ) ;
69
+
70
+ stockRepository = await dataAccessManager . Process ( ) ;
76
71
manager . WriteStockRepositoryCache ( stockRepository , cacheName ) ;
77
72
} else {
78
73
Console . WriteLine ( "Reading cache..." ) ;
@@ -81,19 +76,18 @@ private static async Task ApplyRussell1000() {
81
76
82
77
Console . WriteLine ( "Analyzing data..." ) ;
83
78
var finalPortfolio = screener . PickStocks ( stockRepository ) ;
84
- string xlxsFilename = ConfigurationManager . AppSettings [ "ModelPortfolioExcelFile" ] ;
85
79
86
80
ExcelManager excelManager = new ExcelManager ( ) ;
87
- excelManager . WriteExcelFile ( xlxsFilename , finalPortfolio , stockRepository . Stocks ) ;
81
+ excelManager . WriteExcelFile ( outputXlsFilename , finalPortfolio , stockRepository . Stocks ) ;
88
82
89
- Console . WriteLine ( $ "An excel file has been generated with your portfolio selection. Name: { xlxsFilename } ") ;
83
+ Console . WriteLine ( $ "An excel file has been generated with your portfolio selection. Name: { outputXlsFilename } ") ;
90
84
bool showExcel = AskQuestion ( "Do you want to open this Excel file now?" ) ;
91
85
if ( showExcel ) {
92
- Process . Start ( xlxsFilename ) ;
86
+ System . Diagnostics . Process . Start ( outputXlsFilename ) ;
93
87
}
94
88
95
89
Console . WriteLine ( ) ;
96
- Console . WriteLine ( "Press a key to close this application." ) ;
90
+ Console . WriteLine ( "Press Enter to close this application." ) ;
97
91
Console . ReadLine ( ) ;
98
92
}
99
93
@@ -109,12 +103,6 @@ public static bool AskQuestion(string question) {
109
103
110
104
#endregion Methods
111
105
112
- #region Fields
113
-
114
- const string ETF_FILENAME = "russell.csv" ;
115
-
116
-
117
- #endregion Fields
118
106
119
107
}
120
108
}
0 commit comments