Untitled

Anonymous
Plain Text
11/04/2025 1:25 PM
2.7 KB
10
Indexable
Never
pred = model.predict_proba(Test_X)
Test['pred_val'] = pred[:,1]
pred = [p[1] > 0.61  for p in pred]
Test['pred'] = pred

Sell = Test.loc[(Test['pred']==True)&(Test['YLots']>2000000)&(Test['SellPrice'].between(30,200))]

Sell['Lots'] = np.floor(200/Sell['LClose'])
Sell['NetProfit'] = (Sell['Profit'] - Sell['SellPrice'] * 0.002) * Sell['Lots'] * 1000
Sell['AMT'] = (Sell['SellPrice']* Sell['Lots']) * 1000
print((Sell['NetProfit']>0).sum()/(Sell['NetProfit']!=0).sum(),Sell.__len__()/Test.Date.unique().__len__(),Sell['NetProfit'].sum()/Test.Date.unique().__len__(),Sell['AMT'].sum()/Test.Date.unique().__len__(),
      Sell['NetProfit'].sum()/Sell['AMT'].sum(),Sell['ProfitPct'].mean())



SellNetProfit = Sell.groupby('Date')[['NetProfit']].sum()
SellNetProfit = Sell.groupby('Date')[['NetProfit']].sum()
SellNetProfit["Cummax"] = SellNetProfit["NetProfit"].cumsum().cummax()
from matplotlib.pyplot import MultipleLocator
import matplotlib.pyplot as plt

x_major_locator = MultipleLocator(30)
fig, axs = plt.subplots(3, figsize=(18,9))

cummax_high_index = SellNetProfit.reset_index()[["Date", "Cummax"]].groupby("Cummax").first()["Date"].tolist()
dd = (SellNetProfit["NetProfit"].cumsum() - SellNetProfit["NetProfit"].cumsum().cummax())
dd_pct = (SellNetProfit["NetProfit"].cumsum() - SellNetProfit["NetProfit"].cumsum().cummax()) #/ (SellNetProfit["NetProfit"].cumsum() + 2000000)
# dd_pct = (table["Payoff"].cumsum() - table["Payoff"].cumsum().cummax()) / (table["Payoff"].cumsum() + initial_capital)
dd_max = dd_pct.cummin()

axs[0,].plot(SellNetProfit.index, SellNetProfit["NetProfit"].cumsum(), color="b")
axs[0,].scatter(cummax_high_index, SellNetProfit["NetProfit"].cumsum()[cummax_high_index], color="#00ff2f", s=14)
axs[0,].legend(fontsize=12, loc="upper left")
axs[0,].set_ylabel("Accumulated P/Ls [$]", fontsize=13)
axs[0,].xaxis.set_major_locator(x_major_locator)

axs[1,].fill_between(dd_pct.index, dd_pct, 0, color="r", alpha=0.6, label="Drawdown")
axs[1,].plot(dd_max.index, dd_max, color="gray", label="Maximum Drawdown")
axs[1,].scatter(dd_max.index[-1], dd_max.iloc[-1], color="r") 
axs[1,].text(dd_max.index[-1], dd_max.iloc[-1]*0.98, "{} ".format(round(dd_max.iloc[-1],2)), fontsize=14)
axs[1,].set_ylabel("Drawdown", fontsize=13)
axs[1,].legend(fontsize=12, loc="lower left")
axs[1,].xaxis.set_major_locator(x_major_locator)

benchmark = TXF.loc[(TXF['Date'].isin(SellNetProfit.index.to_numpy()))][['Date','Close_FT']]
benchmark.set_index('Date',inplace=True)
benchmark.sort_index(inplace=True)
axs[2,].plot(benchmark.index, benchmark['Close_FT'], color="gray", label="TXF")
axs[2,].legend(fontsize=12, loc="upper left")
axs[2,].xaxis.set_major_locator(x_major_locator)
Editor is loading...
Leave a Comment