Introduction to mean reversion strategy Flashcards
setting if true a new column to 1
df.loc[df.long_entry,’positions_long’]= 1
simple moving average
df[‘moving_average’] = df.prices.rolling(5).mean()
In Python, fillna function is available on dataframe to fill missing values. The syntax is:
df = df.fillna(method=’ffill’)
Where are variables sotored
context.security
When to close
time _rules.market_close(minutes=1)
Hold logic
schedule_function
entry function
def enter_position ( context , data ):
price
price =data.history( context.security, [“close”] , 90 , “1 m”)
Three important points
schedule strategy logic functions
stream and process data
place orders
last You require the last 120 minutes of the close price data of a security. Which of the following options will fetch data to meet your criterion?
- history(security, [‘close’], 120, ‘1m’)
% orders of capital
order_percent
What is Cointegration
Cointegration, combining of two different asset classes to increase stationarity, but with a spread between them.
Define perfect hedge ratio
To established the Hedge ratio using linear regression.