예제 #1
0
        public void SetInterest(string type, double interest)
        {
            DataRow row = InterestTable.FindByType(type);

            if (row != null && !double.IsNaN(interest))
            {
                try
                {
                    row["Interest"] = interest;
                }
                catch { }
            }
        }
        public CalculatorMessage calculateInterestPerformance(decimal amount, int termInDays, MoneyType money)
        {
            //Se genera la caja para encapsular el resultado
            CalculatorMessage result = new CalculatorMessage();

            //Se obtiene los productos
            SavingInvestementProduct product = _factory.createProduct();

            product.Amount     = amount;
            product.TermInDays = termInDays;
            product.Currency   = money;

            //Se crea el verficador para procesar el producto de inversión y ahorro
            ServiceVerifier verifier = _factory.createVerify();

            verifier.Product = product;

            //Verificar la apertura del servicio
            ProductServiceMessage verifyMessage = verifier.canServiceBeOpen();

            if (verifyMessage.CanBeOpen == true)
            {
                //Se crea la tabla de intereses para el producto de inversión y ahorro; más se le adjunta al producto
                string        tableInterest = _productType + money.ToString();
                InterestTable interestTable = InterestTableFactory.GetInterestTableFor(tableInterest);
                product.setInterestTable(interestTable);

                //Se calcula el rendimiento del producto
                product.calculateInterest();

                result.InterestEarned    = product.InterestEarned();
                result.FinalBalance      = product.getFinalBalance();
                result.TaxApplied        = product.getTax();
                result.percentegeApplied = product.getAnnualInterest();
            }
            else
            {
                result.InterestEarned = 0;
                result.FinalBalance   = 0;
                result.TaxApplied     = 0;
            }

            result.Message = verifyMessage.Message;
            return(result);
        }
 public override void setInterestTable(InterestTable interest)
 {
     _interestTable = (AmountInterest)interest;
 }
