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


Python Snapshot.latest_securities_details_in_html方法代码示例

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


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

示例1: Terminal

# 需要导入模块: from snapshot import Snapshot [as 别名]
# 或者: from snapshot.Snapshot import latest_securities_details_in_html [as 别名]

#.........这里部分代码省略.........
            tlabels = xlabels[::d//5+1] + xlabels[-1:]

        # draw return lines
        ax_ret.clear()
        ax_ret.plot(xseries, self._portfolio_return, label='portfolio', linewidth=1.0, color='r')
        ax_ret.plot(xseries, self._benchmark_return, label='benchmark', linewidth=1.0, color='b')

        ax_ret.yaxis.set_major_formatter(FuncFormatter(pct))
        for item in ax_ret.get_yticklabels():
            item.set_size(9)
        ax_ret.set_xlim(0, d-1)
        ax_ret.set_xticks(tseries)
        ax_ret.set_xticklabels(tlabels, fontsize=9)
        ax_ret.set_title('Cumulative Return', fontsize=10)
        ax_ret.grid(True)
        ax_ret.legend(loc=2, prop={'size': 8})

        # draw value line
        ax_val.clear()
        ax_val.plot(xseries, self._portfolio_history, label='portfolio', linewidth=1.0, color='r')

        for item in ax_val.get_yticklabels():
            item.set_size(9)
        ax_val.set_xlim(0, d-1)
        ax_val.set_xticks(tseries)
        ax_val.set_xticklabels(tlabels, fontsize=9)
        ax_val.set_title('Portfolio Value', fontsize=10)
        ax_val.grid(True)

        fig.tight_layout()
        fig.savefig(HISTORY_IMG_FILE)
        logger.info("History image saved at ./static/temp/history.")

    def update_position(self, pos_string):
        new_position = self._parse_new_pos_string(pos_string)

        now = datetime.now()
        today = now.strftime("%Y-%m-%d")
        minute = now.strftime("%H:%M")
        if today in TRADING_DAYS_DICT and "09:30" <= minute <= "15:00":
            self._snapshot.update_position(new_position)
            self._positions.set_current_info(today, self._snapshot.latest_position())

    def _parse_new_pos_string(self, pos_string):
        pos_info = [r.strip() for r in pos_string.strip().split("\n")]
        pos_dict = {}
        pos_dict["cash"] = float(pos_info[0])
        pos_dict["securities"] = {}
        pos_dict["value"] = 0.0

        for r in pos_info[1:]:
            sec, amount = r.split("|")
            sec += ".XSHG" if sec[0] == "6" else ".XSHE"
            pos_dict["securities"][sec] = {
                "amount": float(amount),
                "price": 0.0,
                "name": None,
            }

        short_names = load_sec_shortname(pos_dict["securities"].keys())
        for sec, name in short_names.iteritems():
            pos_dict["securities"][sec]["name"] = name
        return pos_dict

    @property
    def save(self):
        now = datetime.now()
        today = now.strftime("%Y-%m-%d")
        minute = now.strftime("%H:%M")
        if today in TRADING_DAYS_DICT and minute > "15:00":
            self._snapshot.save()
            self._positions.set_current_info(today, self._snapshot.latest_position())
            self._positions.save_current_position()
        return ""

    @property
    def reload_snapshot(self):
        now = datetime.now()
        self._today = now.strftime("%Y-%m-%d")
        self._yesterday = get_trading_days_relatively(self._today, -1)
        self._minute = now.strftime("%H:%M")
        self._is_trading_day = self._today in TRADING_DAYS_DICT

        self._snapshot.refresh()
        return {
            "snapshot_overall_info": self.snapshot_overall_info,
            "snapshot_detail_info": self.snapshot_detail_info
        }

    @property
    def snapshot_overall_info(self):
        return self._snapshot.latest_overall_info_in_html()

    @property
    def snapshot_detail_info(self):
        return self._snapshot.latest_securities_details_in_html()

    @property
    def latest_position_string(self):
        return self._snapshot.latest_position_in_simple_string()
开发者ID:EdwardBetts,项目名称:PortfolioMonitor,代码行数:104,代码来源:terminal.py


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