Artifact Journal

Blogging Artifacts

Field notes from experiments, product thinking, and research design. Short reads with a bias toward clarity and craft.

Feb 28, 2023Artificial Intelligence

Build your own AI: how to teach GPT to search the web and execute code

Large Language Models such as GPT-3, ChatGPT, Bing AI, and Google Bard have recently demonstrated stunning advances in conversational capabilities, text summary, translation, code creation and many other applications. Microsoft’s new AI-powered search assistant Bing showed how these capabilities can be further enhanced by allowing the AI agent to access conventional search engines and read web pages. In this post, we will take a closer look at the Python package langchain , which allows us to easily combine an LLM such as GPT-3 with other functionalities like web search, a Python interpreter, and a terminal session for code execution. With just 50 lines of code, you can create your own personalized AI agent that retrieves information from the internet, implements algorithms in Python, and runs code to solve tasks.

AILarge Language ModelPython
Read story
Dec 20, 2022Probabilistic programming

Probabilistic alpha and beta: quantifying an uncertain edge

In finance, the performance of an asset is often quantified by alpha (the excess returns above a benchmark return) and beta (the volatility or risk of the asset relative to a benchmark). These metrics are estimated from historical data and are often based on only short track records. Even if a long series of historical returns is available for an asset, older data may no longer represent the current market dynamics due to regime switches. In this post, we develop time-varying, probabilistic versions of alpha and beta, and go through the process of using these new metrics to build a dynamic stocks/bonds portfolio to improve on the classic 60/40 portfolio. To accomplish this, we employ probabilistic programming, a technique to build probabilistic models with ease in Python and infer parameters from noisy data.

FinanceProbabilityPythonRisk
Read story
Nov 07, 2022Python

Skewness: the fallacy of the expected return

In this post we will take a closer look at the expected return that is often stated for investments like stocks and other financial assets, or for certain outcomes in gambling. The point we want to convey is that the expected return is only valid for one period or a single “iteration” (say, one year, or one round of a game such as Blackjack), but that the expected return can be highly misleading for more long-term investments that involve continuous re-investing, i.e. compound interest. We will see that compounding introduces substantial positive skewness in the long-term return distribution. While this skewness certainly represents a beautiful property for building wealth in the long-term, it also renders the expected long-term return misleading as there is a high probability that one will not achieve the long-term expected return! We will learn that to correct for skewness, we need to use the geometric mean instead of the arithmetic mean that is used to compute the expected return – which will lead us to the Compound Annual Growth Rate (CAGR).

FinanceProbabilityPythonRisk
Read story
Oct 03, 2022Artificial Intelligence

Talking to machines: prompt engineering & injection

OpenAI has recently publicized the API to access their Large Language Models (LLMs), allowing anyone to sign up for a free account and test the various possible applications that these powerful neural networks enable. In this post, we will:

AILarge Language Model
Read story
Aug 23, 2022Probabilistic programming

Probabilistic programming in finance: a robust Sharpe ratio estimate

In this post, we will develop a time-varying, probabilistic extension of the Sharpe ratio as a widely used performance metric for financial assets. In particular, we devise a Bayesian regime-switching model to capture different market conditions and infer the full distribution the Sharpe ratio as it changes over time using the probabilistic programming framework bayesloop . We show that by focusing on the left tail of the Sharpe distribution we can derive a robust point estimate of the Sharpe ratio that accounts for the additional uncertainty of short track records and avoids overestimating the Sharpe ratio in the case of temporary market rallies. Additionally, we show that the shape of the Sharpe distribution encodes the susceptibility of an asset to different market conditions and can thus help to identify resilient assets for long-term investments.

FinanceProbability
Read story
Aug 03, 2022Risk mitigation

How heavy tails destabilize Markowitz portfolio selection

This is the forth and final post of a short series of posts on extreme events in financial time series. In the first post , we have introduced power-law theory to describe and extrapolate the chance of extreme price movements of the S&P500 index. In the second post , we took a closer look at how statistical moments may become infinite in the presence of power-law tails, rendering common estimators useless. In the third post , we have seen how infinite kurtosis makes GARCH risk models fail on out-of-sample data. In this post, we turn to Markowitz’s Modern Portfolio Theory and show how the heavy tails of financial return distributions drastically increase the uncertainty in portfolio allocation weights.

FinanceProbabilityRisk
Read story
Jul 29, 2022Risk mitigation

Why GARCH models fail out-of-sample

This is the third post of a short series of posts on extreme events in financial time series. In the first post , we have introduced power-law theory to describe and extrapolate the chance of extreme price movements of the S&P500 index. In the second post , we took a closer look at how statistical moments may become infinite in the presence of power-law tails, rendering common estimators useless. In this post, we will investigate the consequences of infinite moments by showing how the popular GARCH risk model almost perfectly describes in-sample data, but fails to extrapolate to out-of-sample data.

FinanceProbabilityRisk
Read story
Jul 20, 2022Risk mitigation

Infinite kurtosis: moment statistics under fat tails

This is the second post of a short series of posts on extreme events in financial time series. In the previous post , we have introduced power-law theory to describe and extrapolate the chance of extreme price movements of the S&P500 index. In this post, we will explore how the power-law tails of a return distribution affect the estimation of metrics such as variance and kurtosis, which lie at the heart of many popular risk models in finance like GARCH and Modern Portfolio Theory. The point I want to convey in this post is that even if you will always estimate a finite sample estimate for kurtosis from a given data set, the true kurtosis that underlies the data generation process (the market) is infinite and many models will fall for the apparent finite sample kurtosis!

FinanceProbabilityRisk
Read story
Jul 15, 2022Risk mitigation

The 23-sigma fallacy

This is the first post of a short series of posts on extreme events in financial time series. We will investigate the return distribution of financial assets, use power-law theory to describe its tails, see how estimating higher moments such as kurtosis becomes meaningless, and finally discuss a fundamental flaw in popular models such as GARCH that arises from fat tails. The point that I want to convey is that without putting much care into the fat-tailedness of financial distributions, models cannot be expected to work out-of-sample, they will always be surprised when that one new extreme data point comes – and those surprises are seldom good ones.

FinanceProbabilityRisk
Read story