Sharpe Ratio on Portfolio Trader

Questions about MultiCharts and user contributed studies.
RadioactiveToy
Posts: 1
Joined: 03 Jul 2020

Sharpe Ratio on Portfolio Trader

Postby RadioactiveToy » 08 Nov 2022

Hi,

I am trying to test/build a rotational portfolio of stocks using Portfolio Trader.

One of the parameter i'd like to use to choose/rank the stocks is the Sharpe Ratio, the problem is that if i try to print the Sharpe Ratio of several underlyings using PT the function returns all zeros.

The same function applied to a single chart returns instead the correct value.


This is the test code i use on PT:

Code: Select all

if LastBarOnChart_s then begin value1 = SharpeRatio(0, 0, LastBarOnChart_s, InitialCapital); print (symbol," ", value1); end;

The SharpeRatio function is the pre-built one (i guess) :

Code: Select all

Input: Period(NumericSimple), {0=monthly, 1=daily} IntRate(NumericSimple), {interest rate} CalculateRatio(TrueFalseSimple), {final calculation} InitCapital(NumericSimple); {initial capital} array: periods_returns[](0), periods_return_percent[](0); var: intrabarpersist last_idx(0); var: new_periods(0); new_periods = 0; var: recalcpersist int_rate_per_period(12); once begin switch (Period) begin case 0 : int_rate_per_period = IntRate / 12 / 100; case 1 : int_rate_per_period = IntRate / 365 / 100; end; end; var: intrabarpersist start(False); once (0 <> i_CurrentContracts or 0 <> i_OpenEquity) start = true; if not start then #return; switch (Period) begin case 0 : begin new_periods = MonthsCount; end; case 1 : begin new_periods = DaysCount; end; end; var: intrabarpersist prev_equity(0); var: Equity(0); Equity = i_OpenEquity; if 0 < new_periods then begin array_setmaxindex(periods_returns, last_idx + new_periods); periods_returns[last_idx + 1] = Equity[1] - prev_equity; for value1 = 2 to new_periods - 1 begin periods_returns[last_idx + value1] = 0; end; last_idx += new_periods; prev_equity = Equity[1]; end; var: intrabarpersist calculated(False); if CalculateRatio and not calculated then begin once calculated = True; if 0 = new_periods and 0 <> i_MarketPosition then begin last_idx += 1; array_setmaxindex(periods_returns, last_idx); periods_returns[last_idx] = Equity - prev_equity; end; RemoveLastZeros(periods_returns, last_idx); array_setmaxindex(periods_return_percent, last_idx); CummRatio(periods_returns, periods_return_percent, last_idx, InitCapital); var: AvgReturnPercent(0), ReturnStdDev(0); AvgReturnPercent = AverageArray( periods_return_percent, last_idx ); ReturnStdDev= StandardDevArray( periods_return_percent, last_idx, 0 ); if 0 <> ReturnStdDev then SharpeRatio = (AvgReturnPercent- int_rate_per_period) / ReturnStdDev; end;

Any suggestion on how to get this working with PT ?

Thanks.

User avatar
rrams
Posts: 128
Joined: 10 Feb 2011
Location: USA
Has thanked: 7 times
Been thanked: 70 times
Contact:

Re: Sharpe Ratio on Portfolio Trader

Postby rrams » 08 Nov 2022

RadioactiveToy, can you specify what you mean by underlyings and how your Portfolio Trader is setup?
It seems to work normally for me.
sharp.png
(53.86 KiB) Not downloaded yet

User avatar
Vlada MultiCharts
Posts: 293
Joined: 22 Apr 2020
Has thanked: 8 times
Been thanked: 76 times

Re: Sharpe Ratio on Portfolio Trader

Postby Vlada MultiCharts » 01 Dec 2022

Hello RadioactiveToy,

Please reproduce the situation in simplified environment and send us the following files to our support email so that we would be able to investigate it:

1. The .pws where the behaviour is reproduced.
2. Export of used symbols (with data) from QuoteManager in .qmd archive.
3. The exported scripts in .pla format with all dependent functions that are used on the workspace.
4. The screenshots demonstrating the situation.
5. Step-by-step instruction how to reproduce the situation.

Please also specify the following:

1. Whether it happens in AT, backtesting or forward testing.
2. The outcome of the calculations you expect.
3. MultiCHarts version.


Return to “MultiCharts”