Exemple #1
0
        private void BuySell_Condition(ref SimulationVariable simulationVariable, ref DataList dataList, ref BasicFinancialReportListModel BasicFinancialData, int j)
        {
            if (!simulationVariable.HasBuy && _strategy.BuyCondition(ref simulationVariable, ref dataList, ref BasicFinancialData, j))
            {
                simulationVariable.CanBuy = true;
            }

            if (simulationVariable.HasBuy && _strategy.SellCondition(ref simulationVariable, ref dataList, ref BasicFinancialData, j))
            {
                simulationVariable.CanBuy = false;
            }
        }
Exemple #2
0
        public TransactionList Run()
        {
            //之後平行化處理看看
            for (int i = 0; i < Company.Count; i++)
            {
                SimulationVariable            _SimulationVariable      = new SimulationVariable();
                Transaction                   transaction              = new Transaction();
                DataList                      DataList                 = new DataList(Company[i]);
                BasicFinancialReportListModel BasicFinancialReportData = new BasicFinancialReportListModel();

                //////////////////
                DataList.LineGraphData(ref DataList.TechData, "ClosePrice");
                DataList.LineGraphData(ref DataList.TechData, "Volume");
                DataList.LineGraphData(ref DataList.TechData, "ReturnOnInvestment");
                DataList.AddLineGraphDictionary("MoveAverageValue", 5);
                DataList.AddLineGraphDictionary("MoveAverageValue", 10);
                DataList.AddLineGraphDictionary("MoveAverageValue", 20);
                DataList.AddLineGraphDictionary("MoveAverageValue", 60);
                DataList.AddLineGraphDictionary("MinValue", 1);
                DataList.AddLineGraphDictionary("MaxValue", 240);
                DataList.AddLineGraphDictionary("MinValue", 20, "Volume");
                DataList.AddLineGraphDictionary("BollingerBandsDown", 20, "ClosePrice", 2.1);
                DataList.AddLineGraphDictionary("BollingerBandsUp", 20, "ClosePrice", 2.1);
                DataList.AddLineGraphDictionary("MoveAverageValue", 1);

                DataList.AddLineGraphDictionary("MoveAverageValue", 30, "Volume");
                DataList.AddLineGraphDictionary("CountDropinDays", 20, "ReturnOnInvestment");
                DataList.AddLineGraphDictionary("CountRaiseinDays", 20, "ReturnOnInvestment");
                DataList.AddLineGraphDictionary("CountRaiseinDays", 10, "ReturnOnInvestment");
                DataList.AddLineGraphDictionary("CountDropinDays", 5, "ReturnOnInvestment");
                DataList.AddLineGraphDictionary("CountRaiseinDays", 5, "ReturnOnInvestment");
                DataList.AddLineGraphDictionary("CountDropinDays", 10, "ReturnOnInvestment");
                DataList.AddLineGraphDictionary("MoveAverageValue", 6, "Volume");



                if (DataList.TechData.Count == 0)
                {
                    continue;
                }

                BasicFinancialReportData.Initial(DataList.TechData[0].Company);
                //////////////////
                SortedDictionary <Decimal, int> Data1 = new SortedDictionary <decimal, int>();
                SortedDictionary <Decimal, int> Data2 = new SortedDictionary <decimal, int>();
                SortedDictionary <Decimal, int> Data3 = new SortedDictionary <decimal, int>();
                ////Decimal AverageMonthPrice = 0;
                ////Decimal CountDay = 0;



                for (int j = 10; j < DataList.TechData.Count; j++)
                {
                    #region
                    //////////////////
                    BasicFinancialReportData.InitialDate(DataList.TechData[j].Date);
                    //////////////////


                    if (_SimulationVariable.HasBuy)
                    {
                        _SimulationVariable.CountDays(DataList.TechData[j]);// put TechData Return on Investment
                    }

                    #region  買賣條件
                    BuySell_Condition(ref _SimulationVariable, ref DataList, ref BasicFinancialReportData, j);
                    #endregion

                    if (_SimulationVariable.CanBuy && !_SimulationVariable.HasBuy)
                    {
                        transaction = new Transaction();
                        transaction.Buy(DataList.TechData[j].Company.ToString(), DataList.TechData[j].CompanyName,
                                        DataList.TechData[j].OpenPrice, DataList.TechData[j].Date);

                        transaction.DataOutput = InitialData.OutputData;

                        _SimulationVariable.HasBuy = true;
                        _SimulationVariable.Buy    = DataList.TechData[j];
                    }

                    if (_SimulationVariable.HasBuy && !_SimulationVariable.CanBuy)
                    {
                        transaction.Sell(DataList.TechData[j].Company.ToString(), DataList.TechData[j].CompanyName,
                                         DataList.TechData[j].ClosePrice, DataList.TechData[j].Date);

                        Transaction_List._TransactionList.Add(transaction);

                        _SimulationVariable.HasBuy = false;
                        _SimulationVariable.Initial();
                    }
                    #endregion
                }



                if (_SimulationVariable.HasBuy) //期末賣出
                {
                    transaction.Sell(DataList.TechData[DataList.TechData.Count - 1].Company.ToString(), DataList.TechData[DataList.TechData.Count - 1].CompanyName,
                                     DataList.TechData[DataList.TechData.Count - 1].HighestPrice, DataList.TechData[DataList.TechData.Count - 1].Date);
                    //期末賣出的不做計算
                    //Transaction_List._TransactionList.Add(transaction);

                    _SimulationVariable.HasBuy = false;
                    _SimulationVariable.Initial();
                }
            }
            //sw.Close();
            return(Transaction_List);
        }