public override void InitDictionary(string rootFolder, StockDictionary stockDictionary, bool download)
 {
     if (!stockDictionary.ContainsKey("Harpex"))
      {
     stockDictionary.Add("Harpex", new StockSerie("Harpex", "Harpex", StockSerie.Groups.INDICATOR, StockDataProvider.Harpex));
      }
 }
        public StockStrategyScannerDlg(StockDictionary stockDictionary, StockSerie.Groups stockGroup, StockSerie.StockBarDuration barDuration, string strategyName)
        {
            InitializeComponent();

             this.stockDictionary = stockDictionary;
             this.barDuration = barDuration;

             // Initialise group combo box
             groupComboBox.Items.AddRange(this.stockDictionary.GetValidGroupNames().ToArray());
             groupComboBox.SelectedItem = stockGroup.ToString();
             groupComboBox.SelectedValueChanged += new EventHandler(groupComboBox_SelectedValueChanged);

             // Initialise Strategy Combo box
             this.strategyComboBox.Items.Clear();
             List<string> strategyList = StrategyManager.GetStrategyList();
             foreach (string name in strategyList)
             {
            this.strategyComboBox.Items.Add(name);
             }
             this.strategyComboBox.SelectedItem = strategyName;
             this.strategyComboBox.SelectedValueChanged += new EventHandler(strategyComboBox_SelectedValueChanged);

             periodComboBox.SelectedIndex = 0;

             OnBarDurationChanged(barDuration);
        }
Example #3
0
 public StockHub(ScritchyBus bus, StockDictionary dict)
 {
     InitializeCommands();
     this.bus  = bus;
     this.dict = dict;
     bus.ApplyNewEventsToAllHandlers();
 }
Example #4
0
 public StockHub(ScritchyBus bus,StockDictionary dict)
 {
     InitializeCommands();
     this.bus = bus;
     this.dict = dict;
     bus.ApplyNewEventsToAllHandlers();
 }
 public CommentReportDlg(StockDictionary stockDictionary, GraphCloseControl graphCloseControl, StockSerie.Groups group)
 {
     InitializeComponent();
      this.stockDictionary = stockDictionary;
      this.graphCloseControl = graphCloseControl;
      this.stockGroup = group;
 }
        public StrategySimulatorDlg(StockDictionary stockDictionary, StockPortofolioList stockPortofolioList, string stockName)
        {
            InitializeComponent();

             // Initialize portofolio combo
             this.stockDictionary = stockDictionary;
             this.portofolioComboBox.Enabled = true;
             this.portofolioComboBox.Items.Clear();
             if (stockPortofolioList.Count == 0)
             {
            StockPortofolio portofolio = new StockPortofolio("SIMULATION");
            stockPortofolioList.Add(portofolio);
             }
             foreach (string name in stockPortofolioList.GetPortofolioNames())
             {
            this.portofolioComboBox.Items.Add(name);
             }
             this.portofolioComboBox.SelectedItem = this.portofolioComboBox.Items[0];

             // Initialize stock combo
             this.stockPortofolioList = stockPortofolioList;
             this.stockComboBox.Enabled = true;
             this.stockComboBox.Items.Clear();
             foreach (StockSerie stockSerie in stockDictionary.Values)
             {
            this.stockComboBox.Items.Add(stockSerie.StockName);
             }
             this.stockComboBox.SelectedItem = this.stockComboBox.Items[0];
        }
        public override void InitDictionary(string rootFolder, StockDictionary stockDictionary, bool download)
        {
            string line;
            string fileName = rootFolder + "\\GeneratedIndicator.txt";

            if (!Directory.Exists(rootFolder + FOLDER))
            {
                Directory.CreateDirectory(rootFolder + FOLDER);
            }
            if (!Directory.Exists(rootFolder + ARCHIVE_FOLDER))
            {
                Directory.CreateDirectory(rootFolder + ARCHIVE_FOLDER);
            }

            if (File.Exists(fileName))
            {
                // Parse GeneratedIndicator.txt file
                using (StreamReader sr = new StreamReader(fileName, true))
                {
                    sr.ReadLine(); // Skip first line
                    while (!sr.EndOfStream)
                    {
                        line = sr.ReadLine();
                        if (!line.StartsWith("#"))
                        {
                            string[] row = line.Split(',');
                            stockDictionary.Add(row[0], new StockSerie(row[0], row[0], (StockSerie.Groups)Enum.Parse(typeof(StockSerie.Groups), row[1]), StockDataProvider.Generated));
                        }
                    }
                }
            }
        }
        public StockbrokersOrderCreationDlg(StockPortofolio stockPortofolio, StockDictionary stockDictionary)
        {
            InitializeComponent();

             this.stockPortofolio = stockPortofolio;
             this.stockDictionary = stockDictionary;
        }
        public PortofolioDlg(StockDictionary stockDictionary, StockPortofolio stockPortofolio)
        {
            InitializeComponent();

             this.stockDictionary = stockDictionary;
             this.stockPortofolio = stockPortofolio;

             // Initialise list view
             InitializeListView();
        }
