WL6 and WL8 both used to produce the same backtest results, however, WL8 seems to be doing something wrong with the last position all of a sudden.
I ran the strategies on July 24 and the strategy is closing the last position at the next opening bar, July 25.
On WL8, the last position shows July 25 as the "Exit Date" but "Exit Price", "Profit" and "Profit %" are all NaN.
That causes the Net Profit to lose the profit of the last open position.
Any idea what's going wrong?
WL6
Net Profit: $92,635,417.06
WL8
Net Profit: $70,949,952,37
$70,949,952,37 + $21,685,464.69 = $92,635,417.06
I ran the strategies on July 24 and the strategy is closing the last position at the next opening bar, July 25.
On WL8, the last position shows July 25 as the "Exit Date" but "Exit Price", "Profit" and "Profit %" are all NaN.
That causes the Net Profit to lose the profit of the last open position.
Any idea what's going wrong?
WL6
Net Profit: $92,635,417.06
CODE:
Position Symbol Quantity Entry Date Entry Price Exit Date Exit Price Profit % Profit $ Bars Held Profit per Bar Long QQQ 376,909 2023/11/02 361.54 2024/04/16 431.06 19.23 $26,202,713.68 113 $231,882.42 Long QQQ 508,929 2024/04/23 420.77 Open Open 10.13 $21,685,464.69 64 $338,835.39
WL8
Net Profit: $70,949,952,37
CODE:
Position Symbol Quantity Entry Date Entry Price Exit Date Exit Price Profit Profit % Bars Held Long QQQ 376909 2023/11/02 361.54 2024/04/16 431.06 26202713.68 19.22885435 113 Long QQQ 508929 2024/04/23 420.77 2024/07/25 NaN NaN NaN 64
$70,949,952,37 + $21,685,464.69 = $92,635,417.06
Rename
WL8 will not load the Daily bar until the end of the session like WL6 did.
If you want, you can see a "partial Daily+ bar" in a Streaming chart, but a backtest will not get the data until the end of the Daily session.
If you want, you can see a "partial Daily+ bar" in a Streaming chart, but a backtest will not get the data until the end of the Daily session.
With another symbol where it has an open position, I get like this.
With another symbol where it has an open position but it is an external symbol, I get like this.
If I select a symbol to run backtest with that symbol instead of hitting the "Run Backtest" button, I get "Historical Data Pre-Emptively Ended" message as the "Exit Signal".
Do these tell you something if I'm doing something wrong?
CODE:
Position Symbol Quantity Entry Date Entry Price Exit Date Exit Price Profit Profit % Bars Held Long DIA 42169 2024/07/23 404.29 Open 0 NaN NaN 17
With another symbol where it has an open position but it is an external symbol, I get like this.
CODE:
Position Symbol Quantity Entry Date Entry Price Exit Date Exit Price Profit Profit % Bars Held Long UDOW 84931 2024/07/23 85.99 2024/07/24 82.35 -309148.84 -4.2330503546924065 2
If I select a symbol to run backtest with that symbol instead of hitting the "Run Backtest" button, I get "Historical Data Pre-Emptively Ended" message as the "Exit Signal".
Do these tell you something if I'm doing something wrong?
QUOTE:
a backtest will not get the data until the end of the Daily session.
I think I don't get it very well.
I run my strategy now but I still get the same results.
It's past the end of the Daily session, isn't it?
The U.S. Market has not even opened today - 25 July 2024.
Re: "Historical Data Pre-Emptively Ended"
https://www.wealth-lab.com/Discussion/Historical-Data-Pre-Emptively-Ended-7533#post1
Re: "Historical Data Pre-Emptively Ended"
https://www.wealth-lab.com/Discussion/Historical-Data-Pre-Emptively-Ended-7533#post1
QUOTE:
The U.S. Market has not even opened today - 25 July 2024.
So if the strategy has an open position, the backtest won't count the open position in the net profit?
In the backtest equity yes, but you're looking at the Positions view and it hasn't exited yet.
In a Strategy, you can use the "AsOf" functions to get the Profit or ProfitPecent.
In a Strategy, you can use the "AsOf" functions to get the Profit or ProfitPecent.
When I run a strategy on both WL6 and WL8 with the data range set to ~2024/07/22 in which the strategy places an order to be executed at the market open of 2024/07/23, WL6's backtest has positions only in the range specified whereas WL8's backtest includes the positions to be opened from the range specified.
On WL8, I'm a bit surprised by the fact that the net profit is calculated based on the open position's today's price.
Is it expected on WL8?
WL6
WL8
On WL8, I'm a bit surprised by the fact that the net profit is calculated based on the open position's today's price.
Is it expected on WL8?
WL6
CODE:
Long UDOW 85,188 2024/06/03 77.1500 2024/07/22 85.8500 11.28 $741,135.60 34
WL8
CODE:
Long UDOW 85188 2024/06/03 77.15 2024/07/22 85.85 741135.599999999 11.276733635774452 33 Long UDOW 84931 2024/07/23 85.99 Open 0 -309148.84 -4.2330503546924065 15
I'm not sure what you're showing me now, but how did you determine it's using "today's price", since it actually uses the last Closing price (for the equity calculation).
Whether I set the data range to ~2024/07/22 or ~2024/07/23, this position's profit (-309148.84) is calculated based on the closing price of today (2024/07/24).
CODE:
Long UDOW 84931 2024/07/23 85.99 Open 0 -309148.84 -4.2330503546924065 15
When I set the data range to ~2024/07/22, WL8 calculates the net profit including the position to be opened on 2024/07/23 which is beyond the data range specified.
Is this expected on WL8?
Is this expected on WL8?
CODE:
Long UDOW 84931 2024/07/23 85.99 Open 0 -309148.84 -4.2330503546924065 15
You're showing values without telling me the source of them.
Show me the code that produced it, and I can probably show you the error.
Show me the code that produced it, and I can probably show you the error.
I think I have narrowed this down to a problem caused by the ExtendedBars.
Single Symbol: SPY
Data Range: Date Range
Problem (1): Setting non-zero value to ExtendedBars causes the backtest results to change.
Problem (2): Setting non-zero value to ExtendedBars causes the trade signal not to be generated.
[ bars.ExtendedBars = 15 ]
Date range from 2024/01/01 to 2024/07/22:
Long SPY 9 2024/07/19 552.42 2024/07/25 NaN NaN NaN 4 0.515911806234391 -0.8164078056551158
Date range from 2024/01/01 to 2024/07/23:
Long SPY 9 2024/07/19 552.42 2024/07/25 NaN NaN NaN 4 0.7811085768075114 -0.8164078056551158
Date range from 2024/01/01 to 2024/07/24:
Long SPY 9 2024/07/19 552.42 2024/07/25 NaN NaN NaN 4 0.7811085768075114 -2.1957930560081094
[ bars.ExtendedBars = 0 ]
Date range from 2024/01/01 to 2024/07/22:
Long SPY 9 2024/07/19 552.42 Open 0 20.070000000000164 0.40367836066761126 2 0.515911806234391 -0.8164078056551158
Date range from 2024/01/01 to 2024/07/23:
Long SPY 9 2024/07/19 552.42 Open 0 12.240000000000123 0.2461894935013239 3 0.7811085768075114 -0.8164078056551158
Date range from 2024/01/01 to 2024/07/24:
Long SPY 9 2024/07/19 552.42 Open 0 -100.70999999999947 -2.0256326707939505 4 0.7811085768075114 -2.1957930560081094
(((Trade Signal)))
Single Symbol: SPY
Data Range: Date Range
Problem (1): Setting non-zero value to ExtendedBars causes the backtest results to change.
Problem (2): Setting non-zero value to ExtendedBars causes the trade signal not to be generated.
[ bars.ExtendedBars = 15 ]
Date range from 2024/01/01 to 2024/07/22:
Long SPY 9 2024/07/19 552.42 2024/07/25 NaN NaN NaN 4 0.515911806234391 -0.8164078056551158
Date range from 2024/01/01 to 2024/07/23:
Long SPY 9 2024/07/19 552.42 2024/07/25 NaN NaN NaN 4 0.7811085768075114 -0.8164078056551158
Date range from 2024/01/01 to 2024/07/24:
Long SPY 9 2024/07/19 552.42 2024/07/25 NaN NaN NaN 4 0.7811085768075114 -2.1957930560081094
[ bars.ExtendedBars = 0 ]
Date range from 2024/01/01 to 2024/07/22:
Long SPY 9 2024/07/19 552.42 Open 0 20.070000000000164 0.40367836066761126 2 0.515911806234391 -0.8164078056551158
Date range from 2024/01/01 to 2024/07/23:
Long SPY 9 2024/07/19 552.42 Open 0 12.240000000000123 0.2461894935013239 3 0.7811085768075114 -0.8164078056551158
Date range from 2024/01/01 to 2024/07/24:
Long SPY 9 2024/07/19 552.42 Open 0 -100.70999999999947 -2.0256326707939505 4 0.7811085768075114 -2.1957930560081094
(((Trade Signal)))
CODE:
public override void Initialize(BarHistory bars) { // Need a little space on the right of the last bar to draw about the position. // This used to be PadBars(15) on WL6. bars.ExtendedBars = 15; } int GetDate(BarHistory bars, int idx) { return bars.DateTimes[idx].Year * 10000 + bars.DateTimes[idx].Month * 100 + bars.DateTimes[idx].Day; } public override void Execute(BarHistory bars, int idx) { int dt = GetDate(bars, idx); if (dt == 20240705 || dt == 20240711 || dt == 20240718) PlaceTrade(bars, TransactionType.Buy, OrderType.Market); if (dt == 20240708 || dt == 20240715 || dt == 20240724) PlaceTrade(bars, TransactionType.Sell, OrderType.Market); }
Yes, the ExtendedBars design comes with those limitations. NaN values are used so that the new bars aren't plotted, but that also prevents pricing for exiting positions or creating new ones (at Market). So that's where the results would differ. You can assign the prices for those bars however you like though.
Any alternative to ExtendedBars that is just to insert space at the right of the chart?
I used PadBars and it’s been serving very well. I don’t need extended bar data but just a space on the chart.
I used PadBars and it’s been serving very well. I don’t need extended bar data but just a space on the chart.
I'd just avoid using that in a strategy, but for simple charts you can drag the right edge of the bars to the left to create space for manual drawing objects if that's what you're after. Behind the scenes, it still add those pesky ExtendedBars though.
Could you consider adding either a UI option to add a space to the chart or WL6's PadBars which is to add the space to the chart, not the bar data?
Let's see if Glitch would even entertain a feature request for that. My feeling is that if it were even possible within the charting framework, then that's the way space would have been added before.
Glitch?
Glitch?
I’m sorry it’s out of scope. If it worked like it did in WL6 then we’d be back to these complaints 🤷🏼♂️
https://wl6.wealth-lab.com/Forum/Posts/How-to-plot-predicted-prices-into-the-area-created-by-PadBars-30429
https://wl6.wealth-lab.com/Forum/Posts/How-to-plot-predicted-prices-into-the-area-created-by-PadBars-30429
Then my request would be rather simple.
Could you consider adding a chart preference next to "Pane Margins Top/Bottom"?
That would be something like "Chart Right Margin".
If it can be set from ChartDisplaySettings(), that would be even better.
Could you consider adding a chart preference next to "Pane Margins Top/Bottom"?
That would be something like "Chart Right Margin".
If it can be set from ChartDisplaySettings(), that would be even better.
I’m sorry Kazuna but it’s not so simple to add to the charting components.
I hoped it was just a matter of putting a space on the right of the chart.
But I can kinda imagine why it is not that simple.
But I can kinda imagine why it is not that simple.
Your Response
Post
Edit Post
Login is required