Exemple #1
0
                color='#547980')

plt.text(pd.to_datetime('2017-12-20'),
         (portfolio['total asset'] +
          np.std(portfolio['total asset'])).loc['2017-12-20'],
         'What if we use MACD here?')
plt.axvline('2017/11/15', linestyle=':', label='Exit', c='#ff847c')
plt.legend()
plt.title('Portfolio Performance')
plt.ylabel('Asset Value')
plt.xlabel('Date')
plt.show()

import oil_money_trading_backtest as om

signals = om.signal_generation(dataset, 'brent', 'nok', om.oil_money)
p = om.portfolio(signals, 'nok')
om.plot(signals, 'nok')
om.profit(p, 'nok')

dic = {}
for holdingt in range(5, 20):
    for stopp in np.arange(0.3, 1.1, 0.05):
        signals=om.signal_generation(dataset,'brent','nok',om.oil_money, \
                                     holding_threshold=holdingt, \
                                     stop=stopp)

        p = om.portfolio(signals, 'nok')
        dic[holdingt, stopp] = p['asset'].iloc[-1] / p['asset'].iloc[0] - 1

profile = pd.DataFrame({
#best to follow up with a momentum strategy
#maybe this is not a statistical arbitrage after all
#the model is a trend following entry indicator


# In[17]:
#now lets construct a trend following strategy based on the previous strategy
#call it oil money version 2 or whatever
#here i would only import the strategy script as this is a script for analytics and visualization
#the official trading strategy script is in the following link
# https://github.com/je-suis-tm/quant-trading/blob/master/Oil%20Money%20project/Oil%20Money%20Trading%20backtest.py
import oil_money_trading_backtest as om

#generate signals,monitor portfolio performance
#plot positions and total asset
signals=om.signal_generation(dataset,'brent','nok',om.oil_money)
p=om.portfolio(signals,'nok')
om.plot(signals,'nok')
om.profit(p,'nok')

#but thats not enough, we are not happy with the return
#come on, 2 percent return?
#i may as well as deposit the money into the current account 
#and get 0.75% risk free interest rate
#therefore, we gotta try different holding period and stop loss/profit point
#the double loop is very slow, i almost wanna do it in julia
#plz go get a coffee or even lunch and dont wait for it
dic={}
for holdingt in range(5,20):
    for stopp in np.arange(0.3,1.1,0.05):
        signals=om.signal_generation(dataset,'brent','nok',om.oil_money \
Exemple #3
0
#shrink data size for better viz
dataset = df['2016':]
dataset.reset_index(inplace=True)

# In[14]:

#import the strategy script as this is a script for analytics and visualization
#the official trading strategy script is in the following link
# https://github.com/je-suis-tm/quant-trading/blob/master/Oil%20Money%20project/Oil%20Money%20Trading%20backtest.py
import oil_money_trading_backtest as om

#generate signals,monitor portfolio performance
#plot positions and total asset
signals = om.signal_generation(dataset,
                               'vasconia',
                               'cop',
                               om.oil_money,
                               stop=0.001)
p = om.portfolio(signals, 'cop')
om.plot(signals, 'cop')
om.profit(p, 'cop')

# In[15]:

#try different holding period and stop loss/profit point
dic = {}
for holdingt in range(5, 20):
    for stopp in np.arange(0.001, 0.005, 0.0005):
        signals = om.signal_generation(dataset,
                                       'vasconia',
                                       'cop',