Example #10
0
        public OrderListDlg(StockDictionary stockDictionary, StockOrderList stockOrderList)
        {
            InitializeComponent();

             this.stockDictionary = stockDictionary;
             this.stockOrderList = stockOrderList;

             // Initialise view
             InitializeListView();
        }
        public EuronextDataProviderConfigDlg(StockDictionary stockDico)
        {
            InitializeComponent();

             this.dataProvider = new ABCDataProvider();
             this.stockDictionary = stockDico;

             this.step1GroupBox.Enabled = true;
             this.step2GroupBox.Enabled = false;

             // Init group combo box
             this.groupComboBox.Items.Clear();
             this.groupComboBox.Items.AddRange(stockDico.GetValidGroupNames().ToArray());

             string[] userGroups = { "USER1", "USER2", "USER3" };
             foreach (string group in userGroups)
             {
            if (!this.groupComboBox.Items.Contains(group))
            {
               this.groupComboBox.Items.Add(group);
            }
             }
             this.groupComboBox.SelectedItem = userGroups[0];

             // Init personal list view
             string fileName = Settings.Default.RootFolder + this.dataProvider.UserConfigFileName;
             if (File.Exists(fileName))
             {
            using (StreamReader sr = new StreamReader(fileName, true))
            {
               string line;
               while (!sr.EndOfStream)
               {
                  line = sr.ReadLine();
                  if (!line.StartsWith("#"))
                  {
                     string[] row = line.Split(';');

                     ListViewItem viewItem = new ListViewItem(row[0]);
                     viewItem.SubItems.Add(row[3]);  // Name is before code
                     viewItem.SubItems.Add(row[1]);
                     viewItem.SubItems.Add(row[4]);
                     this.personalListView.Items.Add(viewItem);
                  }
               }
            }
             }

             needRestart = false;

             mepMapping.Add("FR", "1");
             mepMapping.Add("LU", "2");
             mepMapping.Add("FI", "2");
             mepMapping.Add("BE", "3");
        }
        public override void InitDictionary(string rootFolder, StockDictionary stockDictionary, bool download)
        {
            SortedDictionary<string, string> cotIncludeList = new SortedDictionary<string, string>();
             string[] fields;

             string fileName = Settings.Default.RootFolder + @"\COT.cfg";
             if (File.Exists(fileName))
             {
            using (StreamReader sr = new StreamReader(fileName))
            {
               while (!sr.EndOfStream)
               {
                  fields = sr.ReadLine().Split(';');
                  if (!stockDictionary.CotDictionary.ContainsKey(fields[0]))
                  {
                     stockDictionary.CotDictionary.Add(fields[0], new CotSerie(fields[0]));
                     if (fields.Length > 1)
                     {
                        cotIncludeList.Add(fields[0], fields[1]);
                        if (stockDictionary.ContainsKey(fields[1]))
                        {
                           stockDictionary[fields[1]].CotSerie = stockDictionary.CotDictionary[fields[0]];
                        }
                     }
                  }
               }
            }
            // Check if download Needed
            CotSerie SP500CotSerie = stockDictionary["SP500"].CotSerie;
            if (SP500CotSerie != null)
            {
               if (SP500CotSerie.Initialise())
               {
                   DateTime lastDate = DateTime.Today.AddMonths(-2);
                      lastDate = SP500CotSerie.Keys.Last();
                  if ((DateTime.Today - lastDate) > new TimeSpan(10, 0, 0, 0, 0))
                  {
                     // Need to download new COT
                     StockWebHelper swh = new StockWebHelper();
                     bool upToDate = false;

                     NotifyProgress("Downloading commitment of traders data...");

                     if (swh.DownloadCOT(Settings.Default.RootFolder, ref upToDate))
                     {
                        NotifyProgress("Parsing commitment of traders data...");
                        ParseFullCotSeries(cotIncludeList, stockDictionary);
                     }
                  }
               }
            }
             }
        }
        public BatchStrategySimulatorDlg(StockDictionary stockDictionary, StockPortofolioList stockPortofolioList, StockSerie.Groups group, StockSerie.StockBarDuration barDuration, ToolStripProgressBar progressBar)
        {
            InitializeComponent();

             this.stockPortofolioList = stockPortofolioList;
             this.stockDictionary = stockDictionary;

             this.progressBar = progressBar;

             this.group = group;
             this.BarDuration = barDuration;
        }
 public static IStockPortfolioStrategy CreateStrategy(string name, List<StockSerie> stockSeries, StockPortofolio portfolio, StockDictionary stockDictionary)
 {
     IStockPortfolioStrategy strategy = null;
      if (strategyList == null)
      {
     GetStrategyList();
      }
      if (strategyList.Contains(name))
      {
     PortfolioStrategyManager sm = new PortfolioStrategyManager();
     strategy = (IStockPortfolioStrategy)sm.GetType().Assembly.CreateInstance("StockAnalyzer.StockPortfolioStrategy." + name);
     strategy.Initialise(stockSeries, portfolio, stockDictionary);
      }
      return strategy;
 }
 public override void InitDictionary(string rootFolder, StockDictionary stockDictionary, bool download)
 {
     AAIIDataProvider.stockDictionary = stockDictionary;
      if (!stockDictionary.ContainsKey(bearBullRatioName))
      {
     stockDictionary.Add(bearBullRatioName, new StockSerie(bearBullRatioName, bearBullRatioName, StockSerie.Groups.INDICATOR, StockDataProvider.AAII));
      }
      if (!stockDictionary.ContainsKey(bearBullLogRatioName))
      {
     stockDictionary.Add(bearBullLogRatioName, new StockSerie(bearBullLogRatioName, bearBullLogRatioName, StockSerie.Groups.INDICATOR, StockDataProvider.AAII));
      }
      if (!stockDictionary.ContainsKey(bullBearLogRatioName))
      {
     stockDictionary.Add(bullBearLogRatioName, new StockSerie(bullBearLogRatioName, bullBearLogRatioName, StockSerie.Groups.INDICATOR, StockDataProvider.AAII));
      }
 }
        public override void InitDictionary(string rootFolder, StockDictionary stockDictionary, bool download)
        {
            string line;
             string fileName = rootFolder + "\\RatioIndicator.txt";
             // Parse yahoo.cfg file// Create data folder if not existing
             if (!Directory.Exists(rootFolder + FOLDER))
             {
            Directory.CreateDirectory(rootFolder + FOLDER);
             }
             if (!Directory.Exists(rootFolder + ARCHIVE_FOLDER))
             {
            Directory.CreateDirectory(rootFolder + ARCHIVE_FOLDER);
             }

             if (File.Exists(fileName))
             {
            // Parse RatioIndicator.txt file
            using (StreamReader sr = new StreamReader(fileName, true))
            {
               sr.ReadLine(); // Skip first line
               while (!sr.EndOfStream)
               {
                  line = sr.ReadLine();
                  if (!line.StartsWith("#"))
                  {
                     string[] row = line.Split(',');
                     string serieName = row[0] + "/" + row[1];
                     if (!stockDictionary.ContainsKey(serieName))
                     {
                        if (!stockDictionary.ContainsKey(row[0]))
                        {
                           throw new Exception("Stock " + row[0] + " Not found, cannot calculate ratio");
                        }
                        StockSerie s1 = stockDictionary[row[0]];
                        if (!stockDictionary.ContainsKey(row[1]))
                        {
                           throw new Exception("Stock " + row[1] + " Not found, cannot calculate ratio");
                        }
                        StockSerie s2 = stockDictionary[row[1]];

                        stockDictionary.Add(serieName, new StockSerie(serieName, serieName, StockSerie.Groups.RATIO, StockDataProvider.Ratio));
                     }
                  }
               }
            }
             }
        }
