Exemplo n.º 1
0
        public IActionResult SaveFinacialReportsDB(string symbol)
        {
            IEXHandler  webHandler = new IEXHandler();
            FinanceInfo tempFinfo  = new FinanceInfo();

            tempFinfo = webHandler.GetFinancials(symbol);
            if (tempFinfo.financials != null)
            {
                foreach (FinancialReport fr in tempFinfo.financials)
                {
                    fr.symbol = tempFinfo.symbol;

                    dbContext.FinancialReports.Add(fr);
                }
                dbContext.SaveChanges();
                ViewBag.dbSuccessComp = 1;
            }
            return(View("Index"));
        }
Exemplo n.º 2
0
        /****
        * The Chart action calls the GetChart method that returns 1 year's equities for the passed symbol.
        * A ViewModel CompaniesEquities containing the list of companies, prices, volumes, avg price and volume.
        * This ViewModel is passed to the Chart view.
        ****/
        public IActionResult Chart(string symbol)
        {
            //Set ViewBag variable first
            ViewBag.dbSuccessChart = 0;
            List <Equity> equities = new List <Equity>();

            if (symbol != null)
            {
                IEXHandler webHandler = new IEXHandler();
                equities = webHandler.GetChart(symbol);
                equities = equities.OrderBy(c => c.date).ToList(); //Make sure the data is in ascending order of date.
            }

            CompaniesEquities companiesEquities = getCompaniesEquitiesModel(equities);



            return(View(companiesEquities));
        }
        public IActionResult StockRecommendation()
        {
            dbContext.Repositories.RemoveRange(dbContext.Repositories);
            //TODO: STOCK PICKING STRATEGY:
            List <Company>   companies  = dbContext.Companies.ToList();
            List <Financial> financials = new List <Financial>();

            foreach (Company company in companies)
            {
                IEXHandler webHandler = new IEXHandler();
                Financial  financial  = webHandler.getFinancial(company.symbol);
                financials.Add(financial);
            }

            //Filt out good stocks depend on the financial report data
            financials = financials.OrderByDescending(f => f.operatingRevenue).ToList().GetRange(0, 15);
            financials = financials.OrderByDescending(f => f.totalAssets).ToList().GetRange(0, 10);
            financials = financials.OrderByDescending(f => f.cashFlow).ToList().GetRange(0, 5);

            foreach (Financial finance in financials)
            {
                foreach (Company company in companies)
                {
                    if (finance.symbol == company.symbol)
                    {
                        IEXHandler    webHandler = new IEXHandler();
                        List <Equity> equities   = webHandler.GetChart(company.symbol);
                        string        Name       = company.name;
                        string        Type       = company.type;
                        string        Date       = equities.Last().date;
                        float         AvgPrice   = equities.Average(e => e.high);
                        int           Volume     = equities.Last().volume;
                        float         peRatio    = company.peRatio;

                        Repository repository = new Repository(company.symbol, Name, Date, Type, AvgPrice, Volume, peRatio);
                        dbContext.Repositories.Add(repository);
                    }
                }
            }
            dbContext.SaveChanges();

            return(View("MyRepository", dbContext.Repositories.ToList()));
        }
Exemplo n.º 4
0
        public IActionResult Compare(String[] symbols, String range, String parameter)
        {
            //Input: Comparing Parameter, Stocks to compare, Chart Range
            //Output: Symbols, Chart Data
            //String symbol = ViewData["symbol"].ToString();
            if (range == null)
            {
                range = "1m";
            }
            List <string> s = new List <string>();

            if (symbols.Length == 0)
            {
                s.Add("A");
                s.Add("AAPL");
                symbols = s.ToArray();
            }

            ViewData["range"]      = range;
            ViewData["symbols"]    = symbols;
            ViewData["param"]      = parameter;
            ViewBag.dbSuccessChart = 0;
            //SaveCompanies();
            List <Stock> Stocks = null;
            SortedList <String, List <Stock> > companyStocks = new SortedList <String, List <Stock> >();

            if (symbols.Length != 0)
            {
                for (int i = 0; i < symbols.Length; i++)
                {
                    IEXHandler webHandler = new IEXHandler();
                    String     symbol     = symbols[i];
                    Stocks = webHandler.GetChart(symbols[i], range);
                    Stocks = Stocks.OrderBy(c => c.date).ToList(); //Make sure the data is in ascending order of date.
                    companyStocks.Add(symbol, Stocks);
                }
            }

            CompareCompanies compareCompanies = getCompareCompaniesModel(companyStocks);

            return(View(compareCompanies));
            //return View();
        }
        public IActionResult SaveQuote(string symbol)
        {
            IEXHandler webHandler = new IEXHandler();
            Quote      quote      = webHandler.GetQuote(symbol);

            //List<Equity> equities = JsonConvert.DeserializeObject<List<Equity>>(TempData["Equities"].ToString());

            if (dbContext.Quotes.Where(c => c.symbol.Equals(quote.symbol)).Count() == 0)
            {
                quote.lastSaved = DateTime.Now;
                dbContext.Quotes.Add(quote);
            }


            dbContext.SaveChanges();
            ViewBag.dbSuccessChart = 1;

            return(View("GetQuote", getCompaniesQuoteModel(quote)));
        }
Exemplo n.º 6
0
        public IActionResult SaveFinancials(string symbol)
        {
            IEXHandler       webHandler = new IEXHandler();
            List <Financial> financials = webHandler.GetFinancials(symbol);

            foreach (Financial financial in financials)
            {
                if (dbContext.Financials.Where(c => c.reportDate.Equals(financial.reportDate)).Where(c => c.symbol.Equals(financial.symbol)).Count() == 0)
                {
                    dbContext.Financials.Add(financial);
                }
            }

            dbContext.SaveChanges();
            ViewBag.dbSuccessChart = 1;

            CompaniesFinancials companiesFinancials = getCompaniesFinancialsModel(financials);

            return(View("Financials", companiesFinancials));
        }
Exemplo n.º 7
0
/* Script to Get all Symbols into Database */

        public IActionResult PopulateSymbolsDB()
        {
            ViewBag.dbSucessComp = 0;
            IEXHandler     webHandler = new IEXHandler();
            List <Company> companies  = webHandler.GetSymbolsTotal();

            //List<Company> companies = JsonConvert.DeserializeObject<List<Company>>(TempData["Companies"].ToString());
            foreach (Company company in companies)
            {
                //Database will give PK constraint violation error when trying to insert record with existing PK.
                //So add company only if it doesnt exist, check existence using symbol (PK)
                if (dbContext.Companies.Where(c => c.symbol.Equals(company.symbol)).Count() == 0)
                {
                    dbContext.Companies.Add(company);
                }
            }
            dbContext.SaveChanges();
            ViewBag.dbSuccessComp = 1;
            return(View("Symbols", companies));
        }
Exemplo n.º 8
0
        public IActionResult Financials(string symbol)
        {
            PopulateGainers();
            CompaniesStatistics stat = new CompaniesStatistics();

            stat.Companies = dbContext.Gainers.ToList();
            if (symbol != null)
            {
                stat.symbol = symbol;
                IEXHandler webHandler = new IEXHandler();
                stat.financials = webHandler.getFinancials(symbol);
                foreach (FinancialsData data in stat.financials.financials)
                {
                    data.symbol = symbol;
                    dbContext.FinancialData.Add(data);
                }
            }
            dbContext.SaveChanges();
            return(View(stat));
        }
        /****
        * Saves the equities in database.
        ****/
        public IActionResult SaveCharts(string symbol)
        {
            IEXHandler    webHandler = new IEXHandler();
            List <Equity> equities   = webHandler.GetChart(symbol);

            //List<Equity> equities = JsonConvert.DeserializeObject<List<Equity>>(TempData["Equities"].ToString());
            foreach (Equity equity in equities)
            {
                if (dbContext.Equities.Where(c => c.date.Equals(equity.date)).Count() == 0)
                {
                    dbContext.Equities.Add(equity);
                }
            }

            dbContext.SaveChanges();
            ViewBag.dbSuccessChart = 1;

            CompaniesEquities companiesEquities = getCmpnyEqtMdll(equities);

            return(View("Chart", companiesEquities));
        }
