コード例 #1
0
 def load_sd_col(self, data_col_tickers, decision, startdate):
     for ticker in data_col_tickers:
         sd = stk.StockData()
         sd.load(ticker, startdate)
         des = copy.deepcopy(decision)
         des_col = DecisionCollection("PORTF", 10000)
         des.decision.post_set(sd, des_col)
         self.decision_lst.append(des)
コード例 #2
0
    def do_simulation(self, arg):
        ticker, startdate = arg.split()
        calc = stk.StockCalcIndex(self.stk_data_coll)
        sd = stk.StockData()
        sd.load(ticker, startdate)

        port = des.DecisionCollection(ticker, 50000)
        decision = des.DecisionSimpleSMA(ticker, (sd.Cs, sd.dates), port)
        decision.looper()
        print ticker, ":", str(port)

        port2 = des.DecisionCollection(ticker, 50000)
        decision2 = des.DecisionSimpleStopSMA(
            ticker,
            (sd.Cs, sd.dates),
            port2,
            risk_factor=0.01,
        )
        decision2.looper()
        print ticker, ":", str(port2)
        port2.print_all()

        a_plot = plot.Plot(plot.PlotCell((sd.Cs, sd.dates)))

        a_plot.addSimple(
            plot.PlotCell(calc.sma((sd.Cs, sd.dates), 200), overlay=True))
        a_plot.addSimple(
            plot.PlotCell(calc.sma((sd.Cs, sd.dates), 50), overlay=True))
        a_plot.addSimple(
            plot.PlotCell(calc.llv((sd.Cs, sd.dates), 100), overlay=True))

        a_plot.addSimple(
            plot.PlotCell(port2.get_enter_plot_cell(),
                          overlay=True,
                          color='go'))
        a_plot.addSimple(
            plot.PlotCell(port2.get_leave_plot_cell(),
                          overlay=True,
                          color='ro'))

        a_plot.addSimple(plot.PlotCell(port2.get_value_plot_cell()))
        a_plot.plot()
コード例 #3
0
    def do_plot_collection(self, arg):
        calc = stk.StockCalcIndex(self.stk_data_coll)
        sd = stk.StockData()
        ticker, startdate = arg.split()

        sd.load(ticker, startdate)
        a_plot = plot.Plot(plot.PlotCell((sd.Cs, sd.dates)))

        a_plot.addSimple(
            plot.PlotCell(calc.sma((sd.Cs, sd.dates), 200), overlay=True))
        a_plot.addSimple(
            plot.PlotCell(calc.sma((sd.Cs, sd.dates), 50), overlay=True))
        a_plot.addSimple(
            plot.PlotCell(calc.llv((sd.Cs, sd.dates), 100), overlay=True))

        a_plot.addSimple(plot.PlotCell(calc.sma((sd.Vs, sd.dates), 20)))
        a_plot.addSimple(plot.PlotCell(calc.obv((sd.Cs, sd.Vs, sd.dates))))

        a_plot.addSimple(plot.PlotCell(calc.correlation_adj(
            (sd.Cs, sd.dates))))

        a_plot.plot()
コード例 #4
0
    def do_simulation_collection(self, arg):
        for ticker in self.stk_data_coll.stk_data_coll:
            sd = stk.StockData()
            sd.load(ticker, arg)

            port = des.DecisionCollection(ticker, 50000)
            decision = des.DecisionSimpleStopSMA(ticker, (sd.Cs, sd.dates),
                                                 port,
                                                 risk_factor=0.02,
                                                 sma_fast=10,
                                                 sma_slow=50,
                                                 stop_per=5)
            decision.looper()

            port4 = des.DecisionCollection(ticker, 50000)
            decision4 = des.DecisionSimpleSMA(ticker, (sd.Cs, sd.dates),
                                              port4,
                                              sma_fast=10,
                                              sma_slow=50,
                                              stop_per=5)
            decision4.looper()

            port2 = des.DecisionCollection(ticker, 50000)
            decision2 = des.DecisionSimpleSMA(ticker, (sd.Cs, sd.dates), port2)
            decision2.looper()

            port3 = des.DecisionCollection(ticker, 50000)
            decision3 = des.DecisionSimpleStopSMA(ticker, (sd.Cs, sd.dates),
                                                  port3,
                                                  risk_factor=0.02,
                                                  sma_fast=50,
                                                  sma_slow=200,
                                                  stop_per=40)
            decision3.looper()

            print "STOP_FAST - ", ticker, " ", str(port)
            print "SIMPLE_FAST - ", ticker, " ", str(port4)
            print "STOP_SLOW - ", ticker, " ", str(port3)
            print "SIMPLE_SLOW - ", ticker, " ", str(port2)
コード例 #5
0
    def do_plot_ticker_indexes(self, arg):
        calc = stk.StockCalcIndex(self.stk_data_coll)
        sd = stk.StockData()
        ticker, indexes, startdate = arg.split()
        indexes = indexes.split(',', 1)

        sd.load(ticker, startdate)
        a_plot = plot.Plot(plot.PlotCell((sd.Cs, sd.dates)))

        a_plot.addSimple(
            plot.PlotCell(calc.sma((sd.Cs, sd.dates), 200), overlay=True))
        a_plot.addSimple(
            plot.PlotCell(calc.sma((sd.Cs, sd.dates), 50), overlay=True))

        for index in indexes:
            p = plot.PlotCellIndex(index)
            p.truncate(startdate)
            a_plot.addSimple(plot.PlotCell((p.data, p.dates)))
            a_plot.addSimple(plot.PlotCell(calc.sma((p.data, p.dates), 20)))
            a_plot.addSimple(
                plot.PlotCell(calc.sma((p.data, p.dates), 50), overlay=True))

        a_plot.plot()
コード例 #6
0
ファイル: quote.py プロジェクト: rcshadman/workspace_python
import stock as stk
import portfolio as portf
import sys

if __name__ == "__main__":
    a = stk.StockData()
    a.load(sys.argv[1], sys.argv[2], sys.argv[3])

    calc = stk.StockCalc()

    at = portf.AT(a.history, 10000)
    at.add_indicator(calc.sma((a.Cs, a.dates), 50))
    at.add_indicator(calc.sma((a.Cs, a.dates), 200))

    at.run()
    #at.port.print_log()

    #print a.plot()
    a_plot = stk.StockPlot(stk.StockPlotCell((a.Cs, a.dates)))
    a_plot.addSimple(
        stk.StockPlotCell(calc.sma((a.Cs, a.dates), 200), overlay=True))
    a_plot.addSimple(
        stk.StockPlotCell(calc.sma((a.Cs, a.dates), 50), overlay=True))
    a_plot.addSimple(
        stk.StockPlotCell(at.get_buy_plot_cell(), overlay=True, color='go'))
    a_plot.addSimple(
        stk.StockPlotCell(at.get_sell_plot_cell(), overlay=True, color='ro'))

    a_plot.addSimple(stk.StockPlotCell(calc.sma((a.Vs, a.dates), 5)))
    a_plot.addSimple(stk.StockPlotCell(calc.obv((a.Cs, a.Vs, a.dates))))
    #a_plot.addSimple(stk.StockPlotCell( stkCalc.perc_diffs((a.get_close_list(), a.get_date_list()))))