Hello all, just joined a couple days ago and its my first time doing any form of coding, have an algo almost done, but have run into a bit of an issue.
If I have a stock, AAA, and after doing some testing, have determined that it follows a normal distribution very highly. What I want to do is to take that stock, and given its average and standard deviation from the last 252 days and its current price, return to me a probability.
IE, if the mean is 10, and the standard deviation is 2, then if i plug in a 12, it would return 69.1%. Here is what I have so far:
def initialize(context):
context.stocks = symbols('AAA')
schedule_function(rebalance,
date_rule = date_rules.every_day(),
time_rule = time_rules.market_open())
def rebalance(context, data):
MA = data[symbol('AAA')].mavg(252)
SP = data[symbol('AAA')].price
SD = data[symbol('AAA')].stddev(252)
I would then want to use my average (MA), current price (SP), and std.dev (SD). to give me the probability(P) of that current price occuring on a normal distribution of mean MA and Stddev SD, which i would then turn into an order like so.
if (SP >( MA + .5*SD)):
order_target_percent('AAA', -P)
order_target_percent('Hedge stock',1- P)
context.short=True
if (SP >(MA - .5*SD)):
order_target_percent('AAA', P)
order_target_percent('Hedge stock', P-1)
context.short=False