Exemplo n.º 10
0
        public IActionResult SaveCompanies()
        {
            List <Company> companies  = new List <Company>();
            IEXHandler     webHandler = new IEXHandler();

            companies = webHandler.GetSymbols();
            companies = companies.OrderBy(c => c.symbol).ToList();
            foreach (Company company in companies)
            {
                if (dbContext.Companies.Where(c => c.symbol.Equals(company.symbol)).Count() == 0)
                {
                    dbContext.Companies.Add(company);
                }
            }
            dbContext.SaveChanges();
            List <Stock>    stocks          = webHandler.GetChart("A", "1m");
            CompaniesStocks companiesStocks = getCompaniesStocksModel(stocks);

            ViewData["message"] = "Companies refreshed successfully.";
            return(View("Index", companiesStocks));
        }
Exemplo n.º 11
0
        //TODO: Unfinished!!!
        public Recommendation GetRecommendationModel(List <Company> companies)
        {
            List <string> symbols  = new List <string>();
            List <Equity> equities = new List <Equity>();
            Dictionary <string, float[]>  chart = new Dictionary <string, float[]>();
            Dictionary <string, string[]> date  = new Dictionary <string, string[]>();

            foreach (Company company in companies)
            {
                symbols.Add(company.symbol);
            }
            foreach (string symbol in symbols)
            {
                IEXHandler webHandler = new IEXHandler();
                equities = webHandler.GetChart(symbol);
                equities = equities.OrderBy(c => c.date).ToList();

                //chart.Add(symbol, equities.)
            }

            return(new Recommendation(companies, chart, date));
        }
Exemplo n.º 12
0
        public IActionResult SaveCharts(string symbol)
        {
            IEXHandler   webHandler = new IEXHandler();
            List <Stock> stocks     = webHandler.GetChart(symbol, "1m");

            //List<Equity> equities = JsonConvert.DeserializeObject<List<Equity>>(TempData["Equities"].ToString());
            foreach (Stock stock in stocks)
            {
                if (dbContext.Stocks.Where(c => c.date.Equals(stock.date)).Count() == 0)
                {
                    dbContext.Stocks.Add(stock);
                }
            }

            dbContext.SaveChanges();
            ViewBag.dbSuccessChart = 1;

            CompaniesStocks companiesStocks = getCompaniesStocksModel(stocks);

            ViewData["message"] = "Chart saved successfully for " + symbol + " for 1 month.";
            return(View("Index", companiesStocks));
        }
Exemplo n.º 13
0
        public IActionResult Index(String symbol, String range)
        {
            //Input: User logged In?, Chart Range, Chart Parameters, Company Symbol
            //Output: Chart Data, Stock List, Top stocks, ButtonName-{Sign In, Account}
            //ViewData["symbol"] = "aapl";

            //String symbol = ViewData["symbol"].ToString();
            if (range == null)
            {
                range = "1m";
            }
            if (symbol == null)
            {
                symbol = "A";
            }

            ViewData["range"]  = range;
            ViewData["symbol"] = symbol;
            String cookie = Request.Cookies["range"];

            if (Request.Cookies["user"] != null)
            {
            }
            ViewData["Account"]    = "Sign In";
            ViewBag.dbSuccessChart = 0;
            //SaveCompanies();
            List <Stock> Stocks = null;

            if (symbol != null)
            {
                IEXHandler webHandler = new IEXHandler();
                Stocks = webHandler.GetChart(symbol, range);
                /*Stocks = Stocks.OrderBy(c => c.date).ToList();*/ //Make sure the data is in ascending order of date.
            }

            CompaniesStocks companiesStocks = getCompaniesStocksModel(Stocks);

            return(View(companiesStocks));
        }
Exemplo n.º 14
0
        /****
        * The Chart action calls the GetaMonthEquitiesforSymbol method that returns 1 month's equities for the passed symbol.
        * A getRecommendationCompaniesEquitiesModel method returns ViewModel CompaniesEquities containing the list of companies, prices, volumes, avg price,
        *  volume, maximum high price, minimum high price and Recommendation to Buy/Sell.
        * This ViewModel is passed to the Recommendation view.
        ****/
        public IActionResult Recommendation()
        {
            //Set ViewBag variable first
            ViewBag.dbSuccessChart = 0;

            CompaniesEquities recommendationEquity;
            List <Equity>     equities   = new List <Equity>();
            IEXHandler        webHandler = new IEXHandler();
            List <Company>    companies  = dbContext.Companies.ToList();

            if (companies.Count > 0)
            {
                foreach (Company company in companies)
                {
                    webHandler = new IEXHandler();
                    if (companiesEquities == null)
                    {
                        companiesEquities = new List <CompaniesEquities>();
                    }

                    if (companiesEquities.Where(c => c != null && c.Current.symbol.Equals(company.symbol)).Count() == 0)
                    {
                        equities = webHandler.GetaMonthEquitiesforSymbol(company.symbol);
                        equities = equities.OrderBy(c => c.date).ToList(); //Make sure the data is in ascending order of date.

                        recommendationEquity = getRecommendationCompaniesEquitiesModel(equities);
                        companiesEquities.Add(recommendationEquity);
                    }
                }

                companiesEquities = companiesEquities.OrderByDescending(o => o.AvgPrice).ToList();

                if (companiesEquities.Count > 5)
                {
                    companiesEquities = companiesEquities.GetRange(0, 5);
                }
            }
            return(View(companiesEquities));
        }