예제 #4
0
        public void UpdateLocalCache()
        {
            // customization mode
            try
            {
                CustomizationMode = GetParameter("Customization Mode");
            }
            catch { CustomizationMode = ""; }

            // last command
            try
            {
                int arg = 0;
                int.TryParse(GetParameter("Last Command"), out arg);

                LastCommand = arg;
            }
            catch { LastCommand = 0; }

            // interest rate
            try
            {
                FederalIterest = (double)InterestTable.FindByType("Federal")["Interest"];
            }
            catch { FederalIterest = 0; }
            try
            {
                DebitIterest = (double)InterestTable.FindByType("Debit")["Interest"];
            }
            catch { DebitIterest = 0; }
            try
            {
                CreditIterest = (double)InterestTable.FindByType("Credit")["Interest"];
            }
            catch { CreditIterest = 0; }

            // server mode
            try
            {
                string val = GetParameter("Online Server");
                if (val == null)
                {
                    OnlineServer = Global.DEFAULT_ONLINE_SERVER;
                }
                else
                {
                    OnlineServer = val;
                }
            }
            catch { OnlineServer = Global.DEFAULT_ONLINE_SERVER; }
            try
            {
                ServerMode = GetParameter("Server Mode");
            }
            catch { ServerMode = ""; }
            try
            {
                ServerWasSelected = GetParameter("Server Was Selected") == "Yes";
            }
            catch { ServerWasSelected = false; }

            // proxy
            try
            {
                UseProxy = GetParameter("Use Proxy") == "Yes";
            }
            catch { UseProxy = true; }
            try
            {
                ProxyAddress = GetParameter("Proxy Address");
            }
            catch { ProxyAddress = ""; }

            try
            {
                // update current server proxy settings
                if (Comm.IsInitialize)
                {
                    Comm.Server.ProxyAddress = ProxyAddress;
                    Comm.Server.UseProxy     = UseProxy;
                }
            }
            catch { }

            // option indicators
            for (int i = 0; i < Global.MAX_OPTIONS_INDICATORS; i++)
            {
                string id = (i + 1).ToString();

                try
                {
                    OptionsIndicatorName[i] = GetParameter("Options Indicator Name " + id);
                }
                catch { OptionsIndicatorName[i] = ""; }
                try
                {
                    OptionsIndicatorEquation[i] = GetParameter("Options Indicator Equation " + id);
                }
                catch { OptionsIndicatorEquation[i] = ""; }
                try
                {
                    OptionsIndicatorEnable[i] = GetParameter("Options Indicator Enable " + id) == "Yes";
                }
                catch { OptionsIndicatorEnable[i] = false; }
                try
                {
                    OptionsIndicatorFormat[i] = GetParameter("Options Indicator Format " + id);
                }
                catch { OptionsIndicatorFormat[i] = "N2"; }
            }

            // commissions
            try
            {
                SimpleCommisions = (GetParameter("Simple Options Commission") != "No");
            }
            catch { SimpleCommisions = true; }

            // option pricing model
            try
            {
                if (GetParameter("Pricing Model") == "BlackScholes")
                {
                    option_pricing_model = Model.ModelT.BlackScholes;
                }
                else
                {
                    option_pricing_model = Model.ModelT.Binominal;
                }
            }
            catch { option_pricing_model = Model.ModelT.BlackScholes; }

            try
            {
                BinominalSteps = int.Parse(GetParameter("Binominal Steps"));
            }
            catch { BinominalSteps = BinomialTree.DEFAULT_BINOMINAL_STEPS; }

            // last price model
            try
            {
                LastPriceModelT lp = new LastPriceModelT();

                switch (GetParameter("Stock Calculation Prices").ToString())
                {
                case "Last Price":
                default:
                    lp.stock = Model.LastPriceT.LastPrice;
                    break;

                case "Ask/Bid Prices":
                    lp.stock = Model.LastPriceT.AskBidPrice;
                    break;

                case "Ask/Bid Mid Price":
                    lp.stock = Model.LastPriceT.MidAskBidPrice;
                    break;
                }

                switch (GetParameter("Option Calculation Prices").ToString())
                {
                case "Last Price":
                    lp.option = Model.LastPriceT.LastPrice;
                    break;

                case "Ask/Bid Prices":
                default:
                    lp.option = Model.LastPriceT.AskBidPrice;
                    break;

                case "Ask/Bid Mid Price":
                    lp.option = Model.LastPriceT.MidAskBidPrice;
                    break;
                }

                LastPriceModel = lp;
            }
            catch { LastPriceModel = new LastPriceModelT(); }

            // update historical algorithm
            try
            {
                switch (GetParameter("Historical Volatility Algorithm"))
                {
                case "Historical Close-to-Close":
                    HisVolAlgorithm = HisVolAlgorithmT.CLOSE_CLOSE;
                    break;

                case "Historical Low-to-High (Parkinson)":
                    HisVolAlgorithm = HisVolAlgorithmT.HIGH_LOW_PARKINGSON;
                    break;

                case "Historical Open-High-Low-Close (Garman Klass)":
                    HisVolAlgorithm = HisVolAlgorithmT.GARMAN_KLASS;
                    break;

                case "Historical Open-High-Low-Close (Yang Zhang)":
                    HisVolAlgorithm = HisVolAlgorithmT.YANG_ZHANG;
                    break;
                }
            }
            catch { HisVolAlgorithm = HisVolAlgorithmT.HIGH_LOW_PARKINGSON; }

            // update colors
            try
            {
                if (color_config == null)
                {
                    color_config = new ColorConfig();
                }
                color_config.UpdateLocalCache();
            }
            catch { }
        }
