- ago
It seems that the Sharpe ratio is being calculated based on the net capital and not the Sharpe of each trade. That's a philosophical thing I guess.

The weirdness that follows relates to that fact. With the following code I was using for precision issues:

CODE:
using WealthLab.Indicators; using WealthLab.Backtest; using WealthLab.Core; using System; using System.Linq; using System.Drawing; using System.Collections.Generic; namespace WealthScript11 {    public class PrecisionTest : UserStrategyBase    {       //declare private variables below       double profit_target, stop_loss;       public PrecisionTest() : base()       {          AddParameter("Profit Target", ParameterTypes.Double, 2, 1, 3, 1.0);          AddParameter("Stop Loss", ParameterTypes.Double, 2, 1, 3, 0.5);       }       //create indicators and other objects here, this is executed prior to the main trading loop       public override void Initialize(BarHistory bars)       {          profit_target = (double)Parameters[0].Value;          stop_loss = (double)Parameters[1].Value;          StartIndex = (int) 1;       }       //color the background based on the level of profit/loss       public void WinLossBackground(BarHistory bars, int idx)       {          int profit_level = 0;          System.Drawing.Color color;          // use code_s to find the worst trade for overlapping positions          double profit = 0.0, code_s = 0.0;          // First determine the worst profit level at each bar based on the positions          List<Position> positions = GetPositions();                    foreach (Position p in positions)          {             // foreach (Position p in OpenPositions) won't work because it skips the ExitBar             if (!(p.IsOpen || idx == p.ExitBar))                continue;             //can't use p.Profit because the profit isn't calculated yet so it just gives open cost             profit = p.ProfitPctAsOf(idx);             // Profit/Loss in percent             if ((profit > 5))             {                profit_level = (int)-1;             }             else if ((profit > 0.5))             {                profit_level = (int)-2;             }             else if ((profit > -0.5))             {                profit_level = (int)-3;             }             else if ((profit > -5))             {                profit_level = (int)-4;             }             else                // profit <= -5.0                profit_level = (int)-5;             double old_code = 0.0;             // keep most pessimistic in overlapping trades             old_code = (double)code_s;             if ((profit_level < old_code))             {                code_s = profit_level;             }          } // foreach position          // Now set the background color for the bar          int color_code = 0;          color_code = (int)Math.Floor(code_s);          switch (color_code)          {             case -1:                color = Color.LimeGreen;                break;             case -2:                color = Color.LightGreen;                break;             case -3:                color = Color.LightYellow;                break;             case -4:                color = Color.MistyRose;                break;             case -5:                color = Color.LightPink;                break;             default:                color = Color.White;                break;          } // switch   color_code          SetBackgroundColor(bars, idx, color);       } // WinLossBackground       public override void Execute(BarHistory bars, int idx)       {          double limit_price;          //go through each position and put close orders          foreach (Position p in OpenPositions)          { //            ClosePosition(p, OrderType.Limit, p.EntryPrice * (1 + profit_target / 100.0), "Limit"); //            ClosePosition(p, OrderType.Stop, p.EntryPrice * (1 - stop_loss / 100.0), "Stop Loss");             ClosePosition(p, OrderType.Limit, Math.Round(p.EntryPrice * (1 + profit_target / 100.0), 2), "Limit");             ClosePosition(p, OrderType.Stop, Math.Round(p.EntryPrice * (1 - stop_loss / 100.0), 2), "Stop Loss");          } // OpenPositions          // place buy orders          limit_price = 48.08;          limit_price = Math.Round(limit_price, 2);          PlaceTrade(bars, TransactionType.Buy, OrderType.Limit, limit_price, "Rounded");          // color the background          WinLossBackground(bars, idx);       } // Execute    } // class Strategy } // namespace


Run it with 5,000 fixed position size. PDD stock daily for one year.

When you change the starting capital you get different values, although I'm not sure I agree that you should since the risk is per trade amount and not portfolio amount. The values are decreasing and eventually become negative as you increase the capital despite the fact that the strategy's positive return stays positive. This isn't possible so there seems to be a bug.

QUOTE:

Starting Capital Sharpe
10,000 0.60
100,000 0.13
1,000,000 -4.53
0
421
4 Replies

Reply

Bookmark

Sort
- ago
#1
Yes, it has always been based on the equity curve's starting value and so it depends on the starting date. Note that the WL7 number doesn't match WL6 because a true to life risk-free rate adjustment is taking place under the hood.

We will document the performance visualizers in the Help of Build 7 like this:
QUOTE:
Sharpe Ratio

The Sharpe Ratio is a way to measure the risk-adjusted return of an investment. Its ratio measures how much of an investment's return can be attributed to chance. A Sharpe Ratio value of above 1.0 is considered good, while a value above 2.0 is typically considered outstanding.

The Sharpe Ratio calculation assumes a true to life rate of return based on the real historical values of 1-Year U.S. Treasury yield.

The Sharpe Ratio is calculated by obtaining the average of monthly percentage equity returns generated by the system, as well as the standard deviation of those returns. The risk-free rate of return is subtracted from the average monthly return and then annualized by multiplying by 12. This result is divided by the standard deviation of the returns multiplied by Sqrt(12).
0
- ago
#2
Thank you for explaining.

That's not an interesting measure to me. If I wanted a normal unadjusted Sharpe based on the trades only, am I able to calculate my own performance measures through WL7 or do I need to I need Visual Studio or special permission?

The reason that's it interesting to me is because in order to not have any NSF trades you need huge capital and fixed sizes. You lose the information with an adjusted value.

Is there a good basic example or tutorial for how to create custom performance measures?

I miss the risk of ruin calcs. Will those be available again?

Thanks
0
- ago
#3
QUOTE:
I miss the risk of ruin calcs. Will those be available again?

They are already available in Extended Scorecard, part of the extension called "PowerPack":
https://www.wealth-lab.com/extension/detail/PowerPack

QUOTE:
Is there a good basic example or tutorial for how to create custom performance measures?

Sure. Let's not continue this discussion here in the Sharpe topic though
https://www.wealth-lab.com/Support/ExtensionApi/ScoreCard
0
- ago
#4
Ok great to both. I may write my first dll 😀

Lots to do.

Thanks.
0

Reply

Bookmark

Sort