Exemplo n.º 15
0
        /****
        * Saves the Symbols in database.
        ****/
        public void PopulateSymbols()
        {
            IEXHandler     webHandler    = new IEXHandler();
            List <Company> companiesRes  = webHandler.GetSymbols();
            String         companiesData = JsonConvert.SerializeObject(companiesRes);
            List <Company> companies     = null;

            if (companiesData != "")
            {
                companies = JsonConvert.DeserializeObject <List <Company> >(companiesData);
            }

            foreach (Company company in companies)
            {
                //Database will give PK constraint violation error when trying to insert record with existing PK.
                //So add company only if it doesnt exist, check existence using symbol (PK)
                if (dbContext.Companies.Where(c => c.symbol.Equals(company.symbol)).Count() == 0)
                {
                    dbContext.Companies.Add(company);
                }
            }
            dbContext.SaveChanges();
        }
Exemplo n.º 16
0
        //public IActionResult CompareCharts(string symbol)
        //{
        //    List<Equity> equities = new List<Equity>();
        //    if (symbol != null)
        //    {
        //        IEXHandler webHandler = new IEXHandler();
        //        equities = webHandler.GetChart(symbol);
        //        equities = equities.OrderBy(c => c.date).ToList(); //Make sure the data is in ascending order of date.
        //    }

        //    //TODO: TEST WILL DELETE LATER!
        //    //Equity current = equities.Last();
        //    //string dates = string.Join(",", equities.Select(e => e.date));
        //    //string prices = string.Join(",", equities.Select(e => e.high));
        //    //string volumes = string.Join(",", equities.Select(e => e.volume / 1000000)); //Divide vol by million
        //    //float avgprice = equities.Average(e => e.high);
        //    //double avgvol = equities.Average(e => e.volume) / 1000000; //Divide volume by million
        //    //string open = string.Join(",", equities.Select(e => e.open));
        //    //string high = string.Join(",", equities.Select(e => e.high));
        //    //string low = string.Join(",", equities.Select(e => e.low));
        //    //string close = string.Join(",", equities.Select(e => e.close));
        //    //CompaniesEquities companiesEquities = new CompaniesEquities(newCompanies, equities.Last(), dates, prices, volumes, avgprice, avgvol, open, high, low, close);

        //    return View("Recommendation", companiesEquities);
        //}

        public IActionResult StockRecommendation()
        {
            //dbContext.Repositories.RemoveRange(dbContext.Repositories);
            //STOCK PICKING STRATEGY:
            List <Company>   companies  = dbContext.Companies.ToList();
            List <Financial> financials = new List <Financial>();

            foreach (Company company in companies)
            {
                IEXHandler webHandler = new IEXHandler();
                Financial  financial  = webHandler.getFinancial(company.symbol);
                financials.Add(financial);
            }

            //Filt out good stocks depend on the financial report data
            financials = financials.OrderByDescending(f => f.operatingRevenue).ToList().GetRange(0, 15);
            financials = financials.OrderByDescending(f => f.totalAssets).ToList().GetRange(0, 10);
            financials = financials.OrderByDescending(f => f.cashFlow).ToList().GetRange(0, 5);

            List <Company> newCompanies = new List <Company>();

            foreach (Financial finance in financials)
            {
                foreach (Company company in companies)
                {
                    if (finance.symbol == company.symbol)
                    {
                        newCompanies.Add(company);
                    }
                }
            }

            CompaniesEquities companiesEquities = new CompaniesEquities(newCompanies, null, "", "", "", 0, 0, "", "", "", "");

            return(View("Recommendation", companiesEquities));
        }