예제 #5
0
        private bool New()
        {
            DataRow    row;
            MarginMath mm = null;
            ResultMath rm = null;

            bool changed = false;

            try
            {
                string[] AllTypes = new string[] { "Long Stock", "Short Stock", "Long Call", "Short Call", "Long Put", "Short Put" };
                string[] IntTypes = new string[] { "Debit", "Credit", "Federal" };

                foreach (string s in AllTypes)
                {
                    if (CommissionsTable.FindByType(s) == null)
                    {
                        changed               = true;
                        row                   = CommissionsTable.NewRow();
                        row["Type"]           = s;
                        row["PerTransaction"] = 0;
                        row["PerUnit"]        = 0;
                        CommissionsTable.Rows.Add(row);
                    }
                }

                foreach (string s in IntTypes)
                {
                    if (InterestTable.FindByType(s) == null)
                    {
                        changed         = true;
                        row             = InterestTable.NewRow();
                        row["Type"]     = s;
                        row["Interest"] = 0;
                        InterestTable.Rows.Add(row);
                    }
                }

                if (ParametersTable.FindByParameter("Option Calculation Prices") == null)
                {
                    changed          = true;
                    row              = ParametersTable.NewRow();
                    row["Parameter"] = "Option Calculation Prices";
                    row["Value"]     = "Ask/Bid Prices";
                    ParametersTable.Rows.Add(row);
                }

                if (ParametersTable.FindByParameter("Stock Calculation Prices") == null)
                {
                    changed          = true;
                    row              = ParametersTable.NewRow();
                    row["Parameter"] = "Stock Calculation Prices";
                    row["Value"]     = "Last Price";
                    ParametersTable.Rows.Add(row);
                }

                if (ParametersTable.FindByParameter("Simple Options Commission") == null)
                {
                    changed          = true;
                    row              = ParametersTable.NewRow();
                    row["Parameter"] = "Simple Options Commission";
                    row["Value"]     = "Yes";
                    ParametersTable.Rows.Add(row);
                }

                if (ParametersTable.FindByParameter("Created with Version") == null)
                {
                    changed          = true;
                    row              = ParametersTable.NewRow();
                    row["Parameter"] = "Created with Version";
                    row["Value"]     = CurrentVersion;
                    ParametersTable.Rows.Add(row);
                }

                if (ParametersTable.FindByParameter("Installation Date") == null)
                {
                    changed          = true;
                    row              = ParametersTable.NewRow();
                    row["Parameter"] = "Installation Date";
                    row["Value"]     = DateTime.Now.ToShortDateString();
                    ParametersTable.Rows.Add(row);
                }

                if (ParametersTable.FindByParameter("Last Version Check") == null)
                {
                    changed          = true;
                    row              = ParametersTable.NewRow();
                    row["Parameter"] = "Last Version Check";
                    row["Value"]     = CurrentVersion;
                    ParametersTable.Rows.Add(row);
                }

                if (ParametersTable.FindByParameter("Remote Configuration") == null)
                {
                    changed          = true;
                    row              = ParametersTable.NewRow();
                    row["Parameter"] = "Remote Configuration";
                    row["Value"]     = REMOTE_CONFIG;
                    ParametersTable.Rows.Add(row);
                }

                if (ParametersTable.FindByParameter("Online Server") == null)
                {
                    changed          = true;
                    row              = ParametersTable.NewRow();
                    row["Parameter"] = "Online Server";
                    row["Value"]     = Global.DEFAULT_ONLINE_SERVER;
                    ParametersTable.Rows.Add(row);
                }

                if (ParametersTable.FindByParameter("Server Mode") == null)
                {
                    changed          = true;
                    row              = ParametersTable.NewRow();
                    row["Parameter"] = "Server Mode";
                    row["Value"]     = "";
                    ParametersTable.Rows.Add(row);
                }

                if (ParametersTable.FindByParameter("Auto Refresh") == null)
                {
                    changed          = true;
                    row              = ParametersTable.NewRow();
                    row["Parameter"] = "Auto Refresh";
                    row["Value"]     = Global.DEFAULT_AUTO_REFRESH;
                    ParametersTable.Rows.Add(row);
                }

                if (ParametersTable.FindByParameter("Federal Interest Auto Update") == null)
                {
                    changed          = true;
                    row              = ParametersTable.NewRow();
                    row["Parameter"] = "Federal Interest Auto Update";
                    row["Value"]     = Global.DEFAULT_FEDERAL_INTEREST_AUTO_UPDATE;
                    ParametersTable.Rows.Add(row);
                }

                if (ParametersTable.FindByParameter("Volatility Mode") == null)
                {
                    changed          = true;
                    row              = ParametersTable.NewRow();
                    row["Parameter"] = "Volatility Mode";
                    row["Value"]     = Global.DEFAULT_VOLATILITY_MODE;
                    ParametersTable.Rows.Add(row);
                }

                if (ParametersTable.FindByParameter("Fixed Volatility") == null)
                {
                    changed          = true;
                    row              = ParametersTable.NewRow();
                    row["Parameter"] = "Fixed Volatility";
                    row["Value"]     = Global.DEFAULT_FIXED_VOLATILITY;
                    ParametersTable.Rows.Add(row);
                }

                if (ParametersTable.FindByParameter("Download Historical Volatility") == null)
                {
                    changed          = true;
                    row              = ParametersTable.NewRow();
                    row["Parameter"] = "Download Historical Volatility";
                    row["Value"]     = "No";
                    ParametersTable.Rows.Add(row);
                }

                if (ParametersTable.FindByParameter("Use Historical Volatility For StdDev") == null)
                {
                    changed          = true;
                    row              = ParametersTable.NewRow();
                    row["Parameter"] = "Use Historical Volatility For StdDev";
                    row["Value"]     = "No";
                    ParametersTable.Rows.Add(row);
                }

                if (ParametersTable.FindByParameter("Implied Volatility Fallback") == null)
                {
                    changed          = true;
                    row              = ParametersTable.NewRow();
                    row["Parameter"] = "Implied Volatility Fallback";
                    row["Value"]     = "No";
                    ParametersTable.Rows.Add(row);
                }

                if (ParametersTable.FindByParameter("Historical Volatility Algorithm") == null)
                {
                    changed          = true;
                    row              = ParametersTable.NewRow();
                    row["Parameter"] = "Historical Volatility Algorithm";
                    row["Value"]     = Global.DEFAULT_HISVOL_ALGORITHM;
                    ParametersTable.Rows.Add(row);
                }

                if (ParametersTable.FindByParameter("Last Wizard Stock List") == null)
                {
                    changed          = true;
                    row              = ParametersTable.NewRow();
                    row["Parameter"] = "Last Wizard Stock List";
                    row["Value"]     = "";
                    ParametersTable.Rows.Add(row);
                }

                if (ParametersTable.FindByParameter("Pricing Model") == null)
                {
                    changed          = true;
                    row              = ParametersTable.NewRow();
                    row["Parameter"] = "Pricing Model";
                    row["Value"]     = "BlackScholes";
                    ParametersTable.Rows.Add(row);
                }

                if (ParametersTable.FindByParameter("Binominal Steps") == null)
                {
                    changed          = true;
                    row              = ParametersTable.NewRow();
                    row["Parameter"] = "Binominal Steps";
                    row["Value"]     = "50";
                    ParametersTable.Rows.Add(row);
                }

                row = ParametersTable.FindByParameter("Customization Mode");
                if (row == null)
                {
                    changed          = true;
                    row              = ParametersTable.NewRow();
                    row["Parameter"] = "Customization Mode";
                    row["Value"]     = Properties.Resources.AppCustomizationMode.ToString();
                    ParametersTable.Rows.Add(row);
                }
                else if (row["Value"].ToString() == "" && Properties.Resources.AppCustomizationMode.ToString() != "")
                {
                    row["Value"] = Properties.Resources.AppCustomizationMode.ToString();
                }

                // create table view configuration
                TableConfig.CreateDefaultTableView(false);

                // delete old column width configuration
                if (ParametersTable.FindByParameter("Main Table Columns Width") != null ||
                    ParametersTable.FindByParameter("Portfolio Table Columns Width") != null)
                {
                    Config.Local.DeleteParameter("Main Table Columns Width");
                    Config.Local.DeleteParameter("Portfolio Table Columns Width");
                    changed = true;
                }

                // backward competability - rename portfolio OPO list, and create portfolio-list variable
                // which includes list of portfolios

                if (ParametersTable.FindByParameter("Portfolio OPO List") != null)
                {
                    changed = RenameParameter("Portfolio OPO List", "Portfolio (My Portfolio)");
                }

                if (ParametersTable.FindByParameter("Table Columns Width") != null)
                {
                    changed = RenameParameter("Table Columns Width", "Main Table Columns Width");
                }

                if (ParametersTable.FindByParameter("Portfolio List") == null)
                {
                    changed          = true;
                    row              = ParametersTable.NewRow();
                    row["Parameter"] = "Portfolio List";
                    row["Value"]     = "My Portfolio";
                    ParametersTable.Rows.Add(row);
                }

                if (MarginTable.Rows.Count == 0)
                {
                    // reset margin
                    if (mm == null)
                    {
                        mm = new MarginMath(null);
                    }
                    mm.resetToMarginAccount();
                }

                if (CriteriaTable.Rows.Count == 0)
                {
                    // reset criteria
                    if (rm == null)
                    {
                        rm = new ResultMath(null);
                    }
                    rm.resetToDefaultCriteriaList();
                }
                CriteriaTable.DefaultView.Sort = "Index ASC";

                if (LinksTable.Rows.Count == 0)
                {
                    // reset links
                    LinksConfig.ResetToDefaultLinks();
                }

                // accept changes
                CriteriaTable.AcceptChanges();
                CommissionsTable.AcceptChanges();
                MarginTable.AcceptChanges();
                InterestTable.AcceptChanges();
                ParametersTable.AcceptChanges();
                LinksTable.AcceptChanges();
            }
            catch { }

            // rename old parameters name to new ones
            for (int j = 1; j <= 2; j++)
            {
                RenameParameter("Indicator" + j.ToString() + " Name", "Last Wizard Indicator Name " + j.ToString());
                RenameParameter("Indicator" + j.ToString() + " Equation", "Last Wizard Indicator Equation " + j.ToString());
                RenameParameter("Indicator" + j.ToString() + " Enable", "Last Wizard Indicator Enable " + j.ToString());
                RenameParameter("Indicator" + j.ToString() + " Filter Enable", "Last Wizard Indicator Filter Enable " + j.ToString());
                RenameParameter("Indicator" + j.ToString() + " Min Value", "Last Wizard Indicator Min Value " + j.ToString());
                RenameParameter("Indicator" + j.ToString() + " Max Value", "Last Wizard Indicator Max Value " + j.ToString());
            }

            row = ParametersTable.FindByParameter("Created with Version");
            if (row != null)
            {
                // 1.0.8.0 -> 1.0.8.1
                if ((string)row["Value"] == "1.0.8.0")
                {
                    changed = true;

                    // update configuration version
                    row["Value"] = "1.0.8.1";

                    // update and save
                    ParametersTable.AcceptChanges();

                    // mark upgrade flag
                    first_upgrade = true;
                }
                // 1.0.8.1 -> 1.0.8.2
                if ((string)row["Value"] == "1.0.8.1")
                {
                    changed = true;

                    // update configuration version
                    row["Value"] = "1.0.8.2";

                    if (MessageBox.Show("As part of the upgrade to version 1.0.8.2, OptionsOracle needs to reset your margin-account configuration.    \nIf you are using private or cash-account configuration press \"Cancel\", otherwise please press \"OK\".", "Confirmation", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.OK)
                    {
                        // reset margin
                        if (mm == null)
                        {
                            mm = new MarginMath(null);
                        }
                        mm.resetToMarginAccount();
                    }

                    // update and save
                    ParametersTable.AcceptChanges();

                    // mark upgrade flag
                    first_upgrade = true;
                }
                // -> CurrentVersion
                if ((string)row["Value"] != CurrentVersion)
                {
                    changed = true;

                    // update configuration version
                    row["Value"] = CurrentVersion;

                    // don't show the market selection message
                    Config.Local.SetParameter("Server Was Selected", "Yes");
                    Config.Local.SetParameter("Last Command", "0");

                    // update and save
                    ParametersTable.AcceptChanges();

                    // mark upgrade flag
                    first_upgrade = true;
                }
            }

            return(changed);
        }
예제 #6
0
 public override void setInterestTable(InterestTable interest)
 {
     _interestTable = (TermInterest)interest;
 }