Back

Percentage plot

Hello Everyone. 

I'm simply trying to plot the percentage change of an asset over a given period. I'm doing this so I can workout the percentage change over a given period of time of different assets within the same plot. 

I tried using the SetDataNormalization as TotalReturn but unfortunately seems like total return does something irrelevent 

My workaround was to use the close price of the frst day, but that would be quite tedious if I do this for multiple assetts. 

Thanks! 

 

Update Backtest








0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Hello Hamad,

There are a few indicators that can be used to track the percentage change of an asset during a certain period of time. For example, WilliamsPercentR (WILR). I’ve also attached a backtest to shown how to plot the indicator WILR for different assets. To see the plot, check the corresponding option as shown below. Please refer to this documentation for more information about indicators and indicator-plotting.

 

Best,

Yuxin Guan

87488_1592539287.jpg87488_1592539296.jpg

0


def Initialize(self):

self.symbols = ['SPY', 'AAPL', ]
for symbol in self.symbols:
self.AddEquity(symbol, Resolution.Minute)

self.lastClose = {}

self.Schedule.On(self.DateRules.EveryDay('SPY'), # Change this to frequency of returns you want to plot
self.TimeRules.BeforeMarketClose(0),
self.PlotReturns)

def PlotReturns(self):
for symbol in self.symbols:
close = self.Securities[symbol].Close

# Track last closing prices
if symbol not in self.lastClose:
self.lastClose[symbol] = close
continue

# Plot returns
returns = (close / self.lastClose[symbol])-1
self.Plot('Returns', f'{symbol}', returns)

# Update last close
self.lastClose[symbol] = close









 

 

 

 

0

Sorry the backtest is attached here.

0


Update Backtest





0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Loading...

This discussion is closed