当前位置: 首页>>代码示例>>Python>>正文


Python Account.sell_stock方法代码示例

本文整理汇总了Python中account.Account.sell_stock方法的典型用法代码示例。如果您正苦于以下问题:Python Account.sell_stock方法的具体用法?Python Account.sell_stock怎么用?Python Account.sell_stock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在account.Account的用法示例。


在下文中一共展示了Account.sell_stock方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: analyse_trade_stock

# 需要导入模块: from account import Account [as 别名]
# 或者: from account.Account import sell_stock [as 别名]
    def analyse_trade_stock(self, in_market_stra, out_market_stra, stock_id = '999999'):
        account = Account(50000*1000)  # initial money
        market_trigger = StraTrigger(in_market_stra, out_market_stra)
        market_status_in_market = False
        hold_stock_days = 0

        # tick: (time, [(stock_id, (open, close, high, low, volume)), (stock_id, ()), ...])
        for tick in self.stocks.iter_ticks():
            time_, stocks_price = tick
            for sid, price in stocks_price:
                if sid == stock_id:
                    in_market_trigger, out_market_trigger = market_trigger.update(price)
                    if not market_status_in_market:  # 不在市场内, 寻找入市机会
                        if in_market_trigger:
                            account.buy_stock(stock_id, price[1], today = time_)  # close价格作为买入, 卖出价
                            market_status_in_market = True
                            market_trigger.enter_market()
                            hold_stock_days = 0
                    else:
                        if price: hold_stock_days += 1
                        if out_market_trigger:
                            account.sell_stock(stock_id, price[1], today = time_, hold_stock_days = hold_stock_days)
                            market_status_in_market = False
                            market_trigger.quit_market()
                break
            account.update(tick)
        account.summarize()
        total_profit = account.report['account_total_profit']
        no_fee_profit = account.report['no_fee_total_profit']
        max_backoff = account.report['max_backoff']
        self._show_account_info(account)
        #self._show_stock_trade(account)
        return (total_profit, no_fee_profit, max_backoff)
开发者ID:ul1234,项目名称:st,代码行数:35,代码来源:analyse_2.py

示例2: analyse_real_trade

# 需要导入模块: from account import Account [as 别名]
# 或者: from account.Account import sell_stock [as 别名]
    def analyse_real_trade(self, in_market_stra_class, out_market_stra_class, buy_stock_stra_class, selected_stock_id = None):
        market_trigger = {}
        market_status_in_market = {}
        hold_stock_days = {}

        if selected_stock_id and not isinstance(selected_stock_id, list): selected_stock_id = [selected_stock_id]

        buy_stra = self._class_instance(buy_stock_stra_class)
        account = Account(50000)  # initial money
        for stock_id in self.stocks.stock_list:
            if stock_id not in Stock.SPECIAL_LIST:
                market_trigger[stock_id] = StraTrigger(self._class_instance(in_market_stra_class), self._class_instance(out_market_stra_class))
                market_status_in_market[stock_id] = False
                hold_stock_days[stock_id] = 0

        # tick: (time, [(stock_id, (open, close, high, low, volume)), (stock_id, ()), ...])
        for tick in self.stocks.iter_ticks():
            time_, stocks_price = tick
            in_trigger_stocks = []
            for stock_id, price in stocks_price:
                if stock_id not in Stock.SPECIAL_LIST and (not selected_stock_id or stock_id in selected_stock_id):
                    in_market_trigger, out_market_trigger = market_trigger[stock_id].update(price)
                    if in_market_trigger:
                        in_trigger_stocks.append(stock_id)
                    # deal with sell first
                    if market_status_in_market[stock_id]:   # have the stock
                        if price: hold_stock_days[stock_id] += 1
                        if out_market_trigger:
                            account.sell_stock(stock_id, price[1], today = time_, hold_stock_days = hold_stock_days[stock_id])
                            market_status_in_market[stock_id] = False
                            market_trigger[stock_id].quit_market()
            # deal with buy
            buy_stocks = buy_stra.buy_stock(in_trigger_stocks, tick, account)
            for stock_id in buy_stocks:
                market_status_in_market[stock_id] = True
                hold_stock_days[stock_id] = 0
                market_trigger[stock_id].enter_market()
            account.update(tick)
        account.summarize()
        total_profit = account.report['account_total_profit']
        no_fee_profit = account.report['no_fee_total_profit']
        max_backoff = account.report['max_backoff']
        self._show_account_info(account)
        #self._show_stock_trade(account)
        return (total_profit, no_fee_profit, max_backoff)
开发者ID:ul1234,项目名称:st,代码行数:47,代码来源:analyse.py


注:本文中的account.Account.sell_stock方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。