Example #17
0
        internal void GetInventory(Entities edc, StockDictionary balanceStock, StockDictionary.StockValueKey key, double quantityOnStock)
        {
            switch (this.BatchStatus.Value)
            {
            case Linq.BatchStatus.Progress:
                double _portion = quantityOnStock / this.FGQuantity.Value;
                foreach (Material _mtx in this.Material(edc, false))
                {
                    _mtx.GetInventory(balanceStock, key, _portion);
                }
                break;

            case Linq.BatchStatus.Intermediate:
            case Linq.BatchStatus.Final:
                break;
            }
        }
        public PortfolioSimulatorDlg(StockDictionary stockDictionary, StockPortofolioList stockPortofolioList,
          string stockName, List<StockWatchList> watchLists)
        {
            InitializeComponent();

             foreach (var val in Enum.GetValues(typeof(UpdatePeriod)))
             {
            this.frequencyComboBox.Items.Add(val);
             }
             this.frequencyComboBox.SelectedIndex = 0;

             // Initialize portofolio combo
             this.stockDictionary = stockDictionary;
             this.portofolioComboBox.Enabled = true;
             this.stockPortofolioList = stockPortofolioList;
             this.portofolioComboBox.Items.Clear();
             if (stockPortofolioList.Count == 0)
             {
            StockPortofolio portofolio = new StockPortofolio("SIMULATION");
            stockPortofolioList.Add(portofolio);
             }
             foreach (string name in stockPortofolioList.GetPortofolioNames())
             {
            this.portofolioComboBox.Items.Add(name);
             }
             this.portofolioComboBox.SelectedItem = this.portofolioComboBox.Items[0];

             // Initialise input series
             this.watchLists = watchLists;
             this.portfolioStockSeries = new List<StockSerie>();
             foreach (string wlName in this.watchLists.Select(wl => wl.Name))
             {
            this.watchListComboBox.Items.Add(wlName);
             }
             this.watchListComboBox.SelectedIndex = 1;

             // Initialize Strategy combo
             this.strategyComboBox.Enabled = true;
             this.strategyComboBox.Items.Clear();
             foreach (string name in PortfolioStrategyManager.GetStrategyList())
             {
            this.strategyComboBox.Items.Add(name);
             }
             this.strategyComboBox.SelectedIndex = 0;
        }
        public StockScannerDlg(StockDictionary stockDictionary, StockSerie.Groups stockGroup, StockSerie.StockBarDuration barDuration, Dictionary<string, List<string>> theme)
        {
            InitializeComponent();

            this.stockDictionary = stockDictionary;
            this.barDuration = barDuration;

            // Initialise group combo box
            groupComboBox.Items.AddRange(this.stockDictionary.GetValidGroupNames().ToArray());
            groupComboBox.SelectedItem = stockGroup.ToString();
            groupComboBox.SelectedValueChanged += new EventHandler(groupComboBox_SelectedValueChanged);

            periodComboBox.SelectedIndex = 0;
            completeBarCheckBox.Checked = true;

            OnThemeChanged(theme);
            OnBarDurationChanged(barDuration);

            oneRadioButton.Checked = true;
        }
        public override void InitDictionary(string rootFolder, StockDictionary stockDictionary, bool download)
        {
            string line;
            string fileName = rootFolder + "\\BreadthCfg.txt";
            // Parse yahoo.cfg file// Create data folder if not existing
            if (!Directory.Exists(rootFolder + FOLDER))
            {
                Directory.CreateDirectory(rootFolder + FOLDER);
            }
            if (!Directory.Exists(rootFolder + ARCHIVE_FOLDER))
            {
                Directory.CreateDirectory(rootFolder + ARCHIVE_FOLDER);
            }

            BreadthDataProvider.stockDictionary = stockDictionary;
            if (File.Exists(fileName))
            {
                // Parse GeneratedIndicator.txt file
                using (StreamReader sr = new StreamReader(fileName, true))
                {
                    sr.ReadLine(); // Skip first line
                    while (!sr.EndOfStream)
                    {
                        line = sr.ReadLine();
                        if (!line.StartsWith("#"))
                        {
                            string[] row = line.Split(',');
                            string longName = row[0];
                            if (row[0] == "EQW.SRD") longName = "SRD";
                            if (row[0] == "EQW.CACALL") longName = "CACALL";

                            if (!stockDictionary.ContainsKey(longName))
                            {
                                stockDictionary.Add(longName, new StockSerie(longName, row[0], (StockSerie.Groups)Enum.Parse(typeof(StockSerie.Groups), row[1]), StockDataProvider.Breadth));
                            }
                        }
                    }
                }
            }
        }
        public GoogleIntradayDataProviderConfigDlg(StockDictionary stockDico)
        {
            InitializeComponent();

             this.dataProvider = new GoogleIntradayDataProvider();
             this.stockDictionary = stockDico;

             this.step1GroupBox.Enabled = true;
             this.step2GroupBox.Enabled = false;

             // Init group combo box
             this.groupComboBox.Items.Clear();
             this.groupComboBox.Items.Add("INTRADAY");
             this.groupComboBox.SelectedIndex = 0;

             // Init personal list view
             string fileName = Settings.Default.RootFolder + this.dataProvider.UserConfigFileName;
             if (File.Exists(fileName))
             {
            using (StreamReader sr = new StreamReader(fileName, true))
            {
               string line;
               while (!sr.EndOfStream)
               {
                  line = sr.ReadLine();
                  if (!line.StartsWith("#"))
                  {
                     string[] row = line.Split(',');

                     ListViewItem viewItem = new ListViewItem(row[0]);
                     viewItem.SubItems.Add(row[1]);
                     viewItem.SubItems.Add(row[2]);
                     this.personalListView.Items.Add(viewItem);
                  }
               }
            }
             }
             needRestart = false;
        }
        public SarexCustomTuningDlg(StockDictionary stockDictionary, StockSerie.Groups group, StockPortofolioList stockPortofolioList, ToolStripProgressBar progressBar)
        {
            InitializeComponent();

            this.stockPortofolioList = stockPortofolioList;
            this.stockDictionary = stockDictionary;
            this.group = group;

            // Initialize stock combo
            this.stockComboBox.Enabled = true;
            this.stockComboBox.Items.Clear();

            // Count the stock to simulate to initialise the progress bar
            foreach (StockSerie stockSerie in this.stockDictionary.Values)
            {
                if (!stockSerie.StockAnalysis.Excluded && !stockSerie.IsPortofolioSerie && stockSerie.BelongsToGroup(this.group))
                {
                    this.stockComboBox.Items.Add(stockSerie.StockName);
                }
            }
            this.stockComboBox.SelectedItem = this.stockComboBox.Items[0];

            this.progressBar = progressBar;
        }
        public override void InitDictionary(string rootFolder, StockDictionary stockDictionary, bool download)
        {
            string dirName = Settings.Default.RootFolder + SI_ARCHIVE_SUBFOLDER;
             if (!Directory.Exists(dirName))
             {
            Directory.CreateDirectory(dirName);
             }
             dirName = Settings.Default.RootFolder + SHORTINTEREST_FOLDER;
             if (!Directory.Exists(dirName))
             {
            Directory.CreateDirectory(dirName);
             }
             string fileName = Settings.Default.RootFolder + @"\ShortInterest.cfg";
             if (File.Exists(fileName))
             {
            using (StreamReader sr = new StreamReader(fileName))
            {
               while (!sr.EndOfStream)
               {
                  string[] fields = sr.ReadLine().Split(';');
                  if (stockDictionary.ContainsKey(fields[0]) && !stockDictionary.ShortInterestDictionary.ContainsKey(fields[0]))
                  {
                     NotifyProgress("Short Interest for " + fields[0]);
                     stockDictionary[fields[0]].HasShortInterest = true;

                     ShortInterestSerie siSerie = new ShortInterestSerie(fields[0]);
                     stockDictionary.ShortInterestDictionary.Add(fields[0], siSerie);

                     if (download)
                     {
                        this.DownloadDailyData(Settings.Default.RootFolder, stockDictionary[fields[0]]);
                     }
                  }
                  else
                  {
                     StockLog.Write("Short interest for not supported stock: " + fields[0]);
                  }
               }
            }
             }
        }
 public override void InitDictionary(string rootFolder, StockDictionary stockDictionary, bool download)
 {
 }
        private void ParseFullCotSeries(SortedDictionary<string, string> cotIncludeList, StockDictionary stockDictionary)
        {
            string line = string.Empty;

             string cotCfgFileName = Settings.Default.RootFolder + @"\COT.cfg";
             StreamWriter sw = null;

             if (!File.Exists(cotCfgFileName))
             {
            sw = new StreamWriter(cotCfgFileName, false);
             }
             try
             {
            // Shall be downloaded from http://www.cftc.gov/MarketReports/files/dea/history/fut_disagg_txt_2015.zip
            // Read new downloaded values
            string cotFolder = Settings.Default.RootFolder + COT_SUBFOLDER;
            string cotArchiveFolder = Settings.Default.RootFolder + COT_ARCHIVE_SUBFOLDER;
            string[] files = System.IO.Directory.GetFiles(cotFolder, "annual_*.txt");

            int cotLargeSpeculatorPositionLongIndex = 8;
            int cotLargeSpeculatorPositionShortIndex = 9;
            int cotLargeSpeculatorPositionSpreadIndex = 10;
            int cotCommercialHedgerPositionLongIndex = 11;
            int cotCommercialHedgerPositionShortIndex = 12;
            int cotSmallSpeculatorPositionLongIndex = 13;
            int cotSmallSpeculatorPositionShortIndex = 14;
            int cotOpenInterestIndex = 7;

            DateTime cotDate;
            float cotLargeSpeculatorPositionLong;
            float cotLargeSpeculatorPositionShort;
            float cotLargeSpeculatorPositionSpread;
            float cotCommercialHedgerPositionLong;
            float cotCommercialHedgerPositionShort;
            float cotSmallSpeculatorPositionLong;
            float cotSmallSpeculatorPositionShort;
            float cotOpenInterest;

            foreach (string fileName in files)
            {
               StreamReader sr = new StreamReader(fileName);
               CotValue readCotValue = null;
               CotSerie cotSerie = null;

               string cotSerieName = string.Empty;

               string[] row;
               sr.ReadLine();   // Skip header line
               while (!sr.EndOfStream)
               {
                  line = sr.ReadLine();
                  if (line == string.Empty)
                  {
                     continue;
                  }

                  string[] fields = ParseCOTLine(line);
                  cotSerieName = fields[0];

                  int index = cotSerieName.IndexOf(" - ");
                  if (index == -1)
                  {
                     continue;
                  }
                  cotSerieName = cotSerieName.Substring(0, index) + "_COT";

                  if (!cotIncludeList.Keys.Contains(cotSerieName))
                  {
                     continue;
                  }

                  row = fields;

                  cotLargeSpeculatorPositionLong = float.Parse(row[cotLargeSpeculatorPositionLongIndex]);
                  cotLargeSpeculatorPositionShort = float.Parse(row[cotLargeSpeculatorPositionShortIndex]);
                  cotLargeSpeculatorPositionSpread = float.Parse(row[cotLargeSpeculatorPositionSpreadIndex]);
                  cotCommercialHedgerPositionLong = float.Parse(row[cotCommercialHedgerPositionLongIndex]);
                  cotCommercialHedgerPositionShort = float.Parse(row[cotCommercialHedgerPositionShortIndex]);
                  cotSmallSpeculatorPositionLong = float.Parse(row[cotSmallSpeculatorPositionLongIndex]);
                  cotSmallSpeculatorPositionShort = float.Parse(row[cotSmallSpeculatorPositionShortIndex]);
                  cotOpenInterest = float.Parse(row[cotOpenInterestIndex]);

                  cotDate = DateTime.Parse(row[2], usCulture);

                  readCotValue = new CotValue(cotDate, cotLargeSpeculatorPositionLong, cotLargeSpeculatorPositionShort, cotLargeSpeculatorPositionSpread,
                      cotSmallSpeculatorPositionLong, cotSmallSpeculatorPositionShort,
                      cotCommercialHedgerPositionLong, cotCommercialHedgerPositionShort, cotOpenInterest);
                  if (stockDictionary.CotDictionary.ContainsKey(cotSerieName))
                  {
                     cotSerie = stockDictionary.CotDictionary[cotSerieName];
                     if (!cotSerie.ContainsKey(readCotValue.Date))
                     {
                        cotSerie.Add(readCotValue.Date, readCotValue);

                        // flag as not initialised as values have to be calculated
                        cotSerie.IsInitialised = false;
                     }
                  }
                  else
                  {
                     cotSerie = new CotSerie(cotSerieName);
                     stockDictionary.CotDictionary.Add(cotSerieName, cotSerie);
                     cotSerie.Add(readCotValue.Date, readCotValue);

                     // Create first COT cfg file, only if not existing.
                     if (sw != null) sw.WriteLine(cotSerieName + ";");

                     if (!string.IsNullOrWhiteSpace(cotIncludeList[cotSerieName]))
                     {
                        if (stockDictionary.ContainsKey(cotIncludeList[cotSerieName]))
                        {
                           stockDictionary[cotIncludeList[cotSerieName]].CotSerie = cotSerie;
                        }
                     }
                  }
               }
               sr.Close();
            }
            foreach (CotSerie cotSerie in stockDictionary.CotDictionary.Values)
            {
               string archiveFileName = cotArchiveFolder + @"\" + cotSerie.CotSerieName + ".csv";

               cotSerie.SaveToFile(archiveFileName);
            }
             }
             catch (System.Exception e)
             {
            MessageBox.Show(e.Message + "\r\r" + line, "Failed to parse COT file");
             }
             finally
             {
            if (sw != null) sw.Dispose();
             }
        }
        public void Initialize(StockDictionary stockDictionary)
        {
            this.stockDictionary = stockDictionary;

             totalIncome = 0.0f;
             currentStockValue = 0.0f;

             // Calculate current Stock Value
             Dictionary<string, int> nbActiveStock = this.OrderList.GetNbActiveStock();

             foreach (string stockName in nbActiveStock.Keys)
             {
            if (stockName != this.Name)
            {
               if (this.stockDictionary.ContainsKey(stockName))
               {
                  StockSerie stockSerie = this.stockDictionary[stockName];
                  if (stockSerie.Initialise())
                  {
                     currentStockValue += stockSerie.Values.Last().CLOSE * nbActiveStock[stockName];
                  }
               }
            }
             }

             // Calculate historic portofolio value
             foreach (StockOrder stockOrder in OrderList)
             {
            if (stockOrder.State == StockOrder.OrderStatus.Executed)
            {
               if (stockOrder.IsBuyOrder())
               {
                  totalIncome -= stockOrder.TotalCost;
               }
               else
               {
                  totalIncome += stockOrder.TotalCost;
               }
            }
             }
        }
