Skip to content

Instantly share code, notes, and snippets.

@boyboi86
Created December 7, 2024 07:09
Show Gist options
  • Save boyboi86/2fbe269f963b4bb0635fae2298ed92a0 to your computer and use it in GitHub Desktop.
Save boyboi86/2fbe269f963b4bb0635fae2298ed92a0 to your computer and use it in GitHub Desktop.
Controlled Price Generator (Based on expected volatility & mean/ DO NOT use it for tail risk test or asset that are highly volatility)
from numpy import around, random, append;
#Generates within expected range/ boundaries
#Good for simple backtest to understand strategy performance within volatility level
#This is very simplified version so don't expect any entropy or stuff
class Price_Gen:
def __init__(self, periodInterval0 = 100, dev0=0.7, mean0=7):
self.priceArr0 = []
for x in range(0, periodInterval0):
def volCtrl0(dev0, mean0):
oldPrice0 = mean0*dev0
upperPrice0 = oldPrice0
lowerPrice0 = -1.0 * oldPrice0
newPrice0 = random.uniform(lowerPrice0+ mean0, upperPrice0+ mean0)
oldPrice0 = newPrice0
return around(newPrice0, 3)
#function for dev
self.priceArr0.append(volCtrl0(dev0, mean0))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment