Exemplo n.º 1
0
        protected override void Start()
        {
            var datas          = new Dictionary <string, string>();
            var cleanData      = new List <Dictionary <string, string> >();
            var ordNda         = new Nda(FileMode.WriteOnly);
            var ordQuoteFuture = new Nda(FileMode.WriteOnly);
            var ordIssueFuture = new Nda(FileMode.WriteOnly);
            var ordFm          = new Fm();
            var ordIdn         = new Idn(FileMode.WriteOnly);

            try
            {
                SetTemplates();
                foreach (var ric in _configObj.Rics)
                {
                    datas = GetInfos(ric.Trim());
                    cleanData.Add(CleanData(datas));
                }
                ordIssueFuture.LoadFromTemplate(_ordIssueFuture, cleanData);
                ordIssueFuture.Save(Path.Combine(_configObj.WorkingDir, String.Format("IssueFutureAdd{0}.csv", _configObj.Market)));
                AddResult("Issue Future Add file", ordIssueFuture.Path, "nda");


                ordIdn.LoadFromTemplate(_ordIdn, cleanData);
                ordIdn.Save(Path.Combine(_configObj.WorkingDir, String.Format("IdnAdd{0}.txt", _configObj.Market)));
                AddResult("Idn Add file", ordIdn.Path, "idn");

                ordNda.LoadFromTemplate(_ordNda, cleanData);
                ordNda.Save(Path.Combine(_configObj.WorkingDir, String.Format("NdaAdd{0}.csv", _configObj.Market)));
                AddResult("Nda Add file", ordNda.Path, "nda");

                ordQuoteFuture.LoadFromTemplate(_ordQuoteFuture, cleanData);
                ordQuoteFuture.Save(Path.Combine(_configObj.WorkingDir, String.Format("QuoteFutureAdd{0}.csv", _configObj.Market)));
                AddResult("Quote Future Add file", ordQuoteFuture.Path, "nda");

                ordFm.LoadFromTemplate(_ordFm, cleanData);
                ordFm.Save(Path.Combine(_configObj.WorkingDir, String.Format("Fm{0}.txt", _configObj.Market)));
                AddResult("Fm file", ordFm.Path, "fm");
            }
            catch (Exception ex)
            {
                LogMessage("Task failed, error: " + ex.Message, Logger.LogType.Error);
                throw new Exception("Task failed, error: " + ex.Message, ex);
            }
            finally
            {
            }
        }
        /// <summary>
        /// Generates Fm from website informations
        /// </summary>
        /// <param name="ric"></param>
        private Dictionary <string, string> GenerateFm(string ric)
        {
            try
            {
                FmInfo res   = GetInfos(ric);
                var    fm    = new Fm();
                var    infos = new Dictionary <string, string>
                {
                    { "ric", res.Ric },
                    { "name", res.EnglishName },
                    { "displayname", GetGatsDisplayName(res.Ric, res.Type) },
                    { "chinesename", res.ChineseName },
                    { "units", String.Format("{0:n0}", Convert.ToInt64(res.Shares.Replace("元", "").Replace(",", "")) / 100) },
                    { "maturedate", res.MatureDate.ToString("ddMMMyy").ToUpper() },
                    { "effectivedate", res.EffectiveDate.ToString("ddMMMyy").ToUpper() },
                    { "effectivedateidn", res.EffectiveDate.ToString("dd/MM/yyyy") },
                    { "isin", res.Isin },
                    { "abbrev", res.EnglishName.ToUpper() },
                    { "strike", res.Strikes.Replace("元", "") },
                    { "type", res.Type }
                };
                fm.AddProp(infos);
                string filename = String.Format("{0}{1}_{2}.txt", configObj.WorkingDir, res.Ric, DateTime.Now.ToString("ddMM"));
                fm.GenerateAndSave("TwTemplate", filename);
                //TaskResultList.Add(new TaskResultEntry("result file" + res.Ric + " FM", "", filename));
                AddResult("result file", filename, "");
                //add "=== End of Proforma ===" in the file end
                AddWordInTheEnd(filename);

                //BCU.txt
                string fileNameBCU = Path.Combine(configObj.WorkingDir, "BCU.txt");
                GeneratorBCUFile(res, fileNameBCU);
                return(infos);
            }
            catch (Exception ex)
            {
                Logger.Log("Fm generation failed for this ric, error: " + ex.Message, Logger.LogType.Warning);
                return(null);
            }
        }
