Recent Questions - Quantitative Finance Stack Exchange most recent 30 from quant.stackexchange.com 2022-07-05T15:24:03Z https://quant.stackexchange.com/feeds https://creativecommons.org/licenses/by-sa/4.0/rdf https://quant.stackexchange.com/q/71494 1 Can I use the QuantLib Monte Carlo engine to price American options using heavy/fat tailed-distributed random numbers? Dan La Russa https://quant.stackexchange.com/users/61693 2022-07-05T01:36:50Z 2022-07-05T01:36:50Z <p>This might be silly, but I’m seeking to use QuantLib to price vanilla American call and put options using a Black-Scholes-Merton process and the Monte Carlo pricing engine based on the Longstaff Schwartz algorithm.</p> <p>My question is: Am I confined to Gaussian pseudorandom numbers in this engine? Or can I use pseudo RNs drawn from some other underlying distribution, like Student T, or some other distribution I can generate via the inverse CDF?</p> <p>Put another way, how do I define a pricing engine for American call and put options that uses random numbers drawn from a student t (or custom) distribution based on mcamericanengine.hpp in QuantLib?</p> <p>I recognize that I may only have the volatility parameter to modify the shape of my distribution. After investigating the Monte Carlo framework in Quantlib and reading over chapter 6 of “Implementing QuantLib”, here’s what I think I need to do:</p> <p>• Define a distribution function (mydistribution.cpp and mydistribution.hpp) in math/distributions with a InverseCumulativeMyDistribution class</p> <p>• Instantiate a class template in rngtraits.hpp</p> <p>• Define a new SingleVariate traits class in mctraits.hpp</p> <p>• Define (I think) a MonteCarloModel as in montecarlomodel.hpp</p> <p>• Do I need to make changes to mcsimulation.hpp, mclongstaffschwartzengine.hpp, and mcamericanengine.hpp as well?</p> <p>Am I on the right track here? Please pardon my ignorance on this framework as I’m very new to both QuantLib and cpp programming. If by some miracle I get this working, how do I take the extra step and expose this new pricing engine in python via QuantLib-SWIG? I’m willing to put in the work! For reference I have vs 1.25 of QuantLib and QuantLib-Python installed on Windows 10 and confirmed both are working.</p> https://quant.stackexchange.com/q/71490 0 Why is the performance of a portfolio based on geometric means boosted by positive correlation? Bazman https://quant.stackexchange.com/users/7077 2022-07-04T14:19:40Z 2022-07-05T10:22:05Z <p><a href="https://qoppac.blogspot.com/2017/02/can-you-eat-geometric-returns.html" rel="nofollow noreferrer">https://qoppac.blogspot.com/2017/02/can-you-eat-geometric-returns.html</a></p> <p>The blog post above by Rob Carver discusses the use of geometric means to evaluate investments. The section &quot;The consequences of using geometric returns&quot; gives the following example.</p> <p>Assuming correlation of 0.85:</p> <ul> <li>1 asset: arithmetic mean 5%, geometric mean 1.3%</li> <li>5 assets: arithmetic mean 5%, geometric mean 1.8%</li> </ul> <p>Unfortunately the calculation is not given so could someone run me through how this was calculated?</p> <p>I want to understand the intuition as to why the geometric mean is improved by the positive correlation what would happen if the correlation was zero or negative?</p> <p>Thanks</p> <p>Baz</p> https://quant.stackexchange.com/q/71489 0 When / how do I vol-scale portfolio weights when optimizing the portfolio? PyRsquared https://quant.stackexchange.com/users/38576 2022-07-04T13:19:23Z 2022-07-04T21:07:04Z <p>I have a set of portfolio weights <span class="math-container">$w$</span>. I'm using <code>cvxpy</code> to optimise the portfolio sharpe, subject to a set of constraints.</p> <p><span class="math-container">$$\text{maximize} \hspace{10mm} \mu^Tw - w^T\Sigma w$$</span> <span class="math-container">$$\text{subject to:} \hspace{5mm} 1^Tw = 0 \hspace{5mm} \text{(Long/Short cash neutral)}$$</span> <span class="math-container">$$||w||_1 \leq L_{max} \hspace{5mm} \text{(Leverage limit)}$$</span> <span class="math-container">$$|w_i| \leq c, \forall i$$</span></p> <p>where <span class="math-container">$\mu$</span> are the expected returns, <span class="math-container">$w$</span> are the target weights, <span class="math-container">$\Sigma$</span> is the covariance matrix of returns, <span class="math-container">$1$</span> is a vector of ones, <span class="math-container">$c$</span> is a maximimum concentration limit per asset (e.g. 1%), and <span class="math-container">$L_{max}$</span> is the maximum allowable leverage.</p> <p>The issue now is, I want to scale the position sizes by a portfolio volatility target in this process, and I am not sure how. In other words, I would like to target, say, an 10% annualised volatility.</p> <p>I could scale <span class="math-container">$w$</span> using a standard method:</p> <p><span class="math-container">$$w_{\text{vol scaled}} = w \times \frac{\text{vol target}}{std(r)}$$</span></p> <p>where <span class="math-container">$std(r)$</span> is the standard deviation of the returns over the last <span class="math-container">$n$</span> periods (e.g. 12 months). The problem with this method is that some weights will break the constraints above after having optimised the portfolio.</p> <p>How can I meet a volatility target, either <strong>before</strong>, <strong>as part of</strong> or <strong>after</strong> portfolio optimisation?</p> https://quant.stackexchange.com/q/71487 2 Why Fed Funds Rate's is higher than U.S. treasury yield on the short term (< 2M) MaPy https://quant.stackexchange.com/users/31650 2022-07-04T12:08:51Z 2022-07-04T18:08:08Z <p>The current Fed Funds Rate is 1.75% whereas the 1 Month Treasury Rate is at 1.28%. I would have expected the Fed Funds Rate to be lower than Treasury rate on short maturities, what is the reason of the spread?</p> https://quant.stackexchange.com/q/71486 0 WML factor on French's web site nbbo2 https://quant.stackexchange.com/users/16148 2022-07-04T09:46:11Z 2022-07-04T09:46:11Z <p>On Prof. French's web site we have the following</p> <p><a href="http://mba.tuck.dartmouth.edu/pages/faculty/ken.french/Data_Library/f-f_developed.html" rel="nofollow noreferrer">http://mba.tuck.dartmouth.edu/pages/faculty/ken.french/Data_Library/f-f_developed.html</a></p> <blockquote> <blockquote> <p>WML is the equal-weight average of the returns for the two winner portfolios for a region minus the average of the returns for the two loser portfolios,</p> <p>WML = 1/2 (Small High + Big High) – 1/2 (Small Low + Big Low).</p> </blockquote> </blockquote> <p>Is there a typo here? Shouldn't this be</p> <p>WML = 1/2 (Small Winner + Big Winner) – 1/2 (Small Loser + Big Loser).</p> <p>To me High/Low means high/low book to market</p> https://quant.stackexchange.com/q/71484 -2 Is there a difference btween carhart 4 factor model and fama french 4 factor model? [closed] Maxi Hasenbaum https://quant.stackexchange.com/users/62589 2022-07-03T19:26:27Z 2022-07-03T19:26:27Z <p>Can someone explain to me if my understanding is correct: If I wanna calculate fama french momentumfactor I need to calculate Mom= 1/2 (SmallHigh + BigHigh) - 1/2 ( SmallLow + BigLow)</p> <p>and for the momentumfactor from Carhart (PR1YR) I need to calculate PY1YR = Highest - Lowest</p> https://quant.stackexchange.com/q/71483 0 Should we use the conditional expectation to write the value of an option? Oscar https://quant.stackexchange.com/users/62753 2022-07-03T18:52:04Z 2022-07-03T18:52:04Z <p>So, I've just started looking into financial mathematics and the following question keeps bugging me. From what I understood, if the market is arbitrage-free and a given contingent claim of value <span class="math-container">$h$</span> is attainable, then there is a measure <span class="math-container">$Q$</span> such that the discounted asset prices <span class="math-container">$(\tilde{S}_t)$</span> form a martingale. Consequently, the discounted values of the portfolio <span class="math-container">$(\tilde{V}_t)$</span> also form a martingale. As such, it makes sense to write:</p> <p><span class="math-container">\begin{align} V_t = e^{-r(T-t)} E^Q[V_T|\mathcal{F}_t] = e^{-r(T-t)} E^Q[h|\mathcal{F}_t] \end{align}</span></p> <p>And then we consider the fair value of the option at time <span class="math-container">$t$</span> to be <span class="math-container">$V_t$</span>.</p> <p>Now, I was reading another author and he writes: &quot;The time-<span class="math-container">$t$</span> price of a European call on a non-dividend paying stock with spot price <span class="math-container">$S_t$</span>, when the strike is <span class="math-container">$K$</span> and the time to maturity is <span class="math-container">$\tau = T − t$</span>, is the discounted expected value of the payoff under the risk-neutral measure <span class="math-container">$Q$</span>.&quot; Hence,</p> <p><span class="math-container">\begin{align} C_t = e^{-r\tau}E^Q[h] = e^{-r(T-t)}E^Q[\max(S_T-K,0)] \end{align}</span></p> <p>My question is: Why can we take the &quot;usual&quot; expectation when computing <span class="math-container">$C_t$</span>, instead of using the conditional expectation to <span class="math-container">$\mathcal{F}_t$</span>? Are they the same? If so, I'm not seeing why... Any help is appreciated. Thanks in advance.</p> https://quant.stackexchange.com/q/71482 0 QuantConnect: ATM IV is different for call and put matt https://quant.stackexchange.com/users/30471 2022-07-03T15:40:26Z 2022-07-03T15:40:26Z <p>I am trying to use <a href="https://www.quantconnect.com/" rel="nofollow noreferrer">QuantConnect</a> to run some historical analysis, which involves comparison of skew (more specifically, <span class="math-container">$\frac{25\Delta\text{ put volatility} - 25\Delta\text{ call volatility}}{50\Delta\text{ call volatility}}$</span> à la <a href="https://www.ivolatility.com/doc/JOD-MIXON_(2011)_+_Appendix.pdf" rel="nofollow noreferrer">Mixon</a>. What troubles me is that I would find, in the data, calls and puts (of same expiry) with near-50 delta having wildly different implied volatilities, which violates put-call parity.</p> <p>My Algorithm (which generates the data and calculates Greeks via setting <code>option.PriceModel</code>) is as follows. I am reluctant to run my own Greeks as it requires knowledge of future dividends at every time step. Not exactly sure where I am tripping up...</p> <pre><code>def Initialize(self): self.SetStartDate(2022, 1, 1) self.SetEndDate(2022, 6, 25) self.SetCash(1000000) self._use_index_options = False # https://www.quantconnect.com/docs/v2/writing-algorithms/reality-modeling/options-models/pricing#04-Supported-Models if self._use_index_options: symbol = &quot;SPX&quot; underlying = self.AddIndex(symbol, Resolution.Daily).Symbol option = self.AddIndexOption(underlying, Resolution.Daily) option.PriceModel = OptionPriceModels.BlackScholes() else: symbol = &quot;SPY&quot; underlying = self.AddEquity(symbol, Resolution.Daily) option = self.AddOption(underlying, Resolution.Daily) option.PriceModel = OptionPriceModels.CrankNicolsonFD() self.option_symbol = option.Symbol self.Securities[symbol].VolatilityModel = StandardDeviationOfReturnsVolatilityModel(30, Resolution.Daily) option.SetFilter(-10, +10, 0, 180) self.SetWarmUp(30, Resolution.Daily) </code></pre> https://quant.stackexchange.com/q/71481 0 Backset LIBOR contract KD007 https://quant.stackexchange.com/users/62710 2022-07-03T10:15:02Z 2022-07-03T14:25:32Z <p>Below is an extract from Steven Shreve’s BK 2, Chapt 10: Term Structure models. <a href="https://www.google.com/books/edition/Stochastic_Calculus_for_Finance_II/O8kD1NwQBsQC?hl=en&amp;gbpv=1&amp;pg=PA437" rel="nofollow noreferrer">LINK</a></p> <p>I am trying to understand Stochastic Calculus from the above book with the help of a Pure Math PhD student. Despite trying to wade through resource in Public domain (Google Search) and a few of the other books I bought, we could not understand the point of arrival of below topic. I have not made any progress on the below topic. Kindly if anyone can refer to a book or an article which details the content below will be highly appreciated. I will be happy if any can also just provide some lead/summarise the topic, I can take it forward from the lead.</p> <p><strong>Section 10.4.3: Pricing a Back set LIBOR Contract</strong></p> <p>An interest rate <em>swap</em> is an agreement between two parties A and B that A will make fixed interest rate payments on some “notional amount” to B at regularly spaced dates and B will make variable interest rate payments on the same notional amount on these same dates .The variable rate is often backset LIBOR , defined on one payment date to be the LIBOR set on the previous payment date. The no-arbitrage price of a payment of backset LIBOR on a notional amount of 1 is given by the following theorem.</p> <p>Theorem 10.4.1 (Price of back set LIBOR). Let 0 ≤ t ≤ T and δ &gt;0 be given. The no-arbitrage price at time t of a contract that pays L(T,T) at time T+δ is <span class="math-container">\begin{equation} S(t)=\begin{cases} { B(t,T+\delta).L(t,T) \; 0\leqq t \leqq T }.\\ { B(t,T+\delta).L(T,T) \; 0\leqq t \leqq T+\delta} \end{cases} \end{equation}</span></p> <p>PROOF : These are two cases to consider . In the first case ,T ≤ t ≤ T +δ, LIBOR has been set at L(T,T) and is known at time t .The value at time t of a contract that pays 1 at time T + δ is B(t,T+δ), so the value at time t of a contract that pays L(T,T) at time T + δ is B(t , T + δ)L(T,T) .</p> <p>In the second case ,0 ≤ t ≤ T, we note from (10.4.4) that <span class="math-container">$$B(t,T+\delta).L(t,T) = \frac{1} {\delta}[B(t,T)-B(t,T+\delta )]$$</span> We must show that the right-hand side is the value at time t of the backset LIBOR contract. To do this, suppose at time t we have <span class="math-container">$\frac{1} {\delta}[B(t,T)-B(t,T+\delta )]$</span>, and we use this capital to set up a portfolio that is : <span class="math-container">$$\text{long} \frac{1} {\delta} \text{bonds maturing at T};$$</span> <span class="math-container">$$\text{short} \frac{1} {\delta} \text{bonds maturing at T+δ}$$</span> At time T ,we receive <span class="math-container">$\frac{1} {\delta}$</span> from the long position and use it to buy <span class="math-container">$\frac{1} {\delta}. \frac{1} {[B(t,T+\delta )]}$</span> bonds maturing at time T+δ, so that we now have a position of <span class="math-container">$\frac{1} {\delta}. \frac{1} {[B(t,T+\delta )]} - \frac{1} {\delta}$</span> in (T+δ)-maturity bonds. At time T+ δ, this portfolio pays</p> <p><span class="math-container">$$\frac{1} {\delta}.\frac{1} {B(T,T+\delta} - \frac{1} {\delta} = \frac{B(t,T)-B(t,T+\delta )}{ \delta B(t,T+\delta)} = L(T,T)$$</span></p> <p>We conclude that the capital <span class="math-container">$\frac{1} {\delta}[B(t,T)-B(t,T+\delta )]$</span> we used at time t to set up the portfolio must be the value at time t of the payment L (T ,T) at time T+δ.</p> https://quant.stackexchange.com/q/71480 1 Synthetix' assets failure scenarios origaminal https://quant.stackexchange.com/users/62724 2022-07-03T06:04:59Z 2022-07-03T06:04:59Z <p>Synthetix project provides the system where different assets like USD, BTC, stocks are emulated by minting tokens representing them (sUSD, sBTC) collateralised by SNX token. Prices are defined via oracles.</p> <p>Docs <a href="https://docs.synthetix.io/" rel="nofollow noreferrer">https://docs.synthetix.io/</a></p> <p>The system looks like a more fragile system than DAI as the collateral implemented in SNX which doesn't have value and utility outside of Synthetix tools.</p> <p>What potential risks and possible failure scenarios for such architecture?</p> <p>Is there any resources that examine how Synthetix' assets (e.g. sUSD) could to lose their peg forever? Any models simulating crash?</p> https://quant.stackexchange.com/q/71477 2 Why is this inequality strict for arbitrage argument for European call? Ice Tea https://quant.stackexchange.com/users/59493 2022-07-03T01:00:19Z 2022-07-03T04:30:37Z <p>in the notes about arbitrage arguments I am reading, I notice the statement</p> <blockquote> <p>We can also see that <span class="math-container">$$C^E_t&gt;(S_t-K\mathrm{e}^{-r(T-t)})^+$$</span> Notice that the inequality holds STRICTLY!</p> </blockquote> <p>I don't particularly understand why the inequality must be strict. What arbitrage can occur when equality occurs? What exactly should I be containing in my portfolio to replicate this?</p> https://quant.stackexchange.com/q/71475 2 Why is the dynamic mean-variance problem time-inconsistent? phdstudent https://quant.stackexchange.com/users/16472 2022-07-02T21:48:28Z 2022-07-02T21:48:28Z <p>A lot of the literature in dynamic mean-variance problem states that the dynamic mean-variance problem is time-inconsistent. Now I was not able to find an example of why the problem is time inconsistent that is easy enough to digest. So the question is: why is the dynamic mean-variance problem time-inconsistent?</p> https://quant.stackexchange.com/q/71472 0 Has anyone tried credit metrics using monte carlo in excel? [closed] Pearl Trivedi https://quant.stackexchange.com/users/62410 2022-07-02T19:10:51Z 2022-07-02T19:10:51Z <p>Has anyone tried credit metrics in excel , if so could you please link your spreadsheet/or link some resources that might help, thanks.</p> https://quant.stackexchange.com/q/71470 2 Cointegration between crypto markets JayK23 https://quant.stackexchange.com/users/62743 2022-07-02T18:13:17Z 2022-07-05T08:53:16Z <p>I'm having an hard time understanding how cointegration works. Basically i'm trying to find cointegrated pairs in the crypto market, so i do the following:</p> <ol> <li>Get OHLC data for the two markets (i'm getting 5k candles on the 5m timeframe)</li> <li>Get the log returns for the two markets</li> <li>Check the p-value when i look for cointegration between the log returns</li> </ol> <p>The problem with my code is that i always get very low p-values, no matter what market i try, and on some markets the p-value is 0.</p> <p>Here is my code:</p> <pre><code>import pandas as pd import json import numpy as np import requests import time import json import mplfinance as mpf import matplotlib.pyplot as plt import matplotlib.dates as mdates import statsmodels.tsa.stattools as ts import threading import scipy import pandas_ta as ta import ccxt from pykalman import KalmanFilter ftx = ccxt.ftx() def get_ohlc_ccxt(market, timeframe): data = ftx.fetch_ohlcv(market, timeframe, limit=5000) ohlcv = pd.DataFrame(data, columns=['time', 'open', 'high', 'low', 'close', 'volume']) ohlcv = ohlcv.drop_duplicates(subset=['time', 'open', 'high', 'low', 'close', 'volume'], keep='first') ohlcv['time'] = ohlcv['time'].astype('int64') ohlcv['time'] = ohlcv['time']/1000 ohlcv['date'] = pd.to_datetime(ohlcv['time'], unit='s') ohlcv = ohlcv.set_index(pd.DatetimeIndex(ohlcv['date'])) return ohlcv def check_pair(first_market, second_market, timeframe): first = get_ohlc_ccxt(first_market, timeframe) second = get_ohlc_ccxt(second_market, timeframe) if len(first) != len(second): length = min(len(first), len(second)) first = first.iloc[-length:] second = second.iloc[-length:] x = first['close'].to_numpy() y = second['close'].to_numpy() first['logret'] = first.ta.log_return() second['logret'] = second.ta.log_return() xr = first['logret'].fillna(0) yr = second['logret'].fillna(0) coint = ts.coint(xr.to_numpy(), yr.to_numpy()) p_value = coint print('Cointegration:', first_market, second_market, p_value) spread = xr-yr return first, second data = check_pair('BTC-PERP', 'ETH-PERP', '5m') </code></pre> <p>In this case the p-value is <code>8.94059749424772e-29</code>. If i try other markets (like BTC-LINK, or BTC-LTC and so on) the p-value will always be incredibly low. Can anyone help me find what i'm doing wrong?</p> https://quant.stackexchange.com/q/71468 0 Relationship between simple Libor spot and forward rates tappis https://quant.stackexchange.com/users/62731 2022-07-02T09:06:18Z 2022-07-03T00:29:43Z <p>How is the simple forward rate L(0,T,T+1) calculated given the spot rate L(0,T)?</p> https://quant.stackexchange.com/q/71463 0 can Soft Actor-Critic reinforcement learning algorithms be used in real-time trading? quant https://quant.stackexchange.com/users/62732 2022-07-01T20:20:58Z 2022-07-04T03:23:02Z <p>I am scratching my head with an optimization problem for Avellaneda and Stoikov market-making algorithm (optimizing the risk aversion parameter), and I've come across <a href="https://github.com/im1235/ISAC" rel="nofollow noreferrer">https://github.com/im1235/ISAC</a></p> <p>which is using SACs to optimize the gamma parameter.</p> <hr /> <p>since SAC is a model-free reinforcement learning, does this mean it is not prone to overfitting?</p> <p>or in other words, can it be applied to live to trade?</p> https://quant.stackexchange.com/q/71418 5 What are some interesting recent machine learning related developments in the QF domain? QuantNero https://quant.stackexchange.com/users/62680 2022-06-29T17:16:40Z 2022-07-05T13:18:41Z <p>In 2020 I wrote a MSc thesis on the hedging of exotic options using recurrent neural networks (loosely based on the paper Deep Hedging (2018)by Buehler et al.).</p> <p>Since then I have been interested in all types of ML applications in the financial domain, but I haven't been reading any of the recent publications/following any of the developments.</p> <p>Hence my question is as follows: In the past few years, have there been any particularly interesting publications/developments in terms of machine learning being used in the QF domain?</p> https://quant.stackexchange.com/q/71113 0 Deriving the stochastic process for a dividend-yielding stock (under Black-Scholes assumptions) Giogre https://quant.stackexchange.com/users/50229 2022-06-02T20:17:18Z 2022-07-04T10:01:15Z <p>In order to derive the Black-Scholes equation for a stock <span class="math-container">$S(t)$</span> yielding dividends at the continuous rate <span class="math-container">$d$</span> <span class="math-container">$$S(t) = S_0 e^{(\mu - d - \frac{\sigma^2}{2})t + \sigma \sqrt{t} N(0,1)} \text{,}$$</span> M. Joshi in <em>The concepts and practice of mathematical finance</em> starts from the stochastic process for a delivery contract <span class="math-container">$X(t) = e^{-d (T - t)} S(t)$</span>, equation (5.76):</p> <p><span class="math-container">$$dX_t = (\mu + d) X_t dt + \sigma X_t dW_t \qquad \qquad (1)$$</span></p> <p>He defines a delivery contract <span class="math-container">$X_t$</span> as a contract where you pay for stock <span class="math-container">$S_t$</span> today, but it gets delivered to you at time <span class="math-container">$T$</span>. He writes that for a non-dividend paying stock, <span class="math-container">$X_t$</span> at time <span class="math-container">$T$</span> has the same value of <span class="math-container">$S_t$</span> as both end up with you holding one <span class="math-container">$S_t$</span>. Then he makes the case of a dividend paying stock (included in text snapshot below): at time <span class="math-container">$T$</span> you will have <span class="math-container">$e^{d(T−t)}S_t$</span> if you held the stock, while only <span class="math-container">$S_t$</span> if you held a delivery contract, so the latter's value at <span class="math-container">$T$</span> must be <span class="math-container">$X_t=e^{−d(T−t)}S_t$</span>.</p> <p>However equation (5.76), renamed (1) above is thrown there as is and not motivated by any derivation. I have tried deriving it from the <span class="math-container">$X_t$</span> and <span class="math-container">$S_t$</span> processes listed above, using the chain rule (<span class="math-container">$=$</span> Ito's lemma here because <span class="math-container">$\dfrac{\partial^2 X_t}{\partial S^2} = 0$</span>):</p> <p><span class="math-container">\begin{align} dX_t(S_t, t) &amp; =\\ &amp;= \frac{\partial X_t}{\partial S_t} dS_t + \left[ \frac{\partial X_t}{\partial t} + \frac{\partial X_t}{\partial S_t} \frac{\partial S_t}{\partial t} \right] dt \\ &amp;= e^{-d(T - t)} \left[ ( \mu - d) S_t dt + \sigma S_t dW_t \right] + \left[ e^{-d (T - t)} S_t d + e^{-d (T - t)} S_t \left(\mu - d - \frac{\sigma^2}{2} \right)\right] dt \\ &amp;= X_t \left[ \left( 2 \mu - d - \frac{\sigma^2}{2} \right) dt + \sigma dW_t \right] \qquad \qquad (2) \end{align}</span></p> <p>where I have used <span class="math-container">$dS_t = (\mu - d) S_t dt + \sigma S_t dW_t$</span>.</p> <p>Equations (1) and (2) differ, in that they have different deterministic components.</p> <p>Can anyone enlighten me as where errors/incongruities are in the above?</p> <p>Below, the passage from the book included as snapshot.</p> <p><a href="https://i.stack.imgur.com/QuW0i.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QuW0i.jpg" alt="Directly from the book" /></a></p> https://quant.stackexchange.com/q/71110 0 Complete formula for calculating forex pip value for XAUUSD with account funded in euros nbonniot https://quant.stackexchange.com/users/62398 2022-06-02T12:35:10Z 2022-07-03T13:01:10Z <p>I'm currently developping forex robot using Python API for Metatrader 5. Among different things, this robot places trades given by external signals (with price, SL and TP).</p> <p>I use euro funded account, trade XAUUSD, and have a 1:100 leverage ratio. In order to implement 1% strategy (meaning never risk more than 1% of capital in one trade), <strong>I would like to calculate precise SL/TP level in euro, my account money, and fail to compute same results as given in my MT5 terminal</strong>.</p> <p>If I take a trade as example (informations sourced from MT5):</p> <ul> <li>SELL XAUUSD, price <strong>\$1849.32</strong></li> <li>lot size : <strong>0.01</strong></li> <li>date : <strong>2022.05.31 13:31:05</strong></li> <li>closed at price <strong>$1848.03</strong></li> <li>profit announced by MT5 : <strong>2,4€</strong></li> </ul> <p><strong>What's the formula used to calculate this amount, placing leverage and exchange rate from USD to EUR ?</strong></p> <p>My method so far:</p> <p>AFAIK, pip value for an USD account with USD as last currency in pair (i.e XAUUSD) is:</p> <p><img src="https://chart.googleapis.com/chart?cht=tx&amp;chl=pip_%7Bvalue%7D=(%5Cfrac%7Bpip_%7Bstep%7D%7D%7Bcurrent_%7Bprice%7D%7D)*lotSize" alt="generic_pip_value" /></p> <p>Applied to given trade above (result in dollars):</p> <p><img src="https://chart.googleapis.com/chart?cht=tx&amp;chl=pip_%7Bvalue%7D=(%5Cfrac%7B0.01%7D%7B1849.32%7D)*100000*0.01=%5Cmathbf%7B0,005407393%7D" alt="dollar_pip_value" /></p> <p>Total trade value (in dollars, without any leverage)</p> <p><img src="https://chart.googleapis.com/chart?cht=tx&amp;chl=trade_%7Bvalue%7D=%7B0,005407393%7D*%5Cfrac%7B(%7B1849.32%7D-%7B1848.03%7D)%7D%7B0.01%7D=0.6976" alt="total_trade_value" /></p> <p>From this point, I can't find any way to include leverage and exchange rate for finding this 2,4€ profit.</p> https://quant.stackexchange.com/q/70018 1 Square root specification of parameters in factor models carl https://quant.stackexchange.com/users/50018 2022-02-26T18:01:01Z 2022-07-03T01:18:10Z <p>The following formulation is from Vasicek and refers to the cond. probability of the loss of a loan (equ. 3 in the reference): <span class="math-container">$$p(Y)=\Phi\left(\frac{\Phi^{-1}(p)-\sqrt{\rho}\,Y}{\sqrt{1-\rho}}\right).$$</span></p> <p>Vasicek also states that the variables in his outlined asset value formula (equ. 1 in the reference) are jointly standard normal distributed with equal pairwise correlations <span class="math-container">$\rho$</span>, leading to:</p> <p><span class="math-container">$$X_i=\sqrt{\rho}\,Y+\sqrt{1-\rho}\,Z_i,$$</span></p> <p>with <span class="math-container">$Y$</span> a portfolio commonn factor and <span class="math-container">$Z_i$</span> a company specific factor (equ. 2 in the reference).</p> <p>Similar specifications are also used, for example, in connection with the risk-weighted assets of the Basel regulations or in the context of default correlations.</p> <p>Why is it common or preferred to use a specification with the square root regarding the parameters (e.g., pairwise correlation) in factor models? Are there any specific benefits to using this specification?</p> <p><a href="https://www.bankofgreece.gr/MediaAttachments/Vasicek.pdf" rel="nofollow noreferrer">Vasicek, O. A. (2002). The Distribution of Loan Portfolio Value, Risk 15(12), 160–162.</a></p> https://quant.stackexchange.com/q/68219 2 PCA analysis within Private Credit Jeweller89 https://quant.stackexchange.com/users/48275 2021-10-04T20:42:38Z 2022-07-03T00:08:15Z <p>A very broad question but nevertheless a important and difficult one.</p> <p>Within private markets (Private Equity funds, infrastructure funds and private credit funds) how should one do a risk-based PCA analysis in order to identify the uncorrelated factors? Within Private Credit should you take some liquid index as a reference or can you use quarterly indices with the very low volatility in mind.</p> <p>Appreciate any feedback</p> https://quant.stackexchange.com/q/68209 5 Help guessing the solution to an optimal control problem Casper Eneqvist https://quant.stackexchange.com/users/59402 2021-10-04T11:29:17Z 2022-07-02T21:43:47Z <p>I am considering an investor facing a discrete-time multi-period minimization problem <span class="math-container">$$\min_{\{v_t\}_{t=0}^\infty}\Bigg[\sum_{t=0}^\infty(1-\rho)^{t+1}\bigg(\frac{1}{2}v_{t}\Omega_{t+1}v_{t}'\bigg)+\frac{(1-\rho)^t}{2}\bigg(\frac{1}{2}\Delta v_t'\Lambda\Delta v_t\bigg) \Bigg] \quad \text{s.t.} \quad v_t'\textbf{1}=1$$</span> Let <span class="math-container">$v_t$</span> be a vector of weights attached to each asset, <span class="math-container">$\Omega_t$</span> be the time-varying covariance matrix and <span class="math-container">$\Lambda$</span> be a symmetric matrix of trading cost. Finally, <span class="math-container">$\rho\in(0,1)$</span> be the discount factor and <span class="math-container">$\textbf{1}$</span> being a vector of 1's. This problem has a corresponding value function <span class="math-container">$$V(v_{t-1})=\min_{v_t}\Bigg[\frac{1}{2}\Delta v_t'\Lambda\Delta v_t+(1-\rho)\bigg(\frac{1}{2}v_{t}\Omega_{t+1} v_{t}' +\mathbb{E}_t[V(v_{t})] \bigg)\Bigg] - \lambda(v_{t-1}'\textbf{1}-1)$$</span></p> <p>I am looking to find the Bellman equation via the 'guess and verify' method (similar to Gârleanu and Pedersen, 2013).</p> <p><em><strong>Without</strong></em> the constraint (<span class="math-container">$v_{t-1}'\textbf{1}=1$</span>), I can verify that <span class="math-container">$$V(v_t)=v_t'A_{vv}v_t+A_0$$</span> is a solution with <span class="math-container">$A_{vv}$</span> a symmetric matrix of parameters. But with the constraint, I have been unable to find a guess that solves the problem. Can you find a suitable guess that includes the constraint?</p> https://quant.stackexchange.com/q/65491 9 Why were Laguerre polynomials a good choice of basis functions for American Monte Carlo? user54908 https://quant.stackexchange.com/users/54908 2021-06-10T17:39:30Z 2022-07-05T09:36:05Z <p>I am implementing LSMC to price American options based on a custom model. I now need to make a choice of basis functions, so I am looking for the theoretical justification for using Laguerre polynomials in the Longstaff Schwartz paper.</p> <p>The section &quot;8.3 Choice of basis functions&quot; in the Longstaff Schwartz paper <em>seems</em> to provide (in words-- not math-) some justification for this choice that might be understandable to a statistician, but does not sufficiently explain to me the preference for Laguerre polynomials:</p> <blockquote> <p>Finally, the choice of basis functions also has implications for the statistical significance of individual basis functions in the regression. In particular, some choices of basis functions are highly correlated with each other, resulting in estimation difficulties for individual regression coefficients akin to the multicolinearity problem in econometrics.</p> </blockquote> <p>In the paper &quot;The Valuation of Real Options with the Least Squares Monte Carlo Simulation Method&quot;, a justification for Laguerre polynomials is given that these produce better numerical results:</p> <blockquote> <p>In our analysis, we have compared eleven polynomial families, used as basis functions to estimate the continuation value, and we have analysed the convergence of the method increasing the number of basis functions. The numerical results suggest that the weighted Laguerre polynomials provide more accurate results, particularly for the case of compound and mutually exclusive options.</p> </blockquote> <p>Is there a better mathematical explanation for why Laguerre polynomials are a good choice of basis functions?</p> https://quant.stackexchange.com/q/60402 1 Starting Point for understanding Financial Theory for a Statistician napoleon https://quant.stackexchange.com/users/51793 2021-01-08T04:54:18Z 2022-07-04T19:04:09Z <p>I am a Master’s student in Statistics who is interested in the field of Financial Modelling. I have very little experience or knowledge of Finance and have mostly worked on introductory projects in finance using CAPM and Event Study Methodology</p> <p>I am interested in a quick introduction to financial theory which can help me in working with Financial Models. Any suggestions for a good book will be really appreciated.</p> https://quant.stackexchange.com/q/54340 2 Dealing with stochastic results of Machine Learning Models user23564 https://quant.stackexchange.com/users/36325 2020-05-23T00:40:14Z 2022-07-04T04:45:38Z <p>I'm building stock selection models, and pick top 5 and bottom 5 stocks. Given the variability in Stochastic gradient decent results, they keep changing. One way to get consistent results is to use the random seed, but I'm looking for if there a better way to deal with this. Also how would you interpret the results, i.e. One set of top 5 versus another set of Top 5 picks (3-4 of them are the same, but may differ in ranking). I'm running enough iterations to know this isn't an issue about convergence.</p> https://quant.stackexchange.com/q/49343 4 Negative Hurst exponent Lori Li https://quant.stackexchange.com/users/43060 2019-10-24T04:37:29Z 2022-07-03T14:04:00Z <p>I am trying to test Hurst exponent in different time lag range. However, i got negative values in some time lag range which is weird, because the Hurst exponent should have values within the range from 0 to 1. </p> <p>This is the Python code to calculate the Hurst exponent:</p> <pre><code>*calculate Hurst* lag1 = 2 lags = range(lag1, 20) tau = [sqrt(std(subtract(ts[lag:], ts[:-lag]))) for lag in lags] plot(log(lags), log(tau)); show() m = polyfit(log(lags), log(tau), 1) hurst = m*2 print 'hurst = ',hurst </code></pre> <p>When <code>lags = range(200,300)</code>, the Hurst exponent is -0.035. My data length is 1643. The log-log plot looks like this, which is not linear: <a href="https://i.stack.imgur.com/kNFJI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kNFJI.png" alt="enter image description here"></a></p> <hr> <p><strong>Is there something wrong with the code or anyone know any good package to test hurst exponent in R or python?</strong> </p> https://quant.stackexchange.com/q/46167 1 From Libor Curve rates to "forward" zero-coupons 11house https://quant.stackexchange.com/users/33326 2019-06-18T13:05:08Z 2022-07-03T15:00:30Z <p>I am provided a 6M euribor curve, constructed from FRA's and swaps of tenor 6M on the euro, as well an EONIA curve, constructed from zero-coupons EONIA swaps. Both curves are provided as functions <span class="math-container">$d\mapsto \textrm{rate at }d$</span> which to a date <span class="math-container">$d$</span> associate the rate at <span class="math-container">$d$</span>. (Imagining interpolations modes have been chosen.)</p> <p>With these to curves, I want to calculate a 1Y forward 10Y swap rate. For this I need the discount zero coupons <span class="math-container">$Z_d$</span> and the "forward" zero-coupons <span class="math-container">$Z_f$</span>.</p> <p>I use <span class="math-container">$Z_d (t) = e^{-\textrm{yearfraction(today},t)\times{\textrm{"discount rate at }t"}}$</span> to get a discout factor from the EONIA <em>rate</em> curve.</p> <p>By "forward" zero-coupon I mean the zero-coupons used to calculate the forward 6M euribor rates as : <span class="math-container">$$L_0^{T_{i-1}, T_i} = \frac{Z_f(T_{i-1}) - Z_f(T_i)}{\delta_i Z_f(T_i)}$$</span></p> <p>is the forward euribor rate from now (0) for the future 6M period <span class="math-container">$[T_{i-1}, T_i]$</span> of year fraction <span class="math-container">$\delta_i$</span>.</p> <p>My question is : how do I calculate the <span class="math-container">$Z_f$</span>'s from the rates I am given ?</p> https://quant.stackexchange.com/q/45552 1 Implied volatility as break-even delta hedge volatility Frido Rolloos https://quant.stackexchange.com/users/34971 2019-05-11T19:06:25Z 2022-07-04T14:04:10Z <p>There have been some posts on this topic, but not what I am looking for, so a new post on an old topic..</p> <p>I think some/most of us here are familiar with the following formula expressing implied volatility as the break-even <em>constant</em> BlackScholes hedge volatility to make the expected final P/L equal to zero. After some re-arranging we get the familiar formula, and restricting now to a pure stochastic volatility model as the true dynamics:</p> <p><span class="math-container">$$\Sigma^2(S_t,t,K,T) = \frac{E_t^Q \int_t^T \sigma_u^2 S_u^2 \Gamma^{BS}(S_u,K,\Sigma(S_t,t,K,T)) du}{E_t^Q \int_t^T S_u^2 \Gamma^{BS}(S_u,K,\Sigma(S_t,t,K,T)) du}$$</span></p> <p>where <span class="math-container">$\sigma_u$</span> is the stochastic volatility, and <span class="math-container">$Q$</span> is the risk-neutral measure for this SV model. Note that the implied volatility in the Black-Scholes gamma terms is always the initial implied volatility (this formula is afterall obtained under the assumption of hedging at constant initial implied volatility).</p> <p>Now this is where I think I am either making an error, or where things get interesting:</p> <p>Assume that the correlation between the spot and vol is zero always. Then we can apply conditioning. So, for a given path of volatility we can take the expectation of the dollar gamma terms, and then take expectation over all volatility paths. </p> <p>But for a given path of realized variance, we know that the dollar gamma is a martingale, and so the resulting initial gamma appears in both denominator and numerator and can therefore be cancelled out. What is left is then the following formula (when <span class="math-container">$dSd\sigma = 0$</span>)</p> <p><span class="math-container">$$\Sigma^2(S_t,t,K,T) = \frac{1}{T-t} E_t^Q \int_t^T \sigma_u^2 du$$</span></p> <p>This cannot be true of course since that would mean for all strikes the break even implied vol is the variance strike and the smile would be flat. Not what we observe in a SV model with zero correlation.</p> <p>The formula for implied volatility as break even constant delta hedge volatility is used by many (e.g. Bergomi in his book, Reghai in his book, Gatheral, and others) as a starting point for expansions and the like. These are very knowledgeable guys so I am sure they won't use something that doesn't make sense logically.</p> <p>My question is, in which step did I make the brain-fart?</p> <p>Thanks.</p> https://quant.stackexchange.com/q/44932 8 American put option. Exercise time is a random variable, calculation of expected payoff Makina https://quant.stackexchange.com/users/36637 2019-04-04T17:37:35Z 2022-07-04T09:06:15Z <p>I got an American put option, where the payoff is <span class="math-container">$V_\tau = \max(K - X_{\tau}, 0)$</span> and <span class="math-container">$X_{\tau}$</span> is the price of an underlying at the stopping time <span class="math-container">$\tau &lt; T$</span>. The underlying follows a standard GBM with <span class="math-container">$r = q = 0$</span>; <span class="math-container">$X_0$</span> is given.</p> <p>I need to calculate the expectation <span class="math-container">$E[V]$</span> under the assumption that <span class="math-container">$\tau$</span> has exponential distribution with intensity <span class="math-container">$\lambda = 0.025$</span>.</p> <hr> <p>I tried transforming this equation into: <span class="math-container">$$\int_0^\infty (K - X_0e^{-\frac{1}{2}\sigma^2 \tau + \sigma \sqrt{\tau}Z})^+\lambda e^{-\lambda \tau}d\tau$$</span> but then I'm just completely lost with how to proceed with the square root. I know that by definition <span class="math-container">$E[\tau] = \frac{1}{\lambda}$</span> but can I use this as an answer? As in, can I claim that: <span class="math-container">$$E[V] = V\left(X_{\frac{1}{\lambda}}, \frac{1}{\lambda}\right) \text{ ?}$$</span></p> https://quant.stackexchange.com/q/36400 16 Avellaneda -Stoikov market making model ragoragino https://quant.stackexchange.com/users/27163 2017-10-12T07:40:11Z 2022-07-04T12:49:12Z <p>I am reading paper High-frequency trading in a limit order book by Marco Avellaneda and Sasha Stoikov. At the end of the paper they obtain a closed-form solution to the optimal market-maker quotes under diffusion without drift. They found that the optimal behaviour of the market-maker would be to set a bid/ask spread of size:</p> <p>$$spread = \gamma\sigma^2(T-t) + \frac{2}{\gamma}ln(1+\frac{\gamma}{k}),$$ where $\gamma$ is a discount factor, $\sigma^2$ is the variance of the process, $k$ is the parameter corresponing to the intensity of arrival of market orders, $T$ is terminal time and $t$ is curent time, around a reservation price given by:</p> <p>$$price = s - q\gamma\sigma^2(T-t),$$</p> <p>where $q$ is the state of the inventory and $s$ is the current price.</p> <p>However, I do not see any specification of bounds for this reservation price and therefore I think there is no guarantee that ask prices computed by the market-maker will be higher or bid prices will be lower than the current price of the process. </p> <p>How is therefore this necessity of market makers' ask prices being higher and bid prices being lower than the actual price enforced in their model (e.g. in their simulations)?</p> <p>Edit: To be more concrete, I just specify, that in my opinion, it needs to hold that:</p> <p>$$price + spread/2 - s &gt; 0$$</p> <p>Lets denote $price$ by $p_{mm}$ and $spread/2$ by $s_{mm}$. Then</p> <p>$$p_{mm} + s_{mm} - s &gt; 0, \\ s - q\gamma\sigma^2(T-t) + \frac{\gamma\sigma^2(T-t)}{2} + \frac{1}{\gamma}ln(1+\frac{\gamma}{k}) - s &gt;0 \\ (...) \\ \frac{1}{2} + \frac{ln(1+\frac{\gamma}{k})}{\gamma^2\sigma^2(T-t)} &gt; q$$ </p> <p>However, this situation does not need to happen, so there is no guarantee he will set prices compatible with current market prices.</p>