1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| def plot_strategy_comparison( principal = 1e5, tol_hi = 0.3, tol_lo = 0.1, position_hi = 1, position_lo = 0.1, data = BABA, ):
position, num_stocks, gain = strategy_modeling( principal, 'Early_Profit_Taker', tol_hi, tol_lo, position_hi, position_lo, data, ) position_, num_stocks_, gain_ = strategy_modeling( principal, 'Early_Loss_Taker', tol_hi, tol_lo, position_hi, position_lo, data, )
fig,ax = plt.subplots(3, 1, sharex=True, figsize=(14,12), gridspec_kw={'height_ratios': [3, 2, 2]}) ax[0].plot(data.index, data["Adj Close"]) ax[0].set_ylabel("Price") ax[1].plot(data.index, position) ax[1].plot(data.index, position_) ax[1].set_ylim(0, 1) ax[1].legend(["Early_Profit_Taker", "Early_Loss_Taker"]) ax[1].set_ylabel("Position") ax[2].plot(data.index, gain) ax[2].plot(data.index, gain_) ax[2].legend(["Early_Profit_Taker", "Early_Loss_Taker"]) ax[2].set_ylabel("Profits")
plt.show()
|