Exemplo n.º 3
0
        protected override void Start()
        {
            try
            {
                //Login1();
                //Login2();
                int i       = 1;
                var propsDw = new List <Dictionary <string, string> >();
                foreach (Dictionary <string, string> infos in GetPages().Select(page => CleanInfos(GetInfos(page))).Where(infos => infos["type"] == "Derivative warrant"))
                {
                    infos.Add("counter", i.ToString());
                    propsDw.Add(infos);
                    i++;
                }
                if (i > 1)
                {
                    //GetFSharpTitleValue(propsDw);


                    var ndaDw1 = new Fm(Format.Horizontal, FileMode.WriteOnly);
                    ndaDw1.LoadFromTemplate(TemplateFm.ThFm, propsDw);
                    ndaDw1.Save(String.Format("{0}Thailand_DW_ADD_{1}.xls", configObj.ResultFolderPath,
                                              DateTime.Now.ToString("ddMM")));
                    AddResult("Dw Fm bulk file", ndaDw1.Path, "fm");

                    var ndaDw2 = new NdaQa(FileMode.WriteOnly);
                    ndaDw2.LoadFromTemplate(Template.QaAdd, propsDw);
                    ndaDw2.Save(String.Format("{0}NDA_QA_ADD_{1}.csv", configObj.ResultFolderPath,
                                              DateTime.Now.ToString("ddMM")));
                    AddResult("Dw Nda bulk file", ndaDw2.Path, "nda");

                    var ndaDw3 = new Idn(FileMode.WriteOnly);
                    ndaDw3.LoadFromTemplate(TemplateIdn.DomChain, propsDw);
                    ndaDw3.Save(String.Format("{0}IDN_Domchain_{1}.txt", configObj.ResultFolderPath,
                                              DateTime.Now.ToString("ddMM")));
                    AddResult("Dw Idn bulk file", ndaDw3.Path, "idn");

                    var ndaDw4 = new Idn(FileMode.WriteOnly);
                    ndaDw4.LoadFromTemplate(TemplateIdn.ForIdn, propsDw);
                    ndaDw4.Save(String.Format("{0}IDN_ADD_{1}.txt", configObj.ResultFolderPath,
                                              DateTime.Now.ToString("ddMM")));
                    AddResult("Dw Idn bulk file", ndaDw4.Path, "idn");

                    var ndaDw5 = new NdaIa(FileMode.WriteOnly);
                    ndaDw5.LoadFromTemplate(Template.IaAdd, propsDw);
                    ndaDw5.Save(String.Format("{0}NDA_IA_ADD_{1}.csv", configObj.ResultFolderPath,
                                              DateTime.Now.ToString("ddMM")));
                    AddResult("Dw Nda bulk file", ndaDw5.Path, "nda");

                    var ndaDw6 = new Tc(FileMode.WriteOnly);
                    ndaDw6.LoadFromTemplate(TemplateTc.WrtAdd, propsDw);
                    ndaDw6.Save(String.Format("{0}WRT_ADD_{1}_thailand.csv", configObj.ResultFolderPath,
                                              DateTime.Now.ToString("ddMMMyyyy")));
                    AddResult("Dw t&c bulk file", ndaDw6.Path, "t&c");
                }
                else
                {
                    LogMessage("No Dw announcement today");
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex);
            }
        }
