Posts

Showing posts with the label statistics

Bollinger Band prediction

Image
The Bollinger Bands plot on a price bar chart is a common component of technical analysis among financial traders. Bollinger Bands display a graphical envelope around the moving average of price, with the width of the envelope representing volatility of the financial instrument charted. Exchange-traded fund SPY showing 20-day moving average (cyan centerline) and 2-standard-deviation Bollinger Bands (red), as charted by TradeStation 10. Traders sometimes use Bollinger Bands for trading signals; for example, if a stock price crosses outside of the 2-standard-deviation envelope, buy or sell the stock. This is fine for signaling market orders, but if you want to set an intra-day stop order or a limit order at a specific price based on a Bollinger Band, you don't know where that price will be, because the band changes size during a single price bar as price moves in the range of the bar. Not only does the moving price affect the value of the moving average, but it also affec...

Most probable array of D&D ability scores

Image
There's an element to the game Dungeons & Dragons that lends itself to a numerical analysis: the initial array of ability scores assigned to a character. Some background: A character in the game has scores assigned to each of six abilities (strength, dexterity, constitution, intelligence, wisdom, and charisma). The first step in creating a character is to generate an array of six numbers by rolling dice, using a method known as "4d6 drop lowest". This means, roll four six-sided dice, remove the lowest value, then add the remaining three dice together (the result ranges from 3 to 18). Do this six times to generate an array of six values, then assign these values to your character's abilities as appropriate for the character's role (fighter, cleric, wizard, etc.). The problem The question I want to answer here is: What does a "typical" array look like? More importantly, how would I know if the array I end up with is better or worse than average? ...

Fake data, part 4: Perturbing volatility

Image
Bypassing the central limit theorem And here is part 4, which I drafted years ago but never published on my blog until now. I didn't quite get done with this project the way I wanted, but it's been a long time and I've moved on. Now I want to see if there is any dependency between successive moves in a market, compared to a random walk. I first built a 21×21 table (corresponding to the integers -10 to +10 on each axis) where each cell contains a count of how many times a move of [row] standard deviations was followed by a move of [column] standard deviations. For example, if the cell at [-2,1] contains the value 87, that means during the entire history of the market, a return of -2 standard deviations was followed by a return of +1 standard deviations 87 times. I used 48 years of data, about 12,000 values for the S&P 500 index. Then I performed a Monte Carlo test. I scrambled the order of log returns (not prices) several hundred times and constructed a similar ta...

Fake data, part 3: Bypassing the central limit theorem

Image
The black swan distribution Perturbing volatility May 2017: This is from my other blog that's no longer online. The original comments are no longer available, but you are welcome to add more. Now that I have my black swan distribution , and I verified that it fits market returns remarkably well while being mathematically tractable, I want to use it to generate artificial market data. Generating a series of closing prices is easy. Select a starting price, take the logarithm Select a mean μ and standard deviation σ of log returns ln( P 0 / P 1 ) where P 0 is the most recent price and P 1 is the previous price. Generate a uniformly-distributed random probability p between 0 and 1. Plug it into the inverse black swan distribution (using a =1.6): $$B^{-1}(p;\mu,s) = \mu - 2 s \, \sinh \left[\frac {\tanh^{-1}(1-2p)} {a} \right]$$ Add the result to a running total. Go to step 3. Repeat as often as desired. Then simply calculate the antilog or exponential of the value...

Fake data, part 2: The black swan distribution

Image
The forgotten logistic distribution Bypassing the central limit theorem May 2017: This is from my other blog that's no longer online. The original comments are no longer available, but you are welcome to add more. In the previous part when I wrote about the logistic distribution , I observed that it fit the S&P 500 daily returns pretty well out to 5 standard deviations (much better than the normal distribution) but broke down in the tails beyond. That has been part of a weeks-long quest to find a distribution that fits, with the criterion that it must be closed-form; that is, we shouldn't need numerical methods to solve for the cumulative distribution or its inverse. Why do this? Because I want to generate an endless stream of artificial market data for analysis. Not only do I want my artificial market to exhibit behavior that is statistically similar a real-world market, but I also want closed-form expressions for ease of programming into Excel or whatever I'll...

Fake data, part 1: The forgotten logistic distribution

Image
The black swan distribution May 2017: This is from my other blog that's no longer online. The original comments are no longer available, but you are welcome to add more. Problem: We need to generate an endless stream of artificial market data, such that it maintains the statistical properties and behaviors of a real market. Everybody is familiar with the normal (Gaussian) distribution. The classic bell curve that underlies many tools in statistics. A normal distribution has a couple of glaring flaws, however: It requires numerical methods to calculate cumulative probability (area under the bell curve) and inverse of probability (i.e. for a known value of cumulative probability, what's the corresponding value of x?) It doesn't model many real-world situations well. Real-world distributions often have more outliers ("fatter tails" in the bell curve) than the normal distribution would suggest. Fortunately, there's a simple alternative: The logistic di...

Expectancy score vs Sharpe ratio

Image
October 2021: I wrote this for a company that is no longer active. I have adapted the article to this blog. Back when I set out to develop my own trading system, two different successful traders recommended that I read Trade Your Way to Financial Freedom by Van K. Tharp. One trader recommended it to me as a good book on position sizing. In spite of its sensationalist title, it's a good book, for no other reason than it contains a valuable feature: how to measure "quality" of a trading strategy objectively , in terms of expectancy multiplied by opportunity. I call this the "expectancy score." Around the same time, I was reading information promoting the use of the Sharpe ratio as the best means to evaluate the quality of a trading system. So I looked at both and decided that expectancy score is superior. Expectancy score Expectancy is how much you expect to earn from each trade for every dollar you risk. Opportunity is how often your strategy trades....

Popular posts from this blog

Syncing Office 365 Outlook to Google calendar using Power Automate

Whose hands are biggest? You may be surprised.

Elliptical-blade NACA airfoil propeller