Artur Sepp Blog on Quantitative Investment Strategies

  • Blog
  • Research
  • About
  • Category: Python

    • Lognormal Stochastic Volatility – Youtube Seminar and Slides

      Posted at 6:14 am by artursepp, on October 25, 2024

      I would like to share the youtube video of my online seminar at Minnesota Center for Financial and Actuarial Mathematics and presentation slides.

      I discuss the motivation behind introducing Karasinki-Sepp log-normal stochastic volatility (SV) model in our IJATF paper with Parviz Rakhmonov. I briefly highlight the advantages of this model over existing SV models. Then I focus on new features of the model.

      For the first time, I formulate the dynamic of log-normal SV model consistent with the forward variance by construction. This formulation enables to automatically fit the model to a given term structure of variance swap strikes implied from market prices. I show that there is a small modification of the closed-form solution presented in our paper so that the existing solution can be applied here as well.

      Also for the first time, I introduce the rough formulation of the log-normal SV model. I note that our exponential affine expansion for the classic log-normal SV model can also be applied for the rough version, but it results in a system of multi-variate system of integral equations which is numerically tedious. We need to resort tom Monte-Carlo simulations of this model and Deep Learning for model calibration. This is work in progress so stay tuned.

      Finally, I present the model calibration to the time series of implied volatilities of options on Bitcoin traded on Deribit. I touch upon the calibration of mean-reversion parameters using empirical auto-correlation function discussed in our paper. The rest of model parameters: the current level and long-term mean volatility, volatility beta, and volatility-of-volatility are fitted in time series calibration.

      Below I show that the model error (the average difference between market and model implied volatility) is less than 1% most of the times. The volatility beta serves as the expected skeweness indicator switching from large negative values during risk-aversion and positive values during risk-seeking periods. This time series construction can serve as a base for relative value analysis and quant trading strategies.

      I mention that Python implementation of model is available in stochvolmodels package at Github. See an example of running the log-normal SV model and example of model calibration using the new formulation of term structure consistent with impled variance.

       

      Disclosure

      This research is a personal opinion and it does not represent an official view of my current and last employers.

      This paper and the post is an investment advice in any possible form.

      Share this:

      • Click to share on LinkedIn (Opens in new window) LinkedIn
      • Click to share on X (Opens in new window) X
      • Click to share on WhatsApp (Opens in new window) WhatsApp
      • Click to email a link to a friend (Opens in new window) Email
      • Click to print (Opens in new window) Print
      Posted in Crypto, Python, Volatility Modeling, Volatility Trading | 2 Comments
    • Optimal allocation to cryptocurrencies in diversified portfolios – update on research paper

      Posted at 3:08 pm by artursepp, on August 18, 2024

      Cryptocurrencies have been acknowledged as an emerging asset class with a relatively low correlation to traditional asset classes and independent drivers of their long-term performance (see for an example excellent papers by Harvey et al (2022) and Adams at al (2024)).

      A year ago in Summer of 2023, I published research article in Risk Magazine (SSRN draft) on quantitative methods for optimal allocation to cryptocurrencies within alternative and balanced portfolios. The metrics for consideration include metrics for portfolio diversification, expected risk-return relationships and skewness of the returns distribution. Using roll-forward historical simulations, I showed that all four allocation methods produce a persistent positive allocation to Bitcoin and Ether in alternative and balanced portfolios with a median allocation of about 2.7%.

      This time, I would like to present the updated outcomes from my model given that Bitcoin and Ether had a strong performance of 95% and 35%, respectively, since the last update to today (from 30Jun2023 to 16Aug2024).

      Spoiler: the performance of all four methods for balanced and alts portfolios have been in line with what has been reported in the article with optimal allocation weights to Bitcoin and Ether largely unchanged. Python code for this analysis is available in OptimalPortfolios packadge github repo.

      First I start with the analysis of annual rolling performance. In Subplot (A) of Figure 1, I  show Sharpe ratios (through the paper and this post, the Sharpe ratio is computed using monthly log-returns adjusted by 3m UST rate) for trailing holding periods with the period start given in the first column and the period end given in the first row. For an example, Sharpe ratio realized from the investment period from 31Dec2020 to 16Aug2024 is 0.29.

      Clearly, the early periods before 2017 are characterized with higher realized Sharpe ratios. What is remarkable that any investment period that starts at the end of each calendar year from 2010 to today generated positive Sharpe ratio. In Subplot (B) of Figure 1, I  show the realised skeweness of monthly returns. In early periods, the monthly performance exhibits highly positive skewness. Also more recently the skeweness became positive again.

      Figure1. Realized Sharpe ratios from the period start (given in the first column) to the period end (given in the first row). Subplot (A) shows Sharpe ratio using average monthly log-returns; Subplot (B) shows skewness of monthly returns.

      Methodology

      The long-term positive performance and positive skeweness of cryptocurrency returns pose well for quantitative allocation methods.

      In the paper I consider four quantitative allocation methods for construction of optimal portfolios:
      1) Two risk-based methods which include portfolios constructed using equal risk contribution and with maximum diversification methods.
      2) Two risk-return based methods which include portfolios constructed using maximum Sharpe ratio and maximum CARA-utility methods.

      For the investment universe, I consider the two mandates:

      1) Alternatives (Alts) or unconstrained mandate that targets absolute returns by investing into alternative assets. This mandate is typical for high net worth private investors and family offices.

      2) Benchmarked (Balanced) mandate which targets excess returns over a benchmark by allocating to a balanced equity/bond portfolio with additional overlay to alternative assets. Such a mandate is typical for institutional investors such as pension funds, insurance companies, and endowments.

      As the balanced benchmark, I use the classic 60/40 equity/bond portfolio. I fix the target weight of the balanced portfolio for this mandate to 75% and assign $25%$ allocation to alternative assets. As a result, I consider the modern 70%/30%$approach for allocation portfolio of institutional mandates (see, for an example, McVey et al (2022)) with 30% allocation to bonds, 45% to public equities and 25% to alternative assets.

      I refer to the paper for the investment universe of this mandates (In this analysis I change the benchmark for macro funds from NEIXMTI Index to HFRIMDT Index). For each allocation method, I evaluate the following portfolios given in Table 1 below. Portfolios 1, 2, 3 provide insights into the marginal contribution of including cryptocurrencies to investable universe alternative portfolios. Portfolios 4, 5 and 6 provide with insights into including cryptocurrencies to alternatives for blending with the 60/40 equity/bond portfolio. The marginal contribution of including cryptocurrencies is estimated using 4 portfolios with either BTC or ETH using 4 allocation methods, with total of 16 different portfolio schemes allocated to cryptocurrencies. I sue spot returns for performances of cryptocurrencies. This provides a sufficient depth for making insights.

      Table 1. Simulated mandate portfolios with cryptocurrencies.

      Optimal Portfolios and Their Performances

      I use quarterly rebalancing and roll-forward analysis for generation and backtest of optimal portfolios. I describe the methodology in the paper  and in github package

      Here, I present the result of roll forward simulations from 31Mar2016 t0 16Aug2024. I will present some key figures here, all outputs can be found in pdf report of backtests.

      Maximum Diversification

      Maximum Diversification is my favorite method because it takes into account only the covariance matrix. Also, unlike Equal Risk Contribution method, Maximum Diversification method may produce zero weights to unattractive instruments. In Table 3, I show the risk-adjusted performance of the simulated portfolios without crypto and with inclusion of BTC and ETH cryptocurrencies. The Sharpe ratio is computed using monthly log-returns adjusted by 3m UST rate, beta and (annualised) alpha are computed by regression of monthly returns against 60%/40% equity/bond (Balanced) portfolio.

      The marginal gain of including BTC and ETH is of +0.24 (=0.70-0.46) and +0.29 (=0.75-0.46) in Sharpe ratio for Alternative portfolios and of +0.23 and +0.21 for Balanced portfolios, which is significant.

      In the last 4 rows I show the weight allocated to cryptocurrencies. The median allocation weight is 2.2%/1.9% and 3.13%/3.04% for BTC or ETH in alternatives and balanced portfolios, respectively.

      Table 3. Risk-adjusted performance of Maximum Diversification allocation method.

      In Figure 2, I show the time series of cumulative performances and drawdowns of Maximum Diversification portfolios. Adding cryptocurrencies to the portfolio universe did not materially impact realised drawdowns.

      Figure2. Cumulative performance of portfolios computed using Maximum Diversification allocation method.

      In Figure 3, I show the stack plot of optimal weights for BTC for alternatives and balanced mandates. We observe that the optimal weight of BTC has been persistent through the backtest period, in contract to other asset classes. It is interesting, that the optimal allocation to alternatives within balanced portfolio includes only Bitcoin and SG Trend instruments for the past two years.

      Figure 3. Optimal Allocation weights for alternative and balanced mandates with universe including BTC.

      Equal Risk Contribution

      Equal risk contribution allocates equal buckets for risk (for Balanced mandate, 75% of risk is assigned to the balanced portfolio). We observe that adding cryptocurrencies improves the risk-adjusted performance of alternatives mandate. Interestingly, from the standpoint of the equal risk contribution method, allocations to BTC and ETH are almost same.

      Table 3. Risk-adjusted performance of Equal Risk Contribution allocation method.

      Maximum Sharpe Ratio

      I use the rolling window of 5 years to estimate asset return and covariances for the estimation of the Sharpe ratio. For alternatives portfolio, the contribution to the performance (+0.80 and +0.67 in Sharpe) from adding cryptocurrencies is significant with their median weights of 9% and 4% for BTC and ETH. It is clear that using past returns as inputs to the optimiser may not be robust, however increasing the universe may lead to better results because of higher degree of freedom.

      Table 4. Risk-adjusted performance of Maximum Sharpe Ratio allocation method.

      Carra Mixture Utility

      To estimate the 3-state mixture of returns distribution for the Carra Mixture utility, I also use the rolling window of 5 years. As I explain in the paper, the Carra Mixture Utility allocation method favors instruments with positive skeweness. Similarly to the Maximum Sharpe ratio, adding cryptocurrencies to the alternatives portfolio improves the realised Sharpe ratio considerably by +0.84 and +0.64 with BTC and ETH, respectively. The median allocated weight is 21% and 8% for alternatives mandate and 19% and 8% for the balanced mandate. The higher weights are the result of overweighting instruments with positive skeweness.

      Table 5. Risk-adjusted performance of Carra Mixture Utility allocation method.

      Summary of Weights

      In the summary, I would like to the review the optimal weight to cryptocurrencies. The major goal of my article is to show that cryptocurrencies deserve an allocation for broad portfolios. In my analysis, I did not impose any allocation constraints to make a fair argument.

      In Figure 4 I show the time series of optimal allocations to BTC and ETH by each method and for each mandate. In Table 6, I show summary of weights aggregated from time series.

      Carra Mixture (CARRA-3) allocation method assigns the highest allocation to cryptocurrencies because it favors assets with high positive skewness.

      We observe that the Maximum Sharpe ratio and Carra Mixture, which take into account the rolling performance of assets, have been producing smaller allocation weights in recent years following smaller the risk-adjusted performances of cryptocurrencies.

      However, the risk based methods including Equal Risk Contribution (ERC) and Maximum Diversification (MaxDiv) produce largely stable allocation to cryptocurrencies, which stay largely intact in past couple of years.

      The median of the time series median allocation is 5.7%, 3.8%, 3.0%, 2.4%, which gives a “median”allocation of 3.4% which slightly increased from 2.7% which I reported originally in the paper.

      Figure 4. Optimal weights to BTC and ETH by allocation methods.

      Table 6. Summary of weights

      Further reading

      Enjoy reading the paper and experiment with Python code

      Disclosure

      This research is a personal opinion and it does not represent an official view of my current and last employers.

      This paper and the post is an investment advice in any possible form.

      Cryptocurrencies are associated with high risk.

      Share this:

      • Click to share on LinkedIn (Opens in new window) LinkedIn
      • Click to share on X (Opens in new window) X
      • Click to share on WhatsApp (Opens in new window) WhatsApp
      • Click to email a link to a friend (Opens in new window) Email
      • Click to print (Opens in new window) Print
      Posted in Asset Allocation, Crypto, Decentralized Finance, Python, Quantitative Strategies, Uncategorized | 2 Comments
    • Log-normal Stochastic Volatility Model for Assets with Positive Return-Volatility Correlation – research paper

      Posted at 3:04 pm by artursepp, on August 10, 2022

      I am introducing my most recent research on log-normal stochastic volatility model with applications to assets with positive implied volatility skews, such as VIX index, short index ETFs, cryptocurrencies, and some commodities.

      Together with Parviz Rakhmonov, we have extended my early work on Karasinski-Sepp log-normal volatility model and we have written an extensive paper with an extra focus on modelling implied volatilities of assets with positive return-volatility correlation in addition to deriving a closed-form solution for option valuation under this model.

      Assets with positive implied volatility skews and return-volatility correlations

      While it is typical to observe negative correlation between returns of an asset and changes in its implied and realized volatilities, there are in fact many assets with positive return-volatility correlation and, as a consequence, with positive implied volatility skews. In below Figure, I show some representative examples.

      (A) The VIX index provides protection against corrections in the S&P 500 index, so that out-of-the-money calls on VIX futures are valuable and demand extra risk-premia than puts.

      (B) Short and leveraged short ETFs on equity indices have positive implied volatility skews because of their anti-correlation with underlying equity indices. I use 3x Short Nasdaq ETF with NYSE ticker SQQQ, which is the largest short ETF in US equity market and which has very liquid listed options market.

      (C) Cryptocurrencies, including Bitcoin and Ethereum, and “meme” stocks, such as AMC, have positive skews during speculative phases when positive returns feed speculative demand for upside. These self-feeding price dynamics increase the demand for calls following a period of rising prices. However, positive return-volatility correlation tend to reverse once “greed” regime is over and “risk-off” regime prevails.

      (D) Gold and commodities in general may have positive volatility skews dependent on supply-demand imbalances, seasonality, etc.

      Importantly, the valuation of options on these assets is not feasible using conventional stochastic volatility models applied in practice such as Heston, SABR, Exponential Ornstein-Uhlenbeck stochastic volatility models, because these models fail to be arbitrage-free (forwards and call prices are not martingals). Curiously enough, the topic of no-arbitrage for SV models with positive return-volatility correlation has not received attention in literature, despite a large number of assets with positive return-volatility correlation.

      Applications to Options on Cryptocurrencies

      Additional, yet important application of our work is the pricing of options on cryptocurrencies, where call and put options with inverse pay-offs are dominant. The advantage of inverse pay-offs for cryptocurrency markets is that all option-related transactions can be handled using units of underlying cryptocurrencies, such as Bitcoin or Ethereum, without using fiat currencies. Critically, since both inverse options (traded on Deribit exchange) and vanilla (traded on CBOE) are traded for cryptocurrencies, a stochastic volatility must satisfy the martingale condition for both money-market-account and inverse measures to exclude arbitrage opportunities between vanilla and inverse options. We show that prices dynamics in our model are martingales under the both inverse and money-market-account measures.

      In below Figure, I show the model fit to Bitcoin options observed on 21-Oct-2021 (the period with positive skew) for most liquid maturities of 2 weeks, 1 month, and 2 and 3 months. We see that the model calibrated to Bitcoin options data is able to capture the market implied skew very well across most liquid maturities with only 5 model parameters. The average mean squared error (MSE) is about 1% in implied volatilities, which is mostly within the quoted bid-ask spread. Calibration to ATM region can be further improved using a term structure of the mean volatility or augmenting the SV model with a local volatility part to fit accurately to the implied volatility surface.

      Model applications

      The quality of model fit is similar for other assets with either positive or negative skews. The main strength of our model is that it can be used for the following purposes.

      1. Cross-sectional no-arbitrage model for different exchanges and options referencing the same underlying.
      2. Model for time series analysis of implied volatility surfaces.
      3. Dynamic valuation model for structured products and option books.

      Further resources

      SSRN paper Log-normal Stochastic Volatility Model with Quadratic Drift https://ssrn.com/abstract=2522425

      Github project with the example of model implementation in Python: https://github.com/ArturSepp/StochVolModels

      Youtube video with lecture I made at Imperial College for model applications for Bitcoin volatility surfaces: https://youtu.be/dv1w_H7NWfQ

      Youtube podcast with introduction of the paper and review of Github project with Python analytics for model implementation: https://youtu.be/YHgw0zyzT14

      Disclaimer

      The views and opinions presented in this article and post are mine alone. This research is not an investment advice.

      Share this:

      • Click to share on LinkedIn (Opens in new window) LinkedIn
      • Click to share on X (Opens in new window) X
      • Click to share on WhatsApp (Opens in new window) WhatsApp
      • Click to email a link to a friend (Opens in new window) Email
      • Click to print (Opens in new window) Print

      Like this:

      Like Loading...
      Posted in Crypto, Python, Volatility Modeling, Volatility Trading | 1 Comment
    • Why Python for quantitative trading?

      Posted at 12:41 pm by artursepp, on October 24, 2018

      “Today a new language is overtaking French as the most popular language taught in primary school. Its name is Python… 6 out of 10 parents want their kids to learn Python”, Joel Clark.

      Well, when I attended school, I learnt BASIC… But I must confess, I do share the excitement taking over the Python language.

      I have recently taken part in a webinar organised by Risk.net and Fincad where we discussed the advantages and challenges in using Python for developing quantitative trading applications. The panel included experts from various corners of the industry including myself and:

      1. Joel Clark, contributing editor, Risk.net (Moderator)
      2. Gary Collier, CTO, Man Group Alpha Technology
      3. Per Eriksson, senior executive, enterprise risk and valuation solutions, FINCAD
      4. Ronnie Shah, head of US quantitative research and quantitative investment solutions, Deutsche Bank

      The webinar was a success with over 500 participants. Since Python is on everyone’s mind, I wanted to highlight some interesting questions and thoughts from our discussion. The audio of the webinar is available here

       

      Why Python has become an increasingly popular programming language in financial markets?

      One of the major advantages of using Python is the ease to interconnect different systems with data feeds and databases, to process data, and to output results into user and trading applications.

      My first experience with Python came in 2012, when Bank of America Merrill Lynch, where I worked as a front office quant strategist, introduced the Quartz system developed in Python. The Quartz was supposed to be the bank-wide solution to share data and trading risks. The reason is that the insufficient centralization and aggregation of positions and risks across all trading books (traditionally differentiated by geographies and asset classes) was one of the key weaknesses shared by large investment banks during and in the aftermath of the 2008 financial crisis.  As a result, the Quartz and Python-based analytics were thought as a bridge to connect different parts of analytics, data centres, and development teams. A daunting task for any large organization employing hundreds of developers and users!

      Moving fast forward, Python has been widely applied by major financial institutions for developing tools to connect different parts of analytics and to increase collaboration within a firm. Over time, people have also started to do more core development in Python in addition to using Python as a glue language.

      New developments using the Python language have been leveraged thanks to a rich Python ecosystem with huge number of libraries for data analytics and visualization. For an example, Man AHL illustrated how they benefited by moving both research and production code to Python.

      Summarising their paper and our panel, Python has become increasingly popular because:

      1. Python enhances the communication between different teams.
      2. Python provides an advanced ecosystem with packages for numerical and statistical analysis, data handling and visualization.
      3. Python is easy to learn and it is flexible to apply, and it’s actually fun to program using the Python language. As a person with many years of doing quantitative modelling in C++ and Matlab, I fully support this view.

       

      How Python works among other languages for data analysis?

      Since data analytics is currently one of the key drivers across all industries including the finance and investment management, choosing the right ecosystem for development may have a crucial impact on the business development and success.

      Presently, the three development tools are widely applied for the data analytics.

      1. Python along with pandas for tabular data structures and multiple packages for data analysis (statsmodels for statistical analysis, matplotlib for data visualization, scikit-learn for machine learning, etc). The advantage is that Python provides a free and open-source solution with plentiful resources for data fetching, processing, and visualization. Python can be easily deployed on either a PC or a server to make scalable firm-wide solutions.
      2. Traditionally, Matlab has been widely applied in academic and research labs but it comes with a heavy cost for commercial firms. Matlab has numerous packages for data processing, analysis, and visualization, however each package is available at a separate price. Personally, I have used Matlab a lot along with its capabilities for the object-oriented programming. While I value some capabilities of Matlab, the major drawback of Matlab, apart from its licensing cost, is that the deployment of Matlab-based analytics is problematic and comes with separate fees. Matlab applications can be compiled and deployed on a server but the deployment process looks complex and not well documented and it may be costly if external consultancy is needed. In my opinion, the insufficient portability and scalability are major obstacles for developing firm-wide solutions using Matlab.
      3. R along with its multiple packages for statistical data analytics. While R is free and it has many packages to do various statistical analyses, the deployment of R across firm-wide platform may not be as efficient. In my opinion, the R language is suitable only for the development of stand-alone tools for statistical analyses. In fact, Jupiter Lab enables to apply R functionality within the Python ecosystem.

       

      How long would it take to convert Matlab production code to Python?

      Given the advantages of Python over Matlab, most firms would now employ Python to start any new development from scratch. How is about converting the legacy code and systems?

      Gary Collier gave one example of AHL converting a fairly complicated trading system for single stock equities to Python within 8-9 months.

      In fact, my friend Saeed Amen has just written a short overview paper on moving from Matlab to Python. The transition is feasible… While there will be short-term costs, the long-term benefit is to have a firm-wide solution developed in one multi-purpose language that everyone can understand and contribute to.

       

      Python everywhere?

      To conclude, the top figure shows the share of questions about various programming languages asked each month at Stack Overflow, which is the largest online community for developers. We clearly see the growing trend for Python against all other major programming languages. Perhaps soon enough the Python will overtake all other languages taught not only in primary school but e,plyed everywhere else…

      Share this:

      • Click to share on LinkedIn (Opens in new window) LinkedIn
      • Click to share on X (Opens in new window) X
      • Click to share on WhatsApp (Opens in new window) WhatsApp
      • Click to email a link to a friend (Opens in new window) Email
      • Click to print (Opens in new window) Print
      Posted in Python, Uncategorized | 1 Comment
    • Receive notifications of new posts by email

      Join 6,306 other subscribers
    • Recent Posts

      • The Science and Practice of Trend-following Systems: paper and presentation
      • Lognormal Stochastic Volatility – Youtube Seminar and Slides
      • Optimal allocation to cryptocurrencies in diversified portfolios – update on research paper
      • Unified Approach for Hedging Impermanent Loss of Liquidity Provision – Research paper
      • Log-normal stochastic volatility with quadratic drift – open access publication
      • Stochastic Volatility for Factor Heath-Jarrow-Morton Framework – research paper
      • AD Derivatives podcast on volatility modeling and DeFi
      • What is a robust stochastic volatility model – research paper
      • Robust Log-normal Stochastic Volatility for Interest Rate Dynamics – research paper
      • Optimal Allocation to Cryptocurrencies in Diversified Portfolios – research paper
      • Log-normal Stochastic Volatility Model for Assets with Positive Return-Volatility Correlation – research paper
      • Developing systematic smart beta strategies for crypto assets – QuantMinds Presentation
      • Toward an efficient hybrid method for pricing barrier options on assets with stochastic volatility – research paper
      • Paper on Automated Market Making for DeFi: arbitrage-fee exchange between on-chain and traditional markets
      • Tail risk of systematic investment strategies and risk-premia alpha
      • Trend-Following CTAs vs Alternative Risk-Premia (ARP) products: crisis beta vs risk-premia alpha
      • My talk on Machine Learning in Finance: why Alternative Risk Premia (ARP) products failed
      • Why Python for quantitative trading?
      • Machine Learning for Volatility Trading
      • Trend-following strategies for tail-risk hedging and alpha generation
    • Categories

      • Asset Allocation (10)
      • Crypto (8)
      • Decentralized Finance (5)
      • Python (4)
      • Quantitative Strategies (17)
      • Trend-following (4)
      • Uncategorized (20)
      • Volatility Modeling (18)
      • Volatility Trading (13)

 

Loading Comments...
 

    %d