Example #27
0
 public StockDictionaryHandler(StockDictionary instance)
 {
     this.instance = instance;
 }
        public override void InitDictionary(string rootFolder, StockDictionary stockDictionary, bool download)
        {
            // Create data folder if not existing
             if (!Directory.Exists(rootFolder + ARCHIVE_FOLDER))
             {
            Directory.CreateDirectory(rootFolder + ARCHIVE_FOLDER);
             }
             foreach (StockSerie.StockBarDuration duration in cacheDurations)
             {
            string durationFileName = rootFolder + ARCHIVE_FOLDER + "\\" + duration;
            if (!Directory.Exists(durationFileName))
            {
               Directory.CreateDirectory(durationFileName);
            }
             }

             if (!Directory.Exists(rootFolder + INTRADAY_FOLDER))
             {
            Directory.CreateDirectory(rootFolder + INTRADAY_FOLDER);
             }
             else
             {
            foreach (string file in Directory.GetFiles(rootFolder + INTRADAY_FOLDER))
            {
               if (File.GetLastWriteTime(file).Date != DateTime.Today)
               {
                  File.Delete(file);
               }
            }
             }

             // Parse CommerzBankDownload.cfg file
             this.needDownload = download;
             InitFromFile(rootFolder, stockDictionary, download, rootFolder + CONFIG_FILE);
             InitFromFile(rootFolder, stockDictionary, download, rootFolder + CONFIG_FILE_USER);
        }
        private void InitFromFile(string rootFolder, StockDictionary stockDictionary, bool download, string fileName)
        {
            string line;
             if (File.Exists(fileName))
             {
            using (StreamReader sr = new StreamReader(fileName, true))
            {
               sr.ReadLine(); // Skip first line
               while (!sr.EndOfStream)
               {
                  line = sr.ReadLine();
                  if (!line.StartsWith("#"))
                  {
                     string[] row = line.Split(',');
                     string stockName = row[2];
                     StockSerie stockSerie = new StockSerie(stockName, stockName, row[0], StockSerie.Groups.TURBO, StockDataProvider.CommerzBankIntraday);

                     if (!stockDictionary.ContainsKey(stockName))
                     {
                        stockDictionary.Add(stockName, stockSerie);
                     }
                     else
                     {
                        StockLog.Write("CommerzBank Entry: " + stockName + " already in stockDictionary");
                     }
                     if (download && this.needDownload)
                     {
                        this.needDownload = this.DownloadDailyData(rootFolder, stockSerie);
                     }
                  }
               }
            }
             }
        }
 public DialogResult ShowDialog(StockDictionary stockDico)
 {
     //CommerzBankIntradayDataProviderConfigDlg configDlg = new CommerzBankIntradayDataProviderConfigDlg(stockDico);
      //return configDlg.ShowDialog();
      throw new NotImplementedException();
 }
        public override void InitDictionary(string rootFolder, StockDictionary stockDictionary, bool download)
        {
            return;
             /*
             string line;
             string fileName = rootFolder + "\\RydexDownload.cfg";
             // Parse Rydex.cfg file// Create data folder if not existing
             if (!Directory.Exists(rootFolder + FOLDER))
             {
             Directory.CreateDirectory(rootFolder + FOLDER);
             }
             if (!Directory.Exists(rootFolder + ARCHIVE_FOLDER))
             {
             Directory.CreateDirectory(rootFolder + ARCHIVE_FOLDER);
             }

             // Parse RydexDownload.cfg file
             if (File.Exists(fileName))
             {
             using (StreamReader sr = new StreamReader(fileName, true))
             {
                 sr.ReadLine(); // Skip first line
                 while (!sr.EndOfStream)
                 {
                     line = sr.ReadLine();
                     if (!line.StartsWith("#"))
                     {
                         string[] row = line.Split(',');
                         StockSerie stockSerie = new StockSerie(row[1], row[0], (StockSerie.Groups)Enum.Parse(typeof(StockSerie.Groups), row[2]), StockDataProvider.Rydex);

                         if (!stockDictionary.ContainsKey(row[1]))
                         {
                             stockDictionary.Add(row[1], stockSerie);
                         }
                         else
                         {
                             StockLog.Write("Rydex Entry: " + row[1] + " already in stockDictionary");
                         }
                         if (download && this.needDownload)
                         {
                             this.DownloadDailyData(rootFolder, stockSerie);
                         }
                     }
                 }
             }
             }
             */
        }
 public override void InitDictionary(string rootFolder, StockDictionary stockDictionary, bool download)
 {
     // Create data folder if not existing
      if (!Directory.Exists(rootFolder + FOLDER))
      {
     Directory.CreateDirectory(rootFolder + FOLDER);
      }
      string[] names = new string[] { "PCR.EQUITY", "PCR.INDEX", "PCR.TOTAL", "PCR.VIX", "EVZ", "GVZ", "OVX" };
      StockSerie stockSerie = null;
      foreach (string name in names)
      {
     if (!stockDictionary.ContainsKey(name))
     {
        stockSerie = new StockSerie(name, name, StockSerie.Groups.INDICATOR, StockDataProvider.CBOE);
        stockDictionary.Add(name, stockSerie);
        if (download && this.needDownload)
        {
           this.DownloadDailyData(rootFolder, stockSerie);
        }
     }
      }
 }
