<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
    <channel>
        <title>RossPedia</title>
        <link>https://ross.selfcoding.cn/</link>
        <description></description>
        <lastBuildDate>Sun, 11 Oct 2026 08:44:11 GMT</lastBuildDate>
        <docs>https://validator.w3.org/feed/docs/rss2.html</docs>
        <generator>https://github.com/jpmonette/feed</generator>
        <language>zh-CN</language>
        <copyright>All rights reserved 2026, Ross</copyright>
        <item>
            <title><![CDATA[金融基础之价格冲击]]></title>
            <link>https://ross.selfcoding.cn/article/价格冲击</link>
            <guid>e056a79c-6304-4cf8-b43f-67b4f1561e9a</guid>
            <pubDate>Fri, 05 Jul 2024 00:00:00 GMT</pubDate>
            <description><![CDATA[在金融交易的世界中，了解交易如何影响市场价格对于交易者和市场分析师来说都至关重要。价格冲击指的是一笔交易对资产市场价格的影响（即交易量跟价格变化的关系）。本文将探讨用于量化价格冲击的关键概念和度量标准，包括市场深度、Hasbrouck度量和Amihud度量。]]></description>
            <content:encoded><![CDATA[<div id="container" class="max-w-5xl font-medium mx-auto undefined"><main class="notion light-mode notion-page notion-block-e056a79c63044cf8b43f67b4f1561e9a"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-5eaa86b874604603a4f9c7b7b2a54226" data-id="5eaa86b874604603a4f9c7b7b2a54226"><span><div id="5eaa86b874604603a4f9c7b7b2a54226" class="notion-header-anchor"></div><a class="notion-hash-link" href="#5eaa86b874604603a4f9c7b7b2a54226" title="交易中的价格冲击"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">交易中的价格冲击</span></span></h2><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-bc661a70f9f44beda3ef510eb5502a95" data-id="bc661a70f9f44beda3ef510eb5502a95"><span><div id="bc661a70f9f44beda3ef510eb5502a95" class="notion-header-anchor"></div><a class="notion-hash-link" href="#bc661a70f9f44beda3ef510eb5502a95" title="介绍"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">介绍</span></span></h3><div class="notion-text notion-block-f7ba67026ed446f386befd79a95fb69d">在金融交易的世界中，了解交易如何影响市场价格对于交易者和市场分析师来说都至关重要。价格冲击指的是一笔交易对资产市场价格的影响（即交易量跟价格变化的关系）。本文将探讨用于量化价格冲击的关键概念和度量标准，包括市场深度、Hasbrouck度量和Amihud度量。</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-afb690e174bd42b28b5011253b893ee0" data-id="afb690e174bd42b28b5011253b893ee0"><span><div id="afb690e174bd42b28b5011253b893ee0" class="notion-header-anchor"></div><a class="notion-hash-link" href="#afb690e174bd42b28b5011253b893ee0" title="市场深度和价格冲击"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">市场深度和价格冲击</span></span></h3><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-9233e21850cf48abb02c093826ef3f25" data-id="9233e21850cf48abb02c093826ef3f25"><span><div id="9233e21850cf48abb02c093826ef3f25" class="notion-header-anchor"></div><a class="notion-hash-link" href="#9233e21850cf48abb02c093826ef3f25" title="市场深度"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">市场深度</span></span></h4><div class="notion-text notion-block-f0f2404706d4416db69efa078bd8c0b3">市场深度指的是市场在不显著影响资产价格的情况下吸收大订单的能力。它可以由参数 <span role="button" tabindex="0" class="notion-equation notion-equation-inline"><span></span></span> 来衡量。小 <span role="button" tabindex="0" class="notion-equation notion-equation-inline"><span></span></span> 表示市场深度大，较大的交易可以发生而价格变化最小；而大<span role="button" tabindex="0" class="notion-equation notion-equation-inline"><span></span></span> 表示即使是小额交易也会引起显著的价格变动。深度越好，交易产生的滑点越低，对 taker 越有利。</div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-57e301de91c94330aa5b349eefd27208" data-id="57e301de91c94330aa5b349eefd27208"><span><div id="57e301de91c94330aa5b349eefd27208" class="notion-header-anchor"></div><a class="notion-hash-link" href="#57e301de91c94330aa5b349eefd27208" title="订单失衡和价格变化"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">订单失衡和价格变化</span></span></h4><div class="notion-text notion-block-d3a62bf01c8c4bf9acc702b8e3e6a3b6">由于交易导致的时期 <span role="button" tabindex="0" class="notion-equation notion-equation-inline"><span></span></span> 内的价格变化 <span role="button" tabindex="0" class="notion-equation notion-equation-inline"><span></span></span> 可以表示为：</div><span role="button" tabindex="0" class="notion-equation notion-equation-block"><span></span></span><div class="notion-text notion-block-dc539b1540644c8889aeb2a9505209fb">其中：</div><ul class="notion-list notion-list-disc notion-block-98d806034a264727822a878067453ab6"><li><span role="button" tabindex="0" class="notion-equation notion-equation-inline"><span></span></span> 是时期 t 内的订单失衡（order imbalance）</li></ul><ul class="notion-list notion-list-disc notion-block-686ace392a7b4a03afec0c5967a19621"><li><span role="button" tabindex="0" class="notion-equation notion-equation-inline"><span></span></span> 是噪声项。</li></ul><div class="notion-text notion-block-fe2508b1fc184c3ea4223fd849e65f55">在我们的例子中， <span role="button" tabindex="0" class="notion-equation notion-equation-inline"><span></span></span> 且 <span role="button" tabindex="0" class="notion-equation notion-equation-inline"><span></span></span> 以 100,000 欧元为单位，我们可以估计由于订单失衡引起的价格变化。</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-838d96efb51a46fe87e786c60f76033b" data-id="838d96efb51a46fe87e786c60f76033b"><span><div id="838d96efb51a46fe87e786c60f76033b" class="notion-header-anchor"></div><a class="notion-hash-link" href="#838d96efb51a46fe87e786c60f76033b" title="无方向成交额的简化度量 "><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">无方向成交额的简化度量 <span role="button" tabindex="0" class="notion-equation notion-equation-inline"><span></span></span></span></span></h3><div class="notion-text notion-block-2ada91c1cdb041ee84f4b3c49ff14245">有时候我们只能获取聚合后的成交额，不知道每一笔交易的主动方向。可以用下面的简化关系描述绝对价格变化与成交额的关联；它不应直接称为 Hasbrouck 度量。Hasbrouck（1991）的经典方法使用交易与报价变化的向量自回归系统，分析交易创新的长期价格影响。这里保留一个便于理解的教学关系：
<span role="button" tabindex="0" class="notion-equation notion-equation-inline"><span></span></span></div><div class="notion-text notion-block-4df62c8fd8834b62b33d7db41066ec86">其中：</div><ul class="notion-list notion-list-disc notion-block-55b36cd9bca74cb79386a5261db995ca"><li><span role="button" tabindex="0" class="notion-equation notion-equation-inline"><span></span></span> 是这个简化关系的系数，需要用多期数据估计，不能由一次模拟识别。</li></ul><ul class="notion-list notion-list-disc notion-block-d707e9ea226f49babed01e01afe7826e"><li><span role="button" tabindex="0" class="notion-equation notion-equation-inline"><span></span></span> 是时期 t 内的交易量。</li></ul><div class="notion-text notion-block-72a5de4fb5cb4216bab10e75e4603853">在我们的例子中， <span role="button" tabindex="0" class="notion-equation notion-equation-inline"><span></span></span> = 0.01，交易量 <span role="button" tabindex="0" class="notion-equation notion-equation-inline"><span></span></span> 以 100,000 欧元为单位，可以有多笔订单组成。</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-aab3a3ffaa1543c3a8a21cb94202d80a" data-id="aab3a3ffaa1543c3a8a21cb94202d80a"><span><div id="aab3a3ffaa1543c3a8a21cb94202d80a" class="notion-header-anchor"></div><a class="notion-hash-link" href="#aab3a3ffaa1543c3a8a21cb94202d80a" title="Amihud 度量 "><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">Amihud 度量 <span role="button" tabindex="0" class="notion-equation notion-equation-inline"><span></span></span></span></span></h3><div class="notion-text notion-block-a81f2a182c064a428925a7e9ca41c1ba">由 Amihud (2002) 引入的 Amihud 度量，通过计算日绝对收益率 <span role="button" tabindex="0" class="notion-equation notion-equation-inline"><span></span></span> 与当日美元成交额 <span role="button" tabindex="0" class="notion-equation notion-equation-inline"><span></span></span> 的比率，再对有效交易日取平均，构造非流动性指标：
<span role="button" tabindex="0" class="notion-equation notion-equation-inline"><span></span></span>，<span role="button" tabindex="0" class="notion-equation notion-equation-inline"><span></span></span>。这里 <span role="button" tabindex="0" class="notion-equation notion-equation-inline"><span></span></span> 是收益率，不是以货币计量的价格变化 <span role="button" tabindex="0" class="notion-equation notion-equation-inline"><span></span></span>；<span role="button" tabindex="0" class="notion-equation notion-equation-inline"><span></span></span> 是成交金额，不是成交股数。零成交额时比率无定义。</div><div class="notion-text notion-block-add474b6207e4b5485228152d38cf004">此度量提供了每单位交易量的价格冲击指示，较高的值表明流动性较低。</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-0ebf18d615df440ab43aa471220e3d80" data-id="0ebf18d615df440ab43aa471220e3d80"><span><div id="0ebf18d615df440ab43aa471220e3d80" class="notion-header-anchor"></div><a class="notion-hash-link" href="#0ebf18d615df440ab43aa471220e3d80" title="动手实验：同样的成交额，为什么冲击不同？"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">动手实验：同样的成交额，为什么冲击不同？</span></span></h3><div class="notion-text notion-block-7130163ee9054baf9f98725f96eae9d9">下面的工具沿用前文的线性模型，初始中间价设为 100 欧元。将每笔成交按主动买方或主动卖方归类，分别记为 B 和 S；每笔只计一次，因此总成交额 V = B + S，订单失衡按 10 万欧元缩放为 q = (B − S) / 100,000。</div><figure class="notion-asset-wrapper notion-asset-wrapper-embed notion-block-f1603d216a3b4035889c5864a981ba64"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:320px"><iframe class="notion-asset-object-fit" src="https://ross.selfcoding.cn/tools/price-impact.html" title="iframe embed" frameBorder="0" allowfullscreen="" loading="lazy" scrolling="auto"></iframe></div><figcaption class="notion-asset-caption">价格冲击实验室：调整买卖成交额、λ 与 ε，观察价格与图表的实时变化。</figcaption></figure><div class="notion-text notion-block-3bae76b4429b41ed911da15af275728b"><a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://ross.selfcoding.cn/tools/price-impact.html">在独立窗口打开价格冲击实验室</a></div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-afee23070ed741b0a124c1a13a858386" data-id="afee23070ed741b0a124c1a13a858386"><span><div id="afee23070ed741b0a124c1a13a858386" class="notion-header-anchor"></div><a class="notion-hash-link" href="#afee23070ed741b0a124c1a13a858386" title="建议按这三个步骤试一试"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">建议按这三个步骤试一试</span></span></h4><ol start="1" class="notion-list notion-list-numbered notion-block-1e4547ab8a554bdf859ca49c5df9dce6"><li>先看“买盘占优”：B = 80 万欧元、S = 20 万欧元，q = 6。λ = 0.15、ε = 0 时，Δm = 0.90 欧元，中间价从 100 变为 100.90。</li></ol><ol start="2" class="notion-list notion-list-numbered notion-block-97f7d58127cf430ca59578fd242c12ef"><li>切到“同成交额 · 买卖平衡”：B = S = 50 万欧元。总成交额仍是 100 万欧元，但 q = 0，模型中的订单流项变为 0。成交活跃不等于存在单向买卖压力。</li></ol><ol start="3" class="notion-list notion-list-numbered notion-block-0dce22a40daa450c9f7fd97cd57e2846"><li>切到“同订单流 · 深度更浅”：保持 B、S 不变，把 λ 提高到 0.40，Δm 变成 2.40 欧元。再拖动 ε，观察其他扰动如何放大、抵消甚至反转观察到的价格变化。</li></ol><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-8e0142a949f3479b93e6def2e05432fc" data-id="8e0142a949f3479b93e6def2e05432fc"><span><div id="8e0142a949f3479b93e6def2e05432fc" class="notion-header-anchor"></div><a class="notion-hash-link" href="#8e0142a949f3479b93e6def2e05432fc" title="如何解读工具中的比率"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">如何解读工具中的比率</span></span></h4><div class="notion-text notion-block-8652c5e68ffd4b10aecf565fa3a59573">为便于阅读，工具显示欧元口径的 Amihud 型单期比率，单位为 bp / 10 万欧元成交额；1 bp = 0.01%。第一个场景的收益率是 0.90%，即 90 bp，成交额为 10 个“10 万欧元”，因此显示 9.00。这是对原始指标的教学类比，不是标准日频、美元口径的实证估计。</div><div class="notion-text notion-block-e2c816eb2b76434096ee03f367781905">λ 是给定的模型参数，Amihud 型比率则由观察到的收益率和成交额计算而来，两者不是同一个量。买卖抵消可能令单期比率为零，噪声也可能使它升高；不能据一次模拟判断真实市场深度。这里模拟的是中间价变化，不是整笔订单的实际平均成交滑点。</div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-7921836b75df4305883527f38af05cbb" data-id="7921836b75df4305883527f38af05cbb"><span><div id="7921836b75df4305883527f38af05cbb" class="notion-header-anchor"></div><a class="notion-hash-link" href="#7921836b75df4305883527f38af05cbb" title="参考阅读"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">参考阅读</span></span></h4><ul class="notion-list notion-list-disc notion-block-94ae74e5680d4a5c9ccf08817af92ab5"><li><a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://www.jstor.org/stable/2328693">Hasbrouck（1991）：Measuring the Information Content of Stock Trades</a></li></ul><ul class="notion-list notion-list-disc notion-block-717ca8f8ff584d09850a76f74a11c529"><li><a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://www.cis.upenn.edu/~mkearns/finread/amihud.pdf">Amihud（2002）：Illiquidity and stock returns</a></li></ul><ul class="notion-list notion-list-disc notion-block-a00b11d3283a4249bd3981345997d436"><li><a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://vlab.stern.nyu.edu/docs/liquidity/ILLIQ-HIST">NYU V-Lab：Amihud 指标及缩放口径</a></li></ul><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-e75bd6ea93e3420e92d2566e4d9fe616" data-id="e75bd6ea93e3420e92d2566e4d9fe616"><span><div id="e75bd6ea93e3420e92d2566e4d9fe616" class="notion-header-anchor"></div><a class="notion-hash-link" href="#e75bd6ea93e3420e92d2566e4d9fe616" title="结论"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">结论</span></span></h3><div class="notion-text notion-block-70a201af898d4714a780e8c414c5b124">了解价格冲击对于有效的交易和市场分析至关重要。通过使用 Hasbrouck 和 Amihud 度量，交易者可以获得市场深度和流动性的洞察，帮助他们做出更明智的决策。</div><div class="notion-text notion-block-154e82b6c0994afcafffef695ff1cdba">无论您是希望最小化交易成本的交易者，还是试图理解市场动态的市场分析师，这些度量提供了评估交易价格冲击的有价值工具。</div><div class="notion-blank notion-block-6609611c1c9f4d5daacf7abd38745e22"> </div></main></div>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[LSMR 做市商定价]]></title>
            <link>https://ross.selfcoding.cn/article/价格偏离</link>
            <guid>31f42bad-fd63-8040-a62f-cffc9a7405e7</guid>
            <pubDate>Wed, 11 Mar 2026 00:00:00 GMT</pubDate>
            <description><![CDATA[预测市场做市商库存偏离]]></description>
            <content:encoded><![CDATA[<div id="container" class="max-w-5xl font-medium mx-auto undefined"><main class="notion light-mode notion-page notion-block-31f42badfd638040a62fcffc9a7405e7"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-31f42badfd63800995c3d7ec15073080" data-id="31f42badfd63800995c3d7ec15073080"><span><div id="31f42badfd63800995c3d7ec15073080" class="notion-header-anchor"></div><a class="notion-hash-link" href="#31f42badfd63800995c3d7ec15073080" title="问题"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">问题</span></span></h2><div class="notion-text notion-block-31f42badfd638016901de2c4da0ebccc">Polymarket 上的价格自带了买卖价差和资金成本，且概率总和可能不完全等于 1。</div><div class="notion-text notion-block-31f42badfd6380e38078e46e1862409a">设 Polymarket 上 n个互斥的结果，其是中间价为 <span role="button" tabindex="0" class="notion-equation notion-equation-inline"><span></span></span> 。</div><div class="notion-text notion-block-31f42badfd63807ab019e35472dc3ebc">你需要将其标准化为基础概率 <span role="button" tabindex="0" class="notion-equation notion-equation-inline"><span></span></span>：</div><div class="notion-text notion-block-31f42badfd638087bae4e125d01ee5de"><span role="button" tabindex="0" class="notion-equation notion-equation-inline"><span></span></span></div><div class="notion-text notion-block-31f42badfd638006a065cb387788957f">此时满足 <span role="button" tabindex="0" class="notion-equation notion-equation-inline"><span></span></span>，这才是的公允价格。</div><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-31f42badfd6380d4babcd320556ef206" data-id="31f42badfd6380d4babcd320556ef206"><span><div id="31f42badfd6380d4babcd320556ef206" class="notion-header-anchor"></div><a class="notion-hash-link" href="#31f42badfd6380d4babcd320556ef206" title="保留价格"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">保留价格</span></span></h4><div class="notion-text notion-block-31f42badfd6380368bc0ce5d36dd3c1b">参数说明</div><ul class="notion-list notion-list-disc notion-block-31f42badfd638069a8a2d6f5c73fa9ba"><li><span role="button" tabindex="0" class="notion-equation notion-equation-inline"><span></span></span>：你考虑了自身库存后的实际内部基准价格。</li></ul><ul class="notion-list notion-list-disc notion-block-31f42badfd6380cab491fe06b59d001f"><li><span role="button" tabindex="0" class="notion-equation notion-equation-inline"><span></span></span>：第一步得出的 Polymarket 标准化参考概率。</li></ul><ul class="notion-list notion-list-disc notion-block-31f42badfd638065b6dcc869f4314c44"><li><span role="button" tabindex="0" class="notion-equation notion-equation-inline"><span></span></span>：你当前持有结果 <span role="button" tabindex="0" class="notion-equation notion-equation-inline"><span></span></span> 的净库存数量。如果是多头，<span role="button" tabindex="0" class="notion-equation notion-equation-inline"><span></span></span> ；如果是空头，<span role="button" tabindex="0" class="notion-equation notion-equation-inline"><span></span></span></li></ul><ul class="notion-list notion-list-disc notion-block-31f42badfd63802ca715c51fb4325788"><li><span role="button" tabindex="0" class="notion-equation notion-equation-inline"><span></span></span>：风险厌恶系数。 <span role="button" tabindex="0" class="notion-equation notion-equation-inline"><span></span></span> 越大，你的价格受库存影响越敏感，倾斜越严重。</li></ul><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-31f42badfd6380f8bec9eeff955bc757" data-id="31f42badfd6380f8bec9eeff955bc757"><span><div id="31f42badfd6380f8bec9eeff955bc757" class="notion-header-anchor"></div><a class="notion-hash-link" href="#31f42badfd6380f8bec9eeff955bc757" title="线性模型"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">线性模型</span></span></h4><div class="notion-text notion-block-31f42badfd63804ab31fc79fcea9b380">加权平均的期望回报</div><div class="notion-text notion-block-31f42badfd638044ba0cd25ef41e1b0a"><span role="button" tabindex="0" class="notion-equation notion-equation-inline"><span></span></span></div><div class="notion-text notion-block-31f42badfd63801f86d0ec5e5ad2700d">保留价格:</div><div class="notion-text notion-block-31f42badfd638076b958fdd114dabb43"><span role="button" tabindex="0" class="notion-equation notion-equation-inline"><span></span></span></div><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-31f42badfd6380bd9551e951a6814c7c" data-id="31f42badfd6380bd9551e951a6814c7c"><span><div id="31f42badfd6380bd9551e951a6814c7c" class="notion-header-anchor"></div><a class="notion-hash-link" href="#31f42badfd6380bd9551e951a6814c7c" title="Logarithmic Market Scoring Rule (LMSR)"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">Logarithmic Market Scoring Rule (LMSR)</span></span></h4><div class="notion-text notion-block-31f42badfd63805d9b9cfab851f845bb">针对 n 个互斥结果，做市商对结果的保留价格 <span role="button" tabindex="0" class="notion-equation notion-equation-inline"><span></span></span>可以通过以下公式计算：</div><div class="notion-text notion-block-31f42badfd63805a8abbff7228ada01a"><span role="button" tabindex="0" class="notion-equation notion-equation-inline"><span></span></span></div></main></div>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[短视频主播 Embedding 建模]]></title>
            <link>https://ross.selfcoding.cn/article/user-embedding</link>
            <guid>7e6a4f4a-27bd-4578-a78a-e63d8c7fecce</guid>
            <pubDate>Tue, 02 Aug 2022 00:00:00 GMT</pubDate>
            <description><![CDATA[随着网络世界的发展，越来越多人开始在直播平台上分享内容。对主播进行建模是一项有趣且有挑战性的任务。在视频号中，主播的行为是复杂且多模态的，复杂体现在主播有简介、历史发步过的短视频，也有直播的信息等；而多模态体现在主播的信息包括文字、图片、视频画面、音频、标签信息等。如何利用这些复杂的信息压缩成一个 n 维的向量是具有挑战性的。]]></description>
            <content:encoded><![CDATA[<div id="container" class="max-w-5xl font-medium mx-auto undefined"><main class="notion light-mode notion-page notion-block-7e6a4f4a27bd4578a78ae63d8c7fecce"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-17396f4aea4347d896b144c2b172e84d" data-id="17396f4aea4347d896b144c2b172e84d"><span><div id="17396f4aea4347d896b144c2b172e84d" class="notion-header-anchor"></div><a class="notion-hash-link" href="#17396f4aea4347d896b144c2b172e84d" title="前言"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">前言</span></span></h2><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-6094c98a92f147c0bd1724037c15a051" data-id="6094c98a92f147c0bd1724037c15a051"><span><div id="6094c98a92f147c0bd1724037c15a051" class="notion-header-anchor"></div><a class="notion-hash-link" href="#6094c98a92f147c0bd1724037c15a051" title="背景"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">背景</span></span></h3><div class="notion-text notion-block-c50f2c7100344c53846ae0b53b9f3615">随着网络世界的发展，越来越多人开始在直播平台上分享内容。对主播进行建模是一项有趣且有挑战性的任务。在视频号中，主播的行为是复杂且多模态的，复杂体现在主播有简介、历史发步过的短视频，也有直播的信息等；而多模态体现在主播的信息包括文字、图片、视频画面、音频、标签信息等。如何利用这些复杂的信息压缩成一个 n 维的向量是具有挑战性的。</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-7d029b3001684dbe8b8d44fc58a6c1f0" data-id="7d029b3001684dbe8b8d44fc58a6c1f0"><span><div id="7d029b3001684dbe8b8d44fc58a6c1f0" class="notion-header-anchor"></div><a class="notion-hash-link" href="#7d029b3001684dbe8b8d44fc58a6c1f0" title="应用场景"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">应用场景</span></span></h3><div class="notion-text notion-block-1470cbf0e0ff4270ba6dbbe4b033c7e6">主播 Embedding 跟其他类型的 Embedding 相似，可以应用在常见的检索场景。以下是主播 Embedding 的使用场景例子：</div><ol start="1" class="notion-list notion-list-numbered notion-block-273d910596a843db9feb505ad45609d8"><li>相似主播检索：在运营和黑产场景，想要通过一个种子主播找出其相关的主播时候使用主播Embedding是非常高效的，这个有利于运营侧快速地找出相似的主播。</li></ol><ol start="2" class="notion-list notion-list-numbered notion-block-7cf728f4216f424c9e0a14ea0b2853a8"><li>主播冷启动：推荐系统通过用户和物品的交互，来预测用为未来的行为和兴趣。但是当有新主播加入的时候，往往需要冷启动将新主播分发给最有可能对其有兴趣的用户，以产生有效的曝光。</li></ol><ol start="3" class="notion-list notion-list-numbered notion-block-abcb0be7dabb452c8a3df09fe0bed578"><li>主播打散/去重：内容相近的主播在Embedding向量空间中距离也相近，搭配聚类算法可达到相似主播去重和打散的效果。</li></ol><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-ad4dc500136a4675a8553b291b960d93" data-id="ad4dc500136a4675a8553b291b960d93"><span><div id="ad4dc500136a4675a8553b291b960d93" class="notion-header-anchor"></div><a class="notion-hash-link" href="#ad4dc500136a4675a8553b291b960d93" title="方案"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">方案</span></span></h2><div class="notion-text notion-block-252f2736b4b6443bae91d638f38bfda2">信息时代数据为王，当可以直接获得用户的点击行为的时候，训练一个主播 Embedding 不是一件困难的事情。然而，由于用户的点击行为是用户的隐私，很多情况下非业务方是无法获取到用户的点击日志的。作为替代，业务方可提供基于用户行为训练的主播 ID-Embedding，可以通过蒸馏的方式进行训练主播内容 Embedding。</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-27ae107653f54f668665ab3279f00bfb" data-id="27ae107653f54f668665ab3279f00bfb"><span><div id="27ae107653f54f668665ab3279f00bfb" class="notion-header-anchor"></div><a class="notion-hash-link" href="#27ae107653f54f668665ab3279f00bfb" title="自监督主播 Embedding"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">自监督主播 Embedding</span></span></h3><div class="notion-text notion-block-7cae3741c3b6435da841a7fe5f45d610">在无法获取任务与用户点击相关的信息之时，而因为标注难度和数量太大无法进行人工标注训练集的时候，使用自监督方式训练是一个有效的方案。</div><div class="notion-text notion-block-32488c7ffd29449a873901cfd39c0042">近年来出现了很多自监督训练的方案，其中 BERT 最广为人知，其通过 Mask Language Model (MLM) 和 Next Sentence Prediction (NSP) 两个预训练任务来建模。MLM是通过随机 Mask 句子中的一些字，用未被 Mask 的上下文预测被 Mask 掉的词，以学习句子的表示；而 NSP 是将两个句子拼接之后，判断两个是否是后面的句子是不是前句的下一句，以学习句子之间的相似信息。语言模型在大规模无标签语料库上进行预训练以强化很多下游任务，受预训练语言模型的启发，微软近年来提出了使用用户行为构建的预训练用户模型 PTUM，提出了Masked Behavior Prediction (MBP) 和 Next K Behaviors Prediction (NBP) 两个用户 Embedding 预训练任务。</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-b079cf26afac422ab409510e7bddd678"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F86befcd3-3600-469d-9334-d8f5b8ef32ba%2FUntitled.png?table=block&amp;id=b079cf26-afac-422a-b409-510e7bddd678" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-b236f65927684fbbbb7ebaec345b2a30">图1：PTUM 架构示意图</div><div class="notion-text notion-block-826381315b364dce94c3845f48361fbe">类似的，我们受到 PTUM 的启发，希望通过 Mask 的方式构造自监督的训练样本对，并通过对比学习进行无监督训练。但是由于应用场景包含多个模态，BERT / PTUM 这一类模型使用未被 MASK 的上下文预测 MASK 元素的 Embedding，在异构的输入上并不适用；因此我们利用对比学习的思想做了一些改造，将预测 MASK 元素的 Embedding 改为预测数据增强之后的主播 Embedding；数据增强采用随机 MASK 输入的方式，为了较少信息泄露，相同的主播可见信息的交集比例需要限制在较小的数值。</div><div class="notion-text notion-block-b20ec163e1784bef8cfeb43938d38db1">损失函数我们采用InfoNCE，同个 Batch 内相同的主播当做是正样本，不同主播之间是负样本。</div><div class="notion-blank notion-block-cec48894f15949f2989bd8645bd6e68a"> </div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-685d01b28e6240acae4389b939d05e00"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2Fafe4fdb6-860a-4c44-aea5-f0a9037d95d2%2FUntitled.png?table=block&amp;id=685d01b2-8e62-40ac-ae43-89b939d05e00" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-5bbbe999e6ab4fa291337ffc0505b871">图2：主播 Embedding 对比学习框架</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-0887135d71da4e8cad00d23aa8c890cb" data-id="0887135d71da4e8cad00d23aa8c890cb"><span><div id="0887135d71da4e8cad00d23aa8c890cb" class="notion-header-anchor"></div><a class="notion-hash-link" href="#0887135d71da4e8cad00d23aa8c890cb" title="将信息从 ID-Embedding 迁移到主播内容 Embedding"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">将信息从 ID-Embedding 迁移到主播内容 Embedding</span></span></h3><div class="notion-text notion-block-d08c8d3ad76b4c0dbc0bac2afd33c099">ID-Embedding 是把用户和物品，并利用点击日志进行训练；而主播内容 Embedding 是通过主播的基本信息和历史行为（历史短视频以及直播）来构造画像。由于兴趣相同的用户一般会和相似的主播进行交互，例如喜欢 NBA 的用户与篮球类的主播交互更多，因此内容相似的主播在 ID-Embedding 的空间上也更加相近，我们希望通过将有用的信息从 ID-Embedding 迁移到主播内容 Embedding。下面将介绍两类已经实践过的知识迁移方式。</div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-62e30a2871cb4a96b380c9dd35872fe4" data-id="62e30a2871cb4a96b380c9dd35872fe4"><span><div id="62e30a2871cb4a96b380c9dd35872fe4" class="notion-header-anchor"></div><a class="notion-hash-link" href="#62e30a2871cb4a96b380c9dd35872fe4" title="基于蒸馏的知识迁移"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">基于蒸馏的知识迁移</span></span></h4><div class="notion-text notion-block-e097035fa18d438d9c210999087d958a">当只有 teacher 模型的输出（ ID-Embedding） 没有 teacher 模型参数时，下面是一些参考的蒸馏方案参考：</div><ul class="notion-list notion-list-disc notion-block-bdb9446b78314c20974e66eb99f9c373"><li>最简单的方式自然是直接把 ID-Embedding 蒸馏到 student 模型的 feature map 上。</li></ul><ul class="notion-list notion-list-disc notion-block-a1f06cdc07f442f3868f1f2fb7ecc58c"><li>在 ID-Embedding 上采用聚类提取伪标签后，student 根据伪标签用分类的方式进行训练。</li></ul><ul class="notion-list notion-list-disc notion-block-313942cc53164285ac77149ab4e1f303"><li>利用样本之间的关系进行蒸馏，比较经典的方案是 RKD loss，其利用一个 batch 内 ID-Embedding 构造相似度矩阵作为监督信息，让 student 模型学习样本之间的关系。</li></ul><div class="notion-text notion-block-efa437fa87754532b2640b22f62a6e9f">然而以上的蒸馏方式在存在两点不足：</div><ul class="notion-list notion-list-disc notion-block-b83224a465124549b2423ec9f8f75c1c"><li>抗噪能力差：如果 ID-Embedding 噪声较多，student 模型学习到的 Embedding 同样也有很多噪声。</li></ul><ul class="notion-list notion-list-disc notion-block-290834ace89048f1ba533ac8232ad6cf"><li>不能充分利用预训练模型：由于是 feature map 层垮了领域，直接蒸馏的会把预训练模型已经学习到的知识破坏，需要在蒸馏过程中加入限制条件。</li></ul><div class="notion-text notion-block-5b69d35a5bc34590bc71d6ef2b2b5cf5">综上，teacher 模型的性能上限决定了 student 模型的性能上限，在跨域的情况下蒸馏信息也会磨损。</div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-89c032d75aaa43c0b62fa42f61b808d0" data-id="89c032d75aaa43c0b62fa42f61b808d0"><span><div id="89c032d75aaa43c0b62fa42f61b808d0" class="notion-header-anchor"></div><a class="notion-hash-link" href="#89c032d75aaa43c0b62fa42f61b808d0" title="基于对比学习的知识迁移"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">基于对比学习的知识迁移</span></span></h4><div class="notion-text notion-block-194c979c243a45c4b051bc5b03568966">为了解决直接蒸馏抗噪能力差和不好利用预训练模型的问题，我们采用基于检索构造正样本 + 对比学习进行知识迁移。其中基于检索构造正样本目的是为了数据降噪；对比学习是有监督与图2的结构一样，而正样本来自 query 样本和其相似召回的结果，负样本是 batch 内出自己之外的其他样本，整个训练过程在预训练模型上搭建，能够充分利用预训练模型的优势。</div><div class="notion-text notion-block-c45a3c25d22542bc88adfc9037128752">由于 ID-Embedding 是基于用户点击训练的，其相似性并非是内容语义相似，因此将 ID-Embedding 召回结果中不是内容语义相似的样本过滤，过滤的方式有很多种，包括计算编辑距离、利用相似模型计算相似度等方式。</div><div class="notion-text notion-block-afd041d16f114a1cb03b1bc1af50d8de">与无监督的对比学习不同的是：有监督的对比学习能够获取困难正/负样本，任务的难度更大，模型在实际场景中使用的时候更鲁棒。</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4bbd1bf75f6540aea49147d5841daf51"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:394px;max-width:100%;flex-direction:column"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F4ff82fd0-12df-46e2-ba13-861743d60660%2FUntitled.png?table=block&amp;id=4bbd1bf7-5f65-40ae-a491-47d5841daf51" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-efa5fb7067bf44088cd21816001a5c87">在真实的业务场景中，ID-Embedding 通常噪声比较多，而对比学习的知识迁移中整个数据清洗过程相对可控，训练过程也能很好的预训练模型的优势。</div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-3ce6e35becd0489ab53dd3072ea3c1ab" data-id="3ce6e35becd0489ab53dd3072ea3c1ab"><span><div id="3ce6e35becd0489ab53dd3072ea3c1ab" class="notion-header-anchor"></div><a class="notion-hash-link" href="#3ce6e35becd0489ab53dd3072ea3c1ab" title="总结"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">总结</span></span></h2><div class="notion-text notion-block-77b42fdb44ef494590a56924bcc0b05a">本文探索了无用户点击数据的情况下构建主播 Embedding 的可能方案，实验对比了两类知识迁移的方式，基于对比学习的知识迁移的效果明显优于基于蒸馏的知识迁移，其中数据清洗的过程对最终效果影响较大。主播级别的 Embedding 可用的信息有很多，但 UGC 平台的数据的噪声也是很大，如何对数据降噪和精简显得格外重要；不仅需要处理模态缺失的问题，还要处理模态信息无意义使得召回效果不稳定的问题。未来，将探索更多的数据挖掘方式和模态交互的方案，以更好得描述用户代表的内容倾向。</div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-e4c65103d0134dbc97c0a288962c69a7" data-id="e4c65103d0134dbc97c0a288962c69a7"><span><div id="e4c65103d0134dbc97c0a288962c69a7" class="notion-header-anchor"></div><a class="notion-hash-link" href="#e4c65103d0134dbc97c0a288962c69a7" title="参考文献"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">参考文献</span></span></h2><ol start="1" class="notion-list notion-list-numbered notion-block-a03b1af8e0e9401782dc574da81673c4"><li>Wu, C., Wu, F., Qi, T., Lian, J., Huang, Y., &amp; Xie, X. (2020). PTUM: Pre-training user model from unlabeled user behaviors via self-supervision. <em>Findings of the Association for Computational Linguistics Findings of ACL: EMNLP 2020</em>, 1939–1944. https://doi.org/10.18653/v1/2020.findings-emnlp.174</li></ol><ol start="2" class="notion-list notion-list-numbered notion-block-e7ab4b3f30ba4e27bff7fbbe983d8453"><li>Gao, T., Yao, X., &amp; Chen, D. (2021). SimCSE: Simple Contrastive Learning of Sentence Embeddings. <em>EMNLP 2021 - 2021 Conference on Empirical Methods in Natural Language Processing, Proceedings</em>, 6894–6910. https://doi.org/10.18653/v1/2021.emnlp-main.552</li></ol><ol start="3" class="notion-list notion-list-numbered notion-block-67ac045c470947bd97b1397d59b9bce4"><li>Devlin, J., Chang, M. W., Lee, K., &amp; Toutanova, K. (2019). BERT: Pre-training of deep bidirectional transformers for language understanding. <em>NAACL HLT 2019 - 2019 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies - Proceedings of the Conference</em>, <em>1</em>, 4171–4186. https://doi.org/10.48550/arxiv.1810.04805</li></ol><ol start="4" class="notion-list notion-list-numbered notion-block-01352e8e181b48e883628d91774af045"><li>Hinton, G., Vinyals, O., &amp; Dean, J. (2015). <em>Distilling the Knowledge in a Neural Network</em>. https://doi.org/10.48550/arxiv.1503.02531</li></ol><ol start="5" class="notion-list notion-list-numbered notion-block-7c091c8417524f8aa4e85ceed9ff7064"><li>Romero, A., Ballas, N., Kahou, S. E., Chassang, A., Gatta, C., &amp; Bengio, Y. (2015, December 19). FitNets: Hints for thin deep nets. <em>3rd International Conference on Learning Representations, ICLR 2015 - Conference Track Proceedings</em>. https://doi.org/10.48550/arxiv.1412.6550</li></ol><ol start="6" class="notion-list notion-list-numbered notion-block-910b8c9b304649488de4ec05cf0b08fe"><li>Park, W., Kim, D., Lu, Y., &amp; Cho, M. (2019). Relational knowledge distillation. <em>Proceedings of the IEEE Computer Society Conference on Computer Vision and Pattern Recognition</em>, <em>2019</em>-<em>June</em>, 3962–3971. https://doi.org/10.1109/CVPR.2019.00409</li></ol></main></div>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[金融基础之交易执行]]></title>
            <link>https://ross.selfcoding.cn/article/996fc1f6-6709-46db-b4b8-4fe965240cf1</link>
            <guid>996fc1f6-6709-46db-b4b8-4fe965240cf1</guid>
            <pubDate>Fri, 05 Jul 2024 00:00:00 GMT</pubDate>
            <description><![CDATA[在金融交易中，评估交易执行的质量对投资者和交易员至关重要。本文将探讨两个常用的衡量交易执行质量的指标：实施缺口（Implementation Shortfall）和成交量加权平均价格（VWAP）。]]></description>
            <content:encoded><![CDATA[<div id="container" class="max-w-5xl font-medium mx-auto undefined"><main class="notion light-mode notion-page notion-block-996fc1f6670946dbb4b84fe965240cf1"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><h4 class="notion-h notion-h3 notion-h-indent-0 notion-block-57e9d0f02784435cb7d1b13d54f6ecbc" data-id="57e9d0f02784435cb7d1b13d54f6ecbc"><span><div id="57e9d0f02784435cb7d1b13d54f6ecbc" class="notion-header-anchor"></div><a class="notion-hash-link" href="#57e9d0f02784435cb7d1b13d54f6ecbc" title="衡量交易执行的指标：实施缺口（Implementation Shortfall）与成交量加权平均价格（VWAP）"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">衡量交易执行的指标：实施缺口（Implementation Shortfall）与成交量加权平均价格（VWAP）</span></span></h4><div class="notion-text notion-block-01a3f4bc32e240609587976a340b1bec">在金融交易中，评估交易执行的质量对投资者和交易员至关重要。本文将探讨两个常用的衡量交易执行质量的指标：实施缺口（Implementation Shortfall）和成交量加权平均价格（VWAP）。</div><h4 class="notion-h notion-h3 notion-h-indent-0 notion-block-fc2c593d1ffd4caabff963a1d0ffd41b" data-id="fc2c593d1ffd4caabff963a1d0ffd41b"><span><div id="fc2c593d1ffd4caabff963a1d0ffd41b" class="notion-header-anchor"></div><a class="notion-hash-link" href="#fc2c593d1ffd4caabff963a1d0ffd41b" title="实施缺口（Implementation Shortfall）"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">实施缺口（Implementation Shortfall）</span></span></h4><div class="notion-text notion-block-a68c683334b549499af4cfe0c0c5098b">实施缺口（IS）是衡量执行成本和机会成本的关键指标。它的定义如下：</div><div class="notion-text notion-block-bb181710f241409ab3a1d7c88414fa67"><span role="button" tabindex="0" class="notion-equation notion-equation-inline"><span></span></span></div><div class="notion-text notion-block-8d0a8ce22d6649b5921494a52f91a345">其中：</div><ul class="notion-list notion-list-disc notion-block-5667db4a93354211b1384b1e22a5efac"><li><span role="button" tabindex="0" class="notion-equation notion-equation-inline"><span></span></span> 是计划购买的股票数量。</li></ul><ul class="notion-list notion-list-disc notion-block-dadaf28547644cacbff3a6ccb5e202a4"><li><span role="button" tabindex="0" class="notion-equation notion-equation-inline"><span></span></span> 是初始市场价格。</li></ul><ul class="notion-list notion-list-disc notion-block-2e8eb3ab47bf4bb9b444fb4deffcdf0d"><li><span role="button" tabindex="0" class="notion-equation notion-equation-inline"><span></span></span> 是时间 t 时的市场价格。</li></ul><ul class="notion-list notion-list-disc notion-block-626aed5b822244cb82d48b6b1c77cc70"><li><span role="button" tabindex="0" class="notion-equation notion-equation-inline"><span></span></span> 是到时间 t 已执行的订单比例。</li></ul><ul class="notion-list notion-list-disc notion-block-10315ccdc2994f1db41d2334ae9da2aa"><li><span role="button" tabindex="0" class="notion-equation notion-equation-inline"><span></span></span> 是已执行订单的平均执行价格。</li></ul><div class="notion-text notion-block-140cdd9a582a42b6a899e716326fa020">进一步展开公式，可以得到：</div><div class="notion-text notion-block-746c46cc50bc4c3685ea3c39be28a715"><span role="button" tabindex="0" class="notion-equation notion-equation-inline"><span></span></span></div><div class="notion-text notion-block-e8545c08463747aeb8dbfc4d0ee2b704">实施缺口反映了交易执行的两个主要成本：</div><ol start="1" class="notion-list notion-list-numbered notion-block-ab5c9da7ebf7436cb3972dfe3d0e7ba3"><li><b>执行成本</b>：已执行订单的执行价格与初始市场价格之间的差异。</li></ol><ol start="2" class="notion-list notion-list-numbered notion-block-16aa843a567d44efab956799e7c1b9be"><li><b>机会成本</b>：未执行部分订单由于市场价格变化而失去的潜在收益。</li></ol><div class="notion-text notion-block-1169c5851e3c4d6397af2f3cee8a8aa5">通过计算实施缺口，交易员可以量化交易过程中因价格冲击和市场波动造成的成本，从而优化交易策略，减少交易成本，提高投资回报。</div><h4 class="notion-h notion-h3 notion-h-indent-0 notion-block-b26aba1dba8e43b6bb65c2995c7ef78c" data-id="b26aba1dba8e43b6bb65c2995c7ef78c"><span><div id="b26aba1dba8e43b6bb65c2995c7ef78c" class="notion-header-anchor"></div><a class="notion-hash-link" href="#b26aba1dba8e43b6bb65c2995c7ef78c" title="成交量加权平均价格（VWAP）"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">成交量加权平均价格（VWAP）</span></span></h4><div class="notion-text notion-block-f15058e2266a4e9ca8ea978882d1e998">成交量加权平均价格（VWAP）是衡量交易执行质量的另一个重要指标。其计算公式为：</div><div class="notion-text notion-block-3313ee3219c64691826ed5d90a4accb6"><span role="button" tabindex="0" class="notion-equation notion-equation-inline"><span></span></span></div><div class="notion-text notion-block-e0d0a9f452ce45c39ff62b7b4e6a9b3c">其中：</div><ul class="notion-list notion-list-disc notion-block-98ffb787af8a4fed9a7a95d64c659389"><li><span role="button" tabindex="0" class="notion-equation notion-equation-inline"><span></span></span> 是订单权重，<span role="button" tabindex="0" class="notion-equation notion-equation-inline"><span></span></span> 是第 <span role="button" tabindex="0" class="notion-equation notion-equation-inline"><span></span></span> 笔订单的数量。</li></ul><ul class="notion-list notion-list-disc notion-block-20b9fef35d0143b0a0d09023c5879972"><li><span role="button" tabindex="0" class="notion-equation notion-equation-inline"><span></span></span> 是第 <span role="button" tabindex="0" class="notion-equation notion-equation-inline"><span></span></span> 笔订单的价格。</li></ul><div class="notion-text notion-block-d4072d8ad7c9482c9eb5f5bb1ac3edc1">VWAP 是总交易额（所有订单的价格乘以相应的交易量的总和）除以总交易量得到的平均价格。它表示在一个时间段内所有交易的成交量加权平均价格。</div><div class="notion-text notion-block-e99f83fd3f594fff8dc8a53e907ebffe">交易员可以将实际获得的交易价格与 VWAP 进行比较：</div><ul class="notion-list notion-list-disc notion-block-54d8368c0ece411fa591fb013c45d481"><li><b>买入时</b>：如果实际价格低于 VWAP，说明交易执行得很好。</li></ul><ul class="notion-list notion-list-disc notion-block-88bec7b6828742d48dce6b2637571b06"><li><b>卖出时</b>：如果实际价格高于 VWAP，说明交易执行得很好。</li></ul><div class="notion-text notion-block-f7d50088e52846f8beb4609c5086b0d9">然而，VWAP 可能过度依赖于少数几笔大额订单，因此在使用时需要谨慎，以防止受到少数异常订单的误导。</div><h4 class="notion-h notion-h3 notion-h-indent-0 notion-block-ee1d08718eed43f799f5fcd99ef02509" data-id="ee1d08718eed43f799f5fcd99ef02509"><span><div id="ee1d08718eed43f799f5fcd99ef02509" class="notion-header-anchor"></div><a class="notion-hash-link" href="#ee1d08718eed43f799f5fcd99ef02509" title="总结"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">总结</span></span></h4><div class="notion-text notion-block-6e392ccbde9e4df1b1d5c3afa723efbf">实施缺口和成交量加权平均价格是评估交易执行质量的两个重要指标。实施缺口通过量化执行成本和机会成本，帮助交易员优化交易策略；而 VWAP 通过衡量一个时间段内的平均交易价格，提供了一个直观的评估交易质量的基准。</div><div class="notion-text notion-block-8d3219d1e0f442d09172a20e2d8f2060">通过结合这两个指标，交易员和投资者可以全面评估交易执行的效率，制定更有效的交易策略，提升投资回报。无论是在快速波动的市场中，还是在稳定的市场环境下，这些指标都能为交易决策提供宝贵的洞见。</div></main></div>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Seaborn 画时序数据图]]></title>
            <link>https://ross.selfcoding.cn/article/seaborn</link>
            <guid>c5574014-fe63-40bc-94d3-77a4c8db4684</guid>
            <pubDate>Thu, 02 Mar 2023 00:00:00 GMT</pubDate>
            <description><![CDATA[seaborn时序数据可视化]]></description>
            <content:encoded><![CDATA[<div id="container" class="max-w-5xl font-medium mx-auto undefined"><main class="notion light-mode notion-page notion-block-c5574014fe6340bc94d377a4c8db4684"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><div class="notion-text notion-block-d274a9642ac548728b4d55dd9052546f">数据可视化在机器学习中是一项关键技术，它可以帮助我们更好地理解数据和模型的行为，并支持我们在模型选择、调整和解释过程中做出更加明智的决策。</div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-0964607c00a849cdb157693c996c3826" data-id="0964607c00a849cdb157693c996c3826"><span><div id="0964607c00a849cdb157693c996c3826" class="notion-header-anchor"></div><a class="notion-hash-link" href="#0964607c00a849cdb157693c996c3826" title="时序数据可视化"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">时序数据可视化</span></span></h2><div class="notion-text notion-block-6c2dc47176c44c5caefef08e40e2dd8d">时序数据比较常用的是二维的折线图，下面用 seaborn 折线图可视化。</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-c2271e1e9ac7412d93eee80ee2a95c4d"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:500px;max-width:100%;flex-direction:column"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F3bea6a56-a1d9-4e79-95da-59a35cf2e1f7%2FUntitled.png?table=block&amp;id=c2271e1e-9ac7-412d-93ee-e80ee2a95c4d" alt="notion image" loading="lazy" decoding="async"/></div></figure><pre class="notion-code"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-python">from typing import List
import seaborn as sns
import matplotlib.pyplot as plt


def plot_lines(x: List[float], y1: List[float], y2: List[float],
               y3: List[float], show: bool = False, save_path: str = None):
    &quot;&quot;&quot;
    画图，双Y轴
    :param y1:
    :param y2:
    :param y3:
    :param show:
    :param save_path:
    :return:
    &quot;&quot;&quot;
    sns.set_style(&#x27;darkgrid&#x27;)
    assert len(y1) == len(y2) == len(y3)
    fig, ax = plt.subplots(figsize=(10, 10))
    sns.lineplot(x=x, y=y1, label=&#x27;y1&#x27;, color=&#x27;green&#x27;, ax=ax)
    sns.lineplot(x=x, y=y2, label=&#x27;y2&#x27;, color=&#x27;blue&#x27;, ax=ax)

    ax.hlines(1.0, x[0], x[-1], colors=&quot;black&quot;, linestyles=&quot;dashed&quot;)
    ax2 = ax.twinx()
    sns.lineplot(x=x, y=y3, label=&#x27;y3&#x27;, color=&#x27;red&#x27;, ax=ax2)
    lines_1, labels_1 = ax.get_legend_handles_labels()
    lines_2, labels_2 = ax2.get_legend_handles_labels()

    lines = lines_1 + lines_2
    labels = labels_1 + labels_2
    ax2.legend().remove()
    ax.legend(lines, labels, loc=&#x27;upper left&#x27;)

    ax.set_xlabel(&#x27;X&#x27;)
    ax.set_ylabel(&#x27;Y_left&#x27;)
		ax2.set_ylabel(&#x27;Y_right&#x27;)
    ax.set_title(&#x27;Title&#x27;)
    if show:
        print(&#x27;showing plot...&#x27;)
        fig.show()
    if save_path is not None:
        fig.savefig(save_path, bbox_inches=&#x27;tight&#x27;)


if __name__ == &#x27;__main__&#x27;:
    import numpy as np

    n_sample = 100
    x = list(range(n_sample))
    y1 = np.random.random(n_sample)
    y1 = np.cumsum(y1)
    y2 = np.random.random(n_sample)
    y2 = np.cumsum(y2)
    y3 = list(range(n_sample))
    plot_lines(x, y1, y2, y3, show=True)</code></pre><div class="notion-text notion-block-9a77e277108e4a7a826c1f1a16c22195">代码解析：</div><ul class="notion-list notion-list-disc notion-block-12464cd4b5164a41add446aa817c063f"><li>第一步：在图上画出绿色和蓝色线，并用 <code class="notion-inline-code">hlines</code> 画一条 y = 1.0 的黑色橫虚线。</li><ul class="notion-list notion-list-disc notion-block-12464cd4b5164a41add446aa817c063f"><pre class="notion-code"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-python">fig, ax = plt.subplots(figsize=(10, 10))
sns.lineplot(x=x, y=y1, label=&#x27;y1&#x27;, color=&#x27;green&#x27;, ax=ax)
sns.lineplot(x=x, y=y2, label=&#x27;y2&#x27;, color=&#x27;blue&#x27;, ax=ax)
ax.hlines(1.0, x[0], x[-1], colors=&quot;black&quot;, linestyles=&quot;dashed&quot;)</code></pre></ul></ul><ul class="notion-list notion-list-disc notion-block-5a8cf6bdd0bb4aedb58b0284814dbf0f"><li>第二步：在图上新建一个 y 轴坐标在右边的 axe，并画线</li><ul class="notion-list notion-list-disc notion-block-5a8cf6bdd0bb4aedb58b0284814dbf0f"><pre class="notion-code"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-python">ax2 = ax.twinx()
sns.lineplot(x=x, y=y3, label=&#x27;y3&#x27;, color=&#x27;red&#x27;, ax=ax2)</code></pre></ul></ul><ul class="notion-list notion-list-disc notion-block-b1f2d93b04a24caba0c543f9c39f2421"><li>第三步：合并 ax 和 ax2 的图例</li><ul class="notion-list notion-list-disc notion-block-b1f2d93b04a24caba0c543f9c39f2421"><pre class="notion-code"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-python"># 得到两个 axe 的线和坐标
lines_1, labels_1 = ax.get_legend_handles_labels()
lines_2, labels_2 = ax2.get_legend_handles_labels()

lines = lines_1 + lines_2
labels = labels_1 + labels_2
# 把 ax2 的图例线去掉，不然左上角会重复出现 y3
ax2.legend().remove()
ax.legend(lines, labels, loc=&#x27;upper left&#x27;)</code></pre></ul></ul><div class="notion-blank notion-block-a6051f3c2d0b46b79ad698d58277b59b"> </div><div class="notion-text notion-block-473af5ae63dc49a08ed31eb4af09fe5e">如果我们把 x 轴的数据替换成 datetime 对象，则效果如下</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-70fad111c8fb4662ac82a6ae183a9d58"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:500px;max-width:100%;flex-direction:column"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F6be1422c-2e8b-43bc-abe2-d95cbb0a8a21%2FUntitled.png?table=block&amp;id=70fad111-c8fb-4662-ac82-a6ae183a9d58" alt="notion image" loading="lazy" decoding="async"/></div></figure><pre class="notion-code"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-python">if __name__ == &#x27;__main__&#x27;:
    import numpy as np
		import datetime
    n_sample = 100

    x = list(range(n_sample))

		base = datetime.datetime.today()
    x = [base + datetime.timedelta(days=x) for x in range(n_sample)]

    y1 = np.random.random(n_sample)
    y1 = np.cumsum(y1)
    y2 = np.random.random(n_sample)
    y2 = np.cumsum(y2)
    y3 = list(range(n_sample))
    plot_lines(x, y1, y2, y3, show=True)</code></pre></main></div>]]></content:encoded>
        </item>
    </channel>
</rss>