<?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 Ramin on Medium]]></title>
        <description><![CDATA[Stories by Ramin on Medium]]></description>
        <link>https://medium.com/@maadotaa?source=rss-7a9314aff340------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*sWI4B052PhjmF1ZY.</url>
            <title>Stories by Ramin on Medium</title>
            <link>https://medium.com/@maadotaa?source=rss-7a9314aff340------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 22:40:34 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@maadotaa/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[Amazon recently added a new useful feature for its Blink cameras which describes what the camera…]]></title>
            <link>https://maadotaa.medium.com/amazon-recently-added-a-new-useful-feature-for-its-blink-cameras-which-describes-what-the-camera-e10e8e71248f?source=rss-7a9314aff340------2</link>
            <guid isPermaLink="false">https://medium.com/p/e10e8e71248f</guid>
            <category><![CDATA[ai-agent]]></category>
            <dc:creator><![CDATA[Ramin]]></dc:creator>
            <pubDate>Fri, 10 Apr 2026 19:13:25 GMT</pubDate>
            <atom:updated>2026-04-10T19:13:25.603Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x9wHGG0x8N4v3x0d2bqF1w.png" /></figure><p>Amazon recently added a new useful feature for its Blink cameras which describes what the camera sees in the snapshot that it takes. <br>This is useful because it removes the need to unlock your phone and launch the Blink app to see what happened in front of your door. They call it “Blink Video Description”.</p><p>Only the “basic ai” and “plus ai” plans include this feature.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rPiCFdCXlpv-YIZ-I5Heyw.png" /></figure><p>The price delta is not too bad ($40 -&gt; $70 annually) but it is something that you can do easily as a DIY project.</p><p>The steps to do this are very straight forward:</p><ul><li>Grab the captured frame from the camera using the unofficial Blink camera <a href="https://github.com/fronzbot/blinkpy">blinkpy</a>.</li><li>Send it to an AI model that takes images as input and ask it to describe what’s in the image. You can adjust the level of detail that you want in the prompt. I use gpt-4.1-mini because it is very inexpensive and works well for this use-case.</li><li>Send a push notification to your phone. The notification will include the image that the camera captured plus a short description of the image. I use the <a href="https://pushover.net/">Pushover</a> service which has a generous free tier.</li></ul><p>As a bonus you can add rate control and automatic snooze functionalities as well. For example, on Tuesdays around 11 our gardener comes in and the camera goes crazy with taking snapshots and sending notifications. In my script I included provisions to handle this by not snoozing the camera during the time that I expect the gardener to be visiting.</p><p>The link to the code for this project is below:<br><a href="https://gist.github.com/rawmean/b976bcfddd43a2d41ca614a8aa25d42e">https://gist.github.com/rawmean/b976bcfddd43a2d41ca614a8aa25d42e</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e10e8e71248f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using TimesFM for Short-Term ETF Forecasting]]></title>
            <link>https://maadotaa.medium.com/using-timesfm-for-short-term-etf-forecasting-68a4acb209cf?source=rss-7a9314aff340------2</link>
            <guid isPermaLink="false">https://medium.com/p/68a4acb209cf</guid>
            <dc:creator><![CDATA[Ramin]]></dc:creator>
            <pubDate>Wed, 25 Feb 2026 23:58:34 GMT</pubDate>
            <atom:updated>2026-02-25T23:58:34.116Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*wpshge5-WomozSas" /><figcaption>How TimesFM works</figcaption></figure><p>If you already use LLMs, TimesFM is easiest to think of as a foundation model for time series rather than text. LLMs learn language patterns by predicting the next token (word/subword) in a sentence. TimesFM learns temporal patterns by forecasting future values from historical sequences. So the core idea is similar (pretraining on lots of sequential data), but the data type, objective, and evaluation are different:</p><ul><li>LLMs: discrete text tokens, next-token prediction, judged by language quality/usefulness.</li><li>TimesFM: numeric time steps, multi-step forecasting, judged by forecast error/calibration.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*dvg2QCQq0xpkTQJ3" /><figcaption>Shared principle: Pre-train on many sequences, adapt for downstream tasks</figcaption></figure><p>For short-term ETF prediction, this matters because ETFs are noisy, regime-dependent, and affected by market microstructure. A pretrained time-series model can provide a strong baseline, but fine-tuning on ETF-specific history is usually where practical gains appear.</p><p>A typical fine-tuning workflow is:</p><ol><li>Collect clean ETF history at your target horizon (for example, daily or intraday bars).</li><li>Build training windows (context in, future horizon out) with strict time-ordering.</li><li>Use walk-forward validation to avoid leakage.</li><li>Fine-tune lightly (small learning rate, few epochs, early stopping), then compare against the frozen pretrained model and simple baselines.</li></ol><h3>Fine Tuning</h3><p>Why fine-tuning helps: pretraining gives broad temporal priors (seasonality, trend shifts, volatility structure), while fine-tuning adapts those priors to ETF-specific behavior like sector rotation sensitivity, gap dynamics, and horizon-specific noise patterns. In practice, this often improves short-horizon error and forecast stability, especially when market conditions deviate from generic training distributions. The following figure shows an example where the fine-tuned model performs significantly better than the base model in predicting future values of the ETF.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*8_A7obybFNxJ7q4j" /><figcaption>Forecasting with and without fine-tuning</figcaption></figure><p>If you found this article interesting, you may be interested in another related article on the topic of ETF value prediction by me: <a href="https://medium.com/@maadotaa/can-we-predict-future-prices-of-equities-using-ai-ed0dbdd5029c">https://medium.com/@maadotaa/can-we-predict-future-prices-of-equities-using-ai-ed0dbdd5029c</a></p><p>Not financial advice.</p><p>Reference: “A decoder-only foundation model for time-series forecasting” <a href="https://arxiv.org/abs/2310.10688">https://arxiv.org/abs/2310.10688</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=68a4acb209cf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Can We Predict When A Bubble Will Burst?]]></title>
            <link>https://maadotaa.medium.com/can-we-predict-when-a-bubble-will-burst-4e5f89bbfd56?source=rss-7a9314aff340------2</link>
            <guid isPermaLink="false">https://medium.com/p/4e5f89bbfd56</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[finance]]></category>
            <category><![CDATA[stock-market]]></category>
            <dc:creator><![CDATA[Ramin]]></dc:creator>
            <pubDate>Fri, 10 Oct 2025 21:49:16 GMT</pubDate>
            <atom:updated>2025-10-10T22:27:01.928Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m8QGv4s9A9HNcS4RHT2FTQ.png" /></figure><p><strong><em>Disclaimer</em></strong><em>: This article is strictly for educational purposes. Do not treat this as financial advice. I know very little about investing. <br>This is a super short article, but if you just want to see the results, skip to the last section</em></p><p>These days there is a lot of talk about AI bubble. Last week a friend asked me if there is a way to predict when it is going to happen. This question made me research the topic. It turns out there is a model called <a href="https://arxiv.org/abs/1003.2920">LPPL</a> which is designed to predict when a bubble in financial markets will burst.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/766/1*gCs_CngM56PqkqtAlk4b8g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6P80B-UcTZ9jr2DwxZihXA.png" /></figure><ul><li>The term B (t_c — t)^m captures the power-law growth</li><li>The term C (t_c — t)^m cos(.) adds oscillations whose frequency increases as t → t_c.</li><li>As t → t_c, (t_c — t)^m → 0, so the magnitude of deviations shrink toward the critical point, but the oscillations get compressed in time.</li></ul><h3>The intuition behind this model</h3><ul><li>Positive feedback / herding: As prices rise, more investors jump in (fear of missing out), which pushes price up further — a self-reinforcing loop.</li><li>Imitation / internal “endogenous” dynamics: Traders influence one another; bubbles are not purely exogenous shocks but build internally.</li><li>Competition between upward expectations and crash risk: As time goes on, the tension between optimistic speculation and fear of crash increases, manifesting as oscillations in market sentiment.</li><li>Critical phenomena analogy: LPPL borrows from ideas in physics (phase transitions, rupture, bifurcations): the market behaves like a system approaching a critical point (a singularity).</li></ul><p>Thus LPPL tries to formalize the idea that a market bubble is not just exponential growth but something super-exponential + oscillatory that becomes unstable near its end.</p><h3>How fit the model</h3><p>The seven parameters of the model can be solved (eg, least squares) by trying to fit the model to time intervals that we suspect are leading to a crash. For example, the model can be trained with a few years of data prior to the 2007 market crash and obtain t_c which predicts the crash date. Of course, the crash dates are approximate because, as with most models, the model never fits reality perfectly.</p><h3>Experiment Result</h3><p>The following figure shows the results of fitting the model to the crash of 2000, 2008 and the most recent potential bubble (brown). <strong>The model predicts a crash in the first quarter of 2026 </strong>(see the legend of the graph). I changed the time intervals prior to a suspect crash to determine how sensitive the model is to the input parameters. Based on my experiment t_c changes for a few months.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ncvLPkmDJTv_usp8wAPOEQ.png" /></figure><p>I have provided the code for this experiment below.<br>If you enjoy this type of topics, you may like<strong> </strong><a href="https://maadotaa.medium.com/can-we-predict-future-prices-of-equities-using-ai-ed0dbdd5029c"><strong>my other article</strong></a> about predicting short term ETF prices</p><pre># lppl_fit_and_plot.py<br>import numpy as np, pandas as pd<br>import matplotlib.pyplot as plt<br>from datetime import datetime<br>from scipy.optimize import least_squares<br>import yfinance as yf<br><br># ---------- CONFIG ----------<br># Using yfinance to get S&amp;P 500 data instead of CSV<br>symbol = &quot;SPY&quot;  # S&amp;P 500 ETF<br>start_date = &quot;1990-01-01&quot;<br>end_date = &quot;2025-12-31&quot;<br># Bubble windows to fit <br>windows = [<br>    (&quot;1995-01-01&quot;,&quot;2000-04-01&quot;),  # dot-com<br>    (&quot;2002-04-01&quot;,&quot;2007-10-01&quot;),  # pre-GFC<br>    (&quot;2023-01-01&quot;,&quot;2025-10-01&quot;),  # recent run-up<br>]<br>out_png = &quot;SP500_LPPL_1990_2025.png&quot;<br># ----------------------------<br><br>def prep_df(symbol, start_date, end_date):<br>    # Fetch data from yfinance<br>    ticker = yf.Ticker(symbol)<br>    df = ticker.history(start=start_date, end=end_date, interval=&quot;1mo&quot;)  # Monthly data<br>    <br>    # Reset index to get date as a column<br>    df = df.reset_index()<br>    <br>    # Rename columns to match expected format<br>    df.rename(columns={&quot;Date&quot;: &quot;date&quot;, &quot;Close&quot;: &quot;close&quot;}, inplace=True)<br>    <br>    # Ensure date column is datetime<br>    df[&quot;date&quot;] = pd.to_datetime(df[&quot;date&quot;])<br>    <br>    # Sort by date and reset index<br>    df = df.sort_values(&quot;date&quot;).reset_index(drop=True)<br>    <br>    # Filter date range and drop NaN values<br>    df = df[(df[&quot;date&quot;] &gt;= start_date) &amp; (df[&quot;date&quot;] &lt;= end_date)]<br>    df = df.dropna(subset=[&quot;close&quot;])<br>    <br>    return df<br><br>def lppl_func(t, A,B,C,m,omega,phi,tc):<br>    # t, tc in float time (e.g., year fraction)<br>    x = tc - t<br>    with np.errstate(divide=&#39;ignore&#39;):<br>        return A + B*(x**m) + C*(x**m)*np.cos(omega*np.log(x) - phi)<br><br>def year_fraction(d):<br>    return d.year + (d.timetuple().tm_yday - 1)/365.25<br><br>def fit_lppl(t, y):<br>    # Reasonable bounds based on literature<br>    # m in (0,1), omega in (6,13), tc just beyond window end<br>    t0, t1 = t[0], t[-1]<br>    y0 = y[0]<br>    p0 = np.array([np.log(y).mean(), -1.0, 0.1, 0.5, 8.0, 0.0, t1 + 0.1])  # initial guess on log-price<br>    lb = np.array([-np.inf, -np.inf, -np.inf,  0.01, 6.0, -np.pi, t1 + 1e-3])<br>    ub = np.array([ np.inf,  np.inf,  np.inf,  0.99,13.0,  np.pi, t1 + 2.0])<br><br>    def resid(p):<br>        A,B,C,m,omega,phi,tc = p<br>        return np.log(y) - lppl_func(t, A,B,C,m,omega,phi,tc)<br><br>    res = least_squares(resid, p0, bounds=(lb,ub), max_nfev=20000)<br>    return res<br><br>def main():<br>    df = prep_df(symbol, start_date, end_date)<br>    df[&quot;t&quot;] = df[&quot;date&quot;].apply(year_fraction).astype(float)<br>    t_all, p_all = df[&quot;t&quot;].values, df[&quot;close&quot;].values<br><br>    plt.figure(figsize=(9,6))<br>    plt.plot(df[&quot;date&quot;], p_all, lw=3, label=&quot;S&amp;P 500&quot;)<br><br>    # Fit each window and overlay<br>    for (start, end) in windows:<br>        w = df[(df[&quot;date&quot;]&gt;=start) &amp; (df[&quot;date&quot;]&lt;=end)].copy()<br>        if len(w) &lt; 30:  # need enough points<br>            continue<br>        t, p = w[&quot;t&quot;].values, w[&quot;close&quot;].values<br>        res = fit_lppl(t, p)<br>        A,B,C,m,omega,phi,tc = res.x<br>        # Draw fitted curve over the window + a bit beyond<br>        t_fit = np.linspace(t.min(), min(tc-1e-3, t.max()+0.25), 400)<br>        y_fit = np.exp(lppl_func(t_fit, A,B,C,m,omega,phi,tc))<br>        # Build dates from year fractions<br>        d_fit = pd.to_datetime((t_fit - 1970)*365.25, unit=&quot;D&quot;, origin=&quot;1970-01-01&quot;)  # simple mapping for axis<br>        plt.plot(d_fit, y_fit, lw=5, label=f&quot;LPPL {start[:7]}–{end[:7]} (tc≈{pd.to_datetime((res.x[-1]-1970)*365.25, unit=&#39;D&#39;, origin=&#39;1970-01-01&#39;).date()})&quot;)<br><br>    plt.title(&quot;S&amp;P 500 with LPPL fits (windows within 1990–2025)&quot;)<br>    plt.xlabel(&quot;Year&quot;)<br>    plt.ylabel(&quot;SPY Price&quot;)<br>    plt.legend()<br>    plt.tight_layout()<br>    plt.savefig(out_png, dpi=220)<br>    print(f&quot;Saved: {out_png}&quot;)<br><br>if __name__ == &quot;__main__&quot;:<br>    main()</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4e5f89bbfd56" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Can we predict future prices of equities using AI]]></title>
            <link>https://maadotaa.medium.com/can-we-predict-future-prices-of-equities-using-ai-ed0dbdd5029c?source=rss-7a9314aff340------2</link>
            <guid isPermaLink="false">https://medium.com/p/ed0dbdd5029c</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[cryptocurrency]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <dc:creator><![CDATA[Ramin]]></dc:creator>
            <pubDate>Tue, 14 Jan 2025 21:59:08 GMT</pubDate>
            <atom:updated>2025-01-15T18:23:22.771Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZnrmGryQYoiVf9s_JUmpSw.jpeg" /></figure><p>The answer is <em>sometimes</em> and for <em>some equities</em>. <br>“Some equities” because individual stocks are too volatile and affected by too many semi-random events (eg, the CEO says something controversial one day and stock declines or some random post on reddit causes a meme stock to “go to the moon”).</p><p>Exchange Traded Funds (ETF) consist of a combination of many equities and, as a result, are typically less volatile compared to individual stocks. They can be traded just like stocks while the market is open (unlike mutual finds where the trade gets executed the next day). Therefore, ETFs seem to be a natural candidate for our prediction challenge.</p><p>I mentioned that prediction is possible <em>sometimes</em> because price prediction is a stochastic problem and, as such, cannot be predicted with 100% certainty. However, to make a profit in the stock market one does not need to be right all the time; you just need to be right more than wrong.</p><p>Let’s try to illustrate this with an example. Suppose you are invited to play a game of flipping coins. In this game you get to bet $X and a “head” outcome earns you $X while a “tail” event costs you $X. The good news is that the coin is biased by 60% in favor of “head” events (ie, 60% of times the outcome is “head”). This seems like a money making machine if you play it right.</p><p>One greedy approach would be to spend a significant portion of your money at each round. Doing so can cause you to go bankrupt quickly as there is 40% chance that you lose a significant portion of your wealth at each trial and eventually everything is lost and the game stops. To take advantage of the biased coin, you must play in such a way that allows you to play the game as much as possible so that the average win probability approaches 60%. Playing the game only a small number of times does not guarantee that you actually win 60% of times.</p><blockquote>In statistics, this is explained by <a href="https://en.wikipedia.org/wiki/Central_limit_theorem">Central Limit Theorem</a> which asserts that the sample mean approaches to mean of the underlaying random variable with increasing certainty as sample size grows.</blockquote><p>So, to be able to profit, one needs an algorithm that can predict future values of an ETF with reasonable accuracy and an opportunity to trade using that algorithm enough times to make the algorithm that is biased towards winning work.</p><h3>How to Predict</h3><p>Machine learning has been used extensively for predicting future values of a sequence given its historical data. <a href="https://deeplearningmath.org/sequence-models">This</a> article explains such techniques in reasonable detail. The predictor is referred to as Recurrent Neural Network (RNN) which is a particular type of Neural Network with properties that are suitable for sequences (eg, historical stock values or historical temperature values in a specific region).</p><p>Essentially an RNN predictor is trained on many samples of historical values for a sequence such that the error between the output of the predictor and the actual future value (which is known during training) is minimized.</p><p>Fortunately, for the purpose of predicting future prices of ETF, there is additional information available to us which may lead to more accurate predictions. Specifically, instead of using just the historical values of the ETF, we can also provide historical values of various indices (eg, Dow Jones, S&amp;P 500, Russel 1000, etc). As long as there is some correlation (positive or negative) between the extra information and the ETF of interest, the RNN predictor can make use of them to improve prediction accuracy. The following image shows an abstract representation of information that can be used as input to the predictor. Each string represents historical values associated with one of the inputs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pVXRYWxOr9hrhRHM3Md6Rw.jpeg" /></figure><h3>Relationship to Technical Analysis</h3><p>It is likely that you have come across a series of techniques referred to as <a href="https://en.wikipedia.org/wiki/Technical_analysis">Technical Analysis</a> (TA) for predicting the direction of stocks and other equities based on past values. In that sense, TA techniques strive to achieve the same goal as we are attempting to do using RNN predictors. One salient difference is that TA techniques tend to be simple and intuitive</p><p>For example, consider one popular TA method called <a href="https://en.wikipedia.org/wiki/Bollinger_Bands">Bollinger Bands</a>. This method computes moving average of the price certain standard deviations above and below the actual price. When the price breaches an upper or lower band, it could indicate an overbought or oversold condition according to this TA method. An example is shown in the following image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/846/1*NTdFsXfe_jLyGicWceUmbg.png" /><figcaption>Bollinger Bands</figcaption></figure><p>This method is certainly simple and intuitive. But intuition may not be enough for a complex problem such as price prediction. TA methods tend to analyze single-dimensional information which we as humans can understand and visualize. We cannot visualize more than three dimensions and cannot reason about and find patters in higher dimensions intuitively.</p><p>Neural networks are very efficient at processing and finding patterns in higher dimensions. That is one of the reasons why RNN predictors are suitable for sequence prediction.</p><p>Neural networks minimize the error between the true value (eg, future price) and the predicted value by iterating over the training data and improving the prediction after each iteration. An example of such process is shown in the following image. The vertical axis is the average prediction error and the horizontal axis is the iteration number.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/706/1*l1-PIFIf0tIivpanDVXGvQ.png" /><figcaption>Prediction Error vs. Iteration number</figcaption></figure><h3>Does it work: Back-Testing</h3><p>To train a neural network, historical data is divided into training set and test set (there is also another important validation set that for sake of brevity we will not describe here). Separating the data into disjoint training and test set is important to make sure the model does not overfit (ie, work really well for the data that is used to train it but not for new data that the model has not seen before). Also, the test set allows us to perform back-testing: the process of determining how the model performs on data that it has not seen. For example you can train the model on data from years 2000 through 2015 and then ask it to perform prediction on data from year 2024.</p><p>In the following graph we show price of QQQ (a popular ETF) from mid 2022 to early 2025 together with the prediction values. The prediction and actual values are quite close to each other.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EfkIouwLJKgGJabnVwfGdQ.png" /><figcaption>Back-testing</figcaption></figure><p>To see the deviations, we can examine the zoomed-in versin of the same graph.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kpRB6ZWW8RvFE-jNPyzDsg.png" /><figcaption>Back-testing Zoomed Version</figcaption></figure><p>Quantitatively, the prediction falls within 1% of the actual values 96% of the time.</p><p>Another way to quantify the prediction error of a model is to use the RMSPE metric (Root Mean Squared Percentage Error). This metric measures the distance between a model’s predicted values and the actual values in the dataset (a.k.a. the “residual” or prediction error) . The lower the score, the better the predictive performance of the model. The following is the definition of this metric.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/563/1*XFGiWDPr6l8S9L6AzPMYOA.png" /></figure><p>The RMSPE in our QQQ example (shown in the figure above) is 0.15% which is quite small (smaller is better).</p><h3>Sample Prediction Results</h3><p>The following graph shows an example of prediction results for QQQ. The horizontal axis is date and each dor represents a day. It is important to point out that the model attempts to predict the moving average value of the price. This removes the noise associated with high frequency fluctuations. The orange dots represent the future value predictions of the moving average in the next few days. The blue graph is the actual moving average. The gray band shows the 1% band above and below the prediction (for visualization purposes).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gL6VrTZGWq7-yfTRD3QiNA.png" /></figure><h3>Value Metric</h3><p>It would be useful to use the model to assign a normalized metric to each ETF that represents how undervalued/overvalued that ETF is. This is similar to the RSI metric (Relative Strength Index) in Technical Analysis only in terms of representation but, obviously, obtained based on out RNN model and not based on TA.</p><p>One way to achieve this is to pass the difference between the prediction and the current price to a sigmoid function and use the output as a Value Metric (VM). The following is the formula for the sigmoid function. In practice, we use 1 minus the sigmoid to compute the VM.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/306/1*2rNref5HmPJaDNpkvH7_cw.png" /></figure><h3>Buy/Sell Opportunities</h3><p>We can then use the value metric to come up with but or sell opportunities notifications. For example, an ETF is undervalued/overvalued if the VM is below/above a certain threshold.</p><h3>How to use the Value Metric</h3><p>As we pointed out at the beginning of this article, no prediction algorithm is perfect (in particular, the ones that attempt to predict future price of equities). But we strive to make the prediction as accurate as possible. It is similar to our biased coin example where we hope that by using our algorithm we have a better handle on “buying low and selling high”.</p><p>The algorithm computes a normalized metric that indicates how overvalued or undervalued an ETF is. So, we can use this knowledge to buy an ETF when the VM for the ETF is below a certain threshold (eg, 20%).</p><p>Once we have purchased an ETF, when do we sell? Depending on your style of investment you may adopt one of the following strategies:</p><ul><li>You can sell the ETF when the associated VM approaches ~50%. This means that the algorithm predict that in the near future (eg, a week), the average price will not change much compared to the current price. Alternatively, you can wait until the associated VM approaches a higher threshold (eg, 80%) which indicates that the algorithm predicts that average short-term future price is going to drop. Technically, VM above 50% indicates a future drop.</li><li>If you are a type of investor that prefers to “buy and hold” and the ETF is in question is one that you typically invest in periodically, you may use the buy indications (eg, VM below 20%) as opportunity to add to your position.</li><li>Finally, you can also sell if the price drops below your personal risk threshold or goes above a personal percentage for profit taking.</li></ul><h3>FundOracle App</h3><p>I have packaged all this in a simple and easy-to-use app called <a href="https://apps.apple.com/us/app/fundoracle-invest-with-ai/id6737210385">FundOracle</a>.</p><figure><a href="https://apps.apple.com/us/app/fundoracle-invest-with-ai/id6737210385"><img alt="https://apps.apple.com/us/app/fundoracle-invest-with-ai/id6737210385" src="https://cdn-images-1.medium.com/max/968/1*9_muIBjyPjpOp_T7lgAmMg.jpeg" /></a></figure><p>The app includes models for more than 60 popular ETFs and updates every 30 minutes (when the market is open). The user receives notifications for buy and sell opportunities based on the criteria described in the previous sections.</p><figure><a href="https://apps.apple.com/us/app/fundoracle-invest-with-ai/id6737210385"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f8llPaLhUpmx2oDxal7tuA.png" /></a></figure><p>The app even provides a Home Widget so that you can see the top undervalued/overvalued ETFs at a glance without launching the app.</p><figure><a href="https://apps.apple.com/us/app/fundoracle-invest-with-ai/id6737210385"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cQoLxIFJ6kJ4imsUNT8_eA.png" /></a></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ed0dbdd5029c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to use GPT to search documents and databases?]]></title>
            <link>https://maadotaa.medium.com/how-to-use-gpt-to-search-documents-and-databases-84d7b89328ce?source=rss-7a9314aff340------2</link>
            <guid isPermaLink="false">https://medium.com/p/84d7b89328ce</guid>
            <category><![CDATA[search]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[chatgpt]]></category>
            <dc:creator><![CDATA[Ramin]]></dc:creator>
            <pubDate>Tue, 16 May 2023 18:56:43 GMT</pubDate>
            <atom:updated>2023-05-16T19:32:53.809Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xtk3uy9DxSHGxaAzhxWqGQ.png" /></figure><p>CharGPT is very useful, but what if you want it to use it to search relevant segments in a big document or database? <br>In this article, I explain how to do this using openAI API.</p><h3>Outline</h3><ul><li>Segment out the database or big chunk of text or document into smaller chunks that consist of a few sentences.</li><li>Assign a vector to each segment using openAI embedding. This assigns a numeric vector based on the meaning of the chunk of text. So segments whose meaning are close semantically, will have embedding vectors that are close to each other (in L2 norm sense)</li></ul><p>At query time:</p><ul><li>Assign an embedding vector to the query</li><li>Find the K nearest neighbors in the list of chunks in embedding space. Call this “context”</li><li>Construct a prompt for ChatGPT that reads something like this:</li></ul><pre>    system = f&quot;&quot;&quot;<br>    Answer questions based on the context provided below. :<br><br>    Context: {context}<br>    &quot;&quot;&quot;</pre><p>Ask openAI chatCompletion API to create a response based on the prompt.</p><p>You can also create reference to your original database/document by saving the indexes to the K nearest chunks which was computed above.</p><h3>Code</h3><p>This is the code for generating the embeddings associated with the big database/document:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6125f87ff285df7b17ecf8feaed9d840/href">https://medium.com/media/6125f87ff285df7b17ecf8feaed9d840/href</a></iframe><p>This is the code for searching and using CharGPT to come up with the response and index to the original database/document:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a822e6be582542f9b55b2cc586e8fe9a/href">https://medium.com/media/a822e6be582542f9b55b2cc586e8fe9a/href</a></iframe><p>In this example, I am using this method to create a web app for answering questions from Tesla car manuals. You can easily modify it to work with your own document or database. The web app is here:</p><p><a href="https://www.asktesla.app/">Ask Tesla</a></p><p>I used streamlit for creating this site and hosting it. It’s a fantastic way of creating web pages with python backend. Please don’t judge me on the quality and cleanliness of my code :)<br>Also, I should mention that significant chunks of this code is from the sample codes <a href="https://github.com/openai/openai-cookbook/tree/main/examples">provided by openAI</a></p><p>Shameless plug: If you are interested in this kind of stuff, you may like my most recent app which summarizes web articles right from the browser on iPhone/iPad. It also puts chatGPT on your watch:</p><p><a href="https://apps.apple.com/us/app/ask-summarize/id6446225669">‎Ask &amp; Summarize</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=84d7b89328ce" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What are Diffusion Models and Stable Diffusion?]]></title>
            <link>https://maadotaa.medium.com/what-are-diffusion-models-and-stable-diffusion-b9d829ea931b?source=rss-7a9314aff340------2</link>
            <guid isPermaLink="false">https://medium.com/p/b9d829ea931b</guid>
            <category><![CDATA[diffusion-models]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[stable-diffusion]]></category>
            <dc:creator><![CDATA[Ramin]]></dc:creator>
            <pubDate>Fri, 09 Sep 2022 00:19:46 GMT</pubDate>
            <atom:updated>2025-02-27T07:30:49.402Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*1mYjDPTuVw44PIgke6eKug.png" /><figcaption>Image generated using Stable Diffusion with prompt: “a photograph of diffusion model”</figcaption></figure><p>If you have heard these names and seen the amazing results of Stable Diffusion model which converts a short textual description to a high-res image and curious to know how these things work, you have come to the right place.</p><p>In this short article, I give a high-level description of these concepts which is not too fluffy (as you may find in a pseudo-technical blog) and not too detailed to put you to sleep. The goal here is to understand the concept of diffusion models and Stable Diffusion so that you can dig deeper. This overview is a summary of 3 papers and two blogs that are listed at the end of this article.</p><h3>What is a Diffusion Model</h3><p>The story started with <a href="https://arxiv.org/pdf/2006.11239.pdf">this paper</a> by Ho et. al. in late 2020 (this paper itself is based on work of several other researchers, of course). The goal of such model is to create machine-generated images that resembles the images on which the model is trained. This is similar to what a GAN or a Variational Auto-encoder can do. Specifically, we want to feed noise to our model and get an image that resembles a “real” image from our model.</p><p>To do this, we train a network that has learned to remove Gaussian noise from images progressively. It can do this so well that it can start from complete noise and produce a “real” image. So, to generate training data from our model, we start from an image in the training set and add isometric Gaussian noise to it. Isometric here just means that the noise is independent for each pixel (i.e., the covariance matrix is diagonal).</p><p>In the following image, as we go from right to left, noise is added at each step such that xₜ is noisier than xₜ -₁. This is called the forward process.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eGPMpXnXC4iTzJ9tspG5BA.png" /></figure><p>Formally, noise is added as follows (mean and covariance are the 2nd and 3rd parameters, respectively):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/778/1*KHk_Uy-j9QEoNZEMZMtg8Q.png" /></figure><p>where, 0&lt;<em>β</em>1​&lt;<em>β</em>2​&lt;…&lt;<em>βT</em>​&lt;1</p><p>Using the property of Gaussian noise that sum of Gaussians is also Gaussian, one can easily show that the following holds:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/736/1*kjEMoD0_ioq1t4N-LOFYmA.png" /></figure><p>where,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/558/1*FBrL8usMIz_IEvZ5fWSVhw.png" /></figure><p>So, given an image from the training set, x₀, and a noise level ‘<em>t</em>’, we can produce a noisy image xₜ, using the above relationship.</p><p>The training steps are as follows:</p><ul><li>pick an image, x₀, from the training set</li><li>pick a noise level <em>t</em> between 1 and T at random</li><li>create a noisy image xₜ computed as shown below</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/388/1*uL1llAssVfsjMKhCDmR51w.png" /></figure><p>where</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/206/1*gfAnx7t170ctDmY-5VDByw.png" /></figure><ul><li>Feed scalar <em>t</em> and image xₜ as inputs to the network</li><li>train a network to predict ɛ</li></ul><p>The following is the pseudo-code for the training algorithm:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/892/1*uhg66NOdoqyUn0zDlWAMRg.png" /></figure><h3>Notes about the Neural Network</h3><p>One of the inputs to the network is <em>t</em> which is a scalar and the other one is xₜ which is an image. A typical technique for feeding a scalar input in such cases is to use locational embedding which given a scalar, creates a deterministic tensor of size (num_channels, height, width) which can be concatenated with the input image features in early stages of the network.</p><p>The network is to produce an “image” of the same size as the input noisy image, so a U-Net is a reasonable choice. In practice, adding an attention block helps.</p><h3>Image Generation (aka Sampling)</h3><p>A network trained as described above is able to predict the noise added at a given noise level, <em>t</em>. So, we can start from pure noise which represents x_{T} and ask the network to predict the noise level that is needed to construct x_{T-1} and repeat this until we construct x0. In the following pseudo-code, Z_{theta} represents the trained model and:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/154/1*xLVCm_5M-Ba-4jxBHtPHmw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z9IQQdcQXDJyqc30dqzl7w.png" /></figure><p>That’s it! Now you know what the diffusion model is and I hope the intuition behind it is clear.</p><h3>Guidance</h3><p>Stable Diffusion has become a household name primarily because of its capability of generating high-resolution images based on a short textual description (aka prompt) and that is something that we have not discussed yet.</p><p>The “Classifier-free Diffusion Guidance” <a href="https://arxiv.org/pdf/2207.12598.pdf">paper</a> by Ho &amp; Salimans proposes a clever modification to the general diffusion model as follows:</p><p>In the training phase, instead of picking images randomly from a dataset (eg, ImageNet) and feeding them to the model as input, also supply the class (or a short textual description) associated with that image to the model. Of course, the text needs to be tokenized and transformed into a feature space (eg, using a pre-trained BERT or CLIP model) to be combined with other features of the U-Net network.</p><p>So, the model now has three inputs, the image (or the latent features associated with it), the noise level (denoted by <em>t</em> in the previous section), and <em>c </em>which represents features associated with the textual description for the image). The following algorithm shows the modified training steps:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zeaDRmcwKureCm1WM06dpg.png" /></figure><p>You notice that in step 3 of this algorithm, the class is suppressed with a certain fixed probability. This is one of the major contributions of the “Classifier-free Diffusion Guidance” <a href="https://arxiv.org/pdf/2207.12598.pdf">paper</a> which distinguishes it from other diffusion-based models that use a classifier (ie, the textual description) for generating images (hence, the name “classifier-free”). Eliminating a classifier simplifies training and sampling significantly.</p><p>The sampling process is very similar to the sampling process described in the previous section with the difference that it takes another input, <em>c</em> , which is the textual description of the image that we want the sampling process to generate. This process is shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aXr-Rl3lDim1RxzKZ-o6hQ.png" /></figure><p>Note that in step 3, we perform the inference twice: once with the input <em>c</em> (aka “guidance”) and once without it. In practice, for the inference without guidance, we use the exact same model but provide an empty string for the input <em>c. </em>The predicted noise model is then linearly combined using a “guidance weight” parameter <em>w. </em>This parameter allows a trade-off between diversity of generated images and fidelity to the guidance phrase (<em>c</em>).</p><h3>Stable Diffusion</h3><p>In the previous sections we notice that to generate a “real” image from pure noise we need to run the inference T times (a typical value for T is ~200) and each time the input to the model has the same resolution as the final image. This is relatively slow and memory consuming.</p><p>The “High-Resolution Image Synthesis with Latent Diffusion Models” <a href="https://arxiv.org/pdf/2112.10752.pdf">paper</a> addresses this problem by noting that instead of processing everything in the pixel space, we can operate at a much lower resolution by executing all the steps in training and sampling on “compressed” feature space produced by a variational auto-encoder. At the end of the T steps of de-noising (aka Sampling), the de-noised latent features are given to the decoder portion of the auto-encoder to produce a high resolution “real” image.</p><p>The following shows the flow diagram of the sampling process:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1004/1*9Qml-1PQxU_TvfCQyopx2Q.png" /><figcaption>source: <a href="https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers/stable_diffusion.ipynb">this</a></figcaption></figure><p>Now you also know how Stable Diffusion works and some theory behind it.</p><p>I hope you find this short article useful and it motivated you to dig deeper.</p><h3>References</h3><ul><li>“<a href="https://arxiv.org/abs/2112.10752">High-Resolution Image Synthesis with Latent Diffusion Models</a></li><li><a href="https://arxiv.org/abs/2207.12598">CLASSIFIER-FREE DIFFUSION GUIDANCE</a></li><li>“<a href="https://arxiv.org/abs/2006.11239">Denoising Diffusion Probabilistic Models</a>”</li><li>“<a href="https://huggingface.co/blog/annotated-diffusion">The Annotated Diffusion Model</a>”</li><li>“<a href="https://huggingface.co/blog/stable_diffusion">Stable Diffusion with Diffusers</a>”</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b9d829ea931b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Are you sitting correctly in the car?]]></title>
            <link>https://maadotaa.medium.com/are-you-sitting-right-in-the-car-af61eea8572d?source=rss-7a9314aff340------2</link>
            <guid isPermaLink="false">https://medium.com/p/af61eea8572d</guid>
            <category><![CDATA[posture]]></category>
            <category><![CDATA[tesla]]></category>
            <category><![CDATA[seating]]></category>
            <category><![CDATA[ergonomics]]></category>
            <dc:creator><![CDATA[Ramin]]></dc:creator>
            <pubDate>Sat, 27 Aug 2022 19:11:39 GMT</pubDate>
            <atom:updated>2022-08-27T19:13:03.481Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PHpbqC-FJWDQj_UAPhkPqQ.jpeg" /></figure><p>Most of us spend a lot of time driving and it is easy to develop back pain or general discomfort if we do not pay attention to our driving pose.</p><p>In this short article, I list a few easy changes that you can make to your seat settings and steering wheel settings to avoid back pain and minimize fatigue due to non-optimal driving pose.</p><h3>The angle between torso and upper leg</h3><p>Some people tend to push the seat too far back (mostly men) and some lean forward too much. The optimal value for the angle between the torso and upper leg is about <strong>100</strong> degrees. You can adjust this angle by movingthe back of the seat forward/backward.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*D0K_OVepG9rywmR1NFwJ5A.png" /></figure><h3>The knee angle</h3><p>The recommended knee angle for driving is about <strong>120</strong> degrees. Move the seat forward or backward to adjust this angle.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/601/1*sTkzZXCBimi6aK4XPexyEw.png" /></figure><h3>The elbow angle</h3><p>The recommended knee angle for driving is about 130 degrees. Most cars allow you to move the steering wheel closer or farther from you. I have observed a lot of drivers who drive with straight arms (ie, elbow angle close to 180 degrees). Driving in that position puts too much stress on the arms. Try to maintain a <strong>130</strong> degree bend for optimal driving pose and reduce stree on the arms.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/599/1*F5YzJ9NQO6ltcA4YJ85raw.png" /></figure><h3>Do not slouch</h3><p>We all tend to slouch when we sit for a long time. Doing so can cause discomfort and, over time, can change our normal posture. Try to maintain an angle close to <strong>190</strong> degree as shown in the figure below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/601/1*-GLKY7odxRuzIalVgmrrog.png" /></figure><h3>Upper leg tilt</h3><p>While driving, it is recommended that your hip to be almost level with your knees. Most cars allow you to change the seat height. Lower or raise the seat height until your hip is almost at the same height is your knees. In the following image, the seat height is a little too low.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/599/1*-kboe4dyxdstQIgx-Qgjrw.png" /></figure><h3>Summary</h3><p>The recommendations in this article can help you reduce fatigue and potentially avoid pain and discomfort associated with being seated for long periods of time in the car.</p><p>I am the developer of <a href="https://www.maadotaa.com/"><strong>Stats app for Tesla</strong></a> and recently I have added a new free feature in the <a href="https://www.maadotaa.com/"><strong>Stats app</strong></a> which uses computer vision and AI to analyze your driving pose and make recommendations based on that analysis. You just need to take one image of yourself in the car (similar to the one we have been using in this article). <a href="https://www.maadotaa.com/"><strong>The app</strong></a> does everything else automatically.</p><p>For an illustrated list of Stats app features please see <a href="https://www.maadotaa.com/"><strong>maadotaa.com</strong></a></p><figure><a href="https://apple.co/3ji4JdK"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1JJxIlJZM9IN1B9Gl8UCiA.png" /></a></figure><figure><a href="https://apple.co/3ji4JdK"><img alt="" src="https://cdn-images-1.medium.com/max/149/1*Og9RT3hDbaNoyMzD4qQYKA.jpeg" /></a></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=af61eea8572d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What Does Mr. Data Have to Say About Tesla Battery]]></title>
            <link>https://maadotaa.medium.com/what-does-mr-data-have-to-say-about-tesla-battery-72aeba340388?source=rss-7a9314aff340------2</link>
            <guid isPermaLink="false">https://medium.com/p/72aeba340388</guid>
            <category><![CDATA[battery-life]]></category>
            <category><![CDATA[supercharging]]></category>
            <category><![CDATA[tesla]]></category>
            <category><![CDATA[supercharger]]></category>
            <dc:creator><![CDATA[Ramin]]></dc:creator>
            <pubDate>Wed, 06 Jul 2022 19:15:30 GMT</pubDate>
            <atom:updated>2022-07-06T19:15:30.901Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qP9lAJv0L5aauI6-6XOPyQ.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@maxberg?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Maxim Berg</a> on <a href="https://unsplash.com/@maxberg?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>Tesla battery is an important and expensive part of the car. Naturally, owners are very interested in knowing more about how to preserve their batteries and comparing their battery performance with other cars with the same age and model.</p><p>I am the developer of <a href="https://apple.co/3ji4JdK">Stats for Tesla</a> app which has several tens of thousands of users (many with multiple cars). As a data scientist I am interested in stories that data can tell. In this article, we will analyze the data related to charging and battery capacity to discover facts about Tesla battery preservation and charging habits of users whose battery capacity is above and below average. So, let&#39;s get started.</p><p>A note about how to read histograms: The X-axis in each histogram represents the quantity described in the title of the histogram. The Y-axis represents the fraction of data associated with the quantity on the X-axis. <a href="https://en.wikipedia.org/wiki/Histogram">Wikipedia</a> has a good article about histograms with lots of examples. If you find histograms and charts confusing, do not worry; I add a short sentence after each histograms to interpret what the chart conveys.</p><h3>Charging Habits</h3><p>First we look at statistics for SoC (state of charge). The following graph shows the histogram of minimum SoC. This is the SoC after which users start charging their cars.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HUa5VTWPiwI5izyleZd33g.png" /></figure><p><strong><em>Observation</em></strong><em>: Most users start charging the car after SoC reaches ~25%</em></p><p>How about the maximum SoC? The following chart shows the histogram of the charge limit that owners use. Note that this histogram is for cars that do not have an LFP battery. The LFP batteries can charge to 100% more often (To determine if your vehicle has an LFP Battery, navigate to <strong>Controls &gt; Software &gt; Additional Vehicle Information</strong>).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DAfw8dxthJcLcwSoXZPfcg.png" /></figure><p><strong><em>Observation</em></strong><em>: Most users set the charge limit to ~90%</em></p><p>It is also interesting to know the statistics of how much charge owners add to the car in each charging session.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D4UDx5eja6-F5zG1zVKznw.png" /></figure><p><strong><em>Observation</em></strong><em>: Most users add ~55% each time they charge their car</em></p><h3>How Much Do People Supercharge?</h3><p>Most people charge at home and some people who do not have access to a home charger always supercharge. This histogram shows the distribution of fraction of times that cars supercharge.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oSJm4DKfGLJsUVLpTM0ZjA.png" /></figure><p><strong><em>Observation</em></strong><em>: Vast majority of times, users do not supercharge, but there is a bump at the “fraction =1.0” which represents people who almost always supercharge (eg, homes with no access to a charger in the garage)</em></p><h3>How Often Do People Charge the Car?</h3><p>I do not drive much and charge the car about once week. It looks like I am in the minority in that regard:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/718/1*uP0Y0zqdHVioXi8e21XNRw.png" /></figure><p><strong><em>Observation</em></strong><em>: Most users charge their cars every two days</em></p><h3>Is There a Winning Charging Strategy?</h3><p>I have always wondered if there is a charging behavior that can minimize battery degradation. For example, should I set the charge limit to 60% and maintain an SoC that is close to 50% as much as possible? Should I let the SoC reach to single digits and then charge the car to 90%?</p><p>There are many recommendations that one can find in various Tesla forums (some even attributed to Tesla service center employees). Some sound plausible (eg, charging from 5% to 100% so that the BMS get calibrated). But I wanted the data to show me what the best charging behavior is (if there is one).</p><p>For this study, I selected Model 3, AWD (dual motor), 2019 cars because there are more of them and they have been driven for a few years by now. The magenta line shows a polynomial fit to the data (the trend line).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/739/1*QYrpPR5MBgVU73TTtfNy8w.png" /></figure><p>The trend is quite reasonable and the degradation as a function of miles driven is relatively flat (which is good).</p><p>Now, let’s analyze the behavior of cars that are above and below the trend line in the previous graph. The blue histogram is for the “least degradation” and the pink one is associated with “most degradation”. As we can see from the following two charts, there is not an obvious difference between the two distributions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/725/1*RX6nGE0GNupKjpAX_s2EMA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/726/1*eMLmgFzRCaissCzt9kfteQ.png" /></figure><p><strong><em>Observation</em></strong><em>: How much charge users add in each charging session does not seem to affect the battery degradation significantly.</em></p><p>The next two charts provide another way of looking at the data for the same analysis. The top and bottom of each bar in each graph represent the min and max SoC for that car. Again, blue color represents cars with less battery degradation and pink represents higher degradation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/712/1*41DVlB3RjdVVu9qc4ac_qw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/708/1*q7B1ciFy9_fnkv6N6RWc5w.png" /></figure><h3>Is Supercharging Harmful to the Battery?</h3><p>This is another frequently asked question that I also often wonder about. Again Mr. Data probably has something to say about this.</p><p>As before, blue represents “lower degradation” and pink is “higher degradation”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/688/1*AVWE5QrZzKPBmM567JDHwA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/712/1*_HKlKlAZPVGpsFqUMXH9xA.png" /></figure><p><strong><em>Observation</em></strong><em>: Supercharging does not seem to have an obvious effect on battery degradation</em></p><p>Quantitatively speaking, we can even compare the 90 percentile of the supercharging fraction for the two cases (lower degradation even used superchargers slightly more):</p><p>90 percentile of lower degradation = 0.34 <br>90 percentile of higher degradation = 0.30</p><h3>Conclusion</h3><p>I find these results somewhat comforting and liberating because they tell me that:</p><ul><li>I don’t have to be worried about the battery degradation because it is relatively small and does not go down drastically as the car ages.</li><li>I don’t have to be super careful about how I charge my car. Lower SoC and higher charge limit do not seem to affect battery degradation in a significant way</li><li>Supercharging does not cause severe battery degradation</li></ul><p>Please keep in mind that these are statistical observations. As with any statistical analysis, there are always outliers and may contradict some or all of these conclusions.</p><p>Finally, if you enjoy knowing more about your Tesla and like doing automation and using Siri to interact with you car from iPhone/iPad or Apple Watch or if you are interested in knowing how your car’s current battery capacity compares with other Tesla cars with the same model and year and odometer, you may like my <a href="http://maadotaa.com/"><strong>Stats for Tesla app</strong></a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2EFV1EWvYpnofBW5ACy1jw.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=72aeba340388" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Optimal Portfolio: Is free lunch possible?]]></title>
            <link>https://maadotaa.medium.com/optimal-portfolio-is-free-lunch-possible-762a083cfada?source=rss-7a9314aff340------2</link>
            <guid isPermaLink="false">https://medium.com/p/762a083cfada</guid>
            <category><![CDATA[investing]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[Ramin]]></dc:creator>
            <pubDate>Sun, 03 Oct 2021 18:27:18 GMT</pubDate>
            <atom:updated>2021-10-03T18:27:18.447Z</atom:updated>
            <content:encoded><![CDATA[<p>Free lunch usually does not exist, but it is possible to combine multiple ETFs or stocks together in your portfolio in order to dampen the volatility without sacrificing returns.</p><p>This can be done by traversing the space of all possible portfolios and selecting a combination of funds which minimizes volatility for a given average annualized gain.</p><p>For example, consider the following graph and assume ‘stock a’ and ‘stock b’ represent stocks or funds in which you are considering to invest. Both ‘stock a’ and ‘stock b’ fluctuate somewhat, but if they are properly combined (say, with equal weights), then the portfolio experiences almost no volatility while it enjoys the same average return. This is because, A and B are negatively correlated.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w9r_idPUfoY-D04L3NR8-A.png" /></figure><p>The concept of combining funds in order to minimize risk and attain maximum return is not new. In fact, it was proposed by Dr. Harry Markowitz in 1952 when he created the modern portfolio theory (MPT) to help investors match their risk tolerance with their reward expectations in order to create their ideal portfolio.</p><p>However, the amount of computation involved in calculating the optimal portfolio given a level of risk tolerance is non-trivial and until recently it required at least a desktop computer. More importantly, these types of computations are typically done as a service by money managers for a fee that is proportional to the value of the portfolio.</p><p>My “<a href="https://apps.apple.com/ph/app/ai-portfolio/id1499921065">AI Portfolio</a>” app enables any user to design their own portfolio and re-balance as required. All you need to do is to observe the risk/reward graph presented in the app and select the level of risk/reward that you are suits you. The app then conveniently calculates the optimal portfolio which achieves the goal.​</p><p>For example, consider the following screenshot. The graph at the bottom of the screen shows the volatility vs. return. Specifically, the app has pre-computed the maximum return that can be achieved for a given degree of volatility. As you can imagine, there are infinite number of combination of funds and finding the one that achieves this goal is computationally complex. The app uses an efficient AI algorithm to make this computation possible on your device at reasonable time (this computation is done the first time that you launch the app and every time that you make a change in the settings tab of the app).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/303/0*9dDtyy3UamCOpJnQ.png" /></figure><p>Once the user make a risk/reward selection (by tapping on the bottom graph), they can also observe how that portfolio would have performed in the past decade and compare the optimal portfolio in terms of fluctuation and return with the two extreme portfolios of maximum return and minimum volatility. This is shown in the following screenshot.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/319/0*c9AZbXygKlfg52Lh.png" /></figure><p>Disclosure: Nothing in this app or article should be considered investment advice. Past performance is not necessarily indicative of future returns. You should direct all investment related questions that you have to your financial advisor.</p><p><em>Originally published at </em><a href="https://www.maadotaa.com/aiportfolio"><em>https://www.maadotaa.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=762a083cfada" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Warm-up Your Tesla From Your Apple Watch-face]]></title>
            <link>https://maadotaa.medium.com/warm-up-your-tesla-from-your-apple-watch-face-8b0c57443e50?source=rss-7a9314aff340------2</link>
            <guid isPermaLink="false">https://medium.com/p/8b0c57443e50</guid>
            <category><![CDATA[tesla]]></category>
            <category><![CDATA[apple-watch]]></category>
            <dc:creator><![CDATA[Ramin]]></dc:creator>
            <pubDate>Thu, 11 Mar 2021 17:15:19 GMT</pubDate>
            <atom:updated>2021-03-11T17:25:21.110Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nnGkVveuzObV2lWg4S-TjQ.png" /></figure><h3>Simple Instructions</h3><ul><li>Use the <a href="http://maadotaa.com/">Stats app</a> to create a shortcut for setting the climate to the temperature that you want and optionally turning on the seat heaters.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GpHEZczYjzphZLjsT6IpLg.jpeg" /></figure><ul><li>Press and hold on the watch-face,</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/368/1*9BQmzDOOtuVRR5YaAq065w.png" /></figure><ul><li>Tap on edit, and tap on the one of areas on the watch-face that allows adding a complication. Here I have added the “Make it Hot” button to the buttom right corner of my screen.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/368/1*JjvyhOLWFriNz-BjybE_cg.png" /></figure><ul><li>Select Shortcuts app and select the Stats shortcut that you want to add to the watch-face.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/368/1*SH7Q0eJEW1iWu588AxGIvw.png" /></figure><p>That’s it. Now you have a button on your watch-face for warming up the car cabin. Don’t worry about tapping it accidentally because the Shortcuts app will ask for a conformation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/368/1*2K9sYo-V6k0Fu6g0-T9WNQ.png" /></figure><p>Of course, you can also use Siri on your watch to trigger the shortcuts that <a href="http://maadotaa.com/">Stats app</a> provides.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8b0c57443e50" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>