Example #33
0
 public BusController(ICommandBus bus, StockDictionary readmodel, CommandHistory cmdhist)
 {
     this.bus       = bus;
     this.readmodel = readmodel;
     this.cmdhist   = cmdhist;
 }
Example #34
0
        public PalmaresDlg(StockDictionary stockDico, List<StockWatchList> watchLists, StockSerie.Groups selectedGroup, ToolStripProgressBar progressBar)
        {
            InitializeComponent();

             // Initialize dico
             StockDico = stockDico;
             WatchLists = watchLists;

             this.progressBar = progressBar;

             this.groupComboBox.Items.Clear();
             this.groupComboBox.Items.AddRange(stockDico.GetValidGroupNames().ToArray());
             this.groupComboBox.SelectedItem = selectedGroup.ToString();

             this.indicatorTextBox.Text = Settings.Default.MomentumIndicator;

             // Create an instance of a ListView column sorter and assign it to the ListView control.
             lvwColumnSorter = new ListViewColumnSorter();
             this.palmaresView.ListViewItemSorter = (IComparer)lvwColumnSorter;

             // Select default values
             this.untilCheckBox.Checked = false;
             this.untilDateTimePicker.Enabled = this.untilCheckBox.Checked;

             var stockList = stockDico.Values.Where(s => s.BelongsToGroup(selectedGroup));
             if (stockList.Count() > 0 && stockList.ElementAt(0).Initialise())
             {
            this.fromDateTimePicker.MaxDate = stockList.ElementAt(0).Keys.Last();
            DateTime fromDate =new DateTime(stockList.ElementAt(0).Keys.ElementAt(stockList.ElementAt(0).Keys.Count - 2).Year,1,1);
            this.fromDateTimePicker.Value = fromDate;
            this.untilDateTimePicker.Value = stockList.ElementAt(0).Keys.Last();
             }
             else
             {
            this.fromDateTimePicker.Value = System.DateTime.Today.AddYears(-1);
            this.fromDateTimePicker.MaxDate = System.DateTime.Today.AddDays(-1);
            this.untilDateTimePicker.Value = System.DateTime.Today;
             }
             previousFromDate = fromDateTimePicker.Value;
             previousUntilDate = untilDateTimePicker.Value;

             //
             InitializeListView();

             // Activate handlers
             this.fromDateTimePicker.CloseUp += new System.EventHandler(this.fromDateTimePicker_ValueChanged);
             this.fromDateTimePicker.LostFocus += new System.EventHandler(this.fromDateTimePicker_ValueChanged);
             this.untilDateTimePicker.CloseUp += new System.EventHandler(this.untilDateTimePicker_ValueChanged);
             this.untilDateTimePicker.LostFocus += new System.EventHandler(this.untilDateTimePicker_ValueChanged);
             this.groupComboBox.SelectedIndexChanged += new System.EventHandler(this.groupComboBox_SelectedIndexChanged);

             this.TopLevel = true;
        }
