Algo 2K |
Home
(current)
|
Strategy Evaluation
(current)
|
Financial markets
(current)
Search
#Cross moving Avrages Implementation #Sets investment investment= float(10000.0) #sets Strategy aapl = getData('AAPL', [2016,10,1],[2017,10,1]) # Initialize the short and long Avarage lengths short_window = 30 long_window = 100 # Creates Signals data with the Apple stock dates # Initilizes all and signals column to zero signals = pd.DataFrame(index=aapl.index) signals['signal'] = 0.0 # Create moving average over the short window signals['shortMovingAvarage'] = aapl['Close'].rolling(window=short_window, min_periods=1, center=False).mean() signals['longMovingAvarage'] = aapl['Close'].rolling(window=long_window, min_periods=1, center=False).mean() # Calculate trading signals signals['signal'][short_window:] = np.where(signals['shortMovingAvarage'][short_window:] > signals['longMovingAvarage'][short_window:], 1.0, 0.0) # Generate Positions signals['positions'] = signals['signal'].diff()
Upload
GOOGL 1,214.27 USD +102.72 (9.24%) ↑
MSFT 158.83 USD +19.77 (14.22%) ↑
AAPL 277.97 USD +29.74 (11.98%) ↑
ACN 166.51 USD +13.98 (9.17%) ↑
FDS 253.07 USD +19.65 (8.42%) ↑
PAT 0.90 CAD +0.060 (7.14%) ↑
WNDW 1.53 USD −0.28 (15.47%) ↓
RDSB 1,084.02 GBX −15.98 (1.45%) ↓
HSBA 480.95 GBX -36.35 (8.18%) ↓
DBK 5.10 EUR -0.23 (4.80%) ↓
MS 5.10 37.50 USD -6.19 (19.77%) ↓