# Tag Info

10

You seem to have two distinct problems: How to generate random portfolios How optimal portfolios are structured Ad 1) A straightforward way to simulate the weights of random portfolios is to use the Dirichlet distribution $Dir(\alpha_1,\ldots,\alpha_n)$. This is a distribution on the Simplex (i.e. on $S=\{x\in\mathbb{R}^n | \sum x_i =1, x_i\geq 0\}$, ...

6

Let $R$ be a random vector of risky returns and let $r_f$ denote the risk free rate. Let vector of expected returns $\boldsymbol{\mu} = \operatorname{E}[R]$ and covariance matrix $\Sigma = \operatorname{Cov}(R)$. The maximum Sharpe ratio portfolio among risky assets is called the tangency portfolio. Quick method to tangency portfolio Let's find the ...

6

To complement @skoestimeier's answer on the shortselling-allowed case, I provide a vectorised version. Using the original notation in my post (you may change $r$ to something like $r-r_f$, but this doesn't affect the algebraic structure). Our goal is to find the maximiser for the problem $$\max_{w}f(w):=\frac{w^T r}{(w^T\Sigma w)^{1/2}}.$$ Let $$\phi: w\... 5 There are two cases, where short sales are allowed: With riskless lending and borrowing and without. As mentioned in the comments, you just have to solve a linear system. With riskless lending and borrowing The existence of a riskless lending and borrowing rate r_f implies that there is a single portfolio of risky assets, that is preferred to all other ... 4 Having read your comments I'm not sure where the implementation issue is: scipy.integrate.dblquad solves the following iterated integral problem:$$I(\alpha,\beta) = \int_{\alpha}^{\beta} \int_{g(x)}^{h(x)} f(x,y)\; dy \;dx $$If I re-express your variables to be consistent with the scipy documentation, and suppose I changed your integral to be finite:$$...

4

Simulation for timeseries data is not a trivial matter and there are a number of methods to ensure you retain some of the relevant properties (mostly called dependent bootstrap methods): Block bootstrap - contiguous blocks of data chosen so that they are large enough to retain significant autocorrelations. Stationary bootstrap - randomised block size ...

3

It would have been helpful had you provided links to those papers. But in general, you need to distinguish between the optimisation model, and the numerical technique used to solve the model. Suppose you wanted to estimate a linear regression, with the mean squared residual as the criterion of fit, and without further constraints. This is a model. Now you ...

2

