<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Charles D on Medium]]></title>
        <description><![CDATA[Stories by Charles D on Medium]]></description>
        <link>https://medium.com/@kaiqidong?source=rss-71f38422adff------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*6cl6gxMQkjnwngGX.jpg</url>
            <title>Stories by Charles D on Medium</title>
            <link>https://medium.com/@kaiqidong?source=rss-71f38422adff------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 07:13:57 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kaiqidong/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Python Essentials Part 1 — args and kwargs in functions]]></title>
            <link>https://towardsdev.com/python-essentials-part-1-args-and-kwargs-in-functions-93fc3a5db388?source=rss-71f38422adff------2</link>
            <guid isPermaLink="false">https://medium.com/p/93fc3a5db388</guid>
            <category><![CDATA[beginner]]></category>
            <category><![CDATA[functional-programming]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[args-and-kwargs]]></category>
            <dc:creator><![CDATA[Charles D]]></dc:creator>
            <pubDate>Mon, 06 Dec 2021 18:32:36 GMT</pubDate>
            <atom:updated>2021-12-10T12:12:00.973Z</atom:updated>
            <content:encoded><![CDATA[<h3>Python Essentials Part 1 — args and kwargs in functions</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oubC8oopRUKsYle-2POE-A.jpeg" /></figure><p>In this article, I will explain a very basic but useful concept in Python: function arguments and the usage of args and kwargs. In addition, I will explain how unpacking operators and positional-only parameters work.</p><h3><strong>Functions in Python:</strong></h3><p>A function is a self-contained block of code within which performs a defined task. All we should know about a function is what argument(s) it takes (if there is any), and what results it returns (if there is any).</p><pre><strong>def</strong> func(a, b):<br>    return a / b</pre><p>Writing functions has at least a couple advantages:</p><ul><li>Reusability: You can define a function and use it anywhere repeatedly in your application</li><li>Modularity: If you have a big and complex task which can be broken into different tasks to perform, writing different functions to focus on performing different specific sub-tasks instead of putting all code together as a whole, can make your code much easier to read and manage. It is more obvious to see the benefit of modularising very complex tasks this way.</li></ul><h3><strong>Arguments in functions:</strong></h3><p>A function can have 0 or 1 or multiple arguments. There are generally two types of arguments:</p><p><strong>Positional arguments (required arguments):</strong></p><ul><li>You specify comma-separated list of parameters that are defined locally to the function.</li><li>The arguments are bound to the parameters in order, so the order of arguments must match the order of parameters. But you can also specify out of order, so it is users’ responsibility to know what the appropriate arguments are and what they should pass.</li></ul><pre><strong>def</strong> func(a, b):<br>    return a / b</pre><pre>func(1, 2) -&gt; 0.5  <em># 1 is assigned to a, and 2 to b</em><br>func(2, 1) -&gt; 2  <em># 2 is assigned to a, and 1 to b</em></pre><ul><li>Except for the order, it is also mandatory to fill all positional arguments in the call of the function. That’s why positional arguments are also called required arguments, so you cannot leave anyone out.</li></ul><pre><strong>def</strong> func(a, b):<br>    return a / b</pre><pre>func(1)  <em># will raise an error as the value for 2nd arg is missing</em></pre><p><strong>Keyword arguments (named arguments):</strong></p><ul><li>You can specify arguments by <strong><em>keyword=value</em></strong> pair explicitly, and each keyword needs to match the parameter defined in your function</li><li>Keyword arguments are flexible in order.</li><li>When the parameter defined in the function follows the <strong><em>keyword=value</em></strong> form like keyword arguments, then this parameter becomes an optional parameter and the value is the default value for that parameter.</li></ul><pre><strong>def</strong> func(a, b):<br>    return a / b</pre><pre><em># The order is flexible in keyword arguments</em><br>func(a=1, b=2) -&gt; 0.5  <em># 1-&gt;a, 2-&gt;b</em><br>func(b=2, a=1) -&gt; 0.5  <em># 1-&gt;a, 2-&gt;b</em></pre><h3>Unpacking args and kwargs with unpacking operators * and **:</h3><p>If there are many args or kwargs to pass, it could be quite lengthy and less extendable to specify one by one. Therefore, it comes to <strong>*args</strong> and <strong>**kwargs</strong>.</p><blockquote>Note that `args` (short for arguments) and `kwargs` (keyword arguments) are just names widely used by Python developers, you are free to use whatever names you want.</blockquote><p>What <strong>*args </strong>does is to take all parameters that are provided and pack them into a tuple named args. Here the iterable object is a tuple which is immutable.</p><pre><strong>def</strong> func(a, *args):<br>    # print args to see what it is<br>    print(args)</pre><pre>func(1, 2, 3, 4) -&gt; (2, 3, 4)  <em># tuple</em></pre><p><strong>**kwargs</strong> works similarly to <strong>*args</strong>, the difference is the unpacking operator becomes `**` and it accepts named arguments instead.</p><pre><strong>def</strong> func(a, *args, b=2, **kwargs):<br>    # print kwargs to see what it is<br>    print(kwargs)</pre><pre>func(1, 2, c=3, d=4)  -&gt; {&#39;c&#39;: 3, &#39;d&#39;: 4}  <em># dictionary</em></pre><h3>Orders of arguments:</h3><p>In Python functions, the order of arguments is very important. General rule is non-default arguments need to be placed before default arguments, so we can think of splitting all arguments into 2 parts: <strong><em>positional part</em></strong> and <strong><em>named part</em></strong>, positional part always comes before the named part ( can imagine having a boundary line in-between).</p><blockquote>There is a small trick for you to check if your order is right when you have both positional and named arguments: there should always be 1 imaginary boundary line in your function, if you have 2 such lines in your function arguments definition to separate positional and named arguments, then the order is probably wrong.</blockquote><pre><strong>def</strong> func(a, b, *args, c=4):<br>    return a + b + sum(args)</pre><pre>func(a=1, 2, 3, 4) -&gt; <em># SyntaxError: positional argument follows keyword argument (</em><strong><em>a=1 is now keyword argument</em></strong><em>)</em></pre><pre>func(a=1, 2, 3, c=6) -&gt; <em># SyntaxError: positional argument follows keyword argument (</em><strong><em>a=1 is now keyword argument</em></strong><em>)</em></pre><p>Of course, within your positional part, as mentioned above, it is your responsibility to keep the order right as it is order-sensitive.</p><h3>Positional-only parameters: * and / :</h3><p>Let’s have a look at more advanced usage in function arguments which was introduced in <strong>Python 3.8</strong>. Sometimes, you will see a bare * or / used in the definition of functions. A / is to force the arguments on its left to be positional-only, while * is to force the argument on its right to be keywords-only.</p><pre><strong>def</strong> func(a, b, /, c, d, *, e):<br>    print(a, b, c, d, e)</pre><pre>func(1, 2, 3, d=4, e=5) -&gt; (1,2,3,4,5)</pre><pre>func(1, b=2, c=3, d=4, e=5)  # <em>TypeError: func() got some positional-only arguments passed as keyword arguments: &#39;b&#39; (</em><strong><em>b cannot be a keyword argument</em></strong><em>)</em></pre><pre>func(1, 2, 3, 4, 5)  <em># TypeError: func() takes 4 positional arguments but 5 were given (</em><strong><em>e must be a keyword argument</em></strong><em>)</em></pre><pre>func(1, 2, 3, 4, e=5) -&gt; (1,2,3,4,5)  # <em>is also valid (</em><strong><em>c and d can be either positional or keyword, no forcement</em></strong><em>)</em></pre><blockquote>Remember that `*` and `*args` cannot coexist in a signature, but can coexist with `**kwargs`.</blockquote><h3>Summary:</h3><p>Arguments is a very common concept and usage in writing Python functions, and this post introduce:</p><ul><li>Basic concepts of positional and named arguments</li><li>Order of arguments</li><li>Unpacking operator</li><li>Positional-only parameters</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=93fc3a5db388" width="1" height="1" alt=""><hr><p><a href="https://towardsdev.com/python-essentials-part-1-args-and-kwargs-in-functions-93fc3a5db388">Python Essentials Part 1 — args and kwargs in functions</a> was originally published in <a href="https://towardsdev.com/">Towards Dev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[StockInsider: A python tool to collect stock data, calculate and visualize trading indicators]]></title>
            <link>https://medium.com/@kaiqidong/stockinsider-a-python-tool-to-collect-stock-data-calculate-and-visualize-trading-indicators-590ecb76c0f1?source=rss-71f38422adff------2</link>
            <guid isPermaLink="false">https://medium.com/p/590ecb76c0f1</guid>
            <category><![CDATA[trading]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[stock-market]]></category>
            <category><![CDATA[analytics]]></category>
            <category><![CDATA[visualization]]></category>
            <dc:creator><![CDATA[Charles D]]></dc:creator>
            <pubDate>Sat, 25 Apr 2020 08:25:10 GMT</pubDate>
            <atom:updated>2020-04-25T08:48:44.006Z</atom:updated>
            <content:encoded><![CDATA[<p>Recently, I have invested in bunch of my spare time in Chinese stocks together with my friends. And we use a very popular APP called Tonghuashun to trade and check the stock trend and use indicators to guide us buy and sell stocks. But some indicators are only accessible for membership users, therefore, it motivates me to calculate them myself and come up with the StockInsider python tool.</p><p>The tool is fairly simple, but right now only limited to stocks in Shanghai and Shenzhen Stock Exchange (largely because those indicators are quite commonly used for Chinese stock market, I have little knowledge if it also applies to other stock markets because the trading rule is quite different).</p><p>You could easily install it via pip: pip install StockInsider , alternatively, you could also install the latest version through: pip install -U git+https://github.com/charlesdong1991/StockInsider</p><p>Once you download it, all you need to do is to type the stock code together with the Exchange where it is traded, e.g. sh603019 or sz002156 and the frequency of K-line, the default is D which refers to daily price. You could also choose W (weekly) or M (monthly), and then the price is aggregated on weekly or monthly level.</p><p>Currently, the tool is still under active development, and those indicators are available:</p><ul><li>MD (Moving Deviation): si.plot_md()</li><li>EMA (Exponential Moving Average): si.plot_ema()</li><li>MACD (Moving Average Convergence/Divergence): si.plot_macd()</li><li>KDJ: si.plot_kdj</li><li>RSI (Relative Strength Index): si.plot_rsi()</li><li>VRSI (Volumn Relative Strength Index): si.plot_vrsi()</li><li>Volumn change: si.plot_volumn()</li><li>VMA (Volumn Moving Average): si.plot_vma()</li><li>VSTD: si.plot_vstd()</li><li>VMACD (Volumn Moving Average Convergence/Divergence): si.plot_vmacd()</li><li>ENV: si.plot_env()</li><li>VOSC (Volumn Oscillator): si.plot_vosc()</li><li>MI (Momentum Indicator): si.plot_mi()</li><li>MA (Moving Average): si.plot_ma()</li></ul><p>There are some examples of the plots from the tool:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/928/1*DsCG1iPMsuYRG-aiCOlCDw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*0ZYPWhE68owOulbfkD1M3A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/939/1*zrniVp0bHzQE8MCzV01Zfg.png" /></figure><p>And there are more! Feel free to check it out on <a href="https://github.com/charlesdong1991/StockInsider">https://github.com/charlesdong1991/StockInsider</a> And look forward to your feedbacks!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=590ecb76c0f1" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>