Exemplo n.º 4
0
    public static int Main()
    {
        // Loading raw data and converting to logarithmic values
        List <double[]> data = misc.load_data("../data.txt");

        double[] x = data[0]; double[] y = data[1];
        for (int i = 0; i < y.Length; i++)
        {
            y[i] = Log(y[i]);
        }                                           // Logarithmic value
        double[] dy = new double[y.Length];         // Allocate array for y errors
        for (int i = 0; i < dy.Length; i++)
        {
            dy[i] = (Exp(y[i]) / 20) / Exp(y[i]);
        }                                                                           // Logarithmic y errors
        Func <double, double>[] F = new Func <double, double>[] { s => 1, s => s }; // Array of fitting functions

        var    res = new lsq_qr(x, y, dy, F);                                       // Variable storing instance of least square class
        vector c   = res.get_c();                                                   // Retrieve expansion coefficients of fitting functions
        double a   = Exp(c[0]);
        double l   = c[1];

        double[] dc  = res.get_dc();
        double   dl  = Log(2) / (l * l) * dc[1]; // Uncertainty in t 1/2 obtained using error of propagation
        matrix   cov = res.get_cov();

        var outfile = new System.IO.StreamWriter("../out_C.txt", append: false);

        outfile.WriteLine($"---------------------------------------");
        outfile.WriteLine($"ThX decay fit using least square method");
        outfile.WriteLine($"---------------------------------------");
        outfile.WriteLine("Fitting parameters:");
        outfile.WriteLine($"a:                {a}");
        outfile.WriteLine($"lambda:           {l}");
        outfile.WriteLine($"Fitting t_1/2:    {-Log(2)/l}({dl}) days");
        outfile.WriteLine($"Modern t_1/2:     3.66 days");
        outfile.WriteLine("The modern value of t_1/2 seems to be within the uncertainty of the fitting t_1/2\n");
        outfile.WriteLine($"Covariance matrix:");
        for (int ir = 0; ir < cov.size1; ir++)
        {
            for (int ic = 0; ic < cov.size2; ic++)
            {
                outfile.Write("{0,10:g3} ", cov[ir, ic]);
            }
            outfile.WriteLine("");
        }
        outfile.WriteLine("");
        outfile.Close();

        var expout = new System.IO.StreamWriter("expout.txt", append: false);
        var logout = new System.IO.StreamWriter("logout.txt", append: false);

        for (double i = 0; i < 20; i += 0.25)
        {
            expout.WriteLine($"{i} {exp(a,l)(i)} {Exp(Fp(c,dc,F)(i))} {Exp(Fm(c,dc,F)(i))}");
        }
        expout.Close();
        for (int i = 0; i < x.Length; i++)
        {
            logout.WriteLine($"{x[i]} {y[i]} {c[0] + c[1]*x[i]}");
        }
        logout.Close();
        return(0);
    }