Kelly DOES reflect the odds! The simple binary bet form of Kelly is: Kelly Fraction = (p(win) * (odds + 1) - 1) / odds So for a 60% chance of a 50% risk, ie 1:1 equals odds 1, that’s 20% of your capital at risk. More formally, Kelly seeks to maximise log-wealth (LW) LW = sum ( Pi * ln(1 + Stake * Payoffi) Maximise LW, then dLW/dStake = 0 For each ...

2

To answer question one: Operations Research would help you with this topic. Updated: Stochastic Processes is also a good course to take. There is a very good paper titled: Determining Optimal Trading Rules without Backtesting It shows how to determine TP and SL levels using synthetic data.

2

Try Quantopian. I believe they offer all that you are looking for. ps.: I have no affiliation with the company or anyone working there.

1

You can probably also do this with scipy but there is a specific convex optimiser cvxopt that suits this problem. from cvxopt import solvers, matrix For your problem suppose you seek $N$ variables $w$, then let $x$ be a vector where the first $N$ elements are $w$ and the latter $N$ elements are slack variables $t$. i.e. $x=[w,t]^T$ For your problem $P = \... 1 Check this out: library(quadprog) Dmat <- matrix(0,15,15) diag(Dmat) <- 1 dvec <- matrix(0,1,15) bvec <- c(-0.02269294, 0.07120749, -0.01830448, 0.04465172, 0.03508689, -0.0003176476, 0.01089419, 0.06466093, 0.01265293, -0.02748855, 0.04753743, -0.000408749, 0.03108376, -0.07378021, -0.0608137, 1, 0, 0, 0, ... 1 The problem you describe can be handled as an optimization problem: evolve a program such that it maximizes some performance measure. The technique you may want to look into is called "Genetic Programming". For a financial application see for example Single versus Multiple Tree Genetic Programming for Dynamic Decision Making. 1 Looking at this a second time, your implementation is probably not very inefficient since for; $$\quad \hat{f}(u) := \sum_{j}a_j \phi(u - z_j), \quad \int_{-\infty}^y \hat{f}(u) du = \sum_j a_j \Phi(y)\;,$$ where$\Phi(y)$is the transformed cumulative normal distribution function of$y$. This function already exists as scipy.stats.norm.cdf and is ... 1 Do you have correctly formulated the problem for the solver ? If you want to maximise a function (the sharpe ratio)$f$, it is equivalent to minimise$-f\$. This kind of confusion (minimising instead of maximising) would basically lead to a similar outcome as yours.

1

For those experiencing a similar problem, here is the solution that worked for me: ## OPTIMIZE PORTFOLIO WEIGHTS UNDER THE OBJECTIVE OF MAXIMIZING THE SHARPE RATIO ## WHILE CONSTRAINING THE WEIGHTS TO SECTOR BOUNDS ## PAPER: # ACCORDING TO: http://people.stat.sc.edu/sshen/events/backtesting/reference/maximizing%20the%20sharpe%20ratio.pdf np.random.seed(101)...

1

This is very simply done. It involves ensuring the constraints are presented as part of the matrix standard form. You will typically have the constraint that all assets sum to one, i.e. the matrix-vector equation: $$\delta^T x = 1$$ If you want to create an inequality constraint for assets in a sector just isolate them: $$\begin{bmatrix} 1 & 1 &... 1 I get the maximization problem$$ \max\limits_{w} \mathbb{E}\left[W_1\right] - \frac{\gamma}{2} Var(W_1)  st. W_1 = W_0(1 + r_f + w^Tr)So we have \begin{align*} L(w) &= \mathbb{E}\left[W_1\right] - \frac{\gamma}{2} Var(W_1)\\ & = \mathbb{E}\left[W_0(1 + r_f + w^Tr)\right] - \frac{\gamma}{2} Var(W_0(1 + r_f + w^Tr))\\ & = W_0 + ... 1 Please let me know if you have any questions. 1 To optimize:z = f(g(x))$$using traditional calculus with chain rule:$$ \frac{dz}{dx} = \frac{df}{dg} \frac{dg}{dx} $$Set \frac{dz}{dx} = 0 and that will determine either minimum, maximum or saddle points. 1 In theory, the Ledoit and Wolf shrinkage estimator is supposed to guarantee a positive-definite matrix, given that it adds a positive-definite matrix (the target) to a semi-positive one (the sample covariance). I can see four reasons why you didn't get a positive-definite matrix: Your true covariance is effectively not full rank, i..e you have perfect ... 1 If you're happy with equal stock weightings, then this can certainly be done iteratively. I don't know of any closed-form equation. It works for a universe of 100 stocks, but the calculations obviously grow exponentially if you want to increase your selection universe. Pick five stocks at random. Calculate the portfolio variance. There are then 4 * 95 =... 1 Consider the Lagrangian:$$L = \sum_{t=0}^{\infty} \beta ^t \{ U(c_t) + \lambda _t [(1-\delta)k_t+f(k_t) - k_{t+1}-c_t]\}$$The FOC of the Lagrangian with respect to c_t gives:$$\frac{\partial L}{\partial c_t} = 0 \Rightarrow U'(c_t) = \lambda_t$$The FOC with respect to k_{t+1} gives:$$\frac{\partial L}{\partial k_{t+1}} = 0 \Rightarrow \lambda_t ...

1

For Java, combining @vjond answer (as the initial starting estimate for implied Volatility), with a basic Cumulative Density Function for Normal distribution (CDN), and the Black Scholes Model applied to Newton Raphson, below is a basic Implied Volatility calculation for Java : For the NR code (C), plz refer http://finance.bi.no/~bernt/gcc_prog/recipes/...

Only top voted, non community-wiki answers of a minimum length are eligible