Exemple #1
0
    def __init__(self, dataHandler,
                 events,
                 startDate,
                 assets,
                 initialCapital=100000.0,
                 benchmark=None,
                 portfolioType=PortfolioType.CashManageable):
        self.dataHandler = dataHandler
        self.events = events
        self.allTradableAssets = self.dataHandler.allTradableAssets
        self.startDate = startDate
        self.initialCapital = initialCapital
        self.benchmark = benchmark
        self.assets = assets
        self.positionsBook = StocksPositionsBook(assets)
        self.portfolioType = portfolioType

        self.allPositions = self.constructAllPositions()
        self.currentPosition = defaultdict(int, [(s, 0) for s in self.allTradableAssets])

        self.allHoldings = [] # self.constructAllHoldings()
        self.currentHoldings = self.constructCurrentHoldings()

        self.orderBook = None

        vp_settings.set_source(Settings.data_source)
    def __init__(self, dataHandler,
                 events,
                 startDate,
                 assets,
                 initialCapital=100000.0,
                 benchmark=None,
                 portfolioType=PortfolioType.CashManageable):
        self.dataHandler = dataHandler
        self.events = events
        self.allTradableAssets = self.dataHandler.allTradableAssets
        self.startDate = startDate
        self.initialCapital = initialCapital
        self.benchmark = benchmark
        self.assets = assets
        self.positionsBook = StocksPositionsBook(assets)
        self.portfolioType = portfolioType

        self.allPositions = self.constructAllPositions()
        self.currentPosition = defaultdict(int, [(s, 0) for s in self.allTradableAssets])

        self.allHoldings = [] # self.constructAllHoldings()
        self.currentHoldings = self.constructCurrentHoldings()

        self.orderBook = None

        vp_settings.set_source(Settings.data_source)
    start_date = dt.datetime(2005, 1, 1)
    end_date = dt.datetime(2017, 1, 1)
    ma_short = config('GF_MA_SHORT', default=20, cast=int)
    ma_long = config('GF_MA_LONG', default=90, cast=int)

    strategyRunner(userStrategy=GFMovingAverageCrossStrategy,
                   strategyParameters=(ma_short, ma_long),
                   symbolList=universe,
                   startDate=start_date,
                   endDate=end_date,
                   benchmark='000300.zicn',
                   dataSource=DataSource.WIND,
                   logLevel='info',
                   saveFile=True,
                   portfolioType=PortfolioType.CashManageable,
                   plot=True,
                   freq='D')


if __name__ == "__main__":
    from VisualPortfolio.Env import Settings
    from AlgoTrading.Env import Settings

    Settings.set_source(DataSource.WIND)
    startTime = dt.datetime.now()
    print("Start: %s" % startTime)
    run_example()
    endTime = dt.datetime.now()
    print("End : %s" % endTime)
    print("Elapsed: %s" % (endTime - startTime))
Exemple #4
0
                self.order(s, -1, quantity=200)


def run_example():
    universe = set_universe('000300.zicn')[:10]
    startDate = dt.datetime(2007, 1, 1)
    endDate = dt.datetime(2015, 10, 1)

    strategyRunner(userStrategy=MovingAverageCrossStrategy,
                   symbolList=universe,
                   startDate=startDate,
                   endDate=endDate,
                   freq=0,
                   benchmark='000300.zicn',
                   logLevel='info',
                   saveFile=True,
                   plot=True)


if __name__ == "__main__":
    from VisualPortfolio.Env import Settings
    from AlgoTrading.Env import Settings
    Settings.set_source(DataSource.DataYes)
    Settings.set_source(DataSource.DataYes)
    startTime = dt.datetime.now()
    print("Start: %s" % startTime)
    run_example()
    endTime = dt.datetime.now()
    print("End : %s" % endTime)
    print("Elapsed: %s" % (endTime - startTime))
            if self.signal[s] < 0. and amount != 0:
                self.order(s, -1, quantity=200)


def run_example():
    universe = set_universe('000300.zicn')[:200]
    startDate = dt.datetime(2015, 1, 1)
    endDate = dt.datetime(2017, 1, 1)

    strategyRunner(userStrategy=MovingAverageCrossStrategy,
                   symbolList=universe,
                   startDate=startDate,
                   endDate=endDate,
                   benchmark='000300.zicn',
                   logLevel='info',
                   saveFile=True,
                   plot=True,
                   freq='D')


if __name__ == "__main__":
    from VisualPortfolio.Env import Settings
    from AlgoTrading.Env import Settings
    Settings.set_source(DataSource.TUSHARE)
    startTime = dt.datetime.now()
    print("Start: %s" % startTime)
    run_example()
    endTime = dt.datetime.now()
    print("End : %s" % endTime)
    print("Elapsed: %s" % (endTime - startTime))