Exemplo n.º 5
0
        public List <Fm> load(string patch)
        {
            List <Fm> result = new List <Fm>();

            bool firstLine = false;

            foreach (string line in File.ReadLines(Application.StartupPath + @"\Data\" + patch, Encoding.UTF8))
            {
                string[] tokenizer = line.Split(new string[] { "," + '"' }, StringSplitOptions.None);
                //string[] tokenizer = line.Split("\t\r");
                if (tokenizer.Count() != 85)
                {
                    throw new Exception("number of tokenizer isn't correct");
                }
                if (!firstLine)
                {
                    firstLine = true;
                }
                else
                {
                    int id   = parseInt(tokenizer[0].Trim());
                    Fm  temp = new Fm(id);

                    temp.setFirstName(tokenizer[1].Trim('"').Trim());
                    temp.setFirstInitial(tokenizer[2].Trim('"').Trim());
                    if (tokenizer[3].Trim() == "")
                    {
                        throw new Exception("Surname isn't valid (id: " + id + ")");
                    }
                    temp.setSurname(tokenizer[3].Trim('"').Trim());
                    temp.setDateOfBirth(tokenizer[4].Trim('"').Trim());
                    if (tokenizer[5].Trim() == "")
                    {
                        throw new Exception("Nationality isn't valid (id: " + id + ")");
                    }
                    temp.setNation(tokenizer[5].Trim('"').Trim());
                    temp.setClub(tokenizer[6].Trim('"').Trim());
                    temp.setLeftFoot(parseInt(tokenizer[7].Trim()));
                    temp.setRightFoot(parseInt(tokenizer[8].Trim()));
                    if (tokenizer[9].Trim() == "")
                    {
                        throw new Exception("Position isn't valid (id: " + id + ")");
                    }
                    temp.setPosition(tokenizer[9].Trim('"').Trim());
                    temp.setGk(parseInt(tokenizer[10].Trim()));
                    temp.setSw(parseInt(tokenizer[11].Trim()));
                    temp.setRb(parseInt(tokenizer[12].Trim()));
                    temp.setLb(parseInt(tokenizer[13].Trim()));
                    temp.setCb(parseInt(tokenizer[14].Trim()));
                    temp.setWbr(parseInt(tokenizer[15].Trim()));
                    temp.setWbl(parseInt(tokenizer[16].Trim()));
                    temp.setDm(parseInt(tokenizer[17].Trim()));
                    temp.setRm(parseInt(tokenizer[18].Trim()));
                    temp.setLm(parseInt(tokenizer[19].Trim()));
                    temp.setCm(parseInt(tokenizer[20].Trim()));
                    temp.setAml(parseInt(tokenizer[21].Trim()));
                    temp.setAmr(parseInt(tokenizer[22].Trim()));
                    temp.setAmc(parseInt(tokenizer[23].Trim()));
                    temp.setSt(parseInt(tokenizer[24].Trim()));
                    temp.setAcceleration(parseInt(tokenizer[25].Trim()));
                    temp.setAdaptability(parseInt(tokenizer[26].Trim()));
                    temp.setAerialAbility(parseInt(tokenizer[27].Trim()));
                    temp.setAggression(parseInt(tokenizer[28].Trim()));
                    temp.setAgility(parseInt(tokenizer[29].Trim()));
                    temp.setAmbition(parseInt(tokenizer[30].Trim()));
                    temp.setAnticipation(parseInt(tokenizer[31].Trim()));
                    temp.setBalance(parseInt(tokenizer[32].Trim()));
                    temp.setBravery(parseInt(tokenizer[33].Trim()));
                    temp.setCommandOfArea(parseInt(tokenizer[34].Trim()));
                    temp.setCommunication(parseInt(tokenizer[35].Trim()));
                    temp.setComposure(parseInt(tokenizer[36].Trim()));
                    temp.setConcentration(parseInt(tokenizer[37].Trim()));
                    temp.setConsistency(parseInt(tokenizer[38].Trim()));
                    temp.setControversy(parseInt(tokenizer[39].Trim()));
                    temp.setCorners(parseInt(tokenizer[40].Trim()));
                    temp.setCrossing(parseInt(tokenizer[41].Trim()));
                    temp.setDecisions(parseInt(tokenizer[42].Trim()));
                    temp.setDetermination(parseInt(tokenizer[43].Trim()));
                    temp.setDirtiness(parseInt(tokenizer[44].Trim()));
                    temp.setDribbling(parseInt(tokenizer[45].Trim()));
                    temp.setEccentricity(parseInt(tokenizer[46].Trim()));
                    temp.setFinishing(parseInt(tokenizer[47].Trim()));
                    temp.setFirstTouch(parseInt(tokenizer[48].Trim()));
                    temp.setFlair(parseInt(tokenizer[49].Trim()));
                    temp.setFreeKicks(parseInt(tokenizer[50].Trim()));
                    temp.setHandling(parseInt(tokenizer[51].Trim()));
                    temp.setHeading(parseInt(tokenizer[52].Trim()));
                    temp.setImportantMatches(parseInt(tokenizer[53].Trim()));
                    temp.setInjuryProneness(parseInt(tokenizer[54].Trim()));
                    temp.setJumping(parseInt(tokenizer[55].Trim()));
                    temp.setKicking(parseInt(tokenizer[56].Trim()));
                    temp.setLeadership(parseInt(tokenizer[57].Trim()));
                    temp.setLongShots(parseInt(tokenizer[58].Trim()));
                    temp.setLongThrows(parseInt(tokenizer[59].Trim()));
                    temp.setLoyalty(parseInt(tokenizer[60].Trim()));
                    temp.setMarking(parseInt(tokenizer[61].Trim()));
                    temp.setNaturalFitness(parseInt(tokenizer[62].Trim()));
                    temp.setOffTheBall(parseInt(tokenizer[63].Trim()));
                    temp.setOneOnOnes(parseInt(tokenizer[64].Trim()));
                    temp.setPace(parseInt(tokenizer[65].Trim()));
                    temp.setPassing(parseInt(tokenizer[66].Trim()));
                    temp.setPenalties(parseInt(tokenizer[67].Trim()));
                    temp.setPositioning(parseInt(tokenizer[68].Trim()));
                    temp.setPressure(parseInt(tokenizer[69].Trim()));
                    temp.setProfessionalism(parseInt(tokenizer[70].Trim()));
                    temp.setReflexes(parseInt(tokenizer[71].Trim()));
                    temp.setRushingOut(parseInt(tokenizer[72].Trim()));
                    temp.setSportsmanship(parseInt(tokenizer[73].Trim()));
                    temp.setStamina(parseInt(tokenizer[74].Trim()));
                    temp.setStrength(parseInt(tokenizer[75].Trim()));
                    temp.setTackling(parseInt(tokenizer[76].Trim()));
                    temp.setTeamwork(parseInt(tokenizer[77].Trim()));
                    temp.setTechnique(parseInt(tokenizer[78].Trim()));
                    temp.setTemperament(parseInt(tokenizer[79].Trim()));
                    temp.setTendancyToPunch(parseInt(tokenizer[80].Trim()));
                    temp.setThrowing(parseInt(tokenizer[81].Trim()));
                    temp.setVersatility(parseInt(tokenizer[82].Trim()));
                    temp.setVision(parseInt(tokenizer[83].Trim()));
                    temp.setWorkRate(parseInt(tokenizer[84].Trim()));
                    //temp.setHeight(parseInt(tokenizer[84].Trim()));
                    //temp.setWeight(parseInt(tokenizer[85].Trim()));

                    result.Add(temp);
                }
            }

            return(result);
        }