Example #35
0
        /// <summary>
        /// Updates the balance report.
        /// </summary>
        /// <param name="edc">The <see cref="Entities" /> representing data model.</param>
        /// <param name="getOutboundQuantity">Delegate to get outbound quantity.</param>
        /// <param name="batches">The batches.</param>
        /// <param name="trace">The trace action.</param>
        /// <returns><c>true</c> if the stock is valid (consistent), <c>false</c> otherwise.</returns>
        internal bool UpdateBalanceReport(Entities edc, GetOutboundQuantity getOutboundQuantity, List <BalanceBatchWrapper> batches, NamedTraceLogger.TraceAction trace)
        {
            trace("Entering JSOXLib.UpdateBalanceReport", 43, TraceSeverity.Verbose);
            bool            _validated    = false;
            StockDictionary _balanceStock = new StockDictionary();
            Dictionary <string, IGrouping <string, IPR> > _accountGroups = Linq.IPR.GetAllOpen4JSOXGroups(edc).ToDictionary(x => x.Key);

            Linq.StockLib _stock = Stock(edc);
            if (_stock != null)
            {
                _validated = _stock.Validate(edc, _accountGroups, _stock);
                _stock.GetInventory(edc, _balanceStock);
                _stock.Stock2JSOXLibraryIndex = this;
            }
            else
            {
                ActivityLogCT.WriteEntry(edc, "Balance report", "Cannot find stock report - only preliminary report will be created");
            }
            List <string> _processed = new List <string>();
            IEnumerable <BalanceBatch> _existingBatches = this.BalanceBatch(edc);

            foreach (BalanceBatch _bbx in _existingBatches)
            {
                if (_accountGroups.ContainsKey(_bbx.Batch))
                {
                    List <BalanceIPR> _is = new List <BalanceIPR>();
                    _bbx.Update(edc, _accountGroups[_bbx.Batch], _balanceStock.GetOrDefault(_bbx.Batch), _is, trace);
                    batches.Add(new BalanceBatchWrapper()
                    {
                        batch = _bbx, iprCollection = _is.ToArray <BalanceIPR>()
                    });
                }
                else
                {
                    edc.BalanceBatch.DeleteOnSubmit(_bbx);
                }
                _processed.Add(_bbx.Batch);
            }
            foreach (string _btchx in _processed)
            {
                _accountGroups.Remove(_btchx);
            }
            foreach (var _grpx in _accountGroups)
            {
                batches.Add(Linq.BalanceBatch.Create(edc, _grpx.Value, this, _balanceStock.GetOrDefault(_grpx.Key), trace));
            }

            //Introducing
            DateTime _thisIntroducingDateStart = LinqIPRExtensions.DateTimeMaxValue;
            DateTime _thisIntroducingDateEnd   = LinqIPRExtensions.DateTimeMinValue;
            decimal  _introducingQuantity      = Linq.IPR.GetIntroducingData(edc, this, out _thisIntroducingDateStart, out _thisIntroducingDateEnd);

            this.IntroducingDateStart = _thisIntroducingDateStart;
            this.IntroducingDateEnd   = _thisIntroducingDateEnd;
            this.IntroducingQuantity  = Convert.ToDouble(_introducingQuantity);

            //Outbound
            DateTime _thisOutboundDateEnd   = LinqIPRExtensions.DateTimeMinValue;
            DateTime _thisOutboundDateStart = LinqIPRExtensions.DateTimeMaxValue;
            decimal  _outQuantity           = getOutboundQuantity(edc, this, out _thisOutboundDateStart, out _thisOutboundDateEnd);

            this.OutboundQuantity  = _outQuantity.Convert2Double2Decimals();
            this.OutboundDateEnd   = _thisOutboundDateEnd;
            this.OutboundDateStart = _thisOutboundDateStart;

            //Balance
            decimal _thisBalanceQuantity = Convert.ToDecimal(this.PreviousMonthQuantity) + _introducingQuantity - _outQuantity;

            this.BalanceQuantity = _thisBalanceQuantity.Convert2Double2Decimals();

            //Situation at
            decimal _thisSituationQuantity = batches.Select <BalanceBatchWrapper, BalanceBatch>(x => x.batch).Sum <BalanceBatch>(x => x.IPRBookDecimal);

            this.SituationQuantity = Convert.ToDouble(_thisSituationQuantity);

            //Reassign
            this.ReassumeQuantity = (_thisBalanceQuantity - _thisSituationQuantity).Convert2Double2Decimals();